This source file includes following definitions.
- create
- m_desiredNumberOfOutputChannels
- process
- checkNumberOfChannelsForInput
#include "config.h"
#if ENABLE(WEB_AUDIO)
#include "modules/webaudio/ChannelMergerNode.h"
#include "modules/webaudio/AudioContext.h"
#include "modules/webaudio/AudioNodeInput.h"
#include "modules/webaudio/AudioNodeOutput.h"
const unsigned DefaultNumberOfOutputChannels = 1;
namespace WebCore {
PassRefPtr<ChannelMergerNode> ChannelMergerNode::create(AudioContext* context, float sampleRate, unsigned numberOfInputs)
{
if (!numberOfInputs || numberOfInputs > AudioContext::maxNumberOfChannels())
return nullptr;
return adoptRef(new ChannelMergerNode(context, sampleRate, numberOfInputs));
}
ChannelMergerNode::ChannelMergerNode(AudioContext* context, float sampleRate, unsigned numberOfInputs)
: AudioNode(context, sampleRate)
, m_desiredNumberOfOutputChannels(DefaultNumberOfOutputChannels)
{
ScriptWrappable::init(this);
for (unsigned i = 0; i < numberOfInputs; ++i)
addInput(adoptPtr(new AudioNodeInput(this)));
addOutput(adoptPtr(new AudioNodeOutput(this, 1)));
setNodeType(NodeTypeChannelMerger);
initialize();
}
void ChannelMergerNode::process(size_t framesToProcess)
{
AudioNodeOutput* output = this->output(0);
ASSERT(output);
ASSERT_UNUSED(framesToProcess, framesToProcess == output->bus()->length());
if (m_desiredNumberOfOutputChannels != output->numberOfChannels()) {
output->bus()->zero();
return;
}
unsigned outputChannelIndex = 0;
for (unsigned i = 0; i < numberOfInputs(); ++i) {
AudioNodeInput* input = this->input(i);
if (input->isConnected()) {
unsigned numberOfInputChannels = input->bus()->numberOfChannels();
for (unsigned j = 0; j < numberOfInputChannels; ++j) {
AudioChannel* inputChannel = input->bus()->channel(j);
AudioChannel* outputChannel = output->bus()->channel(outputChannelIndex);
outputChannel->copyFrom(inputChannel);
++outputChannelIndex;
}
}
}
ASSERT(outputChannelIndex == output->numberOfChannels());
}
void ChannelMergerNode::checkNumberOfChannelsForInput(AudioNodeInput* input)
{
ASSERT(context()->isAudioThread() && context()->isGraphOwner());
unsigned numberOfOutputChannels = 0;
for (unsigned i = 0; i < numberOfInputs(); ++i) {
AudioNodeInput* input = this->input(i);
if (input->isConnected())
numberOfOutputChannels += input->numberOfChannels();
}
AudioNodeOutput* output = this->output(0);
ASSERT(output);
output->setNumberOfChannels(numberOfOutputChannels);
m_desiredNumberOfOutputChannels = numberOfOutputChannels;
AudioNode::checkNumberOfChannelsForInput(input);
}
}
#endif