This source file includes following definitions.
- m_hasJustReset
- initialize
- uninitialize
- process
- reset
- setNumberOfChannels
- tailTime
- latencyTime
#include "config.h"
#if ENABLE(WEB_AUDIO)
#include "platform/audio/AudioDSPKernelProcessor.h"
#include "platform/audio/AudioDSPKernel.h"
#include "wtf/MainThread.h"
namespace WebCore {
AudioDSPKernelProcessor::AudioDSPKernelProcessor(float sampleRate, unsigned numberOfChannels)
: AudioProcessor(sampleRate, numberOfChannels)
, m_hasJustReset(true)
{
}
void AudioDSPKernelProcessor::initialize()
{
if (isInitialized())
return;
MutexLocker locker(m_processLock);
ASSERT(!m_kernels.size());
for (unsigned i = 0; i < numberOfChannels(); ++i)
m_kernels.append(createKernel());
m_initialized = true;
m_hasJustReset = true;
}
void AudioDSPKernelProcessor::uninitialize()
{
if (!isInitialized())
return;
MutexLocker locker(m_processLock);
m_kernels.clear();
m_initialized = false;
}
void AudioDSPKernelProcessor::process(const AudioBus* source, AudioBus* destination, size_t framesToProcess)
{
ASSERT(source && destination);
if (!source || !destination)
return;
if (!isInitialized()) {
destination->zero();
return;
}
MutexTryLocker tryLocker(m_processLock);
if (tryLocker.locked()) {
bool channelCountMatches = source->numberOfChannels() == destination->numberOfChannels() && source->numberOfChannels() == m_kernels.size();
ASSERT(channelCountMatches);
if (!channelCountMatches)
return;
for (unsigned i = 0; i < m_kernels.size(); ++i)
m_kernels[i]->process(source->channel(i)->data(), destination->channel(i)->mutableData(), framesToProcess);
} else {
destination->zero();
}
}
void AudioDSPKernelProcessor::reset()
{
ASSERT(isMainThread());
if (!isInitialized())
return;
m_hasJustReset = true;
MutexLocker locker(m_processLock);
for (unsigned i = 0; i < m_kernels.size(); ++i)
m_kernels[i]->reset();
}
void AudioDSPKernelProcessor::setNumberOfChannels(unsigned numberOfChannels)
{
if (numberOfChannels == m_numberOfChannels)
return;
ASSERT(!isInitialized());
if (!isInitialized())
m_numberOfChannels = numberOfChannels;
}
double AudioDSPKernelProcessor::tailTime() const
{
ASSERT(!isMainThread());
MutexTryLocker tryLocker(m_processLock);
if (tryLocker.locked()) {
return !m_kernels.isEmpty() ? m_kernels.first()->tailTime() : 0;
}
return std::numeric_limits<double>::infinity();
}
double AudioDSPKernelProcessor::latencyTime() const
{
ASSERT(!isMainThread());
MutexTryLocker tryLocker(m_processLock);
if (tryLocker.locked()) {
return !m_kernels.isEmpty() ? m_kernels.first()->latencyTime() : 0;
}
return std::numeric_limits<double>::infinity();
}
}
#endif