~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/Modules/webaudio/AudioScheduledSourceNode.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012 Google Inc. All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions
 
6
 * are met:
 
7
 *
 
8
 * 1.  Redistributions of source code must retain the above copyright
 
9
 *     notice, this list of conditions and the following disclaimer.
 
10
 * 2.  Redistributions in binary form must reproduce the above copyright
 
11
 *     notice, this list of conditions and the following disclaimer in the
 
12
 *     documentation and/or other materials provided with the distribution.
 
13
 * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
 
14
 *     its contributors may be used to endorse or promote products derived
 
15
 *     from this software without specific prior written permission.
 
16
 *
 
17
 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 
18
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
19
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
20
 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 
21
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 
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
 
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
 
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
27
 */
 
28
 
 
29
#ifndef AudioScheduledSourceNode_h
 
30
#define AudioScheduledSourceNode_h
 
31
 
 
32
#include "AudioSourceNode.h"
 
33
 
 
34
namespace WebCore {
 
35
 
 
36
class AudioBus;
 
37
 
 
38
class AudioScheduledSourceNode : public AudioSourceNode {
 
39
public:
 
40
    // These are the possible states an AudioScheduledSourceNode can be in:
 
41
    //
 
42
    // UNSCHEDULED_STATE - Initial playback state. Created, but not yet scheduled.
 
43
    // SCHEDULED_STATE - Scheduled to play (via noteOn() or noteGrainOn()), but not yet playing.
 
44
    // PLAYING_STATE - Generating sound.
 
45
    // FINISHED_STATE - Finished generating sound.
 
46
    //
 
47
    // The state can only transition to the next state, except for the FINISHED_STATE which can
 
48
    // never be changed.
 
49
    enum PlaybackState {
 
50
        // These must be defined with the same names and values as in the .idl file.
 
51
        UNSCHEDULED_STATE = 0,
 
52
        SCHEDULED_STATE = 1,
 
53
        PLAYING_STATE = 2,
 
54
        FINISHED_STATE = 3
 
55
    };
 
56
    
 
57
    AudioScheduledSourceNode(AudioContext*, float sampleRate);
 
58
 
 
59
    // Scheduling.
 
60
    void start(double when);
 
61
    void stop(double when);
 
62
 
 
63
#if ENABLE(LEGACY_WEB_AUDIO)
 
64
    void noteOn(double when);
 
65
    void noteOff(double when);
 
66
#endif
 
67
 
 
68
    unsigned short playbackState() const { return static_cast<unsigned short>(m_playbackState); }
 
69
    bool isPlayingOrScheduled() const { return m_playbackState == PLAYING_STATE || m_playbackState == SCHEDULED_STATE; }
 
70
    bool hasFinished() const { return m_playbackState == FINISHED_STATE; }
 
71
 
 
72
protected:
 
73
    // Get frame information for the current time quantum.
 
74
    // We handle the transition into PLAYING_STATE and FINISHED_STATE here,
 
75
    // zeroing out portions of the outputBus which are outside the range of startFrame and endFrame.
 
76
    //
 
77
    // Each frame time is relative to the context's currentSampleFrame().
 
78
    // quantumFrameOffset    : Offset frame in this time quantum to start rendering.
 
79
    // nonSilentFramesToProcess : Number of frames rendering non-silence (will be <= quantumFrameSize).
 
80
    void updateSchedulingInfo(size_t quantumFrameSize,
 
81
                              AudioBus* outputBus,
 
82
                              size_t& quantumFrameOffset,
 
83
                              size_t& nonSilentFramesToProcess);
 
84
 
 
85
    // Called when we have no more sound to play or the noteOff() time has been reached.
 
86
    virtual void finish();
 
87
 
 
88
    PlaybackState m_playbackState;
 
89
 
 
90
    // 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").
 
91
    double m_startTime; // in seconds
 
92
 
 
93
    // 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").
 
94
    // If it hasn't been set explicitly, then the sound will not stop playing (if looping) or will stop when the end of the AudioBuffer
 
95
    // has been reached.
 
96
    double m_endTime; // in seconds
 
97
 
 
98
    static const double UnknownTime;
 
99
};
 
100
 
 
101
} // namespace WebCore
 
102
 
 
103
#endif // AudioScheduledSourceNode_h