2022-03-08 03:13:53 -05:00
|
|
|
package funkin.audiovis;
|
2022-02-10 13:17:46 -05:00
|
|
|
|
2022-03-08 03:13:53 -05:00
|
|
|
import funkin.audiovis.dsp.FFT;
|
2021-10-06 18:46:14 -04:00
|
|
|
import flixel.FlxSprite;
|
2021-10-07 21:01:46 -04:00
|
|
|
import flixel.addons.plugin.taskManager.FlxTask;
|
|
|
|
import flixel.graphics.frames.FlxAtlasFrames;
|
2021-10-06 18:46:14 -04:00
|
|
|
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
|
2021-10-07 21:01:46 -04:00
|
|
|
import flixel.math.FlxMath;
|
2023-05-25 18:33:39 -04:00
|
|
|
import flixel.sound.FlxSound;
|
2022-03-08 03:13:53 -05:00
|
|
|
import funkin.ui.PreferencesMenu.CheckboxThingie;
|
2021-10-07 21:01:46 -04:00
|
|
|
|
|
|
|
using Lambda;
|
2021-10-06 18:46:14 -04:00
|
|
|
|
|
|
|
class ABotVis extends FlxTypedSpriteGroup<FlxSprite>
|
|
|
|
{
|
2023-01-22 22:25:45 -05:00
|
|
|
public var vis:VisShit;
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
var volumes:Array<Float> = [];
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
public function new(snd:FlxSound)
|
|
|
|
{
|
|
|
|
super();
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
vis = new VisShit(snd);
|
|
|
|
// vis.snd = snd;
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
var visFrms:FlxAtlasFrames = Paths.getSparrowAtlas('aBotViz');
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
for (lol in 1...8)
|
|
|
|
{
|
|
|
|
// pushes initial value
|
|
|
|
volumes.push(0.0);
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
var viz:FlxSprite = new FlxSprite(50 * lol, 0);
|
|
|
|
viz.frames = visFrms;
|
|
|
|
add(viz);
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
var visStr = 'VIZ';
|
|
|
|
if (lol == 5) visStr = 'viz'; // lol makes it lowercase, accomodates for art that I dont wanna rename!
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
viz.animation.addByPrefix('VIZ', visStr + lol, 0);
|
|
|
|
viz.animation.play('VIZ', false, false, -1);
|
|
|
|
}
|
|
|
|
}
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
override function update(elapsed:Float)
|
|
|
|
{
|
|
|
|
// updateViz();
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
updateFFT(elapsed);
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
super.update(elapsed);
|
|
|
|
}
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
function updateFFT(elapsed:Float)
|
|
|
|
{
|
|
|
|
if (vis.snd != null)
|
|
|
|
{
|
|
|
|
vis.checkAndSetBuffer();
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
if (vis.setBuffer)
|
|
|
|
{
|
|
|
|
var remappedShit:Int = 0;
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
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.songPosition, 0, vis.snd.length, 0, vis.numSamples));
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
var fftSamples:Array<Float> = [];
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
var swagBucks = remappedShit;
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
for (i in remappedShit...remappedShit + (Std.int((44100 * (1 / 144)))))
|
|
|
|
{
|
|
|
|
var left = vis.audioData[swagBucks] / 32767;
|
|
|
|
var right = vis.audioData[swagBucks + 1] / 32767;
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
var balanced = (left + right) / 2;
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
swagBucks += 2;
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
fftSamples.push(balanced);
|
|
|
|
}
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
var freqShit = vis.funnyFFT(fftSamples);
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
for (i in 0...group.members.length)
|
|
|
|
{
|
2023-05-25 18:33:39 -04:00
|
|
|
var getSliceShit = function(s:Int) {
|
2023-01-22 22:25:45 -05:00
|
|
|
var powShit = FlxMath.remapToRange(s, 0, group.members.length, 0, CoolUtil.coolBaseLog(10, freqShit[0].length));
|
|
|
|
return Math.round(Math.pow(10, powShit));
|
|
|
|
};
|
2021-10-08 20:44:32 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
// var powShit:Float = getSliceShit(i);
|
|
|
|
var hzSliced:Int = getSliceShit(i);
|
2021-10-08 20:44:32 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
var sliceLength:Int = Std.int(freqShit[0].length / group.members.length);
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
var volSlice = freqShit[0].slice(hzSliced, getSliceShit(i + 1));
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
var avgVel:Float = 0;
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
for (slice in volSlice)
|
|
|
|
{
|
|
|
|
avgVel += slice;
|
|
|
|
}
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
avgVel /= volSlice.length;
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
avgVel *= 10000000;
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
volumes[i] += avgVel - (elapsed * (volumes[i] * 50));
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
var animFrame:Int = Std.int(volumes[i]);
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
animFrame = Math.floor(Math.min(5, animFrame));
|
|
|
|
animFrame = Math.floor(Math.max(0, animFrame));
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
animFrame = Std.int(Math.abs(animFrame - 5)); // shitty dumbass flip, cuz dave got da shit backwards lol!
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
group.members[i].animation.curAnim.curFrame = animFrame;
|
|
|
|
if (FlxG.keys.justPressed.U)
|
|
|
|
{
|
|
|
|
trace(avgVel);
|
|
|
|
trace(group.members[i].animation.curAnim.curFrame);
|
|
|
|
}
|
|
|
|
}
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
// group.members[0].animation.curAnim.curFrame =
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
public function updateViz()
|
|
|
|
{
|
|
|
|
if (vis.snd != null)
|
|
|
|
{
|
|
|
|
var remappedShit:Int = 0;
|
|
|
|
vis.checkAndSetBuffer();
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
if (vis.setBuffer)
|
|
|
|
{
|
|
|
|
// var startingSample:Int = Std.int(FlxMath.remapToRange)
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
if (vis.snd.playing) remappedShit = Std.int(FlxMath.remapToRange(vis.snd.time, 0, vis.snd.length, 0, vis.numSamples));
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
for (i in 0...group.members.length)
|
|
|
|
{
|
|
|
|
var sampleApprox:Int = Std.int(FlxMath.remapToRange(i, 0, group.members.length, remappedShit, remappedShit + 500));
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
var left = vis.audioData[sampleApprox] / 32767;
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
var animFrame:Int = Std.int(FlxMath.remapToRange(left, -1, 1, 0, 6));
|
2021-10-07 21:01:46 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
group.members[i].animation.curAnim.curFrame = animFrame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-06 18:46:14 -04:00
|
|
|
}
|