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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 72 |
73 ScriptProcessorNode::ScriptProcessorNode(AudioContext* context, float sampleRate
, size_t bufferSize, unsigned numberOfInputChannels, unsigned numberOfOutputChan
nels) | 73 ScriptProcessorNode::ScriptProcessorNode(AudioContext* context, float sampleRate
, size_t bufferSize, unsigned numberOfInputChannels, unsigned numberOfOutputChan
nels) |
74 : AudioNode(context, sampleRate) | 74 : AudioNode(context, sampleRate) |
75 , m_doubleBufferIndex(0) | 75 , m_doubleBufferIndex(0) |
76 , m_doubleBufferIndexForEvent(0) | 76 , m_doubleBufferIndexForEvent(0) |
77 , m_bufferSize(bufferSize) | 77 , m_bufferSize(bufferSize) |
78 , m_bufferReadWriteIndex(0) | 78 , m_bufferReadWriteIndex(0) |
79 , m_isRequestOutstanding(false) | 79 , m_isRequestOutstanding(false) |
80 , m_numberOfInputChannels(numberOfInputChannels) | 80 , m_numberOfInputChannels(numberOfInputChannels) |
81 , m_numberOfOutputChannels(numberOfOutputChannels) | 81 , m_numberOfOutputChannels(numberOfOutputChannels) |
82 , m_internalInputBus(numberOfInputChannels, AudioNode::ProcessingSizeInFrame
s, false) | 82 , m_internalInputBus(AudioBus::create(numberOfInputChannels, AudioNode::Proc
essingSizeInFrames, false)) |
83 { | 83 { |
84 // Regardless of the allowed buffer sizes, we still need to process at the g
ranularity of the AudioNode. | 84 // Regardless of the allowed buffer sizes, we still need to process at the g
ranularity of the AudioNode. |
85 if (m_bufferSize < AudioNode::ProcessingSizeInFrames) | 85 if (m_bufferSize < AudioNode::ProcessingSizeInFrames) |
86 m_bufferSize = AudioNode::ProcessingSizeInFrames; | 86 m_bufferSize = AudioNode::ProcessingSizeInFrames; |
87 | 87 |
88 ASSERT(numberOfInputChannels <= AudioContext::maxNumberOfChannels()); | 88 ASSERT(numberOfInputChannels <= AudioContext::maxNumberOfChannels()); |
89 | 89 |
90 addInput(adoptPtr(new AudioNodeInput(this))); | 90 addInput(adoptPtr(new AudioNodeInput(this))); |
91 addOutput(adoptPtr(new AudioNodeOutput(this, numberOfOutputChannels))); | 91 addOutput(adoptPtr(new AudioNodeOutput(this, numberOfOutputChannels))); |
92 | 92 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 unsigned doubleBufferIndex = this->doubleBufferIndex(); | 147 unsigned doubleBufferIndex = this->doubleBufferIndex(); |
148 bool isDoubleBufferIndexGood = doubleBufferIndex < 2 && doubleBufferIndex <
m_inputBuffers.size() && doubleBufferIndex < m_outputBuffers.size(); | 148 bool isDoubleBufferIndexGood = doubleBufferIndex < 2 && doubleBufferIndex <
m_inputBuffers.size() && doubleBufferIndex < m_outputBuffers.size(); |
149 ASSERT(isDoubleBufferIndexGood); | 149 ASSERT(isDoubleBufferIndexGood); |
150 if (!isDoubleBufferIndexGood) | 150 if (!isDoubleBufferIndexGood) |
151 return; | 151 return; |
152 | 152 |
153 AudioBuffer* inputBuffer = m_inputBuffers[doubleBufferIndex].get(); | 153 AudioBuffer* inputBuffer = m_inputBuffers[doubleBufferIndex].get(); |
154 AudioBuffer* outputBuffer = m_outputBuffers[doubleBufferIndex].get(); | 154 AudioBuffer* outputBuffer = m_outputBuffers[doubleBufferIndex].get(); |
155 | 155 |
156 // Check the consistency of input and output buffers. | 156 // Check the consistency of input and output buffers. |
157 unsigned numberOfInputChannels = m_internalInputBus.numberOfChannels(); | 157 unsigned numberOfInputChannels = m_internalInputBus->numberOfChannels(); |
158 bool buffersAreGood = outputBuffer && bufferSize() == outputBuffer->length()
&& m_bufferReadWriteIndex + framesToProcess <= bufferSize(); | 158 bool buffersAreGood = outputBuffer && bufferSize() == outputBuffer->length()
&& m_bufferReadWriteIndex + framesToProcess <= bufferSize(); |
159 | 159 |
160 // If the number of input channels is zero, it's ok to have inputBuffer = 0. | 160 // If the number of input channels is zero, it's ok to have inputBuffer = 0. |
161 if (m_internalInputBus.numberOfChannels()) | 161 if (m_internalInputBus->numberOfChannels()) |
162 buffersAreGood = buffersAreGood && inputBuffer && bufferSize() == inputB
uffer->length(); | 162 buffersAreGood = buffersAreGood && inputBuffer && bufferSize() == inputB
uffer->length(); |
163 | 163 |
164 ASSERT(buffersAreGood); | 164 ASSERT(buffersAreGood); |
165 if (!buffersAreGood) | 165 if (!buffersAreGood) |
166 return; | 166 return; |
167 | 167 |
168 // We assume that bufferSize() is evenly divisible by framesToProcess - shou
ld always be true, but we should still check. | 168 // We assume that bufferSize() is evenly divisible by framesToProcess - shou
ld always be true, but we should still check. |
169 bool isFramesToProcessGood = framesToProcess && bufferSize() >= framesToProc
ess && !(bufferSize() % framesToProcess); | 169 bool isFramesToProcessGood = framesToProcess && bufferSize() >= framesToProc
ess && !(bufferSize() % framesToProcess); |
170 ASSERT(isFramesToProcessGood); | 170 ASSERT(isFramesToProcessGood); |
171 if (!isFramesToProcessGood) | 171 if (!isFramesToProcessGood) |
172 return; | 172 return; |
173 | 173 |
174 unsigned numberOfOutputChannels = outputBus->numberOfChannels(); | 174 unsigned numberOfOutputChannels = outputBus->numberOfChannels(); |
175 | 175 |
176 bool channelsAreGood = (numberOfInputChannels == m_numberOfInputChannels) &&
(numberOfOutputChannels == m_numberOfOutputChannels); | 176 bool channelsAreGood = (numberOfInputChannels == m_numberOfInputChannels) &&
(numberOfOutputChannels == m_numberOfOutputChannels); |
177 ASSERT(channelsAreGood); | 177 ASSERT(channelsAreGood); |
178 if (!channelsAreGood) | 178 if (!channelsAreGood) |
179 return; | 179 return; |
180 | 180 |
181 for (unsigned i = 0; i < numberOfInputChannels; i++) | 181 for (unsigned i = 0; i < numberOfInputChannels; i++) |
182 m_internalInputBus.setChannelMemory(i, inputBuffer->getChannelData(i)->d
ata() + m_bufferReadWriteIndex, framesToProcess); | 182 m_internalInputBus->setChannelMemory(i, inputBuffer->getChannelData(i)->
data() + m_bufferReadWriteIndex, framesToProcess); |
183 | 183 |
184 if (numberOfInputChannels) | 184 if (numberOfInputChannels) |
185 m_internalInputBus.copyFrom(*inputBus); | 185 m_internalInputBus->copyFrom(*inputBus); |
186 | 186 |
187 // Copy from the output buffer to the output. | 187 // Copy from the output buffer to the output. |
188 for (unsigned i = 0; i < numberOfOutputChannels; ++i) | 188 for (unsigned i = 0; i < numberOfOutputChannels; ++i) |
189 memcpy(outputBus->channel(i)->mutableData(), outputBuffer->getChannelDat
a(i)->data() + m_bufferReadWriteIndex, sizeof(float) * framesToProcess); | 189 memcpy(outputBus->channel(i)->mutableData(), outputBuffer->getChannelDat
a(i)->data() + m_bufferReadWriteIndex, sizeof(float) * framesToProcess); |
190 | 190 |
191 // Update the buffering index. | 191 // Update the buffering index. |
192 m_bufferReadWriteIndex = (m_bufferReadWriteIndex + framesToProcess) % buffer
Size(); | 192 m_bufferReadWriteIndex = (m_bufferReadWriteIndex + framesToProcess) % buffer
Size(); |
193 | 193 |
194 // m_bufferReadWriteIndex will wrap back around to 0 when the current input
and output buffers are full. | 194 // m_bufferReadWriteIndex will wrap back around to 0 when the current input
and output buffers are full. |
195 // When this happens, fire an event and swap buffers. | 195 // When this happens, fire an event and swap buffers. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 } | 279 } |
280 | 280 |
281 double ScriptProcessorNode::latencyTime() const | 281 double ScriptProcessorNode::latencyTime() const |
282 { | 282 { |
283 return std::numeric_limits<double>::infinity(); | 283 return std::numeric_limits<double>::infinity(); |
284 } | 284 } |
285 | 285 |
286 } // namespace WebCore | 286 } // namespace WebCore |
287 | 287 |
288 #endif // ENABLE(WEB_AUDIO) | 288 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |