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

Side by Side Diff: third_party/WebKit/Source/platform/audio/AudioDelayDSPKernel.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 12 matching lines...) Expand all
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/AudioDelayDSPKernel.h" 29 #include "platform/audio/AudioDelayDSPKernel.h"
30 30
31 #include "platform/audio/AudioUtilities.h" 31 #include "platform/audio/AudioUtilities.h"
32 #include "wtf/MathExtras.h" 32 #include "wtf/MathExtras.h"
33 #include <algorithm> 33 #include <cmath>
34 34
35 namespace blink { 35 namespace blink {
36 36
37 const float SmoothingTimeConstant = 0.020f; // 20ms 37 const float SmoothingTimeConstant = 0.020f; // 20ms
38 38
39 AudioDelayDSPKernel::AudioDelayDSPKernel(AudioDSPKernelProcessor* processor, siz e_t processingSizeInFrames) 39 AudioDelayDSPKernel::AudioDelayDSPKernel(AudioDSPKernelProcessor* processor, siz e_t processingSizeInFrames)
40 : AudioDSPKernel(processor) 40 : AudioDSPKernel(processor)
41 , m_writeIndex(0) 41 , m_writeIndex(0)
42 , m_firstTime(true) 42 , m_firstTime(true)
43 , m_delayTimes(processingSizeInFrames) 43 , m_delayTimes(processingSizeInFrames)
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 double maxTime = maxDelayTime(); 106 double maxTime = maxDelayTime();
107 107
108 bool sampleAccurate = hasSampleAccurateValues(); 108 bool sampleAccurate = hasSampleAccurateValues();
109 109
110 if (sampleAccurate) { 110 if (sampleAccurate) {
111 calculateSampleAccurateValues(delayTimes, framesToProcess); 111 calculateSampleAccurateValues(delayTimes, framesToProcess);
112 } else { 112 } else {
113 delayTime = this->delayTime(sampleRate); 113 delayTime = this->delayTime(sampleRate);
114 114
115 // Make sure the delay time is in a valid range. 115 // Make sure the delay time is in a valid range.
116 delayTime = std::min(maxTime, delayTime); 116 delayTime = clampTo(delayTime, 0.0, maxTime);
117 delayTime = std::max(0.0, delayTime);
118 117
119 if (m_firstTime) { 118 if (m_firstTime) {
120 m_currentDelayTime = delayTime; 119 m_currentDelayTime = delayTime;
121 m_firstTime = false; 120 m_firstTime = false;
122 } 121 }
123 } 122 }
124 123
125 for (unsigned i = 0; i < framesToProcess; ++i) { 124 for (unsigned i = 0; i < framesToProcess; ++i) {
126 if (sampleAccurate) { 125 if (sampleAccurate) {
127 delayTime = delayTimes[i]; 126 delayTime = delayTimes[i];
128 delayTime = std::min(maxTime, delayTime); 127 delayTime = clampTo(delayTime, 0.0, maxTime);
129 delayTime = std::max(0.0, delayTime);
130 m_currentDelayTime = delayTime; 128 m_currentDelayTime = delayTime;
131 } else { 129 } else {
132 // Approach desired delay time. 130 // Approach desired delay time.
133 m_currentDelayTime += (delayTime - m_currentDelayTime) * m_smoothing Rate; 131 m_currentDelayTime += (delayTime - m_currentDelayTime) * m_smoothing Rate;
134 } 132 }
135 133
136 double desiredDelayFrames = m_currentDelayTime * sampleRate; 134 double desiredDelayFrames = m_currentDelayTime * sampleRate;
137 135
138 double readPosition = m_writeIndex + bufferLength - desiredDelayFrames; 136 double readPosition = m_writeIndex + bufferLength - desiredDelayFrames;
139 if (readPosition >= bufferLength) 137 if (readPosition >= bufferLength)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 } 169 }
172 170
173 double AudioDelayDSPKernel::latencyTime() const 171 double AudioDelayDSPKernel::latencyTime() const
174 { 172 {
175 return 0; 173 return 0;
176 } 174 }
177 175
178 } // namespace blink 176 } // namespace blink
179 177
180 #endif // ENABLE(WEB_AUDIO) 178 #endif // ENABLE(WEB_AUDIO)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698