diff --git a/dom/media/webaudio/AudioBlock.h b/dom/media/webaudio/AudioBlock.h index 4d97bb47cae8..178ce8569dd3 100644 --- a/dom/media/webaudio/AudioBlock.h +++ b/dom/media/webaudio/AudioBlock.h @@ -46,7 +46,7 @@ public: using AudioChunk::SizeOfExcludingThisIfUnshared; using AudioChunk::SizeOfExcludingThis; // mDuration is not exposed. Use GetDuration(). - // mBuffer is not exposed. Use SetBuffer(). + // mBuffer is not exposed. Use Get/SetBuffer(). using AudioChunk::mChannelData; using AudioChunk::mVolume; using AudioChunk::mBufferFormat; @@ -74,6 +74,7 @@ public: return static_cast(const_cast(mChannelData[aChannel])); } + ThreadSharedObject* GetBuffer() const { return mBuffer; } void SetBuffer(ThreadSharedObject* aNewBuffer); void SetNull(StreamTime aDuration) { MOZ_ASSERT(aDuration == WEBAUDIO_BLOCK_SIZE); diff --git a/dom/media/webaudio/PannerNode.cpp b/dom/media/webaudio/PannerNode.cpp index a95b5779ac30..11f76031bc70 100644 --- a/dom/media/webaudio/PannerNode.cpp +++ b/dom/media/webaudio/PannerNode.cpp @@ -462,9 +462,6 @@ PannerNodeEngine::EqualPowerPanningFunction(const AudioBlock& aInput, return; } - // The output of this node is always stereo, no matter what the inputs are. - aOutput->AllocateChannels(2); - ComputeAzimuthAndElevation(position, azimuth, elevation); coneGain = ComputeConeGain(position, orientation); @@ -508,9 +505,6 @@ PannerNodeEngine::EqualPowerPanningFunction(const AudioBlock& aInput, float orientationY[WEBAUDIO_BLOCK_SIZE]; float orientationZ[WEBAUDIO_BLOCK_SIZE]; - // The output of this node is always stereo, no matter what the inputs are. - aOutput->AllocateChannels(2); - if (!mPositionX.HasSimpleValue()) { mPositionX.GetValuesAtTime(tick, positionX, WEBAUDIO_BLOCK_SIZE); } else { diff --git a/dom/media/webaudio/PanningUtils.h b/dom/media/webaudio/PanningUtils.h index a3be3f45e065..9c9db578db28 100644 --- a/dom/media/webaudio/PanningUtils.h +++ b/dom/media/webaudio/PanningUtils.h @@ -52,6 +52,8 @@ template void ApplyStereoPanning(const AudioBlock& aInput, AudioBlock* aOutput, T aGainL, T aGainR, U aOnLeft) { + aOutput->AllocateChannels(2); + if (aInput.ChannelCount() == 1) { GainMonoToStereo(aInput, aOutput, aGainL, aGainR); } else { diff --git a/dom/media/webaudio/StereoPannerNode.cpp b/dom/media/webaudio/StereoPannerNode.cpp index 325a8854b0fc..339768c68498 100644 --- a/dom/media/webaudio/StereoPannerNode.cpp +++ b/dom/media/webaudio/StereoPannerNode.cpp @@ -92,16 +92,18 @@ public: void UpmixToStereoIfNeeded(const AudioBlock& aInput, AudioBlock* aOutput) { if (aInput.ChannelCount() == 2) { - const float* inputL = static_cast(aInput.mChannelData[0]); - const float* inputR = static_cast(aInput.mChannelData[1]); - float* outputL = aOutput->ChannelFloatsForWrite(0); - float* outputR = aOutput->ChannelFloatsForWrite(1); - - AudioBlockCopyChannelWithScale(inputL, aInput.mVolume, outputL); - AudioBlockCopyChannelWithScale(inputR, aInput.mVolume, outputR); + *aOutput = aInput; } else { MOZ_ASSERT(aInput.ChannelCount() == 1); - GainMonoToStereo(aInput, aOutput, aInput.mVolume, aInput.mVolume); + aOutput->SetBuffer(aInput.GetBuffer()); + aOutput->mChannelData.SetLength(2); + for (uint32_t i = 0; i < 2; ++i) { + aOutput->mChannelData[i] = aInput.ChannelData()[0]; + } + // 1/sqrt(2) multiplier is because StereoPanner up-mixing differs from + // input up-mixing. + aOutput->mVolume = M_SQRT1_2 * aInput.mVolume; + aOutput->mBufferFormat = AUDIO_FORMAT_FLOAT32; } } @@ -119,7 +121,6 @@ public: // If input is silent, so is the output aOutput->SetNull(WEBAUDIO_BLOCK_SIZE); } else if (mPan.HasSimpleValue()) { - aOutput->AllocateChannels(2); float panning = mPan.GetValue(); // If the panning is 0.0, we can simply copy the input to the // output with gain applied, up-mixing to stereo if needed. @@ -138,7 +139,6 @@ public: panning <= 0); } } else { - aOutput->AllocateChannels(2); float computedGain[2*WEBAUDIO_BLOCK_SIZE + 4]; bool onLeft[WEBAUDIO_BLOCK_SIZE];