Bug 1500303 apply input gain correctly for stereo-to-stereo StereoPanner r=padenot
authorKarl Tomlinson <karlt+@karlt.net>
Fri, 19 Oct 2018 09:36:08 +0000
changeset 500708 34266803222fc5017d3aaf900cc12c7554de1646
parent 500707 75d951d7f8acedb2ebd986a4b8668d0bc54f2515
child 500709 bf00005608fd51638394add485699675ce361aa3
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1500303
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1500303 apply input gain correctly for stereo-to-stereo StereoPanner r=padenot The gains passed to GainStereoToStereo() are applied on only one of the input channels. Depends on D9213 Differential Revision: https://phabricator.services.mozilla.com/D9214
dom/media/webaudio/PannerNode.cpp
dom/media/webaudio/PanningUtils.h
dom/media/webaudio/StereoPannerNode.cpp
--- a/dom/media/webaudio/PannerNode.cpp
+++ b/dom/media/webaudio/PannerNode.cpp
@@ -491,17 +491,17 @@ PannerNodeEngine::EqualPowerPanningFunct
 
     // Actually compute the left and right gain.
     gainL = cos(0.5 * M_PI * normalizedAzimuth);
     gainR = sin(0.5 * M_PI * normalizedAzimuth);
 
     // Compute the output.
     ApplyStereoPanning(aInput, aOutput, gainL, gainR, azimuth <= 0);
 
-    aOutput->mVolume = aInput.mVolume * distanceGain * coneGain;
+    aOutput->mVolume *= distanceGain * coneGain;
   } else {
     float positionX[WEBAUDIO_BLOCK_SIZE];
     float positionY[WEBAUDIO_BLOCK_SIZE];
     float positionZ[WEBAUDIO_BLOCK_SIZE];
     float orientationX[WEBAUDIO_BLOCK_SIZE];
     float orientationY[WEBAUDIO_BLOCK_SIZE];
     float orientationZ[WEBAUDIO_BLOCK_SIZE];
 
@@ -586,17 +586,17 @@ PannerNodeEngine::EqualPowerPanningFunct
 
       // Actually compute the left and right gain.
       float gainL = cos(0.5 * M_PI * normalizedAzimuth);
       float gainR = sin(0.5 * M_PI * normalizedAzimuth);
 
 
       alignedPanningL[counter] = gainL;
       alignedPanningR[counter] = gainR;
-      alignedGain[counter] = aInput.mVolume * distanceGain * coneGain;
+      alignedGain[counter] = distanceGain * coneGain;
       onLeft[counter] = azimuth <= 0;
     }
 
     // Apply the panning to the output buffer
     ApplyStereoPanning(aInput, aOutput, alignedPanningL, alignedPanningR, onLeft);
 
     // Apply the input volume, cone and distance gain to the output buffer.
     float* outputL = aOutput->ChannelFloatsForWrite(0);
--- a/dom/media/webaudio/PanningUtils.h
+++ b/dom/media/webaudio/PanningUtils.h
@@ -54,14 +54,15 @@ void ApplyStereoPanning(const AudioBlock
 {
   aOutput->AllocateChannels(2);
 
   if (aInput.ChannelCount() == 1) {
     GainMonoToStereo(aInput, aOutput, aGainL, aGainR);
   } else {
     GainStereoToStereo(aInput, aOutput, aGainL, aGainR, aOnLeft);
   }
+  aOutput->mVolume = aInput.mVolume;
 }
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // PANNING_UTILS_H
--- a/dom/media/webaudio/StereoPannerNode.cpp
+++ b/dom/media/webaudio/StereoPannerNode.cpp
@@ -129,36 +129,35 @@ public:
       } else {
         // Optimize the case where the panning is constant for this processing
         // block: we can just apply a constant gain on the left and right
         // channel
         float gainL, gainR;
 
         GetGainValuesForPanning(panning, monoToStereo, gainL, gainR);
         ApplyStereoPanning(aInput, aOutput,
-                           gainL * aInput.mVolume,
-                           gainR * aInput.mVolume,
+                           gainL, gainR,
                            panning <= 0);
       }
     } else {
       float computedGain[2*WEBAUDIO_BLOCK_SIZE + 4];
       bool onLeft[WEBAUDIO_BLOCK_SIZE];
 
       float values[WEBAUDIO_BLOCK_SIZE];
       StreamTime tick = mDestination->GraphTimeToStreamTime(aFrom);
       mPan.GetValuesAtTime(tick, values, WEBAUDIO_BLOCK_SIZE);
 
       float* alignedComputedGain = ALIGNED16(computedGain);
       ASSERT_ALIGNED16(alignedComputedGain);
       for (size_t counter = 0; counter < WEBAUDIO_BLOCK_SIZE; ++counter) {
         float left, right;
         GetGainValuesForPanning(values[counter], monoToStereo, left, right);
 
-        alignedComputedGain[counter] = left * aInput.mVolume;
-        alignedComputedGain[WEBAUDIO_BLOCK_SIZE + counter] = right * aInput.mVolume;
+        alignedComputedGain[counter] = left;
+        alignedComputedGain[WEBAUDIO_BLOCK_SIZE + counter] = right;
         onLeft[counter] = values[counter] <= 0;
       }
 
       // Apply the gain to the output buffer
       ApplyStereoPanning(aInput, aOutput, alignedComputedGain, &alignedComputedGain[WEBAUDIO_BLOCK_SIZE], onLeft);
     }
   }