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 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 16 matching lines...) Expand all Loading... |
27 #if ENABLE(WEB_AUDIO) | 27 #if ENABLE(WEB_AUDIO) |
28 | 28 |
29 #include "modules/webaudio/AudioNodeInput.h" | 29 #include "modules/webaudio/AudioNodeInput.h" |
30 | 30 |
31 #include "modules/webaudio/AudioContext.h" | 31 #include "modules/webaudio/AudioContext.h" |
32 #include "modules/webaudio/AudioNode.h" | 32 #include "modules/webaudio/AudioNode.h" |
33 #include "modules/webaudio/AudioNodeOutput.h" | 33 #include "modules/webaudio/AudioNodeOutput.h" |
34 #include <algorithm> | 34 #include <algorithm> |
35 | 35 |
36 using namespace std; | 36 using namespace std; |
37 | 37 |
38 namespace WebCore { | 38 namespace WebCore { |
39 | 39 |
40 AudioNodeInput::AudioNodeInput(AudioNode* node) | 40 AudioNodeInput::AudioNodeInput(AudioNode* node) |
41 : AudioSummingJunction(node->context()) | 41 : AudioSummingJunction(node->context()) |
42 , m_node(node) | 42 , m_node(node) |
43 { | 43 { |
44 // Set to mono by default. | 44 // Set to mono by default. |
45 m_internalSummingBus = AudioBus::create(1, AudioNode::ProcessingSizeInFrames
); | 45 m_internalSummingBus = AudioBus::create(1, AudioNode::ProcessingSizeInFrames
); |
46 } | 46 } |
47 | 47 |
48 void AudioNodeInput::connect(AudioNodeOutput* output) | 48 void AudioNodeInput::connect(AudioNodeOutput* output) |
49 { | 49 { |
50 ASSERT(context()->isGraphOwner()); | 50 ASSERT(context()->isGraphOwner()); |
51 | 51 |
52 ASSERT(output && node()); | 52 ASSERT(output && node()); |
53 if (!output || !node()) | 53 if (!output || !node()) |
54 return; | 54 return; |
55 | 55 |
56 // Check if we're already connected to this output. | 56 // Check if we're already connected to this output. |
57 if (m_outputs.contains(output)) | 57 if (m_outputs.contains(output)) |
58 return; | 58 return; |
59 | 59 |
60 output->addInput(this); | 60 output->addInput(this); |
61 m_outputs.add(output); | 61 m_outputs.add(output); |
62 changedOutputs(); | 62 changedOutputs(); |
63 | 63 |
64 // Sombody has just connected to us, so count it as a reference. | 64 // Sombody has just connected to us, so count it as a reference. |
65 node()->ref(AudioNode::RefTypeConnection); | 65 node()->ref(AudioNode::RefTypeConnection); |
66 } | 66 } |
67 | 67 |
68 void AudioNodeInput::disconnect(AudioNodeOutput* output) | 68 void AudioNodeInput::disconnect(AudioNodeOutput* output) |
69 { | 69 { |
70 ASSERT(context()->isGraphOwner()); | 70 ASSERT(context()->isGraphOwner()); |
71 | 71 |
72 ASSERT(output && node()); | 72 ASSERT(output && node()); |
73 if (!output || !node()) | 73 if (!output || !node()) |
74 return; | 74 return; |
75 | 75 |
76 // First try to disconnect from "active" connections. | 76 // First try to disconnect from "active" connections. |
77 if (m_outputs.contains(output)) { | 77 if (m_outputs.contains(output)) { |
78 m_outputs.remove(output); | 78 m_outputs.remove(output); |
79 changedOutputs(); | 79 changedOutputs(); |
80 output->removeInput(this); | 80 output->removeInput(this); |
81 node()->deref(AudioNode::RefTypeConnection); // Note: it's important to
return immediately after all deref() calls since the node may be deleted. | 81 node()->deref(AudioNode::RefTypeConnection); // Note: it's important to
return immediately after all deref() calls since the node may be deleted. |
82 return; | 82 return; |
83 } | 83 } |
84 | 84 |
85 // Otherwise, try to disconnect from disabled connections. | 85 // Otherwise, try to disconnect from disabled connections. |
86 if (m_disabledOutputs.contains(output)) { | 86 if (m_disabledOutputs.contains(output)) { |
87 m_disabledOutputs.remove(output); | 87 m_disabledOutputs.remove(output); |
88 output->removeInput(this); | 88 output->removeInput(this); |
89 node()->deref(AudioNode::RefTypeConnection); // Note: it's important to
return immediately after all deref() calls since the node may be deleted. | 89 node()->deref(AudioNode::RefTypeConnection); // Note: it's important to
return immediately after all deref() calls since the node may be deleted. |
90 return; | 90 return; |
91 } | 91 } |
92 | 92 |
93 ASSERT_NOT_REACHED(); | 93 ASSERT_NOT_REACHED(); |
94 } | 94 } |
95 | 95 |
96 void AudioNodeInput::disable(AudioNodeOutput* output) | 96 void AudioNodeInput::disable(AudioNodeOutput* output) |
97 { | 97 { |
98 ASSERT(context()->isGraphOwner()); | 98 ASSERT(context()->isGraphOwner()); |
99 | 99 |
100 ASSERT(output && node()); | 100 ASSERT(output && node()); |
101 if (!output || !node()) | 101 if (!output || !node()) |
102 return; | 102 return; |
103 | 103 |
104 ASSERT(m_outputs.contains(output)); | 104 ASSERT(m_outputs.contains(output)); |
105 | 105 |
106 m_disabledOutputs.add(output); | 106 m_disabledOutputs.add(output); |
107 m_outputs.remove(output); | 107 m_outputs.remove(output); |
108 changedOutputs(); | 108 changedOutputs(); |
109 | 109 |
110 // Propagate disabled state to outputs. | 110 // Propagate disabled state to outputs. |
111 node()->disableOutputsIfNecessary(); | 111 node()->disableOutputsIfNecessary(); |
112 } | 112 } |
113 | 113 |
114 void AudioNodeInput::enable(AudioNodeOutput* output) | 114 void AudioNodeInput::enable(AudioNodeOutput* output) |
115 { | 115 { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 void AudioNodeInput::sumAllConnections(AudioBus* summingBus, size_t framesToProc
ess) | 191 void AudioNodeInput::sumAllConnections(AudioBus* summingBus, size_t framesToProc
ess) |
192 { | 192 { |
193 ASSERT(context()->isAudioThread()); | 193 ASSERT(context()->isAudioThread()); |
194 | 194 |
195 // We shouldn't be calling this method if there's only one connection, since
it's less efficient. | 195 // We shouldn't be calling this method if there's only one connection, since
it's less efficient. |
196 ASSERT(numberOfRenderingConnections() > 1 || node()->internalChannelCountMod
e() != AudioNode::Max); | 196 ASSERT(numberOfRenderingConnections() > 1 || node()->internalChannelCountMod
e() != AudioNode::Max); |
197 | 197 |
198 ASSERT(summingBus); | 198 ASSERT(summingBus); |
199 if (!summingBus) | 199 if (!summingBus) |
200 return; | 200 return; |
201 | 201 |
202 summingBus->zero(); | 202 summingBus->zero(); |
203 | 203 |
204 AudioBus::ChannelInterpretation interpretation = node()->internalChannelInte
rpretation(); | 204 AudioBus::ChannelInterpretation interpretation = node()->internalChannelInte
rpretation(); |
205 | 205 |
206 for (unsigned i = 0; i < numberOfRenderingConnections(); ++i) { | 206 for (unsigned i = 0; i < numberOfRenderingConnections(); ++i) { |
207 AudioNodeOutput* output = renderingOutput(i); | 207 AudioNodeOutput* output = renderingOutput(i); |
208 ASSERT(output); | 208 ASSERT(output); |
209 | 209 |
210 // Render audio from this output. | 210 // Render audio from this output. |
211 AudioBus* connectionBus = output->pull(0, framesToProcess); | 211 AudioBus* connectionBus = output->pull(0, framesToProcess); |
(...skipping 18 matching lines...) Expand all Loading... |
230 | 230 |
231 if (!numberOfRenderingConnections()) { | 231 if (!numberOfRenderingConnections()) { |
232 // At least, generate silence if we're not connected to anything. | 232 // At least, generate silence if we're not connected to anything. |
233 // FIXME: if we wanted to get fancy, we could propagate a 'silent hint'
here to optimize the downstream graph processing. | 233 // FIXME: if we wanted to get fancy, we could propagate a 'silent hint'
here to optimize the downstream graph processing. |
234 internalSummingBus->zero(); | 234 internalSummingBus->zero(); |
235 return internalSummingBus; | 235 return internalSummingBus; |
236 } | 236 } |
237 | 237 |
238 // Handle multiple connections case. | 238 // Handle multiple connections case. |
239 sumAllConnections(internalSummingBus, framesToProcess); | 239 sumAllConnections(internalSummingBus, framesToProcess); |
240 | 240 |
241 return internalSummingBus; | 241 return internalSummingBus; |
242 } | 242 } |
243 | 243 |
244 } // namespace WebCore | 244 } // namespace WebCore |
245 | 245 |
246 #endif // ENABLE(WEB_AUDIO) | 246 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |