Om  1.0.0
A universal framework for multimedia simulation
Public Member Functions | Protected Member Functions | List of all members
om::sound::base::SoundInputStream Class Referenceabstract

A class that abstracts a read-only source of sound samples. More...

#include <omSoundInputStream.h>

Inheritance diagram for om::sound::base::SoundInputStream:
om::sound::base::Sound om::sound::base::SoundCallbackStream om::sound::base::SoundDataInputStream om::sound::filters::FilterInputStream om::sound::filters::SoundPlayer om::sound::filters::StreamPlayer om::sound::io::AIFFDecoder om::sound::io::FLACDecoder om::sound::io::OggDecoder om::sound::io::WaveDecoder

Public Member Functions

virtual ~SoundInputStream ()
 Destroy this sound input stream and release any resources associated with it. More...
 
SoundResult read (SoundBuffer &buffer, Size numSamples)
 Read the specified number of samples from the input stream into a sound buffer. More...
 
virtual Bool canSeek () const
 Return whether or not seeking is allowed in this input stream. More...
 
virtual Bool canSeek (Int64 relativeSampleOffset) const
 Return whether or not this input stream's current position can be moved by the specified signed sample offset. More...
 
virtual Int64 seek (Int64 relativeSampleOffset)
 Move the current sample frame position in the stream by the specified signed amount. More...
 
virtual SoundSize getSamplesRemaining () const =0
 Return the number of samples remaining in the sound input stream. More...
 
Bool hasSamplesRemaining () const
 Return whether or not this sound input stream has any samples remaining in the stream. More...
 
virtual SampleIndex getPosition () const =0
 Return the current position of the stream in samples relative to the start of the stream. More...
 
virtual Size getChannelCount () const =0
 Return the number of channels that are in the sound input stream. More...
 
virtual SampleRate getSampleRate () const =0
 Return the sample rate of the sound input stream's source audio data. More...
 
virtual SampleType getNativeSampleType () const =0
 Return the actual sample type used in the stream. More...
 
virtual Bool isValid () const =0
 Return whether or not the stream has a valid source of sound data. More...
 

Protected Member Functions

virtual SoundResult readSamples (SoundBuffer &inputBuffer, Size numSamples)=0
 Read the specified number of samples from the input stream into the output buffer. More...
 

Detailed Description

A class that abstracts a read-only source of sound samples.

This class serves as an interface for things like sound file input, streaming input, etc. Reading from a SoundInputStream is very similar to reading from a file. A stream can be either bounded, where it has a defined length and may be seekable, or a stream can be unbounded where its length is unknown and is not seekable.

Constructor & Destructor Documentation

virtual om::sound::base::SoundInputStream::~SoundInputStream ( )
virtual

Destroy this sound input stream and release any resources associated with it.

Member Function Documentation

SoundResult om::sound::base::SoundInputStream::read ( SoundBuffer buffer,
Size  numSamples 
)

Read the specified number of samples from the input stream into a sound buffer.

This method attempts to read the specified number of samples from the stream into the buffer, and returns the number of samples actually read from the stream. The samples are converted to the format stored in the buffer (Sample32f). The input position in the stream is advanced by the number of samples that are read.

This method enlarges the buffer to be at least as large as the number of requested samples, as well as makes sure it has as many channels as the stream has. The resulting buffer takes on the same sample rate as the stream.

virtual Bool om::sound::base::SoundInputStream::canSeek ( ) const
virtual

Return whether or not seeking is allowed in this input stream.

The defaut implementation returns FALSE, disabling seeking. Override the function to allow seeking of input streams.

Reimplemented in om::sound::filters::SoundPlayer, om::sound::filters::StreamPlayer, om::sound::base::Sound, om::sound::io::AIFFDecoder, om::sound::io::FLACDecoder, om::sound::io::OggDecoder, om::sound::io::WaveDecoder, om::sound::base::SoundCallbackStream, and om::sound::base::SoundDataInputStream.

virtual Bool om::sound::base::SoundInputStream::canSeek ( Int64  relativeSampleOffset) const
virtual

Return whether or not this input stream's current position can be moved by the specified signed sample offset.

This sample offset is specified as the number of sample frames to move in the stream - a frame is equal to one sample for each channel in the stream.

The defaut implementation returns FALSE, disabling seeking. Override the function to allow seeking of input streams.

Reimplemented in om::sound::filters::SoundPlayer, om::sound::filters::StreamPlayer, om::sound::base::Sound, om::sound::io::AIFFDecoder, om::sound::io::FLACDecoder, om::sound::io::OggDecoder, om::sound::io::WaveDecoder, om::sound::base::SoundCallbackStream, and om::sound::base::SoundDataInputStream.

virtual Int64 om::sound::base::SoundInputStream::seek ( Int64  relativeSampleOffset)
virtual

Move the current sample frame position in the stream by the specified signed amount.

This method attempts to seek the position in the stream by the specified amount. The method returns the signed amount that the position in the stream was changed by. Thus, if seeking is not allowed, 0 is returned. Otherwise, the stream should seek as far as possible in the specified direction and return the actual change in position.

The defaut implementation returns 0, disabling seeking. Override the function to allow seeking of input streams.

Reimplemented in om::sound::filters::SoundPlayer, om::sound::filters::StreamPlayer, om::sound::base::Sound, om::sound::io::AIFFDecoder, om::sound::io::FLACDecoder, om::sound::io::OggDecoder, om::sound::io::WaveDecoder, om::sound::base::SoundCallbackStream, and om::sound::base::SoundDataInputStream.

virtual SoundSize om::sound::base::SoundInputStream::getSamplesRemaining ( ) const
pure virtual

Return the number of samples remaining in the sound input stream.

The value returned must only be a lower bound on the total number of sample frames in the stream. For instance, if there are samples remaining, the method should return at least 1. If there are no samples remaining, the method should return 0. This behavior is allowed in order to support unbounded streams which might not have a defined endpoint.

Implemented in om::sound::filters::SoundPlayer, om::sound::filters::StreamPlayer, om::sound::base::Sound, om::sound::io::AIFFDecoder, om::sound::io::FLACDecoder, om::sound::io::OggDecoder, om::sound::io::WaveDecoder, om::sound::base::SoundCallbackStream, om::sound::filters::FilterInputStream, and om::sound::base::SoundDataInputStream.

Bool om::sound::base::SoundInputStream::hasSamplesRemaining ( ) const
inline

Return whether or not this sound input stream has any samples remaining in the stream.

virtual SampleIndex om::sound::base::SoundInputStream::getPosition ( ) const
pure virtual

Return the current position of the stream in samples relative to the start of the stream.

The returned value indicates the sample index of the current read position within the sound stream. For unbounded streams, this value should indicate the number of samples that have been read by the stream since it was opened.

Implemented in om::sound::filters::SoundPlayer, om::sound::filters::StreamPlayer, om::sound::base::Sound, om::sound::io::AIFFDecoder, om::sound::io::FLACDecoder, om::sound::io::OggDecoder, om::sound::io::WaveDecoder, om::sound::base::SoundCallbackStream, om::sound::filters::FilterInputStream, and om::sound::base::SoundDataInputStream.

virtual Size om::sound::base::SoundInputStream::getChannelCount ( ) const
pure virtual

Return the number of channels that are in the sound input stream.

This is the number of channels of sound data that will be read with each read call to the stream's read() method.

Implemented in om::sound::filters::SoundPlayer, om::sound::filters::StreamPlayer, om::sound::base::Sound, om::sound::io::AIFFDecoder, om::sound::io::FLACDecoder, om::sound::io::OggDecoder, om::sound::io::WaveDecoder, om::sound::base::SoundCallbackStream, om::sound::filters::FilterInputStream, and om::sound::base::SoundDataInputStream.

virtual SampleRate om::sound::base::SoundInputStream::getSampleRate ( ) const
pure virtual

Return the sample rate of the sound input stream's source audio data.

Since some types of streams support variable sampling rates, this value is not necessarily the sample rate of all audio that is read from the stream. However, for most streams, this value represents the sample rate of the entire stream. One should always test the sample rate of the buffers returned by the stream to see what their sample rates are before doing any operations that assume a sampling rate.

Implemented in om::sound::filters::SoundPlayer, om::sound::filters::StreamPlayer, om::sound::base::Sound, om::sound::io::AIFFDecoder, om::sound::io::FLACDecoder, om::sound::io::OggDecoder, om::sound::io::WaveDecoder, om::sound::base::SoundCallbackStream, om::sound::filters::FilterInputStream, and om::sound::base::SoundDataInputStream.

virtual SampleType om::sound::base::SoundInputStream::getNativeSampleType ( ) const
pure virtual

Return the actual sample type used in the stream.

This is the format of the stream's source data. For instance, a file might be encoded with 8-bit, 16-bit or 24-bit samples. This value indicates that sample type. For formats that don't have a native sample type, such as those which use frequency domain encoding, this function should return SampleType::SAMPLE_32F, indicating that the stream's native format is 32-bit floating point samples.

Implemented in om::sound::filters::SoundPlayer, om::sound::filters::StreamPlayer, om::sound::base::Sound, om::sound::io::AIFFDecoder, om::sound::io::FLACDecoder, om::sound::io::OggDecoder, om::sound::io::WaveDecoder, om::sound::base::SoundCallbackStream, om::sound::filters::FilterInputStream, and om::sound::base::SoundDataInputStream.

virtual Bool om::sound::base::SoundInputStream::isValid ( ) const
pure virtual

Return whether or not the stream has a valid source of sound data.

This method should return TRUE if everything is OK, but might return FALSE if the input stream is not valid (file not found, etc) or if the stream's data has improper format.

Implemented in om::sound::filters::SoundPlayer, om::sound::filters::StreamPlayer, om::sound::base::Sound, om::sound::io::FLACDecoder, om::sound::io::OggDecoder, om::sound::io::AIFFDecoder, om::sound::io::WaveDecoder, om::sound::base::SoundCallbackStream, om::sound::filters::FilterInputStream, and om::sound::base::SoundDataInputStream.

virtual SoundResult om::sound::base::SoundInputStream::readSamples ( SoundBuffer inputBuffer,
Size  numSamples 
)
protectedpure virtual

Read the specified number of samples from the input stream into the output buffer.

This method attempts to read the specified number of samples from the stream into the input buffer. It then returns the total number of valid samples which were read into the output buffer. The samples are converted to the format stored in the input buffer (Sample32f). The input position in the stream is advanced by the number of samples that are read.

The implementor of this method should make sure to set the sample rate of the buffer to be the correct output sample rate.

Implemented in om::sound::base::SoundCallbackStream, om::sound::filters::FilterInputStream, and om::sound::base::SoundDataInputStream.


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