This source file includes following definitions.
- m_hasSampleAccurateValues
- createKernel
- checkForDirtyCoefficients
- process
- setType
- getFrequencyResponse
#include "config.h"
#if ENABLE(WEB_AUDIO)
#include "modules/webaudio/BiquadProcessor.h"
#include "modules/webaudio/BiquadDSPKernel.h"
namespace WebCore {
BiquadProcessor::BiquadProcessor(AudioContext* context, float sampleRate, size_t numberOfChannels, bool autoInitialize)
: AudioDSPKernelProcessor(sampleRate, numberOfChannels)
, m_type(LowPass)
, m_parameter1(nullptr)
, m_parameter2(nullptr)
, m_parameter3(nullptr)
, m_parameter4(nullptr)
, m_filterCoefficientsDirty(true)
, m_hasSampleAccurateValues(false)
{
double nyquist = 0.5 * this->sampleRate();
m_parameter1 = AudioParam::create(context, "frequency", 350.0, 10.0, nyquist);
m_parameter2 = AudioParam::create(context, "Q", 1, 0.0001, 1000.0);
m_parameter3 = AudioParam::create(context, "gain", 0.0, -40, 40);
m_parameter4 = AudioParam::create(context, "detune", 0.0, -4800, 4800);
if (autoInitialize)
initialize();
}
BiquadProcessor::~BiquadProcessor()
{
if (isInitialized())
uninitialize();
}
PassOwnPtr<AudioDSPKernel> BiquadProcessor::createKernel()
{
return adoptPtr(new BiquadDSPKernel(this));
}
void BiquadProcessor::checkForDirtyCoefficients()
{
m_filterCoefficientsDirty = false;
m_hasSampleAccurateValues = false;
if (m_parameter1->hasSampleAccurateValues() || m_parameter2->hasSampleAccurateValues() || m_parameter3->hasSampleAccurateValues() || m_parameter4->hasSampleAccurateValues()) {
m_filterCoefficientsDirty = true;
m_hasSampleAccurateValues = true;
} else {
if (m_hasJustReset) {
m_parameter1->resetSmoothedValue();
m_parameter2->resetSmoothedValue();
m_parameter3->resetSmoothedValue();
m_parameter4->resetSmoothedValue();
m_filterCoefficientsDirty = true;
m_hasJustReset = false;
} else {
bool isStable1 = m_parameter1->smooth();
bool isStable2 = m_parameter2->smooth();
bool isStable3 = m_parameter3->smooth();
bool isStable4 = m_parameter4->smooth();
if (!(isStable1 && isStable2 && isStable3 && isStable4))
m_filterCoefficientsDirty = true;
}
}
}
void BiquadProcessor::process(const AudioBus* source, AudioBus* destination, size_t framesToProcess)
{
if (!isInitialized()) {
destination->zero();
return;
}
checkForDirtyCoefficients();
for (unsigned i = 0; i < m_kernels.size(); ++i)
m_kernels[i]->process(source->channel(i)->data(), destination->channel(i)->mutableData(), framesToProcess);
}
void BiquadProcessor::setType(FilterType type)
{
if (type != m_type) {
m_type = type;
reset();
}
}
void BiquadProcessor::getFrequencyResponse(int nFrequencies,
const float* frequencyHz,
float* magResponse,
float* phaseResponse)
{
OwnPtr<BiquadDSPKernel> responseKernel = adoptPtr(new BiquadDSPKernel(this));
responseKernel->getFrequencyResponse(nFrequencies, frequencyHz, magResponse, phaseResponse);
}
}
#endif