Bug 865256 - Part 3a: Add AudioBufferPeakValue utility. r=ehsan, a=lsblakk
authorRalph Giles <giles@mozilla.com>
Tue, 10 Sep 2013 11:29:00 -0700
changeset 160415 e543dc7ed4a89d66b5432148b26ca2ce86f98531
parent 160414 fb764e648a8f059c4fe312ed01af50cff1bd600d
child 160416 54540fd082e3fae0a3a7f68832beaca7bea04095
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan, lsblakk
bugs865256
milestone26.0a2
Bug 865256 - Part 3a: Add AudioBufferPeakValue utility. r=ehsan, a=lsblakk 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.
content/media/AudioNodeEngine.cpp
content/media/AudioNodeEngine.h
--- a/content/media/AudioNodeEngine.cpp
+++ b/content/media/AudioNodeEngine.cpp
@@ -120,16 +120,29 @@ BufferComplexMultiply(const float* aInpu
     float imag2 = aScale[i + 1];
     float realResult = real1 * real2 - imag1 * imag2;
     float imagResult = real1 * imag2 + imag1 * real2;
     aOutput[i] = realResult;
     aOutput[i + 1] = imagResult;
   }
 }
 
+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],
                                float aOutput[WEBAUDIO_BLOCK_SIZE])
 {
 #ifdef BUILD_ARM_NEON
   if (mozilla::supports_neon()) {
     AudioBlockCopyChannelWithScale_NEON(aInput, aScale, aOutput);
--- a/content/media/AudioNodeEngine.h
+++ b/content/media/AudioNodeEngine.h
@@ -131,16 +131,21 @@ void AudioBlockCopyChannelWithScale(cons
  * Vector complex multiplication on arbitrary sized buffers.
  */
 void BufferComplexMultiply(const float* aInput,
                            const float* aScale,
                            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.
  */
 void AudioBufferInPlaceScale(float aBlock[WEBAUDIO_BLOCK_SIZE],
                              uint32_t aChannelCount,
                              float aScale);
 
 /**
  * In place gain. aScale == 1.0f should be optimized.