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

--HG--
extra : rebase_source : 18e01ed739bb505f7825c3d79e00c8552a70fad0
This commit is contained in:
Ehsan Akhgari 2013-05-24 13:11:18 -04:00
parent c3f2357a32
commit 7243e880a5
2 changed files with 10 additions and 6 deletions

View File

@ -20,24 +20,26 @@ struct ConvertTimeToTickHelper
{
ConvertTimeToTickHelper* This = static_cast<ConvertTimeToTickHelper*> (aClosure);
if (This->mSourceStream) {
MOZ_ASSERT(This->mSourceStream->SampleRate() == This->mDestinationStream->SampleRate());
return WebAudioUtils::ConvertDestinationStreamTimeToSourceStreamTime(
aTime, This->mSourceStream, This->mDestinationStream);
} else {
StreamTime streamTime = This->mDestinationStream->GetCurrentPosition();
return TimeToTicksRoundUp(IdealAudioRate(), streamTime + SecondsToMediaTime(aTime));
TrackRate sampleRate = This->mDestinationStream->SampleRate();
return TimeToTicksRoundUp(sampleRate, streamTime + SecondsToMediaTime(aTime));
}
}
};
TrackTicks
WebAudioUtils::ConvertDestinationStreamTimeToSourceStreamTime(double aTime,
MediaStream* aSource,
AudioNodeStream* aSource,
MediaStream* aDestination)
{
StreamTime streamTime = std::max<MediaTime>(0, SecondsToMediaTime(aTime));
GraphTime graphTime = aDestination->StreamTimeToGraphTime(streamTime);
StreamTime thisStreamTime = aSource->GraphTimeToStreamTimeOptimistic(graphTime);
TrackTicks ticks = TimeToTicksRoundUp(IdealAudioRate(), thisStreamTime);
TrackTicks ticks = TimeToTicksRoundUp(aSource->SampleRate(), thisStreamTime);
return ticks;
}
@ -46,7 +48,8 @@ WebAudioUtils::StreamPositionToDestinationTime(TrackTicks aSourcePosition,
AudioNodeStream* aSource,
AudioNodeStream* aDestination)
{
StreamTime sourceTime = TicksToTimeRoundDown(IdealAudioRate(), aSourcePosition);
MOZ_ASSERT(aSource->SampleRate() == aDestination->SampleRate());
StreamTime sourceTime = TicksToTimeRoundDown(aSource->SampleRate(), aSourcePosition);
GraphTime graphTime = aSource->StreamTimeToGraphTime(sourceTime);
StreamTime destinationTime = aDestination->GraphTimeToStreamTimeOptimistic(graphTime);
return MediaTimeToSeconds(destinationTime);
@ -57,10 +60,11 @@ WebAudioUtils::ConvertAudioParamToTicks(AudioParamTimeline& aParam,
AudioNodeStream* aSource,
AudioNodeStream* aDest)
{
MOZ_ASSERT(!aSource || aSource->SampleRate() == aDest->SampleRate());
ConvertTimeToTickHelper ctth;
ctth.mSourceStream = aSource;
ctth.mDestinationStream = aDest;
aParam.ConvertEventTimesToTicks(ConvertTimeToTickHelper::Convert, &ctth, IdealAudioRate());
aParam.ConvertEventTimesToTicks(ConvertTimeToTickHelper::Convert, &ctth, aDest->SampleRate());
}
}

View File

@ -47,7 +47,7 @@ struct WebAudioUtils {
*/
static TrackTicks
ConvertDestinationStreamTimeToSourceStreamTime(double aTime,
MediaStream* aSource,
AudioNodeStream* aSource,
MediaStream* aDestination);
/**