Panda3D
Public Member Functions | Static Public Member Functions | List of all members
MovieAudioCursor Class Reference

A MovieAudio is actually any source that provides a sequence of audio samples. More...

#include "movieAudioCursor.h"

Inheritance diagram for MovieAudioCursor:
TypedWritableReferenceCount TypedWritable ReferenceCount TypedObject MemoryBase MemoryBase FfmpegAudioCursor FlacAudioCursor UserDataAudioCursor WavAudioCursor

Public Member Functions

 MovieAudioCursor (MovieAudio *src)
 This constructor returns a null audio stream — a stream of total silence, at 8000 samples per second. More...
 
bool aborted () const
 
int audio_channels () const
 
int audio_rate () const
 
bool can_seek () const
 
bool can_seek_fast () const
 
virtual TypeHandle force_init_type ()
 
virtual TypeHandle get_type () const
 
double length () const
 
 PT (MovieAudio) get_source() const
 
void read_samples (int n, Datagram *dg)
 Read audio samples from the stream into a Datagram. More...
 
std::string read_samples (int n)
 Read audio samples from the stream and returns them as a string. More...
 
virtual void read_samples (int n, int16_t *data)
 Read audio samples from the stream. More...
 
virtual int ready () const
 Returns the number of audio samples that are ready to read. More...
 
virtual void seek (double offset)
 Skips to the specified offset within the file. More...
 
void skip_samples (int n)
 
double tell () const
 
- Public Member Functions inherited from TypedWritableReferenceCount
 TypedWritableReferenceCount (const TypedWritableReferenceCount &copy)
 
virtual ReferenceCountas_reference_count ()
 Returns the pointer cast to a ReferenceCount pointer, if it is in fact of that type. More...
 
void operator= (const TypedWritableReferenceCount &copy)
 
- Public Member Functions inherited from TypedWritable
 TypedWritable (const TypedWritable &copy)
 
virtual int complete_pointers (TypedWritable **p_list, BamReader *manager)
 Receives an array of pointers, one for each time manager->read_pointer() was called in fillin(). More...
 
vector_uchar encode_to_bam_stream () const
 Converts the TypedWritable object into a single stream of data using a BamWriter, and returns that data as a bytes object. More...
 
bool encode_to_bam_stream (vector_uchar &data, BamWriter *writer=nullptr) const
 Converts the TypedWritable object into a single stream of data using a BamWriter, and stores that data in the indicated string. More...
 
virtual void 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...
 
virtual void finalize (BamReader *manager)
 Called by the BamReader to perform any final actions needed for setting up the object after all objects have been read and all pointers have been completed. More...
 
UpdateSeq get_bam_modified () const
 Returns the current bam_modified counter. More...
 
void mark_bam_modified ()
 Increments the bam_modified counter, so that this object will be invalidated and retransmitted on any open bam streams. More...
 
void operator= (const TypedWritable &copy)
 
virtual bool require_fully_complete () const
 Some objects require all of their nested pointers to have been completed before the objects themselves can be completed. More...
 
virtual void update_bam_nested (BamWriter *manager)
 Called by the BamWriter when this object has not itself been modified recently, but it should check its nested objects for updates. More...
 
virtual void write_datagram (BamWriter *manager, Datagram &dg)
 Writes the contents of this object to the datagram for shipping out to a Bam file. More...
 
- Public Member Functions inherited from TypedObject
 TypedObject (const TypedObject &copy)=default
 
TypedObjectas_typed_object ()
 Returns the object, upcast (if necessary) to a TypedObject pointer. More...
 
const TypedObjectas_typed_object () const
 Returns the object, upcast (if necessary) to a TypedObject pointer. More...
 
int get_best_parent_from_Set (const std::set< int > &) const
 
int get_type_index () const
 Returns the internal index number associated with this object's TypeHandle, a unique number for each different type. More...
 
bool is_exact_type (TypeHandle handle) const
 Returns true if the current object is the indicated type exactly. More...
 
bool is_of_type (TypeHandle handle) const
 Returns true if the current object is or derives from the indicated type. More...
 
TypedObjectoperator= (const TypedObject &copy)=default
 
- Public Member Functions inherited from ReferenceCount
int get_ref_count () const
 
WeakReferenceListget_weak_list () const
 Returns the WeakReferenceList associated with this ReferenceCount object. More...
 
bool has_weak_list () const
 Returns true if this particular ReferenceCount object has a WeakReferenceList created, false otherwise. More...
 
void local_object ()
 This function should be called, once, immediately after creating a new instance of some ReferenceCount-derived object on the stack. More...
 
void ref () const
 Explicitly increments the reference count. More...
 
bool ref_if_nonzero () const
 Atomically increases the reference count of this object if it is not zero. More...
 
bool test_ref_count_integrity () const
 Does some easy checks to make sure that the reference count isn't completely bogus. More...
 
bool test_ref_count_nonzero () const
 Does some easy checks to make sure that the reference count isn't zero, or completely bogus. More...
 
virtual bool unref () const
 Explicitly decrements the reference count. More...
 
WeakReferenceListweak_ref ()
 Adds the indicated PointerToVoid as a weak reference to this object. More...
 
void weak_unref ()
 Removes the indicated PointerToVoid as a weak reference to this object. More...
 

Static Public Member Functions

static TypeHandle get_class_type ()
 
static void init_type ()
 
- Static Public Member Functions inherited from TypedWritableReferenceCount
static TypeHandle get_class_type ()
 
static void init_type ()
 
static PT (TypedWritableReferenceCount) decode_from_bam_stream(vector_uchar data
 
- Static Public Member Functions inherited from TypedWritable
static bool decode_raw_from_bam_stream (TypedWritable *&ptr, ReferenceCount *&ref_ptr, vector_uchar data, BamReader *reader=nullptr)
 Reads the bytes created by a previous call to encode_to_bam_stream(), and extracts the single object on those bytes. More...
 
static TypeHandle get_class_type ()
 
static void init_type ()
 
- Static Public Member Functions inherited from TypedObject
static TypeHandle get_class_type ()
 
static void init_type ()
 This function is declared non-inline to work around a compiler bug in g++ 2.96. More...
 
- Static Public Member Functions inherited from ReferenceCount
static TypeHandle get_class_type ()
 
static void init_type ()
 

Additional Inherited Members

- Public Attributes inherited from TypedWritableReferenceCount
static BamReaderreader = nullptr)
 
- Public Attributes inherited from TypedObject
 get_type
 
- Public Attributes inherited from ReferenceCount
 get_ref_count
 Returns the current reference count. More...
 
- Static Public Attributes inherited from TypedWritable
static TypedWritable *const Null = nullptr
 

Detailed Description

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.

Definition at line 34 of file movieAudioCursor.h.

Constructor & Destructor Documentation

◆ MovieAudioCursor()

MovieAudioCursor::MovieAudioCursor ( 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.

Definition at line 24 of file movieAudioCursor.cxx.

Member Function Documentation

◆ read_samples() [1/3]

void MovieAudioCursor::read_samples ( 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.

Definition at line 73 of file movieAudioCursor.cxx.

Referenced by read_samples().

◆ read_samples() [2/3]

std::string MovieAudioCursor::read_samples ( 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.

Definition at line 96 of file movieAudioCursor.cxx.

References read_samples().

◆ read_samples() [3/3]

void MovieAudioCursor::read_samples ( int  n,
int16_t *  data 
)
virtual

Read audio samples from the stream.

N is the number of samples you wish to read. Your buffer must be equal in size to N * channels. Multiple-channel audio will be interleaved.

Reimplemented in FfmpegAudioCursor, FlacAudioCursor, UserDataAudioCursor, and WavAudioCursor.

Definition at line 49 of file movieAudioCursor.cxx.

◆ ready()

int MovieAudioCursor::ready ( ) const
virtual

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.

Reimplemented in UserDataAudioCursor.

Definition at line 161 of file movieAudioCursor.cxx.

◆ seek()

void MovieAudioCursor::seek ( double  offset)
virtual

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.

Reimplemented in FfmpegAudioCursor, UserDataAudioCursor, FlacAudioCursor, and WavAudioCursor.

Definition at line 133 of file movieAudioCursor.cxx.


The documentation for this class was generated from the following files: