Bug 867203 - Part 2: Remove useless mPannerNode member in AudioBufferSourceNode....
[gecko.git] / content / media / webaudio / AudioBufferSourceNode.h
blob88dbe61681c6b9902ac13e091ec85456ab2b721f
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef AudioBufferSourceNode_h_
8 #define AudioBufferSourceNode_h_
10 #include "AudioNode.h"
11 #include "AudioBuffer.h"
12 #include "AudioParam.h"
13 #include "mozilla/dom/BindingUtils.h"
15 namespace mozilla {
16 namespace dom {
18 class AudioBufferSourceNode : public AudioNode,
19 public MainThreadMediaStreamListener
21 public:
22 explicit AudioBufferSourceNode(AudioContext* aContext);
23 virtual ~AudioBufferSourceNode();
25 virtual void DestroyMediaStream() MOZ_OVERRIDE
27 if (mStream) {
28 mStream->RemoveMainThreadListener(this);
30 AudioNode::DestroyMediaStream();
32 virtual uint32_t NumberOfInputs() const MOZ_FINAL MOZ_OVERRIDE
34 return 0;
36 virtual AudioBufferSourceNode* AsAudioBufferSourceNode() MOZ_OVERRIDE
38 return this;
40 NS_DECL_ISUPPORTS_INHERITED
41 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioBufferSourceNode, AudioNode)
43 virtual JSObject* WrapObject(JSContext* aCx,
44 JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
46 void Start(double aWhen, double aOffset,
47 const Optional<double>& aDuration, ErrorResult& aRv);
48 void NoteOn(double aWhen, ErrorResult& aRv)
50 Start(aWhen, 0.0, Optional<double>(), aRv);
52 void NoteGrainOn(double aWhen, double aOffset,
53 double aDuration, ErrorResult& aRv)
55 Optional<double> duration;
56 duration.Construct(aDuration);
57 Start(aWhen, aOffset, duration, aRv);
59 void Stop(double aWhen, ErrorResult& aRv);
60 void NoteOff(double aWhen, ErrorResult& aRv)
62 Stop(aWhen, aRv);
65 AudioBuffer* GetBuffer(JSContext* aCx) const
67 return mBuffer;
69 void SetBuffer(JSContext* aCx, AudioBuffer* aBuffer)
71 mBuffer = aBuffer;
72 SendBufferParameterToStream(aCx);
73 SendLoopParametersToStream();
75 AudioParam* PlaybackRate() const
77 return mPlaybackRate;
79 bool Loop() const
81 return mLoop;
83 void SetLoop(bool aLoop)
85 mLoop = aLoop;
86 SendLoopParametersToStream();
88 double LoopStart() const
90 return mLoopStart;
92 void SetLoopStart(double aStart)
94 mLoopStart = aStart;
95 SendLoopParametersToStream();
97 double LoopEnd() const
99 return mLoopEnd;
101 void SetLoopEnd(double aEnd)
103 mLoopEnd = aEnd;
104 SendLoopParametersToStream();
106 void SendDopplerShiftToStream(double aDopplerShift);
108 virtual void NotifyMainThreadStateChanged() MOZ_OVERRIDE;
110 private:
111 friend class AudioBufferSourceNodeEngine;
112 // START, OFFSET and DURATION are always set by start() (along with setting
113 // mBuffer to something non-null).
114 // STOP is set by stop().
115 enum EngineParameters {
116 SAMPLE_RATE,
117 START,
118 STOP,
119 OFFSET,
120 DURATION,
121 LOOP,
122 LOOPSTART,
123 LOOPEND,
124 PLAYBACKRATE,
125 DOPPLERSHIFT
128 void SendLoopParametersToStream();
129 void SendBufferParameterToStream(JSContext* aCx);
130 void SendOffsetAndDurationParametersToStream(AudioNodeStream* aStream,
131 double aOffset,
132 double aDuration);
133 static void SendPlaybackRateToStream(AudioNode* aNode);
135 private:
136 double mLoopStart;
137 double mLoopEnd;
138 double mOffset;
139 double mDuration;
140 nsRefPtr<AudioBuffer> mBuffer;
141 nsRefPtr<AudioParam> mPlaybackRate;
142 SelfReference<AudioBufferSourceNode> mPlayingRef; // a reference to self while playing
143 bool mLoop;
144 bool mStartCalled;
145 bool mOffsetAndDurationRemembered;
151 #endif