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

Side by Side Diff: third_party/WebKit/Source/platform/audio/AudioResamplerKernel.cpp

Issue 1530723004: Use clampTo instead of chaining std::max(std::min(...)) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Handling that minimumThumbLength > trackLen. Created 5 years 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
(...skipping 10 matching lines...) Expand all
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 "platform/audio/AudioResamplerKernel.h" 29 #include "platform/audio/AudioResamplerKernel.h"
30 30
31 #include <algorithm>
32 #include "platform/audio/AudioResampler.h" 31 #include "platform/audio/AudioResampler.h"
32 #include "wtf/MathExtras.h"
33 33
34 namespace blink { 34 namespace blink {
35 35
36 const size_t AudioResamplerKernel::MaxFramesToProcess = 128; 36 const size_t AudioResamplerKernel::MaxFramesToProcess = 128;
37 37
38 AudioResamplerKernel::AudioResamplerKernel(AudioResampler* resampler) 38 AudioResamplerKernel::AudioResamplerKernel(AudioResampler* resampler)
39 : m_resampler(resampler) 39 : m_resampler(resampler)
40 // The buffer size must be large enough to hold up to two extra sample frame s for the linear interpolation. 40 // The buffer size must be large enough to hold up to two extra sample frame s for the linear interpolation.
41 , m_sourceBuffer(2 + static_cast<int>(MaxFramesToProcess * AudioResampler::M axRate)) 41 , m_sourceBuffer(2 + static_cast<int>(MaxFramesToProcess * AudioResampler::M axRate))
42 , m_virtualReadIndex(0.0) 42 , m_virtualReadIndex(0.0)
(...skipping 28 matching lines...) Expand all
71 return m_sourceBuffer.data() + m_fillIndex; 71 return m_sourceBuffer.data() + m_fillIndex;
72 } 72 }
73 73
74 void AudioResamplerKernel::process(float* destination, size_t framesToProcess) 74 void AudioResamplerKernel::process(float* destination, size_t framesToProcess)
75 { 75 {
76 ASSERT(framesToProcess <= MaxFramesToProcess); 76 ASSERT(framesToProcess <= MaxFramesToProcess);
77 77
78 float* source = m_sourceBuffer.data(); 78 float* source = m_sourceBuffer.data();
79 79
80 double rate = this->rate(); 80 double rate = this->rate();
81 rate = std::max(0.0, rate); 81 rate = clampTo(rate, 0.0, AudioResampler::MaxRate);
82 rate = std::min(AudioResampler::MaxRate, rate);
83 82
84 // Start out with the previous saved values (if any). 83 // Start out with the previous saved values (if any).
85 if (m_fillIndex > 0) { 84 if (m_fillIndex > 0) {
86 source[0] = m_lastValues[0]; 85 source[0] = m_lastValues[0];
87 source[1] = m_lastValues[1]; 86 source[1] = m_lastValues[1];
88 } 87 }
89 88
90 // Make a local copy. 89 // Make a local copy.
91 double virtualReadIndex = m_virtualReadIndex; 90 double virtualReadIndex = m_virtualReadIndex;
92 91
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 } 131 }
133 132
134 double AudioResamplerKernel::rate() const 133 double AudioResamplerKernel::rate() const
135 { 134 {
136 return m_resampler->rate(); 135 return m_resampler->rate();
137 } 136 }
138 137
139 } // namespace blink 138 } // namespace blink
140 139
141 #endif // ENABLE(WEB_AUDIO) 140 #endif // ENABLE(WEB_AUDIO)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698