Bug 865256 - Part 3a: Add AudioBufferPeakValue utility. r=ehsan

From 6c057c02970c79d620527d08bc3755491c99b1d3 Mon Sep 17 00:00:00 2001
This is an equivalent, C-only implementation of blink's
VectorMath::maxmgv or Apple's vDSP_maxmgv. It finds the
maximum absolute value of the elements in a float buffer.
Used by blink's PeriodicWave implementation for normalization.
This commit is contained in:
Ralph Giles 2013-09-10 10:54:17 -07:00
parent cafa3e5a01
commit 0608685cbf
2 changed files with 18 additions and 0 deletions

View File

@ -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],

View File

@ -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.
*/