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 10 matching lines...) Expand all Loading... | |
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
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 | 26 |
27 #if ENABLE(WEB_AUDIO) | 27 #if ENABLE(WEB_AUDIO) |
28 | 28 |
29 #include "modules/webaudio/ConvolverNode.h" | 29 #include "modules/webaudio/ConvolverNode.h" |
30 | 30 |
31 #include "bindings/v8/ExceptionState.h" | |
32 #include "core/dom/ExceptionCode.h" | |
31 #include "platform/audio/Reverb.h" | 33 #include "platform/audio/Reverb.h" |
32 #include "modules/webaudio/AudioBuffer.h" | 34 #include "modules/webaudio/AudioBuffer.h" |
33 #include "modules/webaudio/AudioContext.h" | 35 #include "modules/webaudio/AudioContext.h" |
34 #include "modules/webaudio/AudioNodeInput.h" | 36 #include "modules/webaudio/AudioNodeInput.h" |
35 #include "modules/webaudio/AudioNodeOutput.h" | 37 #include "modules/webaudio/AudioNodeOutput.h" |
36 #include "wtf/MainThread.h" | 38 #include "wtf/MainThread.h" |
37 | 39 |
38 // Note about empirical tuning: | 40 // Note about empirical tuning: |
39 // The maximum FFT size affects reverb performance and accuracy. | 41 // 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, | 42 // If the reverb is single-threaded and processes entirely in the real-time audi o thread, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 | 102 |
101 void ConvolverNode::uninitialize() | 103 void ConvolverNode::uninitialize() |
102 { | 104 { |
103 if (!isInitialized()) | 105 if (!isInitialized()) |
104 return; | 106 return; |
105 | 107 |
106 m_reverb.clear(); | 108 m_reverb.clear(); |
107 AudioNode::uninitialize(); | 109 AudioNode::uninitialize(); |
108 } | 110 } |
109 | 111 |
110 void ConvolverNode::setBuffer(AudioBuffer* buffer) | 112 void ConvolverNode::setBuffer(AudioBuffer* buffer, ExceptionState& exceptionStat e) |
111 { | 113 { |
112 ASSERT(isMainThread()); | 114 ASSERT(isMainThread()); |
113 | 115 |
114 if (!buffer) | 116 if (!buffer) |
115 return; | 117 return; |
116 | 118 |
119 if (buffer->sampleRate() != context()->sampleRate()) { | |
120 exceptionState.throwDOMException( | |
121 NotSupportedError, | |
122 "The buffer sample rate of " + String::number(buffer->sampleRate()) | |
123 + " does not match the context rate of " + String::number(context()- >sampleRate()) | |
124 + " Hz."); | |
125 } | |
tkent
2015/04/08 04:52:35
Should we do |return| here?
Raymond Toy
2015/04/08 15:49:44
Yes!
I'll fix this right away.
| |
126 | |
117 unsigned numberOfChannels = buffer->numberOfChannels(); | 127 unsigned numberOfChannels = buffer->numberOfChannels(); |
118 size_t bufferLength = buffer->length(); | 128 size_t bufferLength = buffer->length(); |
119 | 129 |
120 // The current implementation supports up to four channel impulse responses, which are interpreted as true-stereo (see Reverb class). | 130 // The current implementation supports up to four channel impulse responses, which are interpreted as true-stereo (see Reverb class). |
121 bool isBufferGood = numberOfChannels > 0 && numberOfChannels <= 4 && bufferL ength; | 131 bool isBufferGood = numberOfChannels > 0 && numberOfChannels <= 4 && bufferL ength; |
122 ASSERT(isBufferGood); | 132 ASSERT(isBufferGood); |
123 if (!isBufferGood) | 133 if (!isBufferGood) |
124 return; | 134 return; |
125 | 135 |
126 // Wrap the AudioBuffer by an AudioBus. It's an efficient pointer set and no t a memcpy(). | 136 // Wrap the AudioBuffer by an AudioBus. It's an efficient pointer set and no t a memcpy(). |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 if (tryLocker.locked()) | 175 if (tryLocker.locked()) |
166 return m_reverb ? m_reverb->latencyFrames() / static_cast<double>(sample Rate()) : 0; | 176 return m_reverb ? m_reverb->latencyFrames() / static_cast<double>(sample Rate()) : 0; |
167 // Since we don't want to block the Audio Device thread, we return a large v alue | 177 // Since we don't want to block the Audio Device thread, we return a large v alue |
168 // instead of trying to acquire the lock. | 178 // instead of trying to acquire the lock. |
169 return std::numeric_limits<double>::infinity(); | 179 return std::numeric_limits<double>::infinity(); |
170 } | 180 } |
171 | 181 |
172 } // namespace WebCore | 182 } // namespace WebCore |
173 | 183 |
174 #endif // ENABLE(WEB_AUDIO) | 184 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |