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 18 matching lines...) Expand all Loading... |
29 #include "config.h" | 29 #include "config.h" |
30 | 30 |
31 #if ENABLE(WEB_AUDIO) | 31 #if ENABLE(WEB_AUDIO) |
32 | 32 |
33 #include "ChannelMergerNode.h" | 33 #include "ChannelMergerNode.h" |
34 | 34 |
35 #include "AudioContext.h" | 35 #include "AudioContext.h" |
36 #include "AudioNodeInput.h" | 36 #include "AudioNodeInput.h" |
37 #include "AudioNodeOutput.h" | 37 #include "AudioNodeOutput.h" |
38 | 38 |
| 39 const unsigned DefaultNumberOfOutputChannels = 1; |
| 40 |
39 namespace WebCore { | 41 namespace WebCore { |
40 | 42 |
41 PassRefPtr<ChannelMergerNode> ChannelMergerNode::create(AudioContext* context, f
loat sampleRate, unsigned numberOfInputs) | 43 PassRefPtr<ChannelMergerNode> ChannelMergerNode::create(AudioContext* context, f
loat sampleRate, unsigned numberOfInputs) |
42 { | 44 { |
43 if (!numberOfInputs || numberOfInputs > AudioContext::maxNumberOfChannels()) | 45 if (!numberOfInputs || numberOfInputs > AudioContext::maxNumberOfChannels()) |
44 return 0; | 46 return 0; |
45 | 47 |
46 return adoptRef(new ChannelMergerNode(context, sampleRate, numberOfInputs));
| 48 return adoptRef(new ChannelMergerNode(context, sampleRate, numberOfInputs));
|
47 } | 49 } |
48 | 50 |
49 ChannelMergerNode::ChannelMergerNode(AudioContext* context, float sampleRate, un
signed numberOfInputs) | 51 ChannelMergerNode::ChannelMergerNode(AudioContext* context, float sampleRate, un
signed numberOfInputs) |
50 : AudioNode(context, sampleRate) | 52 : AudioNode(context, sampleRate) |
| 53 , m_desiredNumberOfOutputChannels(DefaultNumberOfOutputChannels) |
51 { | 54 { |
52 // Create the requested number of inputs. | 55 // Create the requested number of inputs. |
53 for (unsigned i = 0; i < numberOfInputs; ++i) | 56 for (unsigned i = 0; i < numberOfInputs; ++i) |
54 addInput(adoptPtr(new AudioNodeInput(this))); | 57 addInput(adoptPtr(new AudioNodeInput(this))); |
55 | 58 |
56 addOutput(adoptPtr(new AudioNodeOutput(this, 1))); | 59 addOutput(adoptPtr(new AudioNodeOutput(this, 1))); |
57 | 60 |
58 setNodeType(NodeTypeChannelMerger); | 61 setNodeType(NodeTypeChannelMerger); |
59 | 62 |
60 initialize(); | 63 initialize(); |
61 } | 64 } |
62 | 65 |
63 void ChannelMergerNode::process(size_t framesToProcess) | 66 void ChannelMergerNode::process(size_t framesToProcess) |
64 { | 67 { |
65 AudioNodeOutput* output = this->output(0); | 68 AudioNodeOutput* output = this->output(0); |
66 ASSERT(output); | 69 ASSERT(output); |
67 ASSERT_UNUSED(framesToProcess, framesToProcess == output->bus()->length());
| 70 ASSERT_UNUSED(framesToProcess, framesToProcess == output->bus()->length()); |
| 71 |
| 72 // Output bus not updated yet, so just output silence. |
| 73 if (m_desiredNumberOfOutputChannels != output->numberOfChannels()) { |
| 74 output->bus()->zero(); |
| 75 return; |
| 76 } |
68 | 77 |
69 // Merge all the channels from all the inputs into one output. | 78 // Merge all the channels from all the inputs into one output. |
70 unsigned outputChannelIndex = 0; | 79 unsigned outputChannelIndex = 0; |
71 for (unsigned i = 0; i < numberOfInputs(); ++i) { | 80 for (unsigned i = 0; i < numberOfInputs(); ++i) { |
72 AudioNodeInput* input = this->input(i); | 81 AudioNodeInput* input = this->input(i); |
73 if (input->isConnected()) { | 82 if (input->isConnected()) { |
74 unsigned numberOfInputChannels = input->bus()->numberOfChannels(); | 83 unsigned numberOfInputChannels = input->bus()->numberOfChannels(); |
75 | 84 |
76 // Merge channels from this particular input. | 85 // Merge channels from this particular input. |
77 for (unsigned j = 0; j < numberOfInputChannels; ++j) { | 86 for (unsigned j = 0; j < numberOfInputChannels; ++j) { |
(...skipping 24 matching lines...) Expand all Loading... |
102 for (unsigned i = 0; i < numberOfInputs(); ++i) { | 111 for (unsigned i = 0; i < numberOfInputs(); ++i) { |
103 AudioNodeInput* input = this->input(i); | 112 AudioNodeInput* input = this->input(i); |
104 if (input->isConnected()) | 113 if (input->isConnected()) |
105 numberOfOutputChannels += input->bus()->numberOfChannels(); | 114 numberOfOutputChannels += input->bus()->numberOfChannels(); |
106 } | 115 } |
107 | 116 |
108 // Set the correct number of channels on the output | 117 // Set the correct number of channels on the output |
109 AudioNodeOutput* output = this->output(0); | 118 AudioNodeOutput* output = this->output(0); |
110 ASSERT(output); | 119 ASSERT(output); |
111 output->setNumberOfChannels(numberOfOutputChannels); | 120 output->setNumberOfChannels(numberOfOutputChannels); |
| 121 // There can in rare cases be a slight delay before the output bus is update
d to the new number of |
| 122 // channels because of tryLocks() in the context's updating system. So recor
d the new number of |
| 123 // output channels here. |
| 124 m_desiredNumberOfOutputChannels = numberOfOutputChannels; |
112 | 125 |
113 AudioNode::checkNumberOfChannelsForInput(input); | 126 AudioNode::checkNumberOfChannelsForInput(input); |
114 } | 127 } |
115 | 128 |
116 } // namespace WebCore | 129 } // namespace WebCore |
117 | 130 |
118 #endif // ENABLE(WEB_AUDIO) | 131 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |