This source file includes following definitions.
- configureChannels
- process
- setRate
- reset
#include "config.h"
#if ENABLE(WEB_AUDIO)
#include "platform/audio/AudioResampler.h"
#include <algorithm>
#include "wtf/MathExtras.h"
using namespace std;
namespace WebCore {
const double AudioResampler::MaxRate = 8.0;
AudioResampler::AudioResampler()
: m_rate(1.0)
{
m_kernels.append(adoptPtr(new AudioResamplerKernel(this)));
m_sourceBus = AudioBus::create(1, 0, false);
}
AudioResampler::AudioResampler(unsigned numberOfChannels)
: m_rate(1.0)
{
for (unsigned i = 0; i < numberOfChannels; ++i)
m_kernels.append(adoptPtr(new AudioResamplerKernel(this)));
m_sourceBus = AudioBus::create(numberOfChannels, 0, false);
}
void AudioResampler::configureChannels(unsigned numberOfChannels)
{
unsigned currentSize = m_kernels.size();
if (numberOfChannels == currentSize)
return;
if (numberOfChannels > currentSize) {
for (unsigned i = currentSize; i < numberOfChannels; ++i)
m_kernels.append(adoptPtr(new AudioResamplerKernel(this)));
} else
m_kernels.resize(numberOfChannels);
m_sourceBus = AudioBus::create(numberOfChannels, 0, false);
}
void AudioResampler::process(AudioSourceProvider* provider, AudioBus* destinationBus, size_t framesToProcess)
{
ASSERT(provider);
if (!provider)
return;
unsigned numberOfChannels = m_kernels.size();
bool channelsMatch = (destinationBus && destinationBus->numberOfChannels() == numberOfChannels);
ASSERT(channelsMatch);
if (!channelsMatch)
return;
for (unsigned i = 0; i < numberOfChannels; ++i) {
size_t framesNeeded;
float* fillPointer = m_kernels[i]->getSourcePointer(framesToProcess, &framesNeeded);
ASSERT(fillPointer);
if (!fillPointer)
return;
m_sourceBus->setChannelMemory(i, fillPointer, framesNeeded);
}
provider->provideInput(m_sourceBus.get(), m_sourceBus->length());
for (unsigned i = 0; i < numberOfChannels; ++i) {
float* destination = destinationBus->channel(i)->mutableData();
m_kernels[i]->process(destination, framesToProcess);
}
}
void AudioResampler::setRate(double rate)
{
if (std::isnan(rate) || std::isinf(rate) || rate <= 0.0)
return;
m_rate = min(AudioResampler::MaxRate, rate);
}
void AudioResampler::reset()
{
unsigned numberOfChannels = m_kernels.size();
for (unsigned i = 0; i < numberOfChannels; ++i)
m_kernels[i]->reset();
}
}
#endif