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

Unified Diff: Source/modules/webaudio/OscillatorNode.cpp

Issue 1256053006: Protect AudioScheduledSoureNode::m_startTime and m_endTime. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Use tryLock instead of atomic access Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/webaudio/OscillatorNode.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/webaudio/OscillatorNode.cpp
diff --git a/Source/modules/webaudio/OscillatorNode.cpp b/Source/modules/webaudio/OscillatorNode.cpp
index b62f8244ce254e74767da1609ebf8843b84d99a3..b62e7915f5b50d7c6f766e3e028a624d9bc9e24e 100644
--- a/Source/modules/webaudio/OscillatorNode.cpp
+++ b/Source/modules/webaudio/OscillatorNode.cpp
@@ -226,102 +226,104 @@ void OscillatorHandler::process(size_t framesToProcess)
// The audio thread can't block on this lock, so we call tryLock() instead.
MutexTryLocker tryLocker(m_processLock);
- if (!tryLocker.locked()) {
- // Too bad - the tryLock() failed. We must be in the middle of changing wave-tables.
- outputBus->zero();
- return;
- }
+ if (tryLocker.locked()) {
tkent 2015/09/11 00:02:00 Is this change necessary? The scope of tryLocker
- // We must access m_periodicWave only inside the lock.
- if (!m_periodicWave.get()) {
- outputBus->zero();
- return;
- }
+ // We must access m_periodicWave only inside the lock.
+ if (!m_periodicWave.get()) {
+ outputBus->zero();
+ return;
+ }
- size_t quantumFrameOffset;
- size_t nonSilentFramesToProcess;
+ size_t quantumFrameOffset;
+ size_t nonSilentFramesToProcess;
- updateSchedulingInfo(framesToProcess, outputBus, quantumFrameOffset, nonSilentFramesToProcess);
+ updateSchedulingInfo(framesToProcess, outputBus, quantumFrameOffset, nonSilentFramesToProcess);
- if (!nonSilentFramesToProcess) {
- outputBus->zero();
- return;
- }
+ if (!nonSilentFramesToProcess) {
+ outputBus->zero();
+ return;
+ }
- unsigned periodicWaveSize = m_periodicWave->periodicWaveSize();
- double invPeriodicWaveSize = 1.0 / periodicWaveSize;
+ unsigned periodicWaveSize = m_periodicWave->periodicWaveSize();
+ double invPeriodicWaveSize = 1.0 / periodicWaveSize;
- float* destP = outputBus->channel(0)->mutableData();
+ float* destP = outputBus->channel(0)->mutableData();
- ASSERT(quantumFrameOffset <= framesToProcess);
+ ASSERT(quantumFrameOffset <= framesToProcess);
- // We keep virtualReadIndex double-precision since we're accumulating values.
- double virtualReadIndex = m_virtualReadIndex;
+ // We keep virtualReadIndex double-precision since we're accumulating values.
+ double virtualReadIndex = m_virtualReadIndex;
- float rateScale = m_periodicWave->rateScale();
- float invRateScale = 1 / rateScale;
- bool hasSampleAccurateValues = calculateSampleAccuratePhaseIncrements(framesToProcess);
+ float rateScale = m_periodicWave->rateScale();
+ float invRateScale = 1 / rateScale;
+ bool hasSampleAccurateValues = calculateSampleAccuratePhaseIncrements(framesToProcess);
- float frequency = 0;
- float* higherWaveData = 0;
- float* lowerWaveData = 0;
- float tableInterpolationFactor = 0;
+ float frequency = 0;
+ float* higherWaveData = 0;
+ float* lowerWaveData = 0;
+ float tableInterpolationFactor = 0;
- if (!hasSampleAccurateValues) {
- frequency = m_frequency->smoothedValue();
- float detune = m_detune->smoothedValue();
- float detuneScale = powf(2, detune / 1200);
- frequency *= detuneScale;
- m_periodicWave->waveDataForFundamentalFrequency(frequency, lowerWaveData, higherWaveData, tableInterpolationFactor);
- }
+ if (!hasSampleAccurateValues) {
+ frequency = m_frequency->smoothedValue();
+ float detune = m_detune->smoothedValue();
+ float detuneScale = powf(2, detune / 1200);
+ frequency *= detuneScale;
+ m_periodicWave->waveDataForFundamentalFrequency(frequency, lowerWaveData, higherWaveData, tableInterpolationFactor);
+ }
- float incr = frequency * rateScale;
- float* phaseIncrements = m_phaseIncrements.data();
+ float incr = frequency * rateScale;
+ float* phaseIncrements = m_phaseIncrements.data();
- unsigned readIndexMask = periodicWaveSize - 1;
+ unsigned readIndexMask = periodicWaveSize - 1;
- // Start rendering at the correct offset.
- destP += quantumFrameOffset;
- int n = nonSilentFramesToProcess;
+ // Start rendering at the correct offset.
+ destP += quantumFrameOffset;
+ int n = nonSilentFramesToProcess;
- while (n--) {
- unsigned readIndex = static_cast<unsigned>(virtualReadIndex);
- unsigned readIndex2 = readIndex + 1;
+ while (n--) {
+ unsigned readIndex = static_cast<unsigned>(virtualReadIndex);
+ unsigned readIndex2 = readIndex + 1;
- // Contain within valid range.
- readIndex = readIndex & readIndexMask;
- readIndex2 = readIndex2 & readIndexMask;
+ // Contain within valid range.
+ readIndex = readIndex & readIndexMask;
+ readIndex2 = readIndex2 & readIndexMask;
- if (hasSampleAccurateValues) {
- incr = *phaseIncrements++;
+ if (hasSampleAccurateValues) {
+ incr = *phaseIncrements++;
- frequency = invRateScale * incr;
- m_periodicWave->waveDataForFundamentalFrequency(frequency, lowerWaveData, higherWaveData, tableInterpolationFactor);
- }
+ frequency = invRateScale * incr;
+ m_periodicWave->waveDataForFundamentalFrequency(frequency, lowerWaveData, higherWaveData, tableInterpolationFactor);
+ }
- float sample1Lower = lowerWaveData[readIndex];
- float sample2Lower = lowerWaveData[readIndex2];
- float sample1Higher = higherWaveData[readIndex];
- float sample2Higher = higherWaveData[readIndex2];
+ float sample1Lower = lowerWaveData[readIndex];
+ float sample2Lower = lowerWaveData[readIndex2];
+ float sample1Higher = higherWaveData[readIndex];
+ float sample2Higher = higherWaveData[readIndex2];
- // Linearly interpolate within each table (lower and higher).
- float interpolationFactor = static_cast<float>(virtualReadIndex) - readIndex;
- float sampleHigher = (1 - interpolationFactor) * sample1Higher + interpolationFactor * sample2Higher;
- float sampleLower = (1 - interpolationFactor) * sample1Lower + interpolationFactor * sample2Lower;
+ // Linearly interpolate within each table (lower and higher).
+ float interpolationFactor = static_cast<float>(virtualReadIndex) - readIndex;
+ float sampleHigher = (1 - interpolationFactor) * sample1Higher + interpolationFactor * sample2Higher;
+ float sampleLower = (1 - interpolationFactor) * sample1Lower + interpolationFactor * sample2Lower;
- // Then interpolate between the two tables.
- float sample = (1 - tableInterpolationFactor) * sampleHigher + tableInterpolationFactor * sampleLower;
+ // Then interpolate between the two tables.
+ float sample = (1 - tableInterpolationFactor) * sampleHigher + tableInterpolationFactor * sampleLower;
- *destP++ = sample;
+ *destP++ = sample;
- // Increment virtual read index and wrap virtualReadIndex into the range 0 -> periodicWaveSize.
- virtualReadIndex += incr;
- virtualReadIndex -= floor(virtualReadIndex * invPeriodicWaveSize) * periodicWaveSize;
- }
+ // Increment virtual read index and wrap virtualReadIndex into the range 0 -> periodicWaveSize.
+ virtualReadIndex += incr;
+ virtualReadIndex -= floor(virtualReadIndex * invPeriodicWaveSize) * periodicWaveSize;
+ }
- m_virtualReadIndex = virtualReadIndex;
+ m_virtualReadIndex = virtualReadIndex;
- outputBus->clearSilentFlag();
+ outputBus->clearSilentFlag();
+ } else {
+ // Too bad - the tryLock() failed. We must be in the middle of changing wave-tables or
+ // updating scheduling.
+ outputBus->zero();
+ return;
+ }
}
void OscillatorHandler::setPeriodicWave(PeriodicWave* periodicWave)
« no previous file with comments | « Source/modules/webaudio/OscillatorNode.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698