This source file includes following definitions.
- updateCoefficientsIfNecessary
- process
- getFrequencyResponse
- tailTime
- latencyTime
#include "config.h"
#if ENABLE(WEB_AUDIO)
#include "modules/webaudio/BiquadDSPKernel.h"
#include "platform/FloatConversion.h"
#include <limits.h>
#include "wtf/Vector.h"
namespace WebCore {
static const double MaxBiquadDelayTime = 0.2;
void BiquadDSPKernel::updateCoefficientsIfNecessary(bool useSmoothing, bool forceUpdate)
{
if (forceUpdate || biquadProcessor()->filterCoefficientsDirty()) {
double value1;
double value2;
double gain;
double detune;
if (biquadProcessor()->hasSampleAccurateValues()) {
value1 = biquadProcessor()->parameter1()->finalValue();
value2 = biquadProcessor()->parameter2()->finalValue();
gain = biquadProcessor()->parameter3()->finalValue();
detune = biquadProcessor()->parameter4()->finalValue();
} else if (useSmoothing) {
value1 = biquadProcessor()->parameter1()->smoothedValue();
value2 = biquadProcessor()->parameter2()->smoothedValue();
gain = biquadProcessor()->parameter3()->smoothedValue();
detune = biquadProcessor()->parameter4()->smoothedValue();
} else {
value1 = biquadProcessor()->parameter1()->value();
value2 = biquadProcessor()->parameter2()->value();
gain = biquadProcessor()->parameter3()->value();
detune = biquadProcessor()->parameter4()->value();
}
double nyquist = this->nyquist();
double normalizedFrequency = value1 / nyquist;
if (detune)
normalizedFrequency *= pow(2, detune / 1200);
switch (biquadProcessor()->type()) {
case BiquadProcessor::LowPass:
m_biquad.setLowpassParams(normalizedFrequency, value2);
break;
case BiquadProcessor::HighPass:
m_biquad.setHighpassParams(normalizedFrequency, value2);
break;
case BiquadProcessor::BandPass:
m_biquad.setBandpassParams(normalizedFrequency, value2);
break;
case BiquadProcessor::LowShelf:
m_biquad.setLowShelfParams(normalizedFrequency, gain);
break;
case BiquadProcessor::HighShelf:
m_biquad.setHighShelfParams(normalizedFrequency, gain);
break;
case BiquadProcessor::Peaking:
m_biquad.setPeakingParams(normalizedFrequency, value2, gain);
break;
case BiquadProcessor::Notch:
m_biquad.setNotchParams(normalizedFrequency, value2);
break;
case BiquadProcessor::Allpass:
m_biquad.setAllpassParams(normalizedFrequency, value2);
break;
}
}
}
void BiquadDSPKernel::process(const float* source, float* destination, size_t framesToProcess)
{
ASSERT(source && destination && biquadProcessor());
updateCoefficientsIfNecessary(true, false);
m_biquad.process(source, destination, framesToProcess);
}
void BiquadDSPKernel::getFrequencyResponse(int nFrequencies,
const float* frequencyHz,
float* magResponse,
float* phaseResponse)
{
bool isGood = nFrequencies > 0 && frequencyHz && magResponse && phaseResponse;
ASSERT(isGood);
if (!isGood)
return;
Vector<float> frequency(nFrequencies);
double nyquist = this->nyquist();
for (int k = 0; k < nFrequencies; ++k)
frequency[k] = narrowPrecisionToFloat(frequencyHz[k] / nyquist);
updateCoefficientsIfNecessary(false, true);
m_biquad.getFrequencyResponse(nFrequencies, frequency.data(), magResponse, phaseResponse);
}
double BiquadDSPKernel::tailTime() const
{
return MaxBiquadDelayTime;
}
double BiquadDSPKernel::latencyTime() const
{
return 0;
}
}
#endif