| 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" | |
| 26 #include "bindings/core/v8/ExceptionState.h" | 25 #include "bindings/core/v8/ExceptionState.h" |
| 27 #include "core/dom/ExceptionCode.h" | 26 #include "core/dom/ExceptionCode.h" |
| 28 #include "modules/webaudio/AudioBuffer.h" | 27 #include "modules/webaudio/AudioBuffer.h" |
| 29 #include "modules/webaudio/AudioNodeInput.h" | 28 #include "modules/webaudio/AudioNodeInput.h" |
| 30 #include "modules/webaudio/AudioNodeOutput.h" | 29 #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> |
| 32 | 34 |
| 33 // Note about empirical tuning: | 35 // Note about empirical tuning: |
| 34 // The maximum FFT size affects reverb performance and accuracy. | 36 // The maximum FFT size affects reverb performance and accuracy. |
| 35 // If the reverb is single-threaded and processes entirely in the real-time audi
o thread, | 37 // If the reverb is single-threaded and processes entirely in the real-time audi
o thread, |
| 36 // it's important not to make this too high. In this case 8192 is a good value. | 38 // it's important not to make this too high. In this case 8192 is a good value. |
| 37 // But, the Reverb object is multi-threaded, so we want this as high as possible
without losing too much accuracy. | 39 // But, the Reverb object is multi-threaded, so we want this as high as possible
without losing too much accuracy. |
| 38 // Very large FFTs will have worse phase errors. Given these constraints 32768 i
s a good compromise. | 40 // Very large FFTs will have worse phase errors. Given these constraints 32768 i
s a good compromise. |
| 39 const size_t MaxFFTSize = 32768; | 41 const size_t MaxFFTSize = 32768; |
| 40 | 42 |
| 41 namespace blink { | 43 namespace blink { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 | 122 |
| 121 // Wrap the AudioBuffer by an AudioBus. It's an efficient pointer set and no
t a memcpy(). | 123 // 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. | 124 // 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); | 125 RefPtr<AudioBus> bufferBus = AudioBus::create(numberOfChannels, bufferLength
, false); |
| 124 for (unsigned i = 0; i < numberOfChannels; ++i) | 126 for (unsigned i = 0; i < numberOfChannels; ++i) |
| 125 bufferBus->setChannelMemory(i, buffer->getChannelData(i)->data(), buffer
Length); | 127 bufferBus->setChannelMemory(i, buffer->getChannelData(i)->data(), buffer
Length); |
| 126 | 128 |
| 127 bufferBus->setSampleRate(buffer->sampleRate()); | 129 bufferBus->setSampleRate(buffer->sampleRate()); |
| 128 | 130 |
| 129 // Create the reverb with the given impulse response. | 131 // Create the reverb with the given impulse response. |
| 130 OwnPtr<Reverb> reverb = adoptPtr(new Reverb(bufferBus.get(), ProcessingSizeI
nFrames, MaxFFTSize, 2, context() && context()->hasRealtimeConstraint(), m_norma
lize)); | 132 std::unique_ptr<Reverb> reverb = wrapUnique(new Reverb(bufferBus.get(), Proc
essingSizeInFrames, MaxFFTSize, 2, context() && context()->hasRealtimeConstraint
(), m_normalize)); |
| 131 | 133 |
| 132 { | 134 { |
| 133 // Synchronize with process(). | 135 // Synchronize with process(). |
| 134 MutexLocker locker(m_processLock); | 136 MutexLocker locker(m_processLock); |
| 135 m_reverb = std::move(reverb); | 137 m_reverb = std::move(reverb); |
| 136 m_buffer = buffer; | 138 m_buffer = buffer; |
| 137 } | 139 } |
| 138 } | 140 } |
| 139 | 141 |
| 140 AudioBuffer* ConvolverHandler::buffer() | 142 AudioBuffer* ConvolverHandler::buffer() |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 return convolverHandler().normalize(); | 205 return convolverHandler().normalize(); |
| 204 } | 206 } |
| 205 | 207 |
| 206 void ConvolverNode::setNormalize(bool normalize) | 208 void ConvolverNode::setNormalize(bool normalize) |
| 207 { | 209 { |
| 208 convolverHandler().setNormalize(normalize); | 210 convolverHandler().setNormalize(normalize); |
| 209 } | 211 } |
| 210 | 212 |
| 211 } // namespace blink | 213 } // namespace blink |
| 212 | 214 |
| OLD | NEW |