diff --git a/content/media/AudioNodeEngine.cpp b/content/media/AudioNodeEngine.cpp index e87e1abf9212..b0a0fa78699c 100644 --- a/content/media/AudioNodeEngine.cpp +++ b/content/media/AudioNodeEngine.cpp @@ -125,6 +125,19 @@ BufferComplexMultiply(const float* aInput, } } +float +AudioBufferPeakValue(const float *aInput, uint32_t aSize) +{ + float max = 0.0f; + for (uint32_t i = 0; i < aSize; i++) { + float mag = fabs(aInput[i]); + if (mag > max) { + max = mag; + } + } + return max; +} + void AudioBlockCopyChannelWithScale(const float aInput[WEBAUDIO_BLOCK_SIZE], const float aScale[WEBAUDIO_BLOCK_SIZE], diff --git a/content/media/AudioNodeEngine.h b/content/media/AudioNodeEngine.h index ca0614882eed..ad51fc87d473 100644 --- a/content/media/AudioNodeEngine.h +++ b/content/media/AudioNodeEngine.h @@ -134,6 +134,11 @@ void BufferComplexMultiply(const float* aInput, float* aOutput, uint32_t aSize); +/** + * Vector maximum element magnitude ( max(abs(aInput)) ). + */ +float AudioBufferPeakValue(const float* aInput, uint32_t aSize); + /** * In place gain. aScale == 1.0f should be optimized. */