From 478818a4c120280e2e6c8eb80618f5f207ce5e14 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Wed, 6 Oct 2021 19:27:45 -0400 Subject: [PATCH] almost sorta properly exponent bullshit for frequencies --- source/SpectogramSprite.hx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/source/SpectogramSprite.hx b/source/SpectogramSprite.hx index cd471fb50..4f041a98f 100644 --- a/source/SpectogramSprite.hx +++ b/source/SpectogramSprite.hx @@ -135,8 +135,6 @@ class SpectogramSprite extends FlxTypedSpriteGroup { var remappedShit:Int = 0; - // vis.checkAndSetBuffer(); - checkAndSetBuffer(); if (!doAnim) @@ -182,7 +180,7 @@ class SpectogramSprite extends FlxTypedSpriteGroup // trace(audioData.subarray(remappedShit, remappedShit + lengthOfShit).buffer); } - for (sample in remappedShit...remappedShit + (Std.int((44100 * 0.120) / 4))) + for (sample in remappedShit...remappedShit + (Std.int((44100 * (10 / 60)) / 4))) { var left = audioData[i] / 32767; var right = audioData[i + 1] / 32767; @@ -195,7 +193,7 @@ class SpectogramSprite extends FlxTypedSpriteGroup fftSamples.push(balanced); } - var freqShit = funnyFFT(fftSamples); + var freqShit = funnyFFT(fftSamples, 4); for (i in 0...group.members.length) { @@ -204,8 +202,13 @@ class SpectogramSprite extends FlxTypedSpriteGroup // not every frequency is built the same! // 20hz to 40z is a LOT of subtle low ends, but somethin like 20,000hz to 20,020hz, the difference is NOT the same! + var powedShit:Float = FlxMath.remapToRange(i, 0, group.members.length, 0, 4); + + // a value between 10hz and 100Khz + var hzPicker:Float = Math.pow(10, powedShit); + // var sampleApprox:Int = Std.int(FlxMath.remapToRange(i, 0, group.members.length, startingSample, startingSample + samplesToGen)); - var remappedFreq:Int = Std.int(FlxMath.remapToRange(i, 0, group.members.length, 0, freqShit[0].length - 1)); + var remappedFreq:Int = Std.int(FlxMath.remapToRange(hzPicker + 50, 0, 10000, 0, freqShit[0].length - 1)); group.members[i].x = prevLine.x; group.members[i].y = prevLine.y; @@ -292,11 +295,11 @@ class SpectogramSprite extends FlxTypedSpriteGroup } } - function funnyFFT(samples:Array):Array> + function funnyFFT(samples:Array, ?skipped:Int = 1):Array> { // nab multiple samples at once in while / for loops? - var fs:Float = 44100; // sample rate shit? + var fs:Float = 44100 / skipped; // sample rate shit? final fftN = 2048; final halfN = Std.int(fftN / 2);