X-Git-Url: https://git.webkit.org/?p=WebKit-https.git;a=blobdiff_plain;f=Source%2FWebCore%2Fwebaudio%2FBiquadProcessor.cpp;h=12243c0c99be1cc7753ec2a9f7952839f8699625;hp=c755277485b679df3e89f3af0e315d8ef6392a69;hb=3b4548f1fbceaa085733b83a25384d7dc8156a71;hpb=03ef6ee7a4a2939d8f4822188e07690fe70f8c87 diff --git a/Source/WebCore/webaudio/BiquadProcessor.cpp b/Source/WebCore/webaudio/BiquadProcessor.cpp index c755277485b6..12243c0c99be 100644 --- a/Source/WebCore/webaudio/BiquadProcessor.cpp +++ b/Source/WebCore/webaudio/BiquadProcessor.cpp @@ -90,14 +90,10 @@ PassOwnPtr BiquadProcessor::createKernel() return adoptPtr(new BiquadDSPKernel(this)); } -void BiquadProcessor::process(AudioBus* source, AudioBus* destination, size_t framesToProcess) +void BiquadProcessor::checkForDirtyCoefficients() { - if (!isInitialized()) { - destination->zero(); - return; - } - - // Deal with smoothing / de-zippering. Start out assuming filter parameters are not changing. + // Deal with smoothing / de-zippering. Start out assuming filter parameters are not changing. + // The BiquadDSPKernel objects rely on this value to see if they need to re-compute their internal filter coefficients. m_filterCoefficientsDirty = false; @@ -109,19 +105,51 @@ void BiquadProcessor::process(AudioBus* source, AudioBus* destination, size_t fr m_filterCoefficientsDirty = true; m_hasJustReset = false; } else { - // Smooth all of the filter parameters. If they haven't yet converged to their target value then mark coefficients as dirty. + // Smooth all of the filter parameters. If they haven't yet converged to their target value then mark coefficients as dirty. bool isStable1 = m_parameter1->smooth(); bool isStable2 = m_parameter2->smooth(); bool isStable3 = m_parameter3->smooth(); if (!(isStable1 && isStable2 && isStable3)) m_filterCoefficientsDirty = true; } +} + +void BiquadProcessor::process(AudioBus* source, AudioBus* destination, size_t framesToProcess) +{ + if (!isInitialized()) { + destination->zero(); + return; + } + checkForDirtyCoefficients(); + // For each channel of our input, process using the corresponding BiquadDSPKernel into the output channel. for (unsigned i = 0; i < m_kernels.size(); ++i) m_kernels[i]->process(source->channel(i)->data(), destination->channel(i)->data(), framesToProcess); } +void BiquadProcessor::setType(FilterType type) +{ + if (type != m_type) { + m_type = type; + reset(); // The filter state must be reset only if the type has changed. + } +} + +void BiquadProcessor::getFrequencyResponse(int nFrequencies, + const float* frequencyHz, + float* magResponse, + float* phaseResponse) +{ + // Compute the frequency response on a separate temporary kernel + // to avoid interfering with the processing running in the audio + // thread on the main kernels. + + OwnPtr responseKernel = adoptPtr(new BiquadDSPKernel(this)); + + responseKernel->getFrequencyResponse(nFrequencies, frequencyHz, magResponse, phaseResponse); +} + } // namespace WebCore #endif // ENABLE(WEB_AUDIO)