Bug 873553 - Part 9: Port WebAudioUtils to use the stream's sampling rate; r=roc
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 24 May 2013 13:11:18 -0400
changeset 132929 0d624598cc17f7399d4151eb13be17a6354a7705
parent 132928 a10e7a43eebfe766586fa03e32525431f4b64738
child 132930 976545bf713e1438833a544efe4b91f308d8e5f2
push id24727
push userphilringnalda@gmail.com
push dateSun, 26 May 2013 04:02:45 +0000
treeherdermozilla-central@0fed3377c839 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs873553
milestone24.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 873553 - Part 9: Port WebAudioUtils to use the stream's sampling rate; r=roc
content/media/webaudio/WebAudioUtils.cpp
content/media/webaudio/WebAudioUtils.h
--- a/content/media/webaudio/WebAudioUtils.cpp
+++ b/content/media/webaudio/WebAudioUtils.cpp
@@ -15,53 +15,57 @@ struct ConvertTimeToTickHelper
 {
   AudioNodeStream* mSourceStream;
   AudioNodeStream* mDestinationStream;
 
   static int64_t Convert(double aTime, void* aClosure)
   {
     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;
 }
 
 double
 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);
 }
 
 void
 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());
 }
 
 }
 }
--- a/content/media/webaudio/WebAudioUtils.h
+++ b/content/media/webaudio/WebAudioUtils.h
@@ -42,17 +42,17 @@ struct WebAudioUtils {
   }
 
   /**
    * Convert a time in second relative to the destination stream to
    * TrackTicks relative to the source stream.
    */
   static TrackTicks
   ConvertDestinationStreamTimeToSourceStreamTime(double aTime,
-                                                 MediaStream* aSource,
+                                                 AudioNodeStream* aSource,
                                                  MediaStream* aDestination);
 
   /**
    * Converts AudioParamTimeline floating point time values to tick values
    * with respect to a source and a destination AudioNodeStream.
    *
    * This needs to be called for each AudioParamTimeline that gets sent to an
    * AudioNodeEngine on the engine side where the AudioParamTimeline is