BiquadProcessor.cpp [plain text]
#include "config.h"
#if ENABLE(WEB_AUDIO)
#include "BiquadProcessor.h"
#include "BiquadDSPKernel.h"
namespace WebCore {
BiquadProcessor::BiquadProcessor(FilterType type, double sampleRate, size_t numberOfChannels, bool autoInitialize)
: AudioDSPKernelProcessor(sampleRate, numberOfChannels)
, m_type(type)
, m_parameter1(0)
, m_parameter2(0)
, m_parameter3(0)
, m_filterCoefficientsDirty(true)
{
double nyquist = 0.5 * this->sampleRate();
switch (type) {
case LowPass2:
case HighPass2:
m_parameter1 = AudioParam::create("frequency", 350.0, 20.0, nyquist);
m_parameter2 = AudioParam::create("resonance", 0.0, -20.0, 20.0);
m_parameter3 = AudioParam::create("unused", 0.0, 0.0, 1.0);
break;
case Peaking:
m_parameter1 = AudioParam::create("frequency", 2500.0, 20.0, nyquist);
m_parameter2 = AudioParam::create("gain", 0.0, -20.0, 20.0);
m_parameter3 = AudioParam::create("Q", 0.5, 0.0, 1000.0);
break;
case Allpass:
m_parameter1 = AudioParam::create("frequency", 2500.0, 20.0, nyquist);
m_parameter2 = AudioParam::create("Q", 0.5, 0.0, 1000.0);
m_parameter3 = AudioParam::create("unused", 0.0, 0.0, 1.0);
break;
case LowShelf:
m_parameter1 = AudioParam::create("frequency", 80.0, 20.0, nyquist);
m_parameter2 = AudioParam::create("gain", 0.0, 0.0, 1.0);
m_parameter3 = AudioParam::create("unused", 0.0, 0.0, 1.0);
break;
case HighShelf:
m_parameter1 = AudioParam::create("frequency", 10000.0, 20.0, nyquist);
m_parameter2 = AudioParam::create("gain", 0.0, 0.0, 1.0);
m_parameter3 = AudioParam::create("unused", 0.0, 0.0, 1.0);
break;
}
if (autoInitialize)
initialize();
}
BiquadProcessor::~BiquadProcessor()
{
if (isInitialized())
uninitialize();
}
PassOwnPtr<AudioDSPKernel> BiquadProcessor::createKernel()
{
return adoptPtr(new BiquadDSPKernel(this));
}
void BiquadProcessor::process(AudioBus* source, AudioBus* destination, size_t framesToProcess)
{
if (!isInitialized()) {
destination->zero();
return;
}
m_filterCoefficientsDirty = false;
if (m_hasJustReset) {
m_parameter1->resetSmoothedValue();
m_parameter2->resetSmoothedValue();
m_parameter3->resetSmoothedValue();
m_filterCoefficientsDirty = true;
m_hasJustReset = false;
} else {
bool isStable1 = m_parameter1->smooth();
bool isStable2 = m_parameter2->smooth();
bool isStable3 = m_parameter3->smooth();
if (!(isStable1 && isStable2 && isStable3))
m_filterCoefficientsDirty = true;
}
for (unsigned i = 0; i < m_kernels.size(); ++i)
m_kernels[i]->process(source->channel(i)->data(), destination->channel(i)->data(), framesToProcess);
}
}
#endif // ENABLE(WEB_AUDIO)