Panda3D
movieAudioCursor.I
1 // Filename: movieAudioCursor.I
2 // Created by: jyelon (02Jul07)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 ////////////////////////////////////////////////////////////////////
16 // Function: MovieAudioCursor::get_source
17 // Access: Public
18 // Description: Returns the MovieAudio which this cursor references.
19 ////////////////////////////////////////////////////////////////////
20 INLINE PT(MovieAudio) MovieAudioCursor::
21 get_source() const {
22  return _source;
23 }
24 
25 ////////////////////////////////////////////////////////////////////
26 // Function: MovieAudioCursor::audio_rate
27 // Access: Public
28 // Description: Returns the audio sample rate.
29 ////////////////////////////////////////////////////////////////////
30 INLINE int MovieAudioCursor::
31 audio_rate() const {
32  return _audio_rate;
33 }
34 
35 ////////////////////////////////////////////////////////////////////
36 // Function: MovieAudioCursor::audio_channels
37 // Access: Public
38 // Description: Returns the number of audio channels (ie, two for
39 // stereo, one for mono).
40 ////////////////////////////////////////////////////////////////////
41 INLINE int MovieAudioCursor::
42 audio_channels() const {
43  return _audio_channels;
44 }
45 
46 ////////////////////////////////////////////////////////////////////
47 // Function: MovieAudioCursor::length
48 // Access: Public
49 // Description: Returns the length of the movie. Attempting to read
50 // audio samples beyond the specified length will produce
51 // silent samples.
52 //
53 // Some kinds of Movie, such as internet TV station,
54 // might not have a predictable length. In that case,
55 // the length will be set to a very large number: 1.0E10.
56 //
57 // Some AVI files have incorrect length values encoded
58 // into them - they may be a second or two long or
59 // short. When playing such an AVI using the Movie class,
60 // you may see a slightly truncated video, or a slightly
61 // elongated video (padded with black frames). There are
62 // utilities out there to fix the length values in AVI
63 // files.
64 //
65 // An audio consumer needs to check the length, the
66 // ready status, and the aborted flag.
67 ////////////////////////////////////////////////////////////////////
68 INLINE double MovieAudioCursor::
69 length() const {
70  return _length;
71 }
72 
73 ////////////////////////////////////////////////////////////////////
74 // Function: MovieAudioCursor::can_seek
75 // Access: Public
76 // Description: Returns true if the movie can seek. If this is
77 // true, seeking is still not guaranteed to be fast:
78 // for some movies, seeking is implemented by rewinding
79 // to the beginning and then fast-forwarding to the
80 // desired location. Even if the movie cannot seek,
81 // the seek method can still advance to an arbitrary
82 // location by reading samples and discarding them.
83 // However, to move backward, can_seek must return true.
84 ////////////////////////////////////////////////////////////////////
85 INLINE bool MovieAudioCursor::
86 can_seek() const {
87  return _can_seek;
88 }
89 
90 ////////////////////////////////////////////////////////////////////
91 // Function: MovieAudioCursor::can_seek_fast
92 // Access: Public
93 // Description: Returns true if seek operations are constant time.
94 ////////////////////////////////////////////////////////////////////
95 INLINE bool MovieAudioCursor::
96 can_seek_fast() const {
97  return _can_seek_fast;
98 }
99 
100 ////////////////////////////////////////////////////////////////////
101 // Function: MovieAudioCursor::aborted
102 // Access: Public
103 // Description: If aborted is true, it means that the "ready" samples
104 // are not being replenished. See the method "ready"
105 // for an explanation.
106 ////////////////////////////////////////////////////////////////////
107 INLINE bool MovieAudioCursor::
108 aborted() const {
109  return _aborted;
110 }
111 
112 ////////////////////////////////////////////////////////////////////
113 // Function: MovieAudioCursor::tell
114 // Access: Public
115 // Description: Returns the current offset within the file.
116 ////////////////////////////////////////////////////////////////////
117 INLINE double MovieAudioCursor::
118 tell() const {
119  return _last_seek + ((_samples_read * 1.0) / _audio_rate);
120 }
121 
122 ////////////////////////////////////////////////////////////////////
123 // Function: MovieAudioCursor::skip_samples
124 // Access: Published
125 // Description: Skip audio samples from the stream. This is mostly
126 // for debugging purposes.
127 ////////////////////////////////////////////////////////////////////
128 INLINE void MovieAudioCursor::
129 skip_samples(int n) {
130  read_samples(n, (PN_int16*)0);
131 }
132 
void read_samples(int n, Datagram *dg)
Read audio samples from the stream into a Datagram.
A MovieAudio is actually any source that provides a sequence of audio samples.
Definition: movieAudio.h:48