2013-03-21 21:01:28 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "WebAudioUtils.h"
|
|
|
|
#include "AudioNodeStream.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
struct ConvertTimeToTickHelper
|
|
|
|
{
|
|
|
|
AudioNodeStream* mSourceStream;
|
|
|
|
AudioNodeStream* mDestinationStream;
|
|
|
|
|
|
|
|
static int64_t Convert(double aTime, void* aClosure)
|
|
|
|
{
|
|
|
|
ConvertTimeToTickHelper* This = static_cast<ConvertTimeToTickHelper*> (aClosure);
|
2013-07-12 02:23:21 -07:00
|
|
|
MOZ_ASSERT(This->mSourceStream->SampleRate() == This->mDestinationStream->SampleRate());
|
|
|
|
return WebAudioUtils::ConvertDestinationStreamTimeToSourceStreamTime(
|
|
|
|
aTime, This->mSourceStream, This->mDestinationStream);
|
2013-03-21 21:01:28 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-05-07 20:31:15 -07:00
|
|
|
TrackTicks
|
|
|
|
WebAudioUtils::ConvertDestinationStreamTimeToSourceStreamTime(double aTime,
|
2013-05-24 10:11:18 -07:00
|
|
|
AudioNodeStream* aSource,
|
2013-05-07 20:31:15 -07:00
|
|
|
MediaStream* aDestination)
|
|
|
|
{
|
|
|
|
StreamTime streamTime = std::max<MediaTime>(0, SecondsToMediaTime(aTime));
|
|
|
|
GraphTime graphTime = aDestination->StreamTimeToGraphTime(streamTime);
|
|
|
|
StreamTime thisStreamTime = aSource->GraphTimeToStreamTimeOptimistic(graphTime);
|
2013-05-24 10:11:18 -07:00
|
|
|
TrackTicks ticks = TimeToTicksRoundUp(aSource->SampleRate(), thisStreamTime);
|
2013-05-07 20:31:15 -07:00
|
|
|
return ticks;
|
|
|
|
}
|
|
|
|
|
2013-04-13 18:37:04 -07:00
|
|
|
double
|
|
|
|
WebAudioUtils::StreamPositionToDestinationTime(TrackTicks aSourcePosition,
|
|
|
|
AudioNodeStream* aSource,
|
|
|
|
AudioNodeStream* aDestination)
|
|
|
|
{
|
2013-05-24 10:11:18 -07:00
|
|
|
MOZ_ASSERT(aSource->SampleRate() == aDestination->SampleRate());
|
|
|
|
StreamTime sourceTime = TicksToTimeRoundDown(aSource->SampleRate(), aSourcePosition);
|
2013-04-13 18:37:04 -07:00
|
|
|
GraphTime graphTime = aSource->StreamTimeToGraphTime(sourceTime);
|
|
|
|
StreamTime destinationTime = aDestination->GraphTimeToStreamTimeOptimistic(graphTime);
|
|
|
|
return MediaTimeToSeconds(destinationTime);
|
|
|
|
}
|
|
|
|
|
2013-03-21 21:01:28 -07:00
|
|
|
void
|
|
|
|
WebAudioUtils::ConvertAudioParamToTicks(AudioParamTimeline& aParam,
|
|
|
|
AudioNodeStream* aSource,
|
|
|
|
AudioNodeStream* aDest)
|
|
|
|
{
|
2013-05-24 10:11:18 -07:00
|
|
|
MOZ_ASSERT(!aSource || aSource->SampleRate() == aDest->SampleRate());
|
2013-03-21 21:01:28 -07:00
|
|
|
ConvertTimeToTickHelper ctth;
|
|
|
|
ctth.mSourceStream = aSource;
|
|
|
|
ctth.mDestinationStream = aDest;
|
2013-05-24 10:11:18 -07:00
|
|
|
aParam.ConvertEventTimesToTicks(ConvertTimeToTickHelper::Convert, &ctth, aDest->SampleRate());
|
2013-03-21 21:01:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|