2012-09-18 23:07:33 +00: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 21:39:38 +00:00
|
|
|
#ifndef AudioBufferSourceNode_h_
|
|
|
|
#define AudioBufferSourceNode_h_
|
2012-09-18 23:07:33 +00:00
|
|
|
|
2013-04-09 02:45:02 +00:00
|
|
|
#include "AudioNode.h"
|
2012-09-25 03:31:58 +00:00
|
|
|
#include "AudioBuffer.h"
|
2012-09-18 23:07:33 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-08-15 19:44:14 +00:00
|
|
|
class AudioParam;
|
|
|
|
|
2013-04-09 02:45:02 +00:00
|
|
|
class AudioBufferSourceNode : public AudioNode,
|
2013-02-04 23:07:25 +00:00
|
|
|
public MainThreadMediaStreamListener
|
2012-09-18 23:07:33 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AudioBufferSourceNode(AudioContext* aContext);
|
2013-04-22 12:58:32 +00:00
|
|
|
virtual ~AudioBufferSourceNode();
|
2013-02-04 23:07:25 +00:00
|
|
|
|
|
|
|
virtual void DestroyMediaStream() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
if (mStream) {
|
|
|
|
mStream->RemoveMainThreadListener(this);
|
|
|
|
}
|
2013-04-09 02:45:02 +00:00
|
|
|
AudioNode::DestroyMediaStream();
|
2013-02-04 23:07:25 +00:00
|
|
|
}
|
2013-05-05 15:48:45 +00:00
|
|
|
virtual uint16_t NumberOfInputs() const MOZ_FINAL MOZ_OVERRIDE
|
2013-04-09 02:45:02 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2013-04-11 12:47:57 +00:00
|
|
|
virtual AudioBufferSourceNode* AsAudioBufferSourceNode() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
2012-09-18 23:07:33 +00:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2013-04-09 02:45:02 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioBufferSourceNode, AudioNode)
|
2012-09-25 03:31:58 +00:00
|
|
|
|
2014-04-08 22:27:18 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2012-09-18 23:07:33 +00:00
|
|
|
|
2013-04-22 21:01:22 +00:00
|
|
|
void Start(double aWhen, double aOffset,
|
2013-02-04 23:07:25 +00:00
|
|
|
const Optional<double>& aDuration, ErrorResult& aRv);
|
2013-09-24 01:47:00 +00:00
|
|
|
void Stop(double aWhen, ErrorResult& aRv);
|
2012-09-18 23:07:33 +00:00
|
|
|
|
2013-04-22 21:01:22 +00:00
|
|
|
AudioBuffer* GetBuffer(JSContext* aCx) const
|
2012-09-25 03:31:58 +00:00
|
|
|
{
|
|
|
|
return mBuffer;
|
|
|
|
}
|
2013-04-22 21:01:22 +00:00
|
|
|
void SetBuffer(JSContext* aCx, AudioBuffer* aBuffer)
|
2013-02-04 23:07:25 +00:00
|
|
|
{
|
|
|
|
mBuffer = aBuffer;
|
2013-04-22 21:01:22 +00:00
|
|
|
SendBufferParameterToStream(aCx);
|
2013-04-23 15:42:40 +00:00
|
|
|
SendLoopParametersToStream();
|
2013-02-04 23:07:25 +00:00
|
|
|
}
|
2013-04-09 12:47:42 +00:00
|
|
|
AudioParam* PlaybackRate() const
|
|
|
|
{
|
|
|
|
return mPlaybackRate;
|
|
|
|
}
|
2013-03-10 16:56:14 +00:00
|
|
|
bool Loop() const
|
|
|
|
{
|
|
|
|
return mLoop;
|
|
|
|
}
|
|
|
|
void SetLoop(bool aLoop)
|
|
|
|
{
|
|
|
|
mLoop = aLoop;
|
2013-04-22 04:22:33 +00:00
|
|
|
SendLoopParametersToStream();
|
2013-03-10 16:56:14 +00:00
|
|
|
}
|
|
|
|
double LoopStart() const
|
|
|
|
{
|
|
|
|
return mLoopStart;
|
|
|
|
}
|
|
|
|
void SetLoopStart(double aStart)
|
|
|
|
{
|
|
|
|
mLoopStart = aStart;
|
2013-04-22 04:22:33 +00:00
|
|
|
SendLoopParametersToStream();
|
2013-03-10 16:56:14 +00:00
|
|
|
}
|
|
|
|
double LoopEnd() const
|
|
|
|
{
|
|
|
|
return mLoopEnd;
|
|
|
|
}
|
|
|
|
void SetLoopEnd(double aEnd)
|
|
|
|
{
|
|
|
|
mLoopEnd = aEnd;
|
2013-04-22 04:22:33 +00:00
|
|
|
SendLoopParametersToStream();
|
2013-03-10 16:56:14 +00:00
|
|
|
}
|
2013-04-11 12:47:57 +00:00
|
|
|
void SendDopplerShiftToStream(double aDopplerShift);
|
2013-03-10 16:56:14 +00:00
|
|
|
|
2013-05-06 18:22:01 +00:00
|
|
|
IMPL_EVENT_HANDLER(ended)
|
|
|
|
|
2013-02-04 23:07:25 +00:00
|
|
|
virtual void NotifyMainThreadStateChanged() MOZ_OVERRIDE;
|
2012-09-18 23:07:33 +00:00
|
|
|
|
2014-04-13 18:08:10 +00:00
|
|
|
virtual const char* NodeType() const
|
|
|
|
{
|
|
|
|
return "AudioBufferSourceNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE;
|
|
|
|
virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE;
|
|
|
|
|
2012-09-25 03:31:58 +00:00
|
|
|
private:
|
2013-04-22 04:22:33 +00:00
|
|
|
friend class AudioBufferSourceNodeEngine;
|
2014-01-06 23:53:47 +00:00
|
|
|
// START is sent during Start().
|
|
|
|
// STOP is sent during Stop().
|
2014-02-05 19:27:45 +00:00
|
|
|
// BUFFERSTART and BUFFEREND are sent when SetBuffer() and Start() have
|
2014-01-06 23:53:47 +00:00
|
|
|
// been called (along with sending the buffer).
|
2013-04-22 04:22:33 +00:00
|
|
|
enum EngineParameters {
|
|
|
|
SAMPLE_RATE,
|
|
|
|
START,
|
|
|
|
STOP,
|
2014-02-05 19:27:45 +00:00
|
|
|
// BUFFERSTART is the "offset" passed to start(), multiplied by
|
|
|
|
// buffer.sampleRate.
|
|
|
|
BUFFERSTART,
|
|
|
|
// BUFFEREND is the sum of "offset" and "duration" passed to start(),
|
|
|
|
// multiplied by buffer.sampleRate, or the size of the buffer, if smaller.
|
|
|
|
BUFFEREND,
|
2013-04-22 04:22:33 +00:00
|
|
|
LOOP,
|
|
|
|
LOOPSTART,
|
|
|
|
LOOPEND,
|
|
|
|
PLAYBACKRATE,
|
|
|
|
DOPPLERSHIFT
|
|
|
|
};
|
|
|
|
|
|
|
|
void SendLoopParametersToStream();
|
2013-04-22 21:01:22 +00:00
|
|
|
void SendBufferParameterToStream(JSContext* aCx);
|
2014-01-06 23:53:47 +00:00
|
|
|
void SendOffsetAndDurationParametersToStream(AudioNodeStream* aStream);
|
2013-04-09 12:47:42 +00:00
|
|
|
static void SendPlaybackRateToStream(AudioNode* aNode);
|
2013-04-22 04:22:33 +00:00
|
|
|
|
|
|
|
private:
|
2013-03-10 16:56:14 +00:00
|
|
|
double mLoopStart;
|
|
|
|
double mLoopEnd;
|
2013-04-22 21:01:22 +00:00
|
|
|
double mOffset;
|
|
|
|
double mDuration;
|
2013-04-15 01:52:55 +00:00
|
|
|
nsRefPtr<AudioBuffer> mBuffer;
|
2013-04-09 12:47:42 +00:00
|
|
|
nsRefPtr<AudioParam> mPlaybackRate;
|
2013-04-15 01:52:55 +00:00
|
|
|
bool mLoop;
|
|
|
|
bool mStartCalled;
|
2013-05-06 18:22:01 +00:00
|
|
|
bool mStopped;
|
2012-09-18 23:07:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-30 21:39:38 +00:00
|
|
|
#endif
|
|
|
|
|