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

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/OscillatorNode.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
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/ConstantSourceNode.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 } 232 }
233 233
234 // We must access m_periodicWave only inside the lock. 234 // We must access m_periodicWave only inside the lock.
235 if (!m_periodicWave.get()) { 235 if (!m_periodicWave.get()) {
236 outputBus->zero(); 236 outputBus->zero();
237 return; 237 return;
238 } 238 }
239 239
240 size_t quantumFrameOffset; 240 size_t quantumFrameOffset;
241 size_t nonSilentFramesToProcess; 241 size_t nonSilentFramesToProcess;
242 double startFrameOffset;
242 243
243 updateSchedulingInfo(framesToProcess, outputBus, quantumFrameOffset, 244 updateSchedulingInfo(framesToProcess, outputBus, quantumFrameOffset,
244 nonSilentFramesToProcess); 245 nonSilentFramesToProcess, startFrameOffset);
245 246
246 if (!nonSilentFramesToProcess) { 247 if (!nonSilentFramesToProcess) {
247 outputBus->zero(); 248 outputBus->zero();
248 return; 249 return;
249 } 250 }
250 251
251 unsigned periodicWaveSize = m_periodicWave->periodicWaveSize(); 252 unsigned periodicWaveSize = m_periodicWave->periodicWaveSize();
252 double invPeriodicWaveSize = 1.0 / periodicWaveSize; 253 double invPeriodicWaveSize = 1.0 / periodicWaveSize;
253 254
254 float* destP = outputBus->channel(0)->mutableData(); 255 float* destP = outputBus->channel(0)->mutableData();
(...skipping 24 matching lines...) Expand all
279 280
280 float incr = frequency * rateScale; 281 float incr = frequency * rateScale;
281 float* phaseIncrements = m_phaseIncrements.data(); 282 float* phaseIncrements = m_phaseIncrements.data();
282 283
283 unsigned readIndexMask = periodicWaveSize - 1; 284 unsigned readIndexMask = periodicWaveSize - 1;
284 285
285 // Start rendering at the correct offset. 286 // Start rendering at the correct offset.
286 destP += quantumFrameOffset; 287 destP += quantumFrameOffset;
287 int n = nonSilentFramesToProcess; 288 int n = nonSilentFramesToProcess;
288 289
290 // If startFrameOffset is not 0, that means the oscillator doesn't actually
291 // start at quantumFrameOffset, but just past that time. Adjust destP and n
292 // to reflect that, and adjust virtualReadIndex to start the value at
293 // startFrameOffset.
294 if (startFrameOffset > 0) {
295 ++destP;
296 --n;
297 virtualReadIndex += (1 - startFrameOffset) * frequency * rateScale;
298 DCHECK(virtualReadIndex < periodicWaveSize);
299 } else if (startFrameOffset < 0) {
300 virtualReadIndex = -startFrameOffset * frequency * rateScale;
301 }
302
289 while (n--) { 303 while (n--) {
290 unsigned readIndex = static_cast<unsigned>(virtualReadIndex); 304 unsigned readIndex = static_cast<unsigned>(virtualReadIndex);
291 unsigned readIndex2 = readIndex + 1; 305 unsigned readIndex2 = readIndex + 1;
292 306
293 // Contain within valid range. 307 // Contain within valid range.
294 readIndex = readIndex & readIndexMask; 308 readIndex = readIndex & readIndexMask;
295 readIndex2 = readIndex2 & readIndexMask; 309 readIndex2 = readIndex2 & readIndexMask;
296 310
297 if (hasSampleAccurateValues) { 311 if (hasSampleAccurateValues) {
298 incr = *phaseIncrements++; 312 incr = *phaseIncrements++;
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 458
445 AudioParam* OscillatorNode::detune() { 459 AudioParam* OscillatorNode::detune() {
446 return m_detune; 460 return m_detune;
447 } 461 }
448 462
449 void OscillatorNode::setPeriodicWave(PeriodicWave* wave) { 463 void OscillatorNode::setPeriodicWave(PeriodicWave* wave) {
450 oscillatorHandler().setPeriodicWave(wave); 464 oscillatorHandler().setPeriodicWave(wave);
451 } 465 }
452 466
453 } // namespace blink 467 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/ConstantSourceNode.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698