Panda3D
|
A MovieAudio is actually any source that provides a sequence of audio samples. More...
#include <pandadoc.hpp>
Public Member Functions | |
__init__ (const MovieAudioCursor) | |
__init__ (MovieAudio src) | |
This constructor returns a null audio stream — a stream of total silence, at 8000 samples per second. More... | |
bool | aborted () |
If aborted is true, it means that the "ready" samples are not being replenished. More... | |
int | audioChannels () |
Returns the number of audio channels (ie, two for stereo, one for mono). More... | |
int | audioRate () |
Returns the audio sample rate. More... | |
bool | canSeek () |
Returns true if the movie can seek. More... | |
bool | canSeekFast () |
Returns true if seek operations are constant time. More... | |
MovieAudio | getSource () |
Returns the MovieAudio which this cursor references. More... | |
double | length () |
Returns the length of the movie. More... | |
str | readSamples (int n) |
Read audio samples from the stream and returns them as a string. More... | |
readSamples (int n, Datagram dg) | |
Read audio samples from the stream into a Datagram. More... | |
int | ready () |
Returns the number of audio samples that are ready to read. More... | |
seek (double offset) | |
Skips to the specified offset within the file. More... | |
skipSamples (int n) | |
Skip audio samples from the stream. More... | |
double | tell () |
Returns the current offset within the file. More... | |
![]() | |
object | __reduce__ () |
object | __reduce_persist__ (object pickler) |
VectorUchar | encodeToBamStream () |
Converts the TypedWritable object into a single stream of data using a BamWriter, and returns that data as a bytes object. More... | |
bool | encodeToBamStream (VectorUchar data, BamWriter writer) |
Converts the TypedWritable object into a single stream of data using a BamWriter, and stores that data in the indicated string. More... | |
fillin (DatagramIterator scan, BamReader manager) | |
This internal function is intended to be called by each class's make_from_bam() method to read in all of the relevant data from the BamFile for the new object. More... | |
UpdateSeq | getBamModified () |
Returns the current bam_modified counter. More... | |
markBamModified () | |
Increments the bam_modified counter, so that this object will be invalidated and retransmitted on any open bam streams. More... | |
![]() | |
TypeHandle | getType () |
int | getTypeIndex () |
Returns the internal index number associated with this object's TypeHandle, a unique number for each different type. More... | |
bool | isExactType (TypeHandle handle) |
Returns true if the current object is the indicated type exactly. More... | |
bool | isOfType (TypeHandle handle) |
Returns true if the current object is or derives from the indicated type. More... | |
![]() | |
int | getRefCount () |
Returns the current reference count. More... | |
ref () | |
Explicitly increments the reference count. More... | |
bool | testRefCountIntegrity () |
Does some easy checks to make sure that the reference count isn't completely bogus. More... | |
bool | testRefCountNonzero () |
Does some easy checks to make sure that the reference count isn't zero, or completely bogus. More... | |
bool | unref () |
Explicitly decrements the reference count. More... | |
Static Public Member Functions | |
static TypeHandle | getClassType () |
![]() | |
static TypedWritableReferenceCount | decodeFromBamStream (VectorUchar data, BamReader reader) |
Reads the bytes created by a previous call to encode_to_bam_stream(), and extracts and returns the single object on those bytes. More... | |
static TypeHandle | getClassType () |
![]() | |
static TypeHandle | getClassType () |
![]() | |
static TypeHandle | getClassType () |
![]() | |
static TypeHandle | getClassType () |
Additional Inherited Members | |
![]() | |
TypeHandle | type |
Returns the TypeHandle representing this object's type. More... | |
![]() | |
int | ref_count |
The current reference count. More... | |
A MovieAudio is actually any source that provides a sequence of audio samples.
That could include an AVI file, a microphone, or an internet TV station. A MovieAudioCursor is a handle that lets you read data sequentially from a MovieAudio.
Thread safety: each individual MovieAudioCursor must be owned and accessed by a single thread. It is OK for two different threads to open the same file at the same time, as long as they use separate MovieAudioCursor objects.
__init__ | ( | const | MovieAudioCursor | ) |
__init__ | ( | MovieAudio | src | ) |
This constructor returns a null audio stream — a stream of total silence, at 8000 samples per second.
To get more interesting audio, you need to construct a subclass of this class.
bool aborted | ( | ) |
If aborted is true, it means that the "ready" samples are not being replenished.
See the method "ready" for an explanation.
int audioChannels | ( | ) |
Returns the number of audio channels (ie, two for stereo, one for mono).
int audioRate | ( | ) |
Returns the audio sample rate.
bool canSeek | ( | ) |
Returns true if the movie can seek.
If this is true, seeking is still not guaranteed to be fast: for some movies, seeking is implemented by rewinding to the beginning and then fast-forwarding to the desired location. Even if the movie cannot seek, the seek method can still advance to an arbitrary location by reading samples and discarding them. However, to move backward, can_seek must return true.
bool canSeekFast | ( | ) |
Returns true if seek operations are constant time.
|
static |
MovieAudio getSource | ( | ) |
Returns the MovieAudio which this cursor references.
double length | ( | ) |
Returns the length of the movie.
Attempting to read audio samples beyond the specified length will produce silent samples.
Some kinds of Movie, such as internet TV station, might not have a predictable length. In that case, the length will be set to a very large number: 1.0E10.
Some AVI files have incorrect length values encoded into them - they may be a second or two long or short. When playing such an AVI using the Movie class, you may see a slightly truncated video, or a slightly elongated video (padded with black frames). There are utilities out there to fix the length values in AVI files.
An audio consumer needs to check the length, the ready status, and the aborted flag.
str readSamples | ( | int | n | ) |
Read audio samples from the stream and returns them as a string.
The samples are stored little-endian in the string. N is the number of samples you wish to read. Multiple-channel audio will be interleaved.
This is not particularly efficient, but it may be a convenient way to manipulate samples in python.
readSamples | ( | int | n, |
Datagram | dg | ||
) |
Read audio samples from the stream into a Datagram.
N is the number of samples you wish to read. Multiple-channel audio will be interleaved.
This is not particularly efficient, but it may be a convenient way to manipulate samples in python.
int ready | ( | ) |
Returns the number of audio samples that are ready to read.
This is primarily relevant for sources like microphones which produce samples at a fixed rate. If you try to read more samples than are ready, the result will be silent samples.
Some audio streams do not have a limit on how fast they can produce samples. Such streams will always return 0x40000000 as the ready-count. This may well exceed the length of the audio stream. You therefore need to check length separately.
If the aborted flag is set, that means the ready count is no longer being replenished. For example, a MovieAudioCursor might be reading from an internet radio station, and it might buffer data to avoid underruns. If it loses connection to the radio station, it will set the aborted flag to indicate that the buffer is no longer being replenished. But it is still ok to read the samples that are in the buffer, at least until they run out. Once those are gone, there will be no more.
An audio consumer needs to check the length, the ready status, and the aborted flag.
seek | ( | double | offset | ) |
Skips to the specified offset within the file.
If the movie reports that it cannot seek, then this method can still advance by reading samples and discarding them. However, to move backward, can_seek must be true.
If the movie reports that it can_seek, it doesn't mean that it can do so quickly. It may have to rewind the movie and then fast forward to the desired location. Only if can_seek_fast returns true can seek operations be done in constant time.
Seeking may not be precise, because AVI files often have inaccurate indices. After seeking, tell will indicate that the cursor is at the target location. However, in truth, the data you read may come from a slightly offset location.
skipSamples | ( | int | n | ) |
Skip audio samples from the stream.
This is mostly for debugging purposes.
double tell | ( | ) |
Returns the current offset within the file.