OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 11 matching lines...) Expand all Loading... |
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 */ | 27 */ |
28 | 28 |
29 #ifndef AudioScheduledSourceNode_h | 29 #ifndef AudioScheduledSourceNode_h |
30 #define AudioScheduledSourceNode_h | 30 #define AudioScheduledSourceNode_h |
31 | 31 |
| 32 #include "core/dom/ActiveDOMObject.h" |
32 #include "modules/webaudio/AudioSourceNode.h" | 33 #include "modules/webaudio/AudioSourceNode.h" |
33 | 34 |
34 namespace WebCore { | 35 namespace WebCore { |
35 | 36 |
36 class AudioBus; | 37 class AudioBus; |
37 | 38 |
38 class AudioScheduledSourceNode : public AudioSourceNode { | 39 class AudioScheduledSourceNode : public AudioSourceNode, public ActiveDOMObject
{ |
39 public: | 40 public: |
40 // These are the possible states an AudioScheduledSourceNode can be in: | 41 // These are the possible states an AudioScheduledSourceNode can be in: |
41 // | 42 // |
42 // UNSCHEDULED_STATE - Initial playback state. Created, but not yet schedule
d. | 43 // UNSCHEDULED_STATE - Initial playback state. Created, but not yet schedule
d. |
43 // SCHEDULED_STATE - Scheduled to play (via noteOn() or noteGrainOn()), but
not yet playing. | 44 // SCHEDULED_STATE - Scheduled to play (via noteOn() or noteGrainOn()), but
not yet playing. |
44 // PLAYING_STATE - Generating sound. | 45 // PLAYING_STATE - Generating sound. |
45 // FINISHED_STATE - Finished generating sound. | 46 // FINISHED_STATE - Finished generating sound. |
46 // | 47 // |
47 // The state can only transition to the next state, except for the FINISHED_
STATE which can | 48 // The state can only transition to the next state, except for the FINISHED_
STATE which can |
48 // never be changed. | 49 // never be changed. |
49 enum PlaybackState { | 50 enum PlaybackState { |
50 // These must be defined with the same names and values as in the .idl f
ile. | 51 // These must be defined with the same names and values as in the .idl f
ile. |
51 UNSCHEDULED_STATE = 0, | 52 UNSCHEDULED_STATE = 0, |
52 SCHEDULED_STATE = 1, | 53 SCHEDULED_STATE = 1, |
53 PLAYING_STATE = 2, | 54 PLAYING_STATE = 2, |
54 FINISHED_STATE = 3 | 55 FINISHED_STATE = 3 |
55 }; | 56 }; |
56 | 57 |
57 AudioScheduledSourceNode(AudioContext*, float sampleRate); | 58 AudioScheduledSourceNode(AudioContext*, float sampleRate); |
58 | 59 |
59 // Scheduling. | 60 // Scheduling. |
60 void start(double when); | 61 void start(double when); |
61 void stop(double when); | 62 void stopNote(double when); |
62 | 63 |
63 void noteOn(double when); | 64 void noteOn(double when); |
64 void noteOff(double when); | 65 void noteOff(double when); |
65 | 66 |
66 unsigned short playbackState() const { return static_cast<unsigned short>(m_
playbackState); } | 67 unsigned short playbackState() const { return static_cast<unsigned short>(m_
playbackState); } |
67 bool isPlayingOrScheduled() const { return m_playbackState == PLAYING_STATE
|| m_playbackState == SCHEDULED_STATE; } | 68 bool isPlayingOrScheduled() const { return m_playbackState == PLAYING_STATE
|| m_playbackState == SCHEDULED_STATE; } |
68 bool hasFinished() const { return m_playbackState == FINISHED_STATE; } | 69 bool hasFinished() const { return m_playbackState == FINISHED_STATE; } |
69 | 70 |
70 EventListener* onended(DOMWrapperWorld* isolatedWorld) { return getAttribute
EventListener(eventNames().endedEvent, isolatedWorld); } | 71 EventListener* onended(DOMWrapperWorld* isolatedWorld) { return getAttribute
EventListener(eventNames().endedEvent, isolatedWorld); } |
71 void setOnended(PassRefPtr<EventListener>, DOMWrapperWorld* isolatedWorld =
0); | 72 void setOnended(PassRefPtr<EventListener>, DOMWrapperWorld* isolatedWorld =
0); |
72 | 73 |
| 74 virtual ScriptExecutionContext* scriptExecutionContext() const OVERRIDE; |
| 75 virtual void stop() OVERRIDE; |
| 76 |
73 protected: | 77 protected: |
74 // Get frame information for the current time quantum. | 78 // Get frame information for the current time quantum. |
75 // We handle the transition into PLAYING_STATE and FINISHED_STATE here, | 79 // We handle the transition into PLAYING_STATE and FINISHED_STATE here, |
76 // zeroing out portions of the outputBus which are outside the range of star
tFrame and endFrame. | 80 // zeroing out portions of the outputBus which are outside the range of star
tFrame and endFrame. |
77 // | 81 // |
78 // Each frame time is relative to the context's currentSampleFrame(). | 82 // Each frame time is relative to the context's currentSampleFrame(). |
79 // quantumFrameOffset : Offset frame in this time quantum to start render
ing. | 83 // quantumFrameOffset : Offset frame in this time quantum to start render
ing. |
80 // nonSilentFramesToProcess : Number of frames rendering non-silence (will b
e <= quantumFrameSize). | 84 // nonSilentFramesToProcess : Number of frames rendering non-silence (will b
e <= quantumFrameSize). |
81 void updateSchedulingInfo(size_t quantumFrameSize, | 85 void updateSchedulingInfo(size_t quantumFrameSize, |
82 AudioBus* outputBus, | 86 AudioBus* outputBus, |
(...skipping 10 matching lines...) Expand all Loading... |
93 | 97 |
94 // m_startTime is the time to start playing based on the context's timeline
(0 or a time less than the context's current time means "now"). | 98 // m_startTime is the time to start playing based on the context's timeline
(0 or a time less than the context's current time means "now"). |
95 double m_startTime; // in seconds | 99 double m_startTime; // in seconds |
96 | 100 |
97 // m_endTime is the time to stop playing based on the context's timeline (0
or a time less than the context's current time means "now"). | 101 // m_endTime is the time to stop playing based on the context's timeline (0
or a time less than the context's current time means "now"). |
98 // If it hasn't been set explicitly, then the sound will not stop playing (i
f looping) or will stop when the end of the AudioBuffer | 102 // If it hasn't been set explicitly, then the sound will not stop playing (i
f looping) or will stop when the end of the AudioBuffer |
99 // has been reached. | 103 // has been reached. |
100 double m_endTime; // in seconds | 104 double m_endTime; // in seconds |
101 | 105 |
102 bool m_hasEndedListener; | 106 bool m_hasEndedListener; |
| 107 bool m_notifyingEndedListener; |
103 | 108 |
104 static const double UnknownTime; | 109 static const double UnknownTime; |
105 }; | 110 }; |
106 | 111 |
107 } // namespace WebCore | 112 } // namespace WebCore |
108 | 113 |
109 #endif // AudioScheduledSourceNode_h | 114 #endif // AudioScheduledSourceNode_h |
OLD | NEW |