This source file includes following definitions.
- m_node
- connect
- disconnect
- disable
- enable
- didUpdate
- updateInternalBus
- numberOfChannels
- bus
- internalSummingBus
- sumAllConnections
- pull
#include "config.h"
#if ENABLE(WEB_AUDIO)
#include "modules/webaudio/AudioNodeInput.h"
#include "modules/webaudio/AudioContext.h"
#include "modules/webaudio/AudioNodeOutput.h"
#include <algorithm>
using namespace std;
namespace WebCore {
AudioNodeInput::AudioNodeInput(AudioNode* node)
: AudioSummingJunction(node->context())
, m_node(node)
{
m_internalSummingBus = AudioBus::create(1, AudioNode::ProcessingSizeInFrames);
}
void AudioNodeInput::connect(AudioNodeOutput* output)
{
ASSERT(context()->isGraphOwner());
ASSERT(output && node());
if (!output || !node())
return;
if (m_outputs.contains(output))
return;
output->addInput(this);
m_outputs.add(output);
changedOutputs();
node()->ref(AudioNode::RefTypeConnection);
}
void AudioNodeInput::disconnect(AudioNodeOutput* output)
{
ASSERT(context()->isGraphOwner());
ASSERT(output && node());
if (!output || !node())
return;
if (m_outputs.contains(output)) {
m_outputs.remove(output);
changedOutputs();
output->removeInput(this);
node()->deref(AudioNode::RefTypeConnection);
return;
}
if (m_disabledOutputs.contains(output)) {
m_disabledOutputs.remove(output);
output->removeInput(this);
node()->deref(AudioNode::RefTypeConnection);
return;
}
ASSERT_NOT_REACHED();
}
void AudioNodeInput::disable(AudioNodeOutput* output)
{
ASSERT(context()->isGraphOwner());
ASSERT(output && node());
if (!output || !node())
return;
ASSERT(m_outputs.contains(output));
m_disabledOutputs.add(output);
m_outputs.remove(output);
changedOutputs();
node()->disableOutputsIfNecessary();
}
void AudioNodeInput::enable(AudioNodeOutput* output)
{
ASSERT(context()->isGraphOwner());
ASSERT(output && node());
if (!output || !node())
return;
ASSERT(m_disabledOutputs.contains(output));
m_outputs.add(output);
m_disabledOutputs.remove(output);
changedOutputs();
node()->enableOutputsIfNecessary();
}
void AudioNodeInput::didUpdate()
{
node()->checkNumberOfChannelsForInput(this);
}
void AudioNodeInput::updateInternalBus()
{
ASSERT(context()->isAudioThread() && context()->isGraphOwner());
unsigned numberOfInputChannels = numberOfChannels();
if (numberOfInputChannels == m_internalSummingBus->numberOfChannels())
return;
m_internalSummingBus = AudioBus::create(numberOfInputChannels, AudioNode::ProcessingSizeInFrames);
}
unsigned AudioNodeInput::numberOfChannels() const
{
AudioNode::ChannelCountMode mode = node()->internalChannelCountMode();
if (mode == AudioNode::Explicit)
return node()->channelCount();
unsigned maxChannels = 1;
for (HashSet<AudioNodeOutput*>::iterator i = m_outputs.begin(); i != m_outputs.end(); ++i) {
AudioNodeOutput* output = *i;
maxChannels = max(maxChannels, output->numberOfChannels());
}
if (mode == AudioNode::ClampedMax)
maxChannels = min(maxChannels, static_cast<unsigned>(node()->channelCount()));
return maxChannels;
}
AudioBus* AudioNodeInput::bus()
{
ASSERT(context()->isAudioThread());
if (numberOfRenderingConnections() == 1 && node()->internalChannelCountMode() == AudioNode::Max)
return renderingOutput(0)->bus();
return internalSummingBus();
}
AudioBus* AudioNodeInput::internalSummingBus()
{
ASSERT(context()->isAudioThread());
return m_internalSummingBus.get();
}
void AudioNodeInput::sumAllConnections(AudioBus* summingBus, size_t framesToProcess)
{
ASSERT(context()->isAudioThread());
ASSERT(numberOfRenderingConnections() > 1 || node()->internalChannelCountMode() != AudioNode::Max);
ASSERT(summingBus);
if (!summingBus)
return;
summingBus->zero();
AudioBus::ChannelInterpretation interpretation = node()->internalChannelInterpretation();
for (unsigned i = 0; i < numberOfRenderingConnections(); ++i) {
AudioNodeOutput* output = renderingOutput(i);
ASSERT(output);
AudioBus* connectionBus = output->pull(0, framesToProcess);
summingBus->sumFrom(*connectionBus, interpretation);
}
}
AudioBus* AudioNodeInput::pull(AudioBus* inPlaceBus, size_t framesToProcess)
{
ASSERT(context()->isAudioThread());
if (numberOfRenderingConnections() == 1 && node()->internalChannelCountMode() == AudioNode::Max) {
AudioNodeOutput* output = this->renderingOutput(0);
return output->pull(inPlaceBus, framesToProcess);
}
AudioBus* internalSummingBus = this->internalSummingBus();
if (!numberOfRenderingConnections()) {
internalSummingBus->zero();
return internalSummingBus;
}
sumAllConnections(internalSummingBus, framesToProcess);
return internalSummingBus;
}
}
#endif