2012-09-18 16:07:33 -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/. */
|
|
|
|
|
2012-10-30 14:39:38 -07:00
|
|
|
#ifndef AudioBufferSourceNode_h_
|
|
|
|
#define AudioBufferSourceNode_h_
|
2012-09-18 16:07:33 -07:00
|
|
|
|
2013-04-08 19:45:02 -07:00
|
|
|
#include "AudioNode.h"
|
2012-09-24 20:31:58 -07:00
|
|
|
#include "AudioBuffer.h"
|
2013-04-11 05:47:57 -07:00
|
|
|
#include "AudioParam.h"
|
2013-02-04 15:07:25 -08:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2012-09-18 16:07:33 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-04-08 19:45:02 -07:00
|
|
|
class AudioBufferSourceNode : public AudioNode,
|
2013-02-04 15:07:25 -08:00
|
|
|
public MainThreadMediaStreamListener
|
2012-09-18 16:07:33 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AudioBufferSourceNode(AudioContext* aContext);
|
2013-04-22 05:58:32 -07:00
|
|
|
virtual ~AudioBufferSourceNode();
|
2013-02-04 15:07:25 -08:00
|
|
|
|
|
|
|
virtual void DestroyMediaStream() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
if (mStream) {
|
|
|
|
mStream->RemoveMainThreadListener(this);
|
|
|
|
}
|
2013-04-08 19:45:02 -07:00
|
|
|
AudioNode::DestroyMediaStream();
|
2013-02-04 15:07:25 -08:00
|
|
|
}
|
2013-01-25 13:39:51 -08:00
|
|
|
virtual bool SupportsMediaStreams() const MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2013-04-08 19:45:02 -07:00
|
|
|
virtual uint32_t NumberOfInputs() const MOZ_FINAL MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2013-04-11 05:47:57 -07:00
|
|
|
virtual AudioBufferSourceNode* AsAudioBufferSourceNode() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnregisterPannerNode() {
|
|
|
|
mPannerNode = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegisterPannerNode(PannerNode* aPannerNode) {
|
|
|
|
mPannerNode = aPannerNode;
|
|
|
|
}
|
2013-04-01 13:06:55 -07:00
|
|
|
|
2012-09-18 16:07:33 -07:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2013-04-08 19:45:02 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioBufferSourceNode, AudioNode)
|
2012-09-24 20:31:58 -07:00
|
|
|
|
2013-01-23 16:50:18 -08:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope);
|
2012-09-18 16:07:33 -07:00
|
|
|
|
2013-04-22 14:01:22 -07:00
|
|
|
void Start(double aWhen, double aOffset,
|
2013-02-04 15:07:25 -08:00
|
|
|
const Optional<double>& aDuration, ErrorResult& aRv);
|
2013-04-22 14:01:22 -07:00
|
|
|
void NoteOn(double aWhen, ErrorResult& aRv)
|
2013-04-11 19:08:05 -07:00
|
|
|
{
|
2013-04-22 14:01:22 -07:00
|
|
|
Start(aWhen, 0.0, Optional<double>(), aRv);
|
2013-04-11 19:08:05 -07:00
|
|
|
}
|
2013-04-22 14:01:22 -07:00
|
|
|
void NoteGrainOn(double aWhen, double aOffset,
|
2013-04-11 19:08:05 -07:00
|
|
|
double aDuration, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
Optional<double> duration;
|
|
|
|
duration.Construct(aDuration);
|
2013-04-22 14:01:22 -07:00
|
|
|
Start(aWhen, aOffset, duration, aRv);
|
2013-04-11 19:08:05 -07:00
|
|
|
}
|
2013-02-04 15:07:25 -08:00
|
|
|
void Stop(double aWhen, ErrorResult& aRv);
|
2013-04-11 19:08:05 -07:00
|
|
|
void NoteOff(double aWhen, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
Stop(aWhen, aRv);
|
|
|
|
}
|
2012-09-18 16:07:33 -07:00
|
|
|
|
2013-04-22 14:01:22 -07:00
|
|
|
AudioBuffer* GetBuffer(JSContext* aCx) const
|
2012-09-24 20:31:58 -07:00
|
|
|
{
|
|
|
|
return mBuffer;
|
|
|
|
}
|
2013-04-22 14:01:22 -07:00
|
|
|
void SetBuffer(JSContext* aCx, AudioBuffer* aBuffer)
|
2013-02-04 15:07:25 -08:00
|
|
|
{
|
|
|
|
mBuffer = aBuffer;
|
2013-04-22 14:01:22 -07:00
|
|
|
SendBufferParameterToStream(aCx);
|
2013-02-04 15:07:25 -08:00
|
|
|
}
|
2013-04-09 05:47:42 -07:00
|
|
|
AudioParam* PlaybackRate() const
|
|
|
|
{
|
|
|
|
return mPlaybackRate;
|
|
|
|
}
|
2013-03-10 09:56:14 -07:00
|
|
|
bool Loop() const
|
|
|
|
{
|
|
|
|
return mLoop;
|
|
|
|
}
|
|
|
|
void SetLoop(bool aLoop)
|
|
|
|
{
|
|
|
|
mLoop = aLoop;
|
2013-04-21 21:22:33 -07:00
|
|
|
SendLoopParametersToStream();
|
2013-03-10 09:56:14 -07:00
|
|
|
}
|
|
|
|
double LoopStart() const
|
|
|
|
{
|
|
|
|
return mLoopStart;
|
|
|
|
}
|
|
|
|
void SetLoopStart(double aStart)
|
|
|
|
{
|
|
|
|
mLoopStart = aStart;
|
2013-04-21 21:22:33 -07:00
|
|
|
SendLoopParametersToStream();
|
2013-03-10 09:56:14 -07:00
|
|
|
}
|
|
|
|
double LoopEnd() const
|
|
|
|
{
|
|
|
|
return mLoopEnd;
|
|
|
|
}
|
|
|
|
void SetLoopEnd(double aEnd)
|
|
|
|
{
|
|
|
|
mLoopEnd = aEnd;
|
2013-04-21 21:22:33 -07:00
|
|
|
SendLoopParametersToStream();
|
2013-03-10 09:56:14 -07:00
|
|
|
}
|
2013-04-11 05:47:57 -07:00
|
|
|
void SendDopplerShiftToStream(double aDopplerShift);
|
2013-03-10 09:56:14 -07:00
|
|
|
|
2013-02-04 15:07:25 -08:00
|
|
|
virtual void NotifyMainThreadStateChanged() MOZ_OVERRIDE;
|
2012-09-18 16:07:33 -07:00
|
|
|
|
2012-09-24 20:31:58 -07:00
|
|
|
private:
|
2013-04-21 21:22:33 -07:00
|
|
|
friend class AudioBufferSourceNodeEngine;
|
|
|
|
// START, OFFSET and DURATION are always set by start() (along with setting
|
|
|
|
// mBuffer to something non-null).
|
|
|
|
// STOP is set by stop().
|
|
|
|
enum EngineParameters {
|
|
|
|
SAMPLE_RATE,
|
|
|
|
START,
|
|
|
|
STOP,
|
|
|
|
OFFSET,
|
|
|
|
DURATION,
|
|
|
|
LOOP,
|
|
|
|
LOOPSTART,
|
|
|
|
LOOPEND,
|
|
|
|
PLAYBACKRATE,
|
|
|
|
DOPPLERSHIFT
|
|
|
|
};
|
|
|
|
|
|
|
|
void SendLoopParametersToStream();
|
2013-04-22 14:01:22 -07:00
|
|
|
void SendBufferParameterToStream(JSContext* aCx);
|
|
|
|
void SendOffsetAndDurationParametersToStream(AudioNodeStream* aStream,
|
|
|
|
double aOffset,
|
|
|
|
double aDuration);
|
2013-04-09 05:47:42 -07:00
|
|
|
static void SendPlaybackRateToStream(AudioNode* aNode);
|
2013-04-21 21:22:33 -07:00
|
|
|
|
|
|
|
private:
|
2013-03-10 09:56:14 -07:00
|
|
|
double mLoopStart;
|
|
|
|
double mLoopEnd;
|
2013-04-22 14:01:22 -07:00
|
|
|
double mOffset;
|
|
|
|
double mDuration;
|
2013-04-14 18:52:55 -07:00
|
|
|
nsRefPtr<AudioBuffer> mBuffer;
|
2013-04-09 05:47:42 -07:00
|
|
|
nsRefPtr<AudioParam> mPlaybackRate;
|
2013-04-11 05:47:57 -07:00
|
|
|
PannerNode* mPannerNode;
|
2013-04-14 18:52:55 -07:00
|
|
|
SelfReference<AudioBufferSourceNode> mPlayingRef; // a reference to self while playing
|
|
|
|
bool mLoop;
|
|
|
|
bool mStartCalled;
|
2013-04-22 14:01:22 -07:00
|
|
|
bool mOffsetAndDurationRemembered;
|
2012-09-18 16:07:33 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-30 14:39:38 -07:00
|
|
|
#endif
|
|
|
|
|