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/. */
|
|
|
|
|
|
|
|
#ifndef AudioParamTimeline_h_
|
|
|
|
#define AudioParamTimeline_h_
|
|
|
|
|
|
|
|
#include "AudioEventTimeline.h"
|
|
|
|
#include "mozilla/ErrorResult.h"
|
2013-05-01 18:02:31 -07:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "MediaStreamGraph.h"
|
2013-05-01 20:12:59 -07:00
|
|
|
#include "AudioSegment.h"
|
2013-03-21 21:01:28 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
2013-05-01 18:02:31 -07:00
|
|
|
// This helper class is used to represent the part of the AudioParam
|
|
|
|
// class that gets sent to AudioNodeEngine instances. In addition to
|
|
|
|
// AudioEventTimeline methods, it holds a pointer to an optional
|
|
|
|
// MediaStream which represents the AudioNode inputs to the AudioParam.
|
|
|
|
// This MediaStream is managed by the AudioParam subclass on the main
|
|
|
|
// thread, and can only be obtained from the AudioNodeEngine instances
|
|
|
|
// consuming this class.
|
|
|
|
class AudioParamTimeline : public AudioEventTimeline<ErrorResult>
|
|
|
|
{
|
2013-05-01 20:12:59 -07:00
|
|
|
typedef AudioEventTimeline<ErrorResult> BaseClass;
|
|
|
|
|
2013-05-01 18:02:31 -07:00
|
|
|
public:
|
|
|
|
explicit AudioParamTimeline(float aDefaultValue)
|
2013-05-01 20:12:59 -07:00
|
|
|
: BaseClass(aDefaultValue)
|
2013-05-01 18:02:31 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaStream* Stream() const
|
|
|
|
{
|
|
|
|
return mStream;
|
|
|
|
}
|
|
|
|
|
2013-05-01 20:12:59 -07:00
|
|
|
bool HasSimpleValue() const
|
|
|
|
{
|
|
|
|
return BaseClass::HasSimpleValue() && !mStream;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the value of the AudioParam at time aTime + aCounter.
|
|
|
|
// aCounter here is an offset to aTime if we try to get the value in ticks,
|
|
|
|
// otherwise it should always be zero. aCounter is meant to be used when
|
|
|
|
// getting the value of an a-rate AudioParam for each tick inside an
|
|
|
|
// AudioNodeEngine implementation.
|
|
|
|
template<class TimeType>
|
2013-08-09 06:11:03 -07:00
|
|
|
float GetValueAtTime(TimeType aTime, size_t aCounter = 0)
|
2013-05-01 20:12:59 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aCounter < WEBAUDIO_BLOCK_SIZE);
|
|
|
|
MOZ_ASSERT(!aCounter || !HasSimpleValue());
|
|
|
|
|
|
|
|
// Mix the value of the AudioParam itself with that of the AudioNode inputs.
|
|
|
|
return BaseClass::GetValueAtTime(static_cast<TimeType>(aTime + aCounter)) +
|
|
|
|
(mStream ? AudioNodeInputValue(aCounter) : 0.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
float AudioNodeInputValue(size_t aCounter) const;
|
|
|
|
|
2013-05-01 18:02:31 -07:00
|
|
|
protected:
|
|
|
|
// This is created lazily when needed.
|
|
|
|
nsRefPtr<MediaStream> mStream;
|
|
|
|
};
|
2013-03-21 21:01:28 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|