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 |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y |
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N |
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 "modules/webaudio/ConvolverNode.h" |
25 #include "bindings/core/v8/ExceptionState.h" | 26 #include "bindings/core/v8/ExceptionState.h" |
26 #include "core/dom/ExceptionCode.h" | 27 #include "core/dom/ExceptionCode.h" |
27 #include "modules/webaudio/AudioBuffer.h" | 28 #include "modules/webaudio/AudioBuffer.h" |
28 #include "modules/webaudio/AudioNodeInput.h" | 29 #include "modules/webaudio/AudioNodeInput.h" |
29 #include "modules/webaudio/AudioNodeOutput.h" | 30 #include "modules/webaudio/AudioNodeOutput.h" |
30 #include "modules/webaudio/ConvolverNode.h" | |
31 #include "platform/audio/Reverb.h" | 31 #include "platform/audio/Reverb.h" |
32 #include "wtf/PtrUtil.h" | |
33 #include <memory> | |
34 | 32 |
35 // Note about empirical tuning: | 33 // Note about empirical tuning: |
36 // The maximum FFT size affects reverb performance and accuracy. | 34 // The maximum FFT size affects reverb performance and accuracy. |
37 // If the reverb is single-threaded and processes entirely in the real-time audi
o thread, | 35 // If the reverb is single-threaded and processes entirely in the real-time audi
o thread, |
38 // it's important not to make this too high. In this case 8192 is a good value. | 36 // it's important not to make this too high. In this case 8192 is a good value. |
39 // But, the Reverb object is multi-threaded, so we want this as high as possible
without losing too much accuracy. | 37 // But, the Reverb object is multi-threaded, so we want this as high as possible
without losing too much accuracy. |
40 // Very large FFTs will have worse phase errors. Given these constraints 32768 i
s a good compromise. | 38 // Very large FFTs will have worse phase errors. Given these constraints 32768 i
s a good compromise. |
41 const size_t MaxFFTSize = 32768; | 39 const size_t MaxFFTSize = 32768; |
42 | 40 |
43 namespace blink { | 41 namespace blink { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 120 |
123 // Wrap the AudioBuffer by an AudioBus. It's an efficient pointer set and no
t a memcpy(). | 121 // Wrap the AudioBuffer by an AudioBus. It's an efficient pointer set and no
t a memcpy(). |
124 // This memory is simply used in the Reverb constructor and no reference to
it is kept for later use in that class. | 122 // This memory is simply used in the Reverb constructor and no reference to
it is kept for later use in that class. |
125 RefPtr<AudioBus> bufferBus = AudioBus::create(numberOfChannels, bufferLength
, false); | 123 RefPtr<AudioBus> bufferBus = AudioBus::create(numberOfChannels, bufferLength
, false); |
126 for (unsigned i = 0; i < numberOfChannels; ++i) | 124 for (unsigned i = 0; i < numberOfChannels; ++i) |
127 bufferBus->setChannelMemory(i, buffer->getChannelData(i)->data(), buffer
Length); | 125 bufferBus->setChannelMemory(i, buffer->getChannelData(i)->data(), buffer
Length); |
128 | 126 |
129 bufferBus->setSampleRate(buffer->sampleRate()); | 127 bufferBus->setSampleRate(buffer->sampleRate()); |
130 | 128 |
131 // Create the reverb with the given impulse response. | 129 // Create the reverb with the given impulse response. |
132 std::unique_ptr<Reverb> reverb = wrapUnique(new Reverb(bufferBus.get(), Proc
essingSizeInFrames, MaxFFTSize, 2, context() && context()->hasRealtimeConstraint
(), m_normalize)); | 130 OwnPtr<Reverb> reverb = adoptPtr(new Reverb(bufferBus.get(), ProcessingSizeI
nFrames, MaxFFTSize, 2, context() && context()->hasRealtimeConstraint(), m_norma
lize)); |
133 | 131 |
134 { | 132 { |
135 // Synchronize with process(). | 133 // Synchronize with process(). |
136 MutexLocker locker(m_processLock); | 134 MutexLocker locker(m_processLock); |
137 m_reverb = std::move(reverb); | 135 m_reverb = std::move(reverb); |
138 m_buffer = buffer; | 136 m_buffer = buffer; |
139 } | 137 } |
140 } | 138 } |
141 | 139 |
142 AudioBuffer* ConvolverHandler::buffer() | 140 AudioBuffer* ConvolverHandler::buffer() |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 return convolverHandler().normalize(); | 203 return convolverHandler().normalize(); |
206 } | 204 } |
207 | 205 |
208 void ConvolverNode::setNormalize(bool normalize) | 206 void ConvolverNode::setNormalize(bool normalize) |
209 { | 207 { |
210 convolverHandler().setNormalize(normalize); | 208 convolverHandler().setNormalize(normalize); |
211 } | 209 } |
212 | 210 |
213 } // namespace blink | 211 } // namespace blink |
214 | 212 |
OLD | NEW |