From b801ea30c6b37b6648a4a43e6ff56b7dbca27b7b Mon Sep 17 00:00:00 2001 From: Ralty <78720179+Raltyro@users.noreply.github.com> Date: Mon, 4 Aug 2025 04:41:24 +0700 Subject: [PATCH] Add volume param, forgot the important of all --- source/funkin/backend/utils/AudioAnalyzer.hx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/source/funkin/backend/utils/AudioAnalyzer.hx b/source/funkin/backend/utils/AudioAnalyzer.hx index 24bb2138..eccd5a4d 100644 --- a/source/funkin/backend/utils/AudioAnalyzer.hx +++ b/source/funkin/backend/utils/AudioAnalyzer.hx @@ -314,6 +314,7 @@ final class AudioAnalyzer { /** * Gets levels from an attached FlxSound from startPos, basically a minimized of frequencies. * @param startPos Start Position to get from sound in milliseconds. + * @param volume How much volume multiplier will it affect the output. (Optional, default 1.0). * @param barCount How much bars to get. * @param levels The output for getting the values, to avoid memory leaks (Optional). * @param ratio How much ratio for smoothen the values from the previous levels values (Optional, use CoolUtil.getFPSRatio(1 - ratio) to simulate web AnalyserNode.smoothingTimeConstant, 0.35 of smoothingTime works most of the time). @@ -323,17 +324,18 @@ final class AudioAnalyzer { * @param maxFreq The maximum frequency to cap (Optional, default 22000.0, Above 23000.0 is not recommended). * @return Output of levels/bars that ranges from 0 to 1. */ - public function getLevels(startPos:Float, barCount:Int, ?levels:Array, ?ratio:Float, ?minDb:Float, ?maxDb:Float, ?minFreq:Float, ?maxFreq:Float):Array - return inline getLevelsFromFrequencies(__frequencies = getFrequencies(startPos, __frequencies), buffer.sampleRate, barCount, levels, ratio, minDb, maxDb, minFreq, maxFreq); + public function getLevels(startPos:Float, ?volume:Float, barCount:Int, ?levels:Array, ?ratio:Float, ?minDb:Float, ?maxDb:Float, ?minFreq:Float, ?maxFreq:Float):Array + return inline getLevelsFromFrequencies(__frequencies = getFrequencies(startPos, volume, __frequencies), buffer.sampleRate, barCount, levels, ratio, minDb, maxDb, minFreq, maxFreq); /** * Gets frequencies from an attached FlxSound from startPos. * @param startPos Start Position to get from sound in milliseconds. + * @param volume How much volume multiplier will it affect the output. (Optional, default 1.0). * @param frequencies The output for getting the frequencies, to avoid memory leaks (Optional). * @return Output of frequencies. */ - public function getFrequencies(startPos:Float, ?frequencies:Array):Array - return inline getFrequenciesFromSamples(__freqSamples = getSamples(startPos, fftN, true, __freqSamples), fftN, useWindowingFFT, frequencies); + public function getFrequencies(startPos:Float, ?volume:Float, ?frequencies:Array):Array + return inline getFrequenciesFromSamples(__freqSamples = getSamples(startPos, fftN, true, -1, volume, __freqSamples), fftN, useWindowingFFT, frequencies); /** * Analyzes an attached FlxSound from startPos to endPos in milliseconds to get the amplitudes. @@ -381,14 +383,15 @@ final class AudioAnalyzer { * @param length Length of Samples. * @param mono Merge all of the byte channels of samples in one channel instead (Optional). * @param channel What channels to get from? (-1 == All Channels, Optional, this will be ignored if mono is enabled). + * @param volume How much volume multiplier will it affect the output. (Optional, default 1.0). * @param output An Output that gets passed into this function, usually for to avoid memory leaks (Optional). * @param outputMerge Merge with previous values (Optional, default false). * @return Output of samples. */ - public function getSamples(startPos:Float, length:Int, mono = true, channel = -1, ?output:Array, ?outputMerge = false):Array { + public function getSamples(startPos:Float, length:Int, mono = true, channel = -1, volume = 1.0, ?output:Array, ?outputMerge = false):Array { ((!mono && (__sampleChannel = channel) == -1) ? (__sampleOutputLength = length * buffer.channels) : (__sampleOutputLength = length)); ((output == null) ? (__sampleOutput = output = []) : (__sampleOutput = output)).resize(__sampleOutputLength); - ((mono) ? (__sampleToValue = 1.0 / (byteSize * buffer.channels)) : (__sampleToValue = 1.0 / byteSize)); + ((mono) ? (__sampleToValue = volume / (byteSize * buffer.channels)) : (__sampleToValue = 1.0 / byteSize)); __sampleOutputMerge = outputMerge; __sampleIndex = 0;