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

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

Issue 2342913003: Replace narrowPrecisionToFloat with clampTo<float> (Closed)
Patch Set: Created 4 years, 3 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
(...skipping 11 matching lines...) Expand all
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 "bindings/core/v8/ExceptionMessages.h" 25 #include "bindings/core/v8/ExceptionMessages.h"
26 #include "bindings/core/v8/ExceptionState.h" 26 #include "bindings/core/v8/ExceptionState.h"
27 #include "core/dom/ExceptionCode.h" 27 #include "core/dom/ExceptionCode.h"
28 #include "core/frame/UseCounter.h" 28 #include "core/frame/UseCounter.h"
29 #include "modules/webaudio/AudioBufferSourceNode.h" 29 #include "modules/webaudio/AudioBufferSourceNode.h"
30 #include "modules/webaudio/AudioNodeOutput.h" 30 #include "modules/webaudio/AudioNodeOutput.h"
31 #include "modules/webaudio/BaseAudioContext.h" 31 #include "modules/webaudio/BaseAudioContext.h"
32 #include "platform/FloatConversion.h"
33 #include "platform/audio/AudioUtilities.h" 32 #include "platform/audio/AudioUtilities.h"
34 #include "wtf/MathExtras.h" 33 #include "wtf/MathExtras.h"
35 #include "wtf/PtrUtil.h" 34 #include "wtf/PtrUtil.h"
36 #include <algorithm> 35 #include <algorithm>
37 36
38 namespace blink { 37 namespace blink {
39 38
40 const double DefaultGrainDuration = 0.020; // 20ms 39 const double DefaultGrainDuration = 0.020; // 20ms
41 40
42 // Arbitrary upper limit on playback rate. 41 // Arbitrary upper limit on playback rate.
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 307
309 // Linear interpolation. 308 // Linear interpolation.
310 for (unsigned i = 0; i < numberOfChannels; ++i) { 309 for (unsigned i = 0; i < numberOfChannels; ++i) {
311 float* destination = destinationChannels[i]; 310 float* destination = destinationChannels[i];
312 const float* source = sourceChannels[i]; 311 const float* source = sourceChannels[i];
313 312
314 double sample1 = source[readIndex]; 313 double sample1 = source[readIndex];
315 double sample2 = source[readIndex2]; 314 double sample2 = source[readIndex2];
316 double sample = (1.0 - interpolationFactor) * sample1 + interpol ationFactor * sample2; 315 double sample = (1.0 - interpolationFactor) * sample1 + interpol ationFactor * sample2;
317 316
318 destination[writeIndex] = narrowPrecisionToFloat(sample); 317 destination[writeIndex] = clampTo<float>(sample);
319 } 318 }
320 writeIndex++; 319 writeIndex++;
321 320
322 virtualReadIndex += computedPlaybackRate; 321 virtualReadIndex += computedPlaybackRate;
323 322
324 // Wrap-around, retaining sub-sample position since virtualReadIndex is floating-point. 323 // Wrap-around, retaining sub-sample position since virtualReadIndex is floating-point.
325 if (virtualReadIndex >= virtualEndFrame) { 324 if (virtualReadIndex >= virtualEndFrame) {
326 virtualReadIndex -= virtualDeltaFrames; 325 virtualReadIndex -= virtualDeltaFrames;
327 if (renderSilenceAndFinishIfNotLooping(bus, writeIndex, framesTo Process)) 326 if (renderSilenceAndFinishIfNotLooping(bus, writeIndex, framesTo Process))
328 break; 327 break;
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 { 689 {
691 audioBufferSourceHandler().start(when, grainOffset, exceptionState); 690 audioBufferSourceHandler().start(when, grainOffset, exceptionState);
692 } 691 }
693 692
694 void AudioBufferSourceNode::start(double when, double grainOffset, double grainD uration, ExceptionState& exceptionState) 693 void AudioBufferSourceNode::start(double when, double grainOffset, double grainD uration, ExceptionState& exceptionState)
695 { 694 {
696 audioBufferSourceHandler().start(when, grainOffset, grainDuration, exception State); 695 audioBufferSourceHandler().start(when, grainOffset, grainDuration, exception State);
697 } 696 }
698 697
699 } // namespace blink 698 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698