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

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

Issue 2186813003: Sub-sample accurate start of OscillatorNode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adjust thresholds for Mac 10.11 (retina) Created 3 years, 11 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) 2012, Google Inc. All rights reserved. 2 * Copyright (C) 2012, 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 float sampleRate) 43 float sampleRate)
44 : AudioHandler(nodeType, node, sampleRate), 44 : AudioHandler(nodeType, node, sampleRate),
45 m_startTime(0), 45 m_startTime(0),
46 m_endTime(UnknownTime), 46 m_endTime(UnknownTime),
47 m_playbackState(UNSCHEDULED_STATE) {} 47 m_playbackState(UNSCHEDULED_STATE) {}
48 48
49 void AudioScheduledSourceHandler::updateSchedulingInfo( 49 void AudioScheduledSourceHandler::updateSchedulingInfo(
50 size_t quantumFrameSize, 50 size_t quantumFrameSize,
51 AudioBus* outputBus, 51 AudioBus* outputBus,
52 size_t& quantumFrameOffset, 52 size_t& quantumFrameOffset,
53 size_t& nonSilentFramesToProcess) { 53 size_t& nonSilentFramesToProcess,
54 double& startFrameOffset) {
54 DCHECK(outputBus); 55 DCHECK(outputBus);
55 if (!outputBus) 56 if (!outputBus)
56 return; 57 return;
57 58
58 DCHECK_EQ(quantumFrameSize, 59 DCHECK_EQ(quantumFrameSize,
59 static_cast<size_t>(AudioUtilities::kRenderQuantumFrames)); 60 static_cast<size_t>(AudioUtilities::kRenderQuantumFrames));
60 if (quantumFrameSize != AudioUtilities::kRenderQuantumFrames) 61 if (quantumFrameSize != AudioUtilities::kRenderQuantumFrames)
61 return; 62 return;
62 63
63 double sampleRate = this->sampleRate(); 64 double sampleRate = this->sampleRate();
(...skipping 23 matching lines...) Expand all
87 outputBus->zero(); 88 outputBus->zero();
88 nonSilentFramesToProcess = 0; 89 nonSilentFramesToProcess = 0;
89 return; 90 return;
90 } 91 }
91 92
92 // Check if it's time to start playing. 93 // Check if it's time to start playing.
93 if (state == SCHEDULED_STATE) { 94 if (state == SCHEDULED_STATE) {
94 // Increment the active source count only if we're transitioning from 95 // Increment the active source count only if we're transitioning from
95 // SCHEDULED_STATE to PLAYING_STATE. 96 // SCHEDULED_STATE to PLAYING_STATE.
96 setPlaybackState(PLAYING_STATE); 97 setPlaybackState(PLAYING_STATE);
98 // Determine the offset of the true start time from the starting frame.
99 startFrameOffset = m_startTime * sampleRate - startFrame;
100 } else {
101 startFrameOffset = 0;
97 } 102 }
98 103
99 quantumFrameOffset = 104 quantumFrameOffset =
100 startFrame > quantumStartFrame ? startFrame - quantumStartFrame : 0; 105 startFrame > quantumStartFrame ? startFrame - quantumStartFrame : 0;
101 quantumFrameOffset = 106 quantumFrameOffset =
102 std::min(quantumFrameOffset, quantumFrameSize); // clamp to valid range 107 std::min(quantumFrameOffset, quantumFrameSize); // clamp to valid range
103 nonSilentFramesToProcess = quantumFrameSize - quantumFrameOffset; 108 nonSilentFramesToProcess = quantumFrameSize - quantumFrameOffset;
104 109
105 if (!nonSilentFramesToProcess) { 110 if (!nonSilentFramesToProcess) {
106 // Output silence. 111 // Output silence.
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 // playback state if the context is closed. 280 // playback state if the context is closed.
276 if (context()->isContextClosed()) 281 if (context()->isContextClosed())
277 return false; 282 return false;
278 283
279 // If a node is scheduled or playing, do not collect the node prematurely 284 // If a node is scheduled or playing, do not collect the node prematurely
280 // even its reference is out of scope. Then fire onended event if assigned. 285 // even its reference is out of scope. Then fire onended event if assigned.
281 return audioScheduledSourceHandler().isPlayingOrScheduled(); 286 return audioScheduledSourceHandler().isPlayingOrScheduled();
282 } 287 }
283 288
284 } // namespace blink 289 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698