Bug 873553 - Part 7: Port DelayNode to use the stream's sampling rate; r=roc

--HG--
extra : rebase_source : db35f08edab8a54c6c60a0ead2d7afed59d2c360
This commit is contained in:
Ehsan Akhgari 2013-05-24 13:10:44 -04:00
Родитель 544f957035
Коммит 8e9878cd1b
1 изменённых файлов: 6 добавлений и 6 удалений

Просмотреть файл

@ -107,7 +107,7 @@ public:
}
}
bool EnsureBuffer(uint32_t aNumberOfChannels)
bool EnsureBuffer(uint32_t aNumberOfChannels, TrackRate aSampleRate)
{
if (aNumberOfChannels == 0) {
return false;
@ -116,7 +116,7 @@ public:
if (!mBuffer.SetLength(aNumberOfChannels)) {
return false;
}
const int32_t numFrames = NS_lround(mMaxDelay) * IdealAudioRate();
const int32_t numFrames = NS_lround(mMaxDelay) * aSampleRate;
for (uint32_t channel = 0; channel < aNumberOfChannels; ++channel) {
if (!mBuffer[channel].SetLength(numFrames)) {
return false;
@ -146,7 +146,7 @@ public:
if (!mBuffer.IsEmpty() &&
mLeftOverData == INT32_MIN &&
aStream->AllInputsFinished()) {
mLeftOverData = static_cast<int32_t>(mCurrentDelayTime * IdealAudioRate()) - WEBAUDIO_BLOCK_SIZE;
mLeftOverData = static_cast<int32_t>(mCurrentDelayTime * aStream->SampleRate()) - WEBAUDIO_BLOCK_SIZE;
if (mLeftOverData > 0) {
nsRefPtr<PlayingRefChanged> refchanged =
@ -165,7 +165,7 @@ public:
}
}
if (!EnsureBuffer(numChannels)) {
if (!EnsureBuffer(numChannels, aStream->SampleRate())) {
aOutput->SetNull(0);
return;
}
@ -175,7 +175,7 @@ public:
double delayTime = 0;
float computedDelay[WEBAUDIO_BLOCK_SIZE];
// Use a smoothing range of 20ms
const double smoothingRate = WebAudioUtils::ComputeSmoothingRate(0.02, IdealAudioRate());
const double smoothingRate = WebAudioUtils::ComputeSmoothingRate(0.02, aStream->SampleRate());
if (mDelay.HasSimpleValue()) {
delayTime = std::max(0.0, std::min(mMaxDelay, double(mDelay.GetValue())));
@ -219,7 +219,7 @@ public:
// from currentDelayTime seconds in the past. We also interpolate the two input
// frames in case the read position does not match an integer index.
double readPosition = writeIndex + bufferLength -
(currentDelayTime * IdealAudioRate());
(currentDelayTime * aStream->SampleRate());
if (readPosition >= bufferLength) {
readPosition -= bufferLength;
}