ccAudio
Public Member Functions | Protected Member Functions | Protected Attributes
ost::AudioStream Class Reference

AudioStream accesses AudioFile base class content as fixed frames of streaming linear samples. More...

#include <audio2.h>

Inheritance diagram for ost::AudioStream:
ost::AudioFile ost::AudioBase ost::Audio

List of all members.

Public Member Functions

 AudioStream ()
 Create a new audiostream object.
 AudioStream (const char *name, Mode mode=modeRead, timeout_t framing=0)
 Create an audio stream object and open an existing audio file.
 AudioStream (const char *name, Info *info, bool exclusive=false, timeout_t framing=0)
 Create an audio stream object and a new audio file.
virtual ~AudioStream ()
ssize_t getBuffer (Encoded data, size_t count)
 Virtual for packet i/o intercept.
void open (const char *name, Mode mode=modeRead, timeout_t framing=0)
 Open existing audio file for streaming.
void create (const char *name, Info *info, bool exclusive=false, timeout_t framing=0)
 Create a new audio file for streaming.
void close (void)
 Close the currently open audio file for streaming.
void flush (void)
 flush any unsaved buffered data to disk.
bool isStreamable (void)
 Check if the audio file may be streamed.
unsigned getCount (void)
 Get the number of samples expected in a frame.
unsigned getEncoded (AudioCodec *codec, Encoded address, unsigned frames=1)
 Stream audio data from the file and convert into an alternate encoding based on the codec supplied.
unsigned putEncoded (AudioCodec *codec, Encoded address, unsigned frames=1)
 Stream audio data in an alternate codec into the currently opened file.
unsigned getEncoded (Encoded address, unsigned frames=1)
 Get data from the streamed file in it's native encoding.
unsigned putEncoded (Encoded address, unsigned frames=1)
 Put data encoded in the native format of the stream file.
ssize_t getPacket (Encoded data)
 Get a packet of data from the file.
unsigned getMono (Linear buffer, unsigned frames=1)
 Get and automatically convert audio file data into mono linear audio samples.
unsigned getStereo (Linear buffer, unsigned frames=1)
 Get and automatically convert audio file data into stereo (two channel) linear audio samples.
unsigned putMono (Linear buffer, unsigned frames=1)
 Automatically convert and put mono linear audio data into the audio file.
unsigned putStereo (Linear buffer, unsigned frames=1)
 Automatically convert and put stereo linear audio data into the audio file.
unsigned bufMono (Linear buffer, unsigned count)
 Automatically convert and put arbitrary linear mono data into the audio file.
unsigned bufStereo (Linear buffer, unsigned count)
 Automatically convert and put arbitrary linear stereo data into the audio file.
AudioCodecgetCodec (void)
 Return the codec being used if there is one.

Protected Member Functions

unsigned bufAudio (Linear samples, unsigned count, unsigned size)

Protected Attributes

AudioCodeccodec
Encoded framebuf
bool streamable
Linear bufferFrame
unsigned bufferPosition
unsigned bufferChannels
Linear encBuffer
Linear decBuffer
unsigned encSize
unsigned decSize

Detailed Description

AudioStream accesses AudioFile base class content as fixed frames of streaming linear samples.

If a codec must be assigned to perform conversion to/from linear data, AudioStream will handle conversion automatically. AudioStream will also convert between mono and stereo audio content. AudioStream uses linear samples in the native machine endian format and perform endian byte swapping as needed.

Author:
David Sugar <dyfet@ostel.com> Audio Streaming with Linear Conversion

Constructor & Destructor Documentation

ost::AudioStream::AudioStream ( )

Create a new audiostream object.

ost::AudioStream::AudioStream ( const char *  name,
Mode  mode = modeRead,
timeout_t  framing = 0 
)

Create an audio stream object and open an existing audio file.

Parameters:
nameof file to open.
modeof file access.
framingtime in milliseconds.
ost::AudioStream::AudioStream ( const char *  name,
Info info,
bool  exclusive = false,
timeout_t  framing = 0 
)

Create an audio stream object and a new audio file.

Parameters:
nameof file to open.
infosource description for properties of new file.
exclusiveaccess if true.
framingtime in milliseconds.
virtual ost::AudioStream::~AudioStream ( ) [virtual]

Member Function Documentation

unsigned ost::AudioStream::bufAudio ( Linear  samples,
unsigned  count,
unsigned  size 
) [protected]
unsigned ost::AudioStream::bufMono ( Linear  buffer,
unsigned  count 
)

Automatically convert and put arbitrary linear mono data into the audio file.

Convert to stereo and buffer incomplete frames as needed by the streaming file.

Parameters:
bufferto save linear audio from.
countof linear audio to write.
Returns:
number of linear audio samples written to file.
unsigned ost::AudioStream::bufStereo ( Linear  buffer,
unsigned  count 
)

Automatically convert and put arbitrary linear stereo data into the audio file.

Convert to mono and buffer incomplete frames as needed by the streaming file.

Parameters:
bufferto save linear audio from.
countof linear audio to write.
Returns:
number of linear audio samples written to file.
void ost::AudioStream::close ( void  )

Close the currently open audio file for streaming.

Reimplemented from ost::AudioFile.

void ost::AudioStream::create ( const char *  name,
Info info,
bool  exclusive = false,
timeout_t  framing = 0 
)

Create a new audio file for streaming.

Parameters:
nameof file to create.
infosource description for file properties.
exclusivetrue for exclusive access.
framingtiming in milliseconds.

Reimplemented from ost::AudioFile.

void ost::AudioStream::flush ( void  )

flush any unsaved buffered data to disk.

ssize_t ost::AudioStream::getBuffer ( Encoded  data,
size_t  count 
) [virtual]

Virtual for packet i/o intercept.

Returns:
bytes read.
Parameters:
dataencoding buffer.
countrequested.

Reimplemented from ost::AudioFile.

AudioCodec* ost::AudioStream::getCodec ( void  ) [inline]

Return the codec being used if there is one.

Returns:
codec used.

Reimplemented from ost::AudioFile.

unsigned ost::AudioStream::getCount ( void  )

Get the number of samples expected in a frame.

unsigned ost::AudioStream::getEncoded ( AudioCodec codec,
Encoded  address,
unsigned  frames = 1 
)

Stream audio data from the file and convert into an alternate encoding based on the codec supplied.

Parameters:
codecto apply before saving.
addressof data to save.
framesto stream by the codec.
Returns:
number of frames processed.
unsigned ost::AudioStream::getEncoded ( Encoded  address,
unsigned  frames = 1 
)

Get data from the streamed file in it's native encoding.

Parameters:
addressto save encoded audio.
framesof audio to load.
Returns:
number of frames read.
unsigned ost::AudioStream::getMono ( Linear  buffer,
unsigned  frames = 1 
)

Get and automatically convert audio file data into mono linear audio samples.

Parameters:
bufferto save linear audio into.
framesof audio to read.
Returns:
number of frames read from file.
ssize_t ost::AudioStream::getPacket ( Encoded  data)

Get a packet of data from the file.

This uses the codec to determine what a true packet boundry is.

Parameters:
bufferto save encoded data.
Returns:
number of bytes read as packet.

Reimplemented from ost::AudioBase.

unsigned ost::AudioStream::getStereo ( Linear  buffer,
unsigned  frames = 1 
)

Get and automatically convert audio file data into stereo (two channel) linear audio samples.

Parameters:
bufferto save linear audio into.
framesof audio to read.
Returns:
number of frames read from file.
bool ost::AudioStream::isStreamable ( void  )

Check if the audio file may be streamed.

Files can be streamed if a codec is available or if they are linear.

Returns:
true if streamable.
void ost::AudioStream::open ( const char *  name,
Mode  mode = modeRead,
timeout_t  framing = 0 
)

Open existing audio file for streaming.

Parameters:
nameof file to open.
modeto use file.
framingtimer in milliseconds.

Reimplemented from ost::AudioFile.

unsigned ost::AudioStream::putEncoded ( Encoded  address,
unsigned  frames = 1 
)

Put data encoded in the native format of the stream file.

Parameters:
addressto load encoded audio.
framesof audio to save.
Returns:
number of frames written.
unsigned ost::AudioStream::putEncoded ( AudioCodec codec,
Encoded  address,
unsigned  frames = 1 
)

Stream audio data in an alternate codec into the currently opened file.

Parameters:
codecto convert incoming data from.
addressof data to convert and stream.
framesof audio to stream.
Returns:
number of frames processed.
unsigned ost::AudioStream::putMono ( Linear  buffer,
unsigned  frames = 1 
)

Automatically convert and put mono linear audio data into the audio file.

Convert to stereo as needed by file format.

Parameters:
bufferto save linear audio from.
framesof audio to write.
Returns:
number of frames written to file.
unsigned ost::AudioStream::putStereo ( Linear  buffer,
unsigned  frames = 1 
)

Automatically convert and put stereo linear audio data into the audio file.

Convert to mono as needed by file format.

Parameters:
bufferto save linear audio from.
framesof audio to write.
Returns:
number of frames written to file.

Member Data Documentation

unsigned ost::AudioStream::bufferChannels [protected]
unsigned ost::AudioStream::bufferPosition [protected]
unsigned ost::AudioStream::decSize [protected]
unsigned ost::AudioStream::encSize [protected]
bool ost::AudioStream::streamable [protected]

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