2023-11-07 09:04:22 +00:00
|
|
|
package funkin.audio.visualize;
|
2022-02-10 18:17:46 +00:00
|
|
|
|
2023-11-07 09:04:22 +00:00
|
|
|
import funkin.audio.visualize.dsp.FFT;
|
2021-10-06 22:46:14 +00:00
|
|
|
import flixel.FlxSprite;
|
2021-10-08 01:01:46 +00:00
|
|
|
import flixel.addons.plugin.taskManager.FlxTask;
|
|
|
|
import flixel.graphics.frames.FlxAtlasFrames;
|
2021-10-06 22:46:14 +00:00
|
|
|
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
|
2021-10-08 01:01:46 +00:00
|
|
|
import flixel.math.FlxMath;
|
2023-05-25 22:33:39 +00:00
|
|
|
import flixel.sound.FlxSound;
|
2023-11-07 09:04:22 +00:00
|
|
|
import funkin.util.MathUtil;
|
2024-02-23 09:00:31 +00:00
|
|
|
import funkVis.dsp.SpectralAnalyzer;
|
2021-10-08 01:01:46 +00:00
|
|
|
|
|
|
|
using Lambda;
|
2021-10-06 22:46:14 +00:00
|
|
|
|
|
|
|
class ABotVis extends FlxTypedSpriteGroup<FlxSprite>
|
|
|
|
{
|
2024-02-23 09:00:31 +00:00
|
|
|
// public var vis:VisShit;
|
|
|
|
var analyzer:SpectralAnalyzer;
|
2021-10-08 01:01:46 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
var volumes:Array<Float> = [];
|
2021-10-08 01:01:46 +00:00
|
|
|
|
2024-02-23 09:00:31 +00:00
|
|
|
public var snd:FlxSound;
|
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
public function new(snd:FlxSound)
|
|
|
|
{
|
|
|
|
super();
|
2021-10-08 01:01:46 +00:00
|
|
|
|
2024-02-23 09:00:31 +00:00
|
|
|
this.snd = snd;
|
|
|
|
|
|
|
|
// vis = new VisShit(snd);
|
2023-01-23 03:25:45 +00:00
|
|
|
// vis.snd = snd;
|
2021-10-08 01:01:46 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
var visFrms:FlxAtlasFrames = Paths.getSparrowAtlas('aBotViz');
|
2021-10-08 01:01:46 +00:00
|
|
|
|
2024-02-23 07:03:34 +00:00
|
|
|
// these are the differences in X position, from left to right
|
|
|
|
var positionX:Array<Float> = [0, 59, 56, 66, 54, 52, 51];
|
2024-02-23 07:18:50 +00:00
|
|
|
var positionY:Array<Float> = [0, -8, -3.5, -0.4, 0.5, 4.7, 7];
|
2024-02-23 07:03:34 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
for (lol in 1...8)
|
|
|
|
{
|
|
|
|
// pushes initial value
|
|
|
|
volumes.push(0.0);
|
2024-02-23 07:18:50 +00:00
|
|
|
var sum = function(num:Float, total:Float) return total += num;
|
|
|
|
var posX:Float = positionX.slice(0, lol).fold(sum, 0);
|
|
|
|
var posY:Float = positionY.slice(0, lol).fold(sum, 0);
|
2021-10-08 01:01:46 +00:00
|
|
|
|
2024-02-23 07:18:50 +00:00
|
|
|
var viz:FlxSprite = new FlxSprite(posX, posY);
|
2023-01-23 03:25:45 +00:00
|
|
|
viz.frames = visFrms;
|
|
|
|
add(viz);
|
2021-10-08 01:01:46 +00:00
|
|
|
|
2024-02-22 06:50:55 +00:00
|
|
|
var visStr = 'viz';
|
2023-01-23 03:25:45 +00:00
|
|
|
viz.animation.addByPrefix('VIZ', visStr + lol, 0);
|
|
|
|
viz.animation.play('VIZ', false, false, -1);
|
|
|
|
}
|
|
|
|
}
|
2021-10-08 01:01:46 +00:00
|
|
|
|
2024-02-23 09:00:31 +00:00
|
|
|
public function initAnalyzer()
|
|
|
|
{
|
|
|
|
@:privateAccess
|
|
|
|
analyzer = new SpectralAnalyzer(7, new AudioClip(cast snd._channel.__source), 0.005, 30);
|
|
|
|
}
|
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
override function update(elapsed:Float)
|
|
|
|
{
|
|
|
|
// updateViz();
|
2021-10-08 01:01:46 +00:00
|
|
|
|
2024-02-23 09:00:31 +00:00
|
|
|
// updateFFT(elapsed);
|
2021-10-08 01:01:46 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
super.update(elapsed);
|
|
|
|
}
|
2021-10-08 01:01:46 +00:00
|
|
|
|
2024-02-23 09:00:31 +00:00
|
|
|
static inline function min(x:Int, y:Int):Int
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
2024-02-23 09:00:31 +00:00
|
|
|
return x > y ? y : x;
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
2021-10-08 01:01:46 +00:00
|
|
|
|
2024-02-23 09:00:31 +00:00
|
|
|
override function draw()
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
2024-02-23 09:00:31 +00:00
|
|
|
if (analyzer == null)
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
2024-02-23 09:00:31 +00:00
|
|
|
super.draw();
|
|
|
|
return;
|
|
|
|
}
|
2021-10-08 01:01:46 +00:00
|
|
|
|
2024-02-23 09:00:31 +00:00
|
|
|
var levels = analyzer.getLevels(false);
|
2021-10-08 01:01:46 +00:00
|
|
|
|
2024-02-23 09:00:31 +00:00
|
|
|
for (i in 0...min(group.members.length, levels.length))
|
|
|
|
{
|
|
|
|
var animFrame:Int = Math.round(levels[i].value * 5);
|
2021-10-08 01:01:46 +00:00
|
|
|
|
2024-02-23 09:00:31 +00:00
|
|
|
animFrame = Math.floor(Math.min(5, animFrame));
|
|
|
|
animFrame = Math.floor(Math.max(0, animFrame));
|
2021-10-08 01:01:46 +00:00
|
|
|
|
2024-02-23 09:00:31 +00:00
|
|
|
animFrame = Std.int(Math.abs(animFrame - 5)); // shitty dumbass flip, cuz dave got da shit backwards lol!
|
2021-10-08 01:01:46 +00:00
|
|
|
|
2024-02-23 09:00:31 +00:00
|
|
|
group.members[i].animation.curAnim.curFrame = animFrame;
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
2024-02-23 09:00:31 +00:00
|
|
|
|
|
|
|
super.draw();
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
2024-02-23 09:00:31 +00:00
|
|
|
|
|
|
|
// function updateFFT(elapsed:Float)
|
|
|
|
// {
|
|
|
|
// if (vis.snd != null)
|
|
|
|
// {
|
|
|
|
// vis.checkAndSetBuffer();
|
|
|
|
// if (vis.setBuffer)
|
|
|
|
// {
|
|
|
|
// var remappedShit:Int = 0;
|
|
|
|
// if (vis.snd.playing) remappedShit = Std.int(FlxMath.remapToRange(vis.snd.time, 0, vis.snd.length, 0, vis.numSamples));
|
|
|
|
// else
|
|
|
|
// remappedShit = Std.int(FlxMath.remapToRange(Conductor.instance.songPosition, 0, vis.snd.length, 0, vis.numSamples));
|
|
|
|
// var fftSamples:Array<Float> = [];
|
|
|
|
// var swagBucks = remappedShit;
|
|
|
|
// for (i in remappedShit...remappedShit + (Std.int((44100 * (1 / 144)))))
|
|
|
|
// {
|
|
|
|
// var left = vis.audioData[swagBucks] / 32767;
|
|
|
|
// var right = vis.audioData[swagBucks + 1] / 32767;
|
|
|
|
// var balanced = (left + right) / 2;
|
|
|
|
// swagBucks += 2;
|
|
|
|
// fftSamples.push(balanced);
|
|
|
|
// }
|
|
|
|
// var freqShit = vis.funnyFFT(fftSamples);
|
|
|
|
// for (i in 0...group.members.length)
|
|
|
|
// {
|
|
|
|
// var getSliceShit = function(s:Int) {
|
|
|
|
// var powShit = FlxMath.remapToRange(s, 0, group.members.length, 0, MathUtil.logBase(10, freqShit[0].length));
|
|
|
|
// return Math.round(Math.pow(10, powShit));
|
|
|
|
// };
|
|
|
|
// // var powShit:Float = getSliceShit(i);
|
|
|
|
// var hzSliced:Int = getSliceShit(i);
|
|
|
|
// var sliceLength:Int = Std.int(freqShit[0].length / group.members.length);
|
|
|
|
// var volSlice = freqShit[0].slice(hzSliced, getSliceShit(i + 1));
|
|
|
|
// var avgVel:Float = 0;
|
|
|
|
// for (slice in volSlice)
|
|
|
|
// {
|
|
|
|
// avgVel += slice;
|
|
|
|
// }
|
|
|
|
// avgVel /= volSlice.length;
|
|
|
|
// avgVel *= 10000000;
|
|
|
|
// volumes[i] += avgVel - (elapsed * (volumes[i] * 50));
|
|
|
|
// var animFrame:Int = Std.int(volumes[i]);
|
|
|
|
// animFrame = Math.floor(Math.min(5, animFrame));
|
|
|
|
// animFrame = Math.floor(Math.max(0, animFrame));
|
|
|
|
// animFrame = Std.int(Math.abs(animFrame - 5)); // shitty dumbass flip, cuz dave got da shit backwards lol!
|
|
|
|
// group.members[i].animation.curAnim.curFrame = animFrame;
|
|
|
|
// if (FlxG.keys.justPressed.U)
|
|
|
|
// {
|
|
|
|
// trace(avgVel);
|
|
|
|
// trace(group.members[i].animation.curAnim.curFrame);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// // group.members[0].animation.curAnim.curFrame =
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// public function updateViz()
|
|
|
|
// {
|
|
|
|
// if (vis.snd != null)
|
|
|
|
// {
|
|
|
|
// var remappedShit:Int = 0;
|
|
|
|
// vis.checkAndSetBuffer();
|
|
|
|
// if (vis.setBuffer)
|
|
|
|
// {
|
|
|
|
// // var startingSample:Int = Std.int(FlxMath.remapToRange)
|
|
|
|
// if (vis.snd.playing) remappedShit = Std.int(FlxMath.remapToRange(vis.snd.time, 0, vis.snd.length, 0, vis.numSamples));
|
|
|
|
// for (i in 0...group.members.length)
|
|
|
|
// {
|
|
|
|
// var sampleApprox:Int = Std.int(FlxMath.remapToRange(i, 0, group.members.length, remappedShit, remappedShit + 500));
|
|
|
|
// var left = vis.audioData[sampleApprox] / 32767;
|
|
|
|
// var animFrame:Int = Std.int(FlxMath.remapToRange(left, -1, 1, 0, 6));
|
|
|
|
// group.members[i].animation.curAnim.curFrame = animFrame;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2021-10-06 22:46:14 +00:00
|
|
|
}
|