Ejemplo n.º 1
0
void ChannelMergerHandler::process(size_t framesToProcess) {
  AudioNodeOutput& output = this->output(0);
  DCHECK_EQ(framesToProcess, output.bus()->length());

  unsigned numberOfOutputChannels = output.numberOfChannels();
  DCHECK_EQ(numberOfInputs(), numberOfOutputChannels);

  // Merge multiple inputs into one output.
  for (unsigned i = 0; i < numberOfOutputChannels; ++i) {
    AudioNodeInput& input = this->input(i);
    DCHECK_EQ(input.numberOfChannels(), 1u);
    AudioChannel* outputChannel = output.bus()->channel(i);
    if (input.isConnected()) {
      // The mixing rules will be applied so multiple channels are down-
      // mixed to mono (when the mixing rule is defined). Note that only
      // the first channel will be taken for the undefined input channel
      // layout.
      //
      // See:
      // http://webaudio.github.io/web-audio-api/#channel-up-mixing-and-down-mixing
      AudioChannel* inputChannel = input.bus()->channel(0);
      outputChannel->copyFrom(inputChannel);

    } else {
      // If input is unconnected, fill zeros in the channel.
      outputChannel->zero();
    }
  }
}
Ejemplo n.º 2
0
void ChannelMergerNode::process(size_t framesToProcess)
{
    AudioNodeOutput* output = this->output(0);
    ASSERT(output);
    ASSERT_UNUSED(framesToProcess, framesToProcess == output->bus()->length());

    // Output bus not updated yet, so just output silence.
    if (m_desiredNumberOfOutputChannels != output->numberOfChannels()) {
        output->bus()->zero();
        return;
    }
    
    // Merge all the channels from all the inputs into one output.
    unsigned outputChannelIndex = 0;
    for (unsigned i = 0; i < numberOfInputs(); ++i) {
        AudioNodeInput* input = this->input(i);
        if (input->isConnected()) {
            unsigned numberOfInputChannels = input->bus()->numberOfChannels();
            
            // Merge channels from this particular input.
            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());
}
Ejemplo n.º 3
0
void ChannelMergerNode::process(size_t framesToProcess)
{
    AudioNodeOutput* output = this->output(0);
    ASSERT(output);
    ASSERT_UNUSED(framesToProcess, framesToProcess == output->bus()->length());

    // Output bus not updated yet, so just output silence.
    if (m_desiredNumberOfOutputChannels != output->numberOfChannels()) {
        output->bus()->zero();
        return;
    }

    // Merge all the channels from all the inputs into one output.
    unsigned outputChannelIndex = 0;
    unsigned maxAllowedOutputChannels = output->numberOfChannels();

    for (unsigned i = 0; i < numberOfInputs(); ++i) {
        AudioNodeInput* input = this->input(i);
        if (input->isConnected()) {
            unsigned numberOfInputChannels = input->bus()->numberOfChannels();

            // Merge channels from this particular input, but be careful not to exceed the number of
            // output channels.  (This can happen if there are many inputs with each input
            // containing many channels.)
            for (unsigned j = 0; j < numberOfInputChannels; ++j) {
                if (outputChannelIndex < maxAllowedOutputChannels) {
                    AudioChannel* inputChannel = input->bus()->channel(j);
                    AudioChannel* outputChannel = output->bus()->channel(outputChannelIndex);
                    outputChannel->copyFrom(inputChannel);

                    ++outputChannelIndex;
                }
            }
        }
        if (outputChannelIndex >= maxAllowedOutputChannels)
            break;
    }

    ASSERT(outputChannelIndex == output->numberOfChannels());
}
Ejemplo n.º 4
0
void ChannelMergerNode::process(ContextRenderLock& r, size_t framesToProcess)
{
    auto output = this->output(0);
    ASSERT_UNUSED(framesToProcess, framesToProcess == output->bus(r)->length());

    // Output bus not updated yet, so just output silence. See Note * in checkNumberOfChannelsForInput
    if (m_desiredNumberOfOutputChannels != output->numberOfChannels())
    {
        output->bus(r)->zero();
        return;
    }
    
    // Merge all the channels from all the inputs into one output.
    uint32_t outputChannelIndex = 0;
    for (uint32_t i = 0; i < numberOfInputs(); ++i)
    {
        auto input = this->input(i);
        
        if (input->isConnected())
        {
            uint32_t numberOfInputChannels = input->bus(r)->numberOfChannels();
            
            // Merge channels from this particular input.
            for (uint32_t j = 0; j < numberOfInputChannels; ++j)
            {
                AudioChannel* inputChannel = input->bus(r)->channel(j);
                AudioChannel* outputChannel = output->bus(r)->channel(outputChannelIndex);
                
                outputChannel->copyFrom(inputChannel);
                ++outputChannelIndex;
            }
        }
    }
    
    ASSERT(outputChannelIndex == output->numberOfChannels());
}