From 0ef0cab288cd5313520b313b631853bdfe47f1a8 Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Wed, 2 Oct 2019 10:22:55 +0000 Subject: [PATCH] Bug 1454998 - Remove AudioNodeStream::SampleRate(). r=karlt AudioNodeStream is a subclass of MediaStream, which now exposes a public const mSampleRate member. Differential Revision: https://phabricator.services.mozilla.com/D47688 --HG-- extra : moz-landing-system : lando --- dom/media/MediaStreamGraph.cpp | 4 ++-- dom/media/webaudio/AudioBufferSourceNode.cpp | 4 ++-- dom/media/webaudio/AudioNodeStream.cpp | 15 ++++++++++----- dom/media/webaudio/AudioNodeStream.h | 1 - dom/media/webaudio/BiquadFilterNode.cpp | 4 ++-- dom/media/webaudio/DelayNode.cpp | 4 ++-- dom/media/webaudio/DynamicsCompressorNode.cpp | 4 ++-- dom/media/webaudio/OscillatorNode.cpp | 4 ++-- dom/media/webaudio/ScriptProcessorNode.cpp | 2 +- dom/media/webaudio/WaveShaperNode.cpp | 6 +++--- dom/media/webaudio/WebAudioUtils.cpp | 4 ++-- 11 files changed, 28 insertions(+), 24 deletions(-) diff --git a/dom/media/MediaStreamGraph.cpp b/dom/media/MediaStreamGraph.cpp index d50a98f3d85a..1d4905beec37 100644 --- a/dom/media/MediaStreamGraph.cpp +++ b/dom/media/MediaStreamGraph.cpp @@ -1205,7 +1205,7 @@ void MediaStreamGraphImpl::Process() { for (uint32_t j = i + 1; j < mStreams.Length(); ++j) { AudioNodeStream* nextStream = mStreams[j]->AsAudioNodeStream(); if (nextStream) { - MOZ_ASSERT(n->SampleRate() == nextStream->SampleRate(), + MOZ_ASSERT(n->mSampleRate == nextStream->mSampleRate, "All AudioNodeStreams in the graph must have the same " "sampling rate"); } @@ -1213,7 +1213,7 @@ void MediaStreamGraphImpl::Process() { #endif // Since an AudioNodeStream is present, go ahead and // produce audio block by block for all the rest of the streams. - ProduceDataForStreamsBlockByBlock(i, n->SampleRate()); + ProduceDataForStreamsBlockByBlock(i, n->mSampleRate); doneAllProducing = true; } else { ps->ProcessInput(mProcessedTime, mStateComputedTime, diff --git a/dom/media/webaudio/AudioBufferSourceNode.cpp b/dom/media/webaudio/AudioBufferSourceNode.cpp index 1de1e47038d6..c8d348dcdff1 100644 --- a/dom/media/webaudio/AudioBufferSourceNode.cpp +++ b/dom/media/webaudio/AudioBufferSourceNode.cpp @@ -97,7 +97,7 @@ class AudioBufferSourceNodeEngine final : public AudioNodeEngine { switch (aIndex) { case AudioBufferSourceNode::START: MOZ_ASSERT(!mStart, "Another START?"); - mStart = aParam * mDestination->SampleRate(); + mStart = aParam * mDestination->mSampleRate; // Round to nearest mBeginProcessing = mStart + 0.5; break; @@ -439,7 +439,7 @@ class AudioBufferSourceNodeEngine final : public AudioNodeEngine { float computedPlaybackRate = aPlaybackRate * exp2(aDetune / 1200.f); // Make sure the playback rate is something our resampler can work with. int32_t rate = WebAudioUtils::TruncateFloatToInt( - mSource->SampleRate() / computedPlaybackRate); + mSource->mSampleRate / computedPlaybackRate); return rate ? rate : mBufferSampleRate; } diff --git a/dom/media/webaudio/AudioNodeStream.cpp b/dom/media/webaudio/AudioNodeStream.cpp index 6a0e0d069ada..07545f4ae0c1 100644 --- a/dom/media/webaudio/AudioNodeStream.cpp +++ b/dom/media/webaudio/AudioNodeStream.cpp @@ -194,7 +194,7 @@ void AudioNodeStream::SendTimelineEvent(uint32_t aIndex, const AudioTimelineEvent& aEvent) : ControlMessage(aStream), mEvent(aEvent), - mSampleRate(aStream->SampleRate()), + mSampleRate(aStream->mSampleRate), mIndex(aIndex) {} void Run() override { static_cast(mStream)->Engine()->RecvTimelineEvent( @@ -222,11 +222,15 @@ void AudioNodeStream::SetBuffer(AudioChunk&& aBuffer) { GraphImpl()->AppendMessage(MakeUnique(this, std::move(aBuffer))); } -void AudioNodeStream::SetReverb(WebCore::Reverb* aReverb, uint32_t aImpulseChannelCount) { +void AudioNodeStream::SetReverb(WebCore::Reverb* aReverb, + uint32_t aImpulseChannelCount) { class Message final : public ControlMessage { public: - Message(AudioNodeStream* aStream, WebCore::Reverb* aReverb, uint32_t aImpulseChannelCount) - : ControlMessage(aStream), mReverb(aReverb), mImpulseChanelCount(aImpulseChannelCount) {} + Message(AudioNodeStream* aStream, WebCore::Reverb* aReverb, + uint32_t aImpulseChannelCount) + : ControlMessage(aStream), + mReverb(aReverb), + mImpulseChanelCount(aImpulseChannelCount) {} void Run() override { static_cast(mStream)->Engine()->SetReverb( mReverb.forget(), mImpulseChanelCount); @@ -235,7 +239,8 @@ void AudioNodeStream::SetReverb(WebCore::Reverb* aReverb, uint32_t aImpulseChann uint32_t mImpulseChanelCount; }; - GraphImpl()->AppendMessage(MakeUnique(this, aReverb, aImpulseChannelCount)); + GraphImpl()->AppendMessage( + MakeUnique(this, aReverb, aImpulseChannelCount)); } void AudioNodeStream::SetRawArrayData(nsTArray& aData) { diff --git a/dom/media/webaudio/AudioNodeStream.h b/dom/media/webaudio/AudioNodeStream.h index 54b33e471659..f1f7dd3080b5 100644 --- a/dom/media/webaudio/AudioNodeStream.h +++ b/dom/media/webaudio/AudioNodeStream.h @@ -153,7 +153,6 @@ class AudioNodeStream : public ProcessedMediaStream { // Any thread AudioNodeEngine* Engine() { return mEngine; } - TrackRate SampleRate() const { return mSampleRate; } size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override; size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override; diff --git a/dom/media/webaudio/BiquadFilterNode.cpp b/dom/media/webaudio/BiquadFilterNode.cpp index e4be8b491117..1ee34ba087cc 100644 --- a/dom/media/webaudio/BiquadFilterNode.cpp +++ b/dom/media/webaudio/BiquadFilterNode.cpp @@ -188,8 +188,8 @@ class BiquadFilterNodeEngine final : public AudioNodeEngine { input = alignedInputBuffer; } } - SetParamsOnBiquad(mBiquads[i], aStream->SampleRate(), mType, freq, q, - gain, detune); + SetParamsOnBiquad(mBiquads[i], aStream->mSampleRate, mType, freq, q, gain, + detune); mBiquads[i].process(input, aOutput->ChannelFloatsForWrite(i), aInput.GetDuration()); diff --git a/dom/media/webaudio/DelayNode.cpp b/dom/media/webaudio/DelayNode.cpp index 0069dcb9a05b..805f484e41d7 100644 --- a/dom/media/webaudio/DelayNode.cpp +++ b/dom/media/webaudio/DelayNode.cpp @@ -65,7 +65,7 @@ class DelayNodeEngine final : public AudioNodeEngine { void ProcessBlock(AudioNodeStream* aStream, GraphTime aFrom, const AudioBlock& aInput, AudioBlock* aOutput, bool* aFinished) override { - MOZ_ASSERT(aStream->SampleRate() == mDestination->SampleRate()); + MOZ_ASSERT(aStream->mSampleRate == mDestination->mSampleRate); if (!aInput.IsSilentOrSubnormal()) { if (mLeftOverData <= 0) { @@ -106,7 +106,7 @@ class DelayNodeEngine final : public AudioNodeEngine { void UpdateOutputBlock(AudioNodeStream* aStream, GraphTime aFrom, AudioBlock* aOutput, float minDelay) { float maxDelay = mMaxDelay; - float sampleRate = aStream->SampleRate(); + float sampleRate = aStream->mSampleRate; ChannelInterpretation channelInterpretation = aStream->GetChannelInterpretation(); if (mDelay.HasSimpleValue()) { diff --git a/dom/media/webaudio/DynamicsCompressorNode.cpp b/dom/media/webaudio/DynamicsCompressorNode.cpp index 81bb7a64fd2d..c062146da997 100644 --- a/dom/media/webaudio/DynamicsCompressorNode.cpp +++ b/dom/media/webaudio/DynamicsCompressorNode.cpp @@ -41,7 +41,7 @@ class DynamicsCompressorNodeEngine final : public AudioNodeEngine { mRatio(12.f), mAttack(0.003f), mRelease(0.25f), - mCompressor(new DynamicsCompressor(mDestination->SampleRate(), 2)) {} + mCompressor(new DynamicsCompressor(mDestination->mSampleRate, 2)) {} enum Parameters { THRESHOLD, KNEE, RATIO, ATTACK, RELEASE }; void RecvTimelineEvent(uint32_t aIndex, AudioTimelineEvent& aEvent) override { @@ -82,7 +82,7 @@ class DynamicsCompressorNodeEngine final : public AudioNodeEngine { const uint32_t channelCount = aInput.ChannelCount(); if (mCompressor->numberOfChannels() != channelCount) { // Create a new compressor object with a new channel count - mCompressor = new WebCore::DynamicsCompressor(aStream->SampleRate(), + mCompressor = new WebCore::DynamicsCompressor(aStream->mSampleRate, aInput.ChannelCount()); } diff --git a/dom/media/webaudio/OscillatorNode.cpp b/dom/media/webaudio/OscillatorNode.cpp index 6f954fd79213..6a6322786532 100644 --- a/dom/media/webaudio/OscillatorNode.cpp +++ b/dom/media/webaudio/OscillatorNode.cpp @@ -131,7 +131,7 @@ class OscillatorNodeEngine final : public AudioNodeEngine { "PeriodicWave should have sent two channels"); MOZ_ASSERT(aBuffer.mVolume == 1.0f); mPeriodicWave = WebCore::PeriodicWave::create( - mSource->SampleRate(), aBuffer.ChannelData()[0], + mSource->mSampleRate, aBuffer.ChannelData()[0], aBuffer.ChannelData()[1], aBuffer.mDuration, mCustomDisableNormalization); } @@ -172,7 +172,7 @@ class OscillatorNodeEngine final : public AudioNodeEngine { } float finalFrequency = frequency * exp2(detune / 1200.); - float signalPeriod = mSource->SampleRate() / finalFrequency; + float signalPeriod = mSource->mSampleRate / finalFrequency; mRecomputeParameters = false; mPhaseIncrement = 2 * M_PI / signalPeriod; diff --git a/dom/media/webaudio/ScriptProcessorNode.cpp b/dom/media/webaudio/ScriptProcessorNode.cpp index 30498eb598db..67a1c1671831 100644 --- a/dom/media/webaudio/ScriptProcessorNode.cpp +++ b/dom/media/webaudio/ScriptProcessorNode.cpp @@ -244,7 +244,7 @@ class ScriptProcessorNodeEngine final : public AudioNodeEngine { uint32_t aNumberOfInputChannels) : AudioNodeEngine(aNode), mDestination(aDestination->Stream()), - mSharedBuffers(new SharedBuffers(mDestination->SampleRate())), + mSharedBuffers(new SharedBuffers(mDestination->mSampleRate)), mBufferSize(aBufferSize), mInputChannelCount(aNumberOfInputChannels), mInputWriteIndex(0) {} diff --git a/dom/media/webaudio/WaveShaperNode.cpp b/dom/media/webaudio/WaveShaperNode.cpp index 66bf37f08708..38fcfe6cea27 100644 --- a/dom/media/webaudio/WaveShaperNode.cpp +++ b/dom/media/webaudio/WaveShaperNode.cpp @@ -242,19 +242,19 @@ class WaveShaperNodeEngine final : public AudioNodeEngine { switch (mType) { case OverSampleType::None: - mResampler.Reset(channelCount, aStream->SampleRate(), + mResampler.Reset(channelCount, aStream->mSampleRate, OverSampleType::None); ProcessCurve<1>(inputSamples, outputBuffer); break; case OverSampleType::_2x: - mResampler.Reset(channelCount, aStream->SampleRate(), + mResampler.Reset(channelCount, aStream->mSampleRate, OverSampleType::_2x); sampleBuffer = mResampler.UpSample(i, inputSamples, 2); ProcessCurve<2>(sampleBuffer, sampleBuffer); mResampler.DownSample(i, outputBuffer, 2); break; case OverSampleType::_4x: - mResampler.Reset(channelCount, aStream->SampleRate(), + mResampler.Reset(channelCount, aStream->mSampleRate, OverSampleType::_4x); sampleBuffer = mResampler.UpSample(i, inputSamples, 4); ProcessCurve<4>(sampleBuffer, sampleBuffer); diff --git a/dom/media/webaudio/WebAudioUtils.cpp b/dom/media/webaudio/WebAudioUtils.cpp index 4ededeb14528..ebcff5936639 100644 --- a/dom/media/webaudio/WebAudioUtils.cpp +++ b/dom/media/webaudio/WebAudioUtils.cpp @@ -23,8 +23,8 @@ void WebAudioUtils::ConvertAudioTimelineEventToTicks(AudioTimelineEvent& aEvent, AudioNodeStream* aDest) { aEvent.SetTimeInTicks( aDest->SecondsToNearestStreamTime(aEvent.Time())); - aEvent.mTimeConstant *= aDest->SampleRate(); - aEvent.mDuration *= aDest->SampleRate(); + aEvent.mTimeConstant *= aDest->mSampleRate; + aEvent.mDuration *= aDest->mSampleRate; } void WebAudioUtils::Shutdown() { WebCore::HRTFDatabaseLoader::shutdown(); }