Bug 924286 - Handle non-unit mVolume in BiquadFilterNode. r=ehsan, a=lsblakk
authorKarl Tomlinson <karlt+@karlt.net>
Wed, 09 Oct 2013 15:33:02 +1300
changeset 286408 bb69444071a90ea4977086194605372dc85952e1
parent 286407 2dc0d50848e428fc550302807ea37c207ae9d15d
child 286409 d8a337af4346ac8bc75f73f9e48f92c7c0474dc2
push id218
push userryanvm@gmail.com
push dateWed, 16 Dec 2015 22:58:33 +0000
reviewersehsan, lsblakk
bugs924286
milestone26.0
Bug 924286 - Handle non-unit mVolume in BiquadFilterNode. r=ehsan, a=lsblakk
content/media/webaudio/BiquadFilterNode.cpp
--- a/content/media/webaudio/BiquadFilterNode.cpp
+++ b/content/media/webaudio/BiquadFilterNode.cpp
@@ -20,23 +20,24 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED_4(Biq
                                      mFrequency, mDetune, mQ, mGain)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(BiquadFilterNode)
 NS_INTERFACE_MAP_END_INHERITING(AudioNode)
 
 NS_IMPL_ADDREF_INHERITED(BiquadFilterNode, AudioNode)
 NS_IMPL_RELEASE_INHERITED(BiquadFilterNode, AudioNode)
 
-void SetParamsOnBiquad(WebCore::Biquad& aBiquad,
-                       float aSampleRate,
-                       BiquadFilterType aType,
-                       double aFrequency,
-                       double aQ,
-                       double aGain,
-                       double aDetune)
+static void
+SetParamsOnBiquad(WebCore::Biquad& aBiquad,
+                  float aSampleRate,
+                  BiquadFilterType aType,
+                  double aFrequency,
+                  double aQ,
+                  double aGain,
+                  double aDetune)
 {
   const double nyquist = aSampleRate * 0.5;
   double normalizedFrequency = aFrequency / nyquist;
 
   if (aDetune) {
     normalizedFrequency *= std::pow(2.0, aDetune / 1200);
   }
 
@@ -153,20 +154,26 @@ public:
 
     TrackTicks pos = aStream->GetCurrentPosition();
 
     double freq = mFrequency.GetValueAtTime(pos);
     double q = mQ.GetValueAtTime(pos);
     double gain = mGain.GetValueAtTime(pos);
     double detune = mDetune.GetValueAtTime(pos);
 
+    float inputBuffer[WEBAUDIO_BLOCK_SIZE];
     for (uint32_t i = 0; i < numberOfChannels; ++i) {
+      auto input = static_cast<const float*>(aInput.mChannelData[i]);
+      if (aInput.mVolume != 1.0) {
+        AudioBlockCopyChannelWithScale(input, aInput.mVolume, inputBuffer);
+        input = inputBuffer;
+      }
       SetParamsOnBiquad(mBiquads[i], aStream->SampleRate(), mType, freq, q, gain, detune);
 
-      mBiquads[i].process(static_cast<const float*>(aInput.mChannelData[i]),
+      mBiquads[i].process(input,
                           static_cast<float*>(const_cast<void*>(aOutput->mChannelData[i])),
                           aInput.GetDuration());
     }
   }
 
 private:
   AudioNodeStream* mSource;
   AudioNodeStream* mDestination;