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 11 matching lines...) Expand all Loading... |
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
23 */ | 23 */ |
24 | 24 |
25 #include "config.h" | 25 #include "config.h" |
26 #if ENABLE(WEB_AUDIO) | 26 #if ENABLE(WEB_AUDIO) |
27 #include "modules/webaudio/ConvolverNode.h" | 27 #include "modules/webaudio/ConvolverNode.h" |
28 | 28 |
29 #include "bindings/core/v8/ExceptionState.h" | 29 #include "bindings/core/v8/ExceptionState.h" |
30 #include "core/dom/ExceptionCode.h" | 30 #include "core/dom/ExceptionCode.h" |
31 #include "modules/webaudio/AudioBuffer.h" | 31 #include "modules/webaudio/AudioBuffer.h" |
32 #include "modules/webaudio/AudioContext.h" | |
33 #include "modules/webaudio/AudioNodeInput.h" | 32 #include "modules/webaudio/AudioNodeInput.h" |
34 #include "modules/webaudio/AudioNodeOutput.h" | 33 #include "modules/webaudio/AudioNodeOutput.h" |
35 #include "platform/audio/Reverb.h" | 34 #include "platform/audio/Reverb.h" |
36 #include "wtf/MainThread.h" | 35 #include "wtf/MainThread.h" |
37 | 36 |
38 // Note about empirical tuning: | 37 // Note about empirical tuning: |
39 // The maximum FFT size affects reverb performance and accuracy. | 38 // The maximum FFT size affects reverb performance and accuracy. |
40 // If the reverb is single-threaded and processes entirely in the real-time audi
o thread, | 39 // If the reverb is single-threaded and processes entirely in the real-time audi
o thread, |
41 // it's important not to make this too high. In this case 8192 is a good value. | 40 // it's important not to make this too high. In this case 8192 is a good value. |
42 // But, the Reverb object is multi-threaded, so we want this as high as possible
without losing too much accuracy. | 41 // But, the Reverb object is multi-threaded, so we want this as high as possible
without losing too much accuracy. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 119 |
121 // Wrap the AudioBuffer by an AudioBus. It's an efficient pointer set and no
t a memcpy(). | 120 // Wrap the AudioBuffer by an AudioBus. It's an efficient pointer set and no
t a memcpy(). |
122 // This memory is simply used in the Reverb constructor and no reference to
it is kept for later use in that class. | 121 // This memory is simply used in the Reverb constructor and no reference to
it is kept for later use in that class. |
123 RefPtr<AudioBus> bufferBus = AudioBus::create(numberOfChannels, bufferLength
, false); | 122 RefPtr<AudioBus> bufferBus = AudioBus::create(numberOfChannels, bufferLength
, false); |
124 for (unsigned i = 0; i < numberOfChannels; ++i) | 123 for (unsigned i = 0; i < numberOfChannels; ++i) |
125 bufferBus->setChannelMemory(i, buffer->getChannelData(i)->data(), buffer
Length); | 124 bufferBus->setChannelMemory(i, buffer->getChannelData(i)->data(), buffer
Length); |
126 | 125 |
127 bufferBus->setSampleRate(buffer->sampleRate()); | 126 bufferBus->setSampleRate(buffer->sampleRate()); |
128 | 127 |
129 // Create the reverb with the given impulse response. | 128 // Create the reverb with the given impulse response. |
130 bool useBackgroundThreads = !context()->isOfflineContext(); | 129 OwnPtr<Reverb> reverb = adoptPtr(new Reverb(bufferBus.get(), ProcessingSizeI
nFrames, MaxFFTSize, 2, context() && context()->hasRealtimeConstraint(), m_norma
lize)); |
131 OwnPtr<Reverb> reverb = adoptPtr(new Reverb(bufferBus.get(), ProcessingSizeI
nFrames, MaxFFTSize, 2, useBackgroundThreads, m_normalize)); | |
132 | 130 |
133 { | 131 { |
134 // Synchronize with process(). | 132 // Synchronize with process(). |
135 MutexLocker locker(m_processLock); | 133 MutexLocker locker(m_processLock); |
136 m_reverb = reverb.release(); | 134 m_reverb = reverb.release(); |
137 m_buffer = buffer; | 135 m_buffer = buffer; |
138 } | 136 } |
139 } | 137 } |
140 | 138 |
141 AudioBuffer* ConvolverHandler::buffer() | 139 AudioBuffer* ConvolverHandler::buffer() |
(...skipping 17 matching lines...) Expand all Loading... |
159 MutexTryLocker tryLocker(m_processLock); | 157 MutexTryLocker tryLocker(m_processLock); |
160 if (tryLocker.locked()) | 158 if (tryLocker.locked()) |
161 return m_reverb ? m_reverb->latencyFrames() / static_cast<double>(sample
Rate()) : 0; | 159 return m_reverb ? m_reverb->latencyFrames() / static_cast<double>(sample
Rate()) : 0; |
162 // Since we don't want to block the Audio Device thread, we return a large v
alue | 160 // Since we don't want to block the Audio Device thread, we return a large v
alue |
163 // instead of trying to acquire the lock. | 161 // instead of trying to acquire the lock. |
164 return std::numeric_limits<double>::infinity(); | 162 return std::numeric_limits<double>::infinity(); |
165 } | 163 } |
166 | 164 |
167 // ---------------------------------------------------------------- | 165 // ---------------------------------------------------------------- |
168 | 166 |
169 ConvolverNode::ConvolverNode(AudioContext& context, float sampleRate) | 167 ConvolverNode::ConvolverNode(AbstractAudioContext& context, float sampleRate) |
170 : AudioNode(context) | 168 : AudioNode(context) |
171 { | 169 { |
172 setHandler(ConvolverHandler::create(*this, sampleRate)); | 170 setHandler(ConvolverHandler::create(*this, sampleRate)); |
173 } | 171 } |
174 | 172 |
175 ConvolverNode* ConvolverNode::create(AudioContext& context, float sampleRate) | 173 ConvolverNode* ConvolverNode::create(AbstractAudioContext& context, float sample
Rate) |
176 { | 174 { |
177 return new ConvolverNode(context, sampleRate); | 175 return new ConvolverNode(context, sampleRate); |
178 } | 176 } |
179 | 177 |
180 ConvolverHandler& ConvolverNode::convolverHandler() const | 178 ConvolverHandler& ConvolverNode::convolverHandler() const |
181 { | 179 { |
182 return static_cast<ConvolverHandler&>(handler()); | 180 return static_cast<ConvolverHandler&>(handler()); |
183 } | 181 } |
184 | 182 |
185 AudioBuffer* ConvolverNode::buffer() const | 183 AudioBuffer* ConvolverNode::buffer() const |
(...skipping 12 matching lines...) Expand all Loading... |
198 } | 196 } |
199 | 197 |
200 void ConvolverNode::setNormalize(bool normalize) | 198 void ConvolverNode::setNormalize(bool normalize) |
201 { | 199 { |
202 convolverHandler().setNormalize(normalize); | 200 convolverHandler().setNormalize(normalize); |
203 } | 201 } |
204 | 202 |
205 } // namespace blink | 203 } // namespace blink |
206 | 204 |
207 #endif // ENABLE(WEB_AUDIO) | 205 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |