| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 #include "modules/webaudio/AudioNodeOutput.h" | 37 #include "modules/webaudio/AudioNodeOutput.h" |
| 38 | 38 |
| 39 const unsigned DefaultNumberOfOutputChannels = 1; | 39 const unsigned DefaultNumberOfOutputChannels = 1; |
| 40 | 40 |
| 41 namespace WebCore { | 41 namespace WebCore { |
| 42 | 42 |
| 43 PassRefPtr<ChannelMergerNode> ChannelMergerNode::create(AudioContext* context, f
loat sampleRate, unsigned numberOfInputs) | 43 PassRefPtr<ChannelMergerNode> ChannelMergerNode::create(AudioContext* context, f
loat sampleRate, unsigned numberOfInputs) |
| 44 { | 44 { |
| 45 if (!numberOfInputs || numberOfInputs > AudioContext::maxNumberOfChannels()) | 45 if (!numberOfInputs || numberOfInputs > AudioContext::maxNumberOfChannels()) |
| 46 return 0; | 46 return 0; |
| 47 | 47 |
| 48 return adoptRef(new ChannelMergerNode(context, sampleRate, numberOfInputs));
| 48 return adoptRef(new ChannelMergerNode(context, sampleRate, numberOfInputs)); |
| 49 } | 49 } |
| 50 | 50 |
| 51 ChannelMergerNode::ChannelMergerNode(AudioContext* context, float sampleRate, un
signed numberOfInputs) | 51 ChannelMergerNode::ChannelMergerNode(AudioContext* context, float sampleRate, un
signed numberOfInputs) |
| 52 : AudioNode(context, sampleRate) | 52 : AudioNode(context, sampleRate) |
| 53 , m_desiredNumberOfOutputChannels(DefaultNumberOfOutputChannels) | 53 , m_desiredNumberOfOutputChannels(DefaultNumberOfOutputChannels) |
| 54 { | 54 { |
| 55 ScriptWrappable::init(this); | 55 ScriptWrappable::init(this); |
| 56 // Create the requested number of inputs. | 56 // Create the requested number of inputs. |
| 57 for (unsigned i = 0; i < numberOfInputs; ++i) | 57 for (unsigned i = 0; i < numberOfInputs; ++i) |
| 58 addInput(adoptPtr(new AudioNodeInput(this))); | 58 addInput(adoptPtr(new AudioNodeInput(this))); |
| 59 | 59 |
| 60 addOutput(adoptPtr(new AudioNodeOutput(this, 1))); | 60 addOutput(adoptPtr(new AudioNodeOutput(this, 1))); |
| 61 setNodeType(NodeTypeChannelMerger); | 61 setNodeType(NodeTypeChannelMerger); |
| 62 initialize(); | 62 initialize(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void ChannelMergerNode::process(size_t framesToProcess) | 65 void ChannelMergerNode::process(size_t framesToProcess) |
| 66 { | 66 { |
| 67 AudioNodeOutput* output = this->output(0); | 67 AudioNodeOutput* output = this->output(0); |
| 68 ASSERT(output); | 68 ASSERT(output); |
| 69 ASSERT_UNUSED(framesToProcess, framesToProcess == output->bus()->length()); | 69 ASSERT_UNUSED(framesToProcess, framesToProcess == output->bus()->length()); |
| 70 | 70 |
| 71 // Output bus not updated yet, so just output silence. | 71 // Output bus not updated yet, so just output silence. |
| 72 if (m_desiredNumberOfOutputChannels != output->numberOfChannels()) { | 72 if (m_desiredNumberOfOutputChannels != output->numberOfChannels()) { |
| 73 output->bus()->zero(); | 73 output->bus()->zero(); |
| 74 return; | 74 return; |
| 75 } | 75 } |
| 76 | 76 |
| 77 // Merge all the channels from all the inputs into one output. | 77 // Merge all the channels from all the inputs into one output. |
| 78 unsigned outputChannelIndex = 0; | 78 unsigned outputChannelIndex = 0; |
| 79 for (unsigned i = 0; i < numberOfInputs(); ++i) { | 79 for (unsigned i = 0; i < numberOfInputs(); ++i) { |
| 80 AudioNodeInput* input = this->input(i); | 80 AudioNodeInput* input = this->input(i); |
| 81 if (input->isConnected()) { | 81 if (input->isConnected()) { |
| 82 unsigned numberOfInputChannels = input->bus()->numberOfChannels(); | 82 unsigned numberOfInputChannels = input->bus()->numberOfChannels(); |
| 83 | 83 |
| 84 // Merge channels from this particular input. | 84 // Merge channels from this particular input. |
| 85 for (unsigned j = 0; j < numberOfInputChannels; ++j) { | 85 for (unsigned j = 0; j < numberOfInputChannels; ++j) { |
| 86 AudioChannel* inputChannel = input->bus()->channel(j); | 86 AudioChannel* inputChannel = input->bus()->channel(j); |
| 87 AudioChannel* outputChannel = output->bus()->channel(outputChann
elIndex); | 87 AudioChannel* outputChannel = output->bus()->channel(outputChann
elIndex); |
| 88 outputChannel->copyFrom(inputChannel); | 88 outputChannel->copyFrom(inputChannel); |
| 89 | 89 |
| 90 ++outputChannelIndex; | 90 ++outputChannelIndex; |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 ASSERT(outputChannelIndex == output->numberOfChannels()); | 95 ASSERT(outputChannelIndex == output->numberOfChannels()); |
| 96 } | 96 } |
| 97 | 97 |
| 98 void ChannelMergerNode::reset() | 98 void ChannelMergerNode::reset() |
| 99 { | 99 { |
| 100 } | 100 } |
| 101 | 101 |
| 102 // Any time a connection or disconnection happens on any of our inputs, we poten
tially need to change the | 102 // Any time a connection or disconnection happens on any of our inputs, we poten
tially need to change the |
| 103 // number of channels of our output. | 103 // number of channels of our output. |
| 104 void ChannelMergerNode::checkNumberOfChannelsForInput(AudioNodeInput* input) | 104 void ChannelMergerNode::checkNumberOfChannelsForInput(AudioNodeInput* input) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 121 // channels because of tryLocks() in the context's updating system. So recor
d the new number of | 121 // channels because of tryLocks() in the context's updating system. So recor
d the new number of |
| 122 // output channels here. | 122 // output channels here. |
| 123 m_desiredNumberOfOutputChannels = numberOfOutputChannels; | 123 m_desiredNumberOfOutputChannels = numberOfOutputChannels; |
| 124 | 124 |
| 125 AudioNode::checkNumberOfChannelsForInput(input); | 125 AudioNode::checkNumberOfChannelsForInput(input); |
| 126 } | 126 } |
| 127 | 127 |
| 128 } // namespace WebCore | 128 } // namespace WebCore |
| 129 | 129 |
| 130 #endif // ENABLE(WEB_AUDIO) | 130 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |