| 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 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "platform/audio/FFTFrame.h" | 29 #include "platform/audio/FFTFrame.h" |
| 30 #include "platform/audio/VectorMath.h" | 30 #include "platform/audio/VectorMath.h" |
| 31 #include "platform/Logging.h" | 31 #include "platform/Logging.h" |
| 32 #include "wtf/MathExtras.h" | 32 #include "wtf/MathExtras.h" |
| 33 #include "wtf/PtrUtil.h" | 33 #include "wtf/OwnPtr.h" |
| 34 #include <complex> | 34 #include <complex> |
| 35 #include <memory> | |
| 36 | 35 |
| 37 #ifndef NDEBUG | 36 #ifndef NDEBUG |
| 38 #include <stdio.h> | 37 #include <stdio.h> |
| 39 #endif | 38 #endif |
| 40 | 39 |
| 41 namespace blink { | 40 namespace blink { |
| 42 | 41 |
| 43 void FFTFrame::doPaddedFFT(const float* data, size_t dataSize) | 42 void FFTFrame::doPaddedFFT(const float* data, size_t dataSize) |
| 44 { | 43 { |
| 45 // Zero-pad the impulse response | 44 // Zero-pad the impulse response |
| 46 AudioFloatArray paddedResponse(fftSize()); // zero-initialized | 45 AudioFloatArray paddedResponse(fftSize()); // zero-initialized |
| 47 paddedResponse.copyToRange(data, 0, dataSize); | 46 paddedResponse.copyToRange(data, 0, dataSize); |
| 48 | 47 |
| 49 // Get the frequency-domain version of padded response | 48 // Get the frequency-domain version of padded response |
| 50 doFFT(paddedResponse.data()); | 49 doFFT(paddedResponse.data()); |
| 51 } | 50 } |
| 52 | 51 |
| 53 std::unique_ptr<FFTFrame> FFTFrame::createInterpolatedFrame(const FFTFrame& fram
e1, const FFTFrame& frame2, double x) | 52 PassOwnPtr<FFTFrame> FFTFrame::createInterpolatedFrame(const FFTFrame& frame1, c
onst FFTFrame& frame2, double x) |
| 54 { | 53 { |
| 55 std::unique_ptr<FFTFrame> newFrame = wrapUnique(new FFTFrame(frame1.fftSize(
))); | 54 OwnPtr<FFTFrame> newFrame = adoptPtr(new FFTFrame(frame1.fftSize())); |
| 56 | 55 |
| 57 newFrame->interpolateFrequencyComponents(frame1, frame2, x); | 56 newFrame->interpolateFrequencyComponents(frame1, frame2, x); |
| 58 | 57 |
| 59 // In the time-domain, the 2nd half of the response must be zero, to avoid c
ircular convolution aliasing... | 58 // In the time-domain, the 2nd half of the response must be zero, to avoid c
ircular convolution aliasing... |
| 60 int fftSize = newFrame->fftSize(); | 59 int fftSize = newFrame->fftSize(); |
| 61 AudioFloatArray buffer(fftSize); | 60 AudioFloatArray buffer(fftSize); |
| 62 newFrame->doInverseFFT(buffer.data()); | 61 newFrame->doInverseFFT(buffer.data()); |
| 63 buffer.zeroRange(fftSize / 2, fftSize); | 62 buffer.zeroRange(fftSize / 2, fftSize); |
| 64 | 63 |
| 65 // Put back into frequency domain. | 64 // Put back into frequency domain. |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 | 260 |
| 262 VectorMath::zvmul(realP1, imagP1, realP2, imagP2, realP1, imagP1, halfSize); | 261 VectorMath::zvmul(realP1, imagP1, realP2, imagP2, realP1, imagP1, halfSize); |
| 263 | 262 |
| 264 // Multiply the packed DC/nyquist component | 263 // Multiply the packed DC/nyquist component |
| 265 realP1[0] = real0 * realP2[0]; | 264 realP1[0] = real0 * realP2[0]; |
| 266 imagP1[0] = imag0 * imagP2[0]; | 265 imagP1[0] = imag0 * imagP2[0]; |
| 267 } | 266 } |
| 268 | 267 |
| 269 } // namespace blink | 268 } // namespace blink |
| 270 | 269 |
| OLD | NEW |