Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/RealtimeAnalyser.cpp

Issue 2080623002: Revert "Remove OwnPtr from Blink." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/RealtimeAnalyser.h" 25 #include "modules/webaudio/RealtimeAnalyser.h"
26 #include "platform/audio/AudioBus.h" 26 #include "platform/audio/AudioBus.h"
27 #include "platform/audio/AudioUtilities.h" 27 #include "platform/audio/AudioUtilities.h"
28 #include "platform/audio/VectorMath.h" 28 #include "platform/audio/VectorMath.h"
29 #include "wtf/MathExtras.h" 29 #include "wtf/MathExtras.h"
30 #include "wtf/PtrUtil.h"
31 #include <algorithm> 30 #include <algorithm>
32 #include <complex> 31 #include <complex>
33 #include <limits.h> 32 #include <limits.h>
34 33
35 namespace blink { 34 namespace blink {
36 35
37 const double RealtimeAnalyser::DefaultSmoothingTimeConstant = 0.8; 36 const double RealtimeAnalyser::DefaultSmoothingTimeConstant = 0.8;
38 const double RealtimeAnalyser::DefaultMinDecibels = -100; 37 const double RealtimeAnalyser::DefaultMinDecibels = -100;
39 const double RealtimeAnalyser::DefaultMaxDecibels = -30; 38 const double RealtimeAnalyser::DefaultMaxDecibels = -30;
40 39
41 const unsigned RealtimeAnalyser::DefaultFFTSize = 2048; 40 const unsigned RealtimeAnalyser::DefaultFFTSize = 2048;
42 // All FFT implementations are expected to handle power-of-two sizes MinFFTSize <= size <= MaxFFTSize. 41 // All FFT implementations are expected to handle power-of-two sizes MinFFTSize <= size <= MaxFFTSize.
43 const unsigned RealtimeAnalyser::MinFFTSize = 32; 42 const unsigned RealtimeAnalyser::MinFFTSize = 32;
44 const unsigned RealtimeAnalyser::MaxFFTSize = 32768; 43 const unsigned RealtimeAnalyser::MaxFFTSize = 32768;
45 const unsigned RealtimeAnalyser::InputBufferSize = RealtimeAnalyser::MaxFFTSize * 2; 44 const unsigned RealtimeAnalyser::InputBufferSize = RealtimeAnalyser::MaxFFTSize * 2;
46 45
47 RealtimeAnalyser::RealtimeAnalyser() 46 RealtimeAnalyser::RealtimeAnalyser()
48 : m_inputBuffer(InputBufferSize) 47 : m_inputBuffer(InputBufferSize)
49 , m_writeIndex(0) 48 , m_writeIndex(0)
50 , m_downMixBus(AudioBus::create(1, AudioUtilities::kRenderQuantumFrames)) 49 , m_downMixBus(AudioBus::create(1, AudioUtilities::kRenderQuantumFrames))
51 , m_fftSize(DefaultFFTSize) 50 , m_fftSize(DefaultFFTSize)
52 , m_magnitudeBuffer(DefaultFFTSize / 2) 51 , m_magnitudeBuffer(DefaultFFTSize / 2)
53 , m_smoothingTimeConstant(DefaultSmoothingTimeConstant) 52 , m_smoothingTimeConstant(DefaultSmoothingTimeConstant)
54 , m_minDecibels(DefaultMinDecibels) 53 , m_minDecibels(DefaultMinDecibels)
55 , m_maxDecibels(DefaultMaxDecibels) 54 , m_maxDecibels(DefaultMaxDecibels)
56 , m_lastAnalysisTime(-1) 55 , m_lastAnalysisTime(-1)
57 { 56 {
58 m_analysisFrame = wrapUnique(new FFTFrame(DefaultFFTSize)); 57 m_analysisFrame = adoptPtr(new FFTFrame(DefaultFFTSize));
59 } 58 }
60 59
61 bool RealtimeAnalyser::setFftSize(size_t size) 60 bool RealtimeAnalyser::setFftSize(size_t size)
62 { 61 {
63 ASSERT(isMainThread()); 62 ASSERT(isMainThread());
64 63
65 // Only allow powers of two. 64 // Only allow powers of two.
66 unsigned log2size = static_cast<unsigned>(log2(size)); 65 unsigned log2size = static_cast<unsigned>(log2(size));
67 bool isPOT(1UL << log2size == size); 66 bool isPOT(1UL << log2size == size);
68 67
69 if (!isPOT || size > MaxFFTSize || size < MinFFTSize) 68 if (!isPOT || size > MaxFFTSize || size < MinFFTSize)
70 return false; 69 return false;
71 70
72 if (m_fftSize != size) { 71 if (m_fftSize != size) {
73 m_analysisFrame = wrapUnique(new FFTFrame(size)); 72 m_analysisFrame = adoptPtr(new FFTFrame(size));
74 // m_magnitudeBuffer has size = fftSize / 2 because it contains floats r educed from complex values in m_analysisFrame. 73 // m_magnitudeBuffer has size = fftSize / 2 because it contains floats r educed from complex values in m_analysisFrame.
75 m_magnitudeBuffer.allocate(size / 2); 74 m_magnitudeBuffer.allocate(size / 2);
76 m_fftSize = size; 75 m_fftSize = size;
77 } 76 }
78 77
79 return true; 78 return true;
80 } 79 }
81 80
82 void RealtimeAnalyser::writeInput(AudioBus* bus, size_t framesToProcess) 81 void RealtimeAnalyser::writeInput(AudioBus* bus, size_t framesToProcess)
83 { 82 {
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 if (scaledValue > UCHAR_MAX) 317 if (scaledValue > UCHAR_MAX)
319 scaledValue = UCHAR_MAX; 318 scaledValue = UCHAR_MAX;
320 319
321 destination[i] = static_cast<unsigned char>(scaledValue); 320 destination[i] = static_cast<unsigned char>(scaledValue);
322 } 321 }
323 } 322 }
324 } 323 }
325 324
326 } // namespace blink 325 } // namespace blink
327 326
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698