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

Side by Side Diff: third_party/WebKit/Source/platform/audio/HRTFKernel.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: More rebase Created 4 years, 12 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 * 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 14 matching lines...) Expand all
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/HRTFKernel.h" 29 #include "platform/audio/HRTFKernel.h"
30 30
31 #if ENABLE(WEB_AUDIO) 31 #if ENABLE(WEB_AUDIO)
32 #include "platform/audio/AudioChannel.h" 32 #include "platform/audio/AudioChannel.h"
33 #include "platform/FloatConversion.h" 33 #include "platform/FloatConversion.h"
34 #include "wtf/MathExtras.h" 34 #include "wtf/MathExtras.h"
35 #include <algorithm>
35 36
36 namespace blink { 37 namespace blink {
37 38
38 // Takes the input AudioChannel as an input impulse response and calculates the average group delay. 39 // Takes the input AudioChannel as an input impulse response and calculates the average group delay.
39 // This represents the initial delay before the most energetic part of the impul se response. 40 // This represents the initial delay before the most energetic part of the impul se response.
40 // The sample-frame delay is removed from the impulseP impulse response, and thi s value is returned. 41 // The sample-frame delay is removed from the impulseP impulse response, and thi s value is returned.
41 // the length of the passed in AudioChannel must be a power of 2. 42 // the length of the passed in AudioChannel must be a power of 2.
42 static float extractAverageGroupDelay(AudioChannel* channel, size_t analysisFFTS ize) 43 static float extractAverageGroupDelay(AudioChannel* channel, size_t analysisFFTS ize)
43 { 44 {
44 ASSERT(channel); 45 ASSERT(channel);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 } 105 }
105 106
106 // Interpolates two kernels with x: 0 -> 1 and returns the result. 107 // Interpolates two kernels with x: 0 -> 1 and returns the result.
107 PassOwnPtr<HRTFKernel> HRTFKernel::createInterpolatedKernel(HRTFKernel* kernel1, HRTFKernel* kernel2, float x) 108 PassOwnPtr<HRTFKernel> HRTFKernel::createInterpolatedKernel(HRTFKernel* kernel1, HRTFKernel* kernel2, float x)
108 { 109 {
109 ASSERT(kernel1 && kernel2); 110 ASSERT(kernel1 && kernel2);
110 if (!kernel1 || !kernel2) 111 if (!kernel1 || !kernel2)
111 return nullptr; 112 return nullptr;
112 113
113 ASSERT(x >= 0.0 && x < 1.0); 114 ASSERT(x >= 0.0 && x < 1.0);
114 x = std::min(1.0f, std::max(0.0f, x)); 115 x = clampTo(x, 0.0f, 1.0f);
115 116
116 float sampleRate1 = kernel1->sampleRate(); 117 float sampleRate1 = kernel1->sampleRate();
117 float sampleRate2 = kernel2->sampleRate(); 118 float sampleRate2 = kernel2->sampleRate();
118 ASSERT(sampleRate1 == sampleRate2); 119 ASSERT(sampleRate1 == sampleRate2);
119 if (sampleRate1 != sampleRate2) 120 if (sampleRate1 != sampleRate2)
120 return nullptr; 121 return nullptr;
121 122
122 float frameDelay = (1 - x) * kernel1->frameDelay() + x * kernel2->frameDelay (); 123 float frameDelay = (1 - x) * kernel1->frameDelay() + x * kernel2->frameDelay ();
123 124
124 OwnPtr<FFTFrame> interpolatedFrame = FFTFrame::createInterpolatedFrame(*kern el1->fftFrame(), *kernel2->fftFrame(), x); 125 OwnPtr<FFTFrame> interpolatedFrame = FFTFrame::createInterpolatedFrame(*kern el1->fftFrame(), *kernel2->fftFrame(), x);
125 return HRTFKernel::create(interpolatedFrame.release(), frameDelay, sampleRat e1); 126 return HRTFKernel::create(interpolatedFrame.release(), frameDelay, sampleRat e1);
126 } 127 }
127 128
128 } // namespace blink 129 } // namespace blink
129 130
130 #endif // ENABLE(WEB_AUDIO) 131 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/audio/HRTFDatabase.cpp ('k') | third_party/WebKit/Source/platform/audio/HRTFPanner.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698