From ec959f5d83572648ace9ec684b97afb0dc9c0b9c Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Fri, 8 Oct 2021 20:44:32 -0400 Subject: [PATCH] freq balancing, and also sum math shit lol! --- source/ABotVis.hx | 11 ++++++++++- source/CoolUtil.hx | 5 +++++ source/VisShit.hx | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/source/ABotVis.hx b/source/ABotVis.hx index 48b327077..968960b4c 100644 --- a/source/ABotVis.hx +++ b/source/ABotVis.hx @@ -86,9 +86,18 @@ class ABotVis extends FlxTypedSpriteGroup for (i in 0...group.members.length) { + var getSliceShit = function(s:Int) + { + var powShit = FlxMath.remapToRange(s, 0, group.members.length, 0, CoolUtil.coolBaseLog(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(Std.int(sliceLength * i), Std.int(sliceLength * i) + sliceLength); + var volSlice = freqShit[0].slice(hzSliced, getSliceShit(i + 1)); var avgVel:Float = 0; diff --git a/source/CoolUtil.hx b/source/CoolUtil.hx index 27ba2e415..d548ab7b8 100644 --- a/source/CoolUtil.hx +++ b/source/CoolUtil.hx @@ -28,6 +28,11 @@ class CoolUtil return difficultyArray[PlayState.storyDifficulty]; } + public static function coolBaseLog(base:Float, fin:Float):Float + { + return Math.log(fin) / Math.log(base); + } + public static function coolTextFile(path:String):Array { var daList:Array = []; diff --git a/source/VisShit.hx b/source/VisShit.hx index 29ecf197b..129f07215 100644 --- a/source/VisShit.hx +++ b/source/VisShit.hx @@ -41,7 +41,7 @@ class VisShit final binSize = fs / fftN; final indexToFreq = function(k:Int) { - var powShit:Float = FlxMath.remapToRange(k, 0, halfN, 0, 4.3); // 4.3 is almost 20khz + var powShit:Float = FlxMath.remapToRange(k, 0, halfN, 0, CoolUtil.coolBaseLog(10, halfN)); // 4.3 is almost the log of 20Khz or so. Close enuf lol return 1.0 * (Math.pow(10, powShit)); // we need the `1.0` to avoid overflows };