Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages

DeviceAudioSdl Class Reference

SDL based stereo audio mixer/playback device. More...

#include <proAudioSdl.h>

Inheritance diagram for DeviceAudioSdl:

DeviceAudio List of all members.

Public Member Functions

virtual unsigned int sampleFromMemory (const AudioSample &sample, float volume=1.0f)
virtual bool sampleDestroy (unsigned int sample)
virtual unsigned int soundPlay (unsigned int sample, float volumeL=1.0f, float volumeR=1.0f, float disparity=0.0f, float pitch=1.0f)
virtual unsigned int soundLoop (unsigned int sample, float volumeL=1.0f, float volumeR=1.0f, float disparity=0.0f, float pitch=1.0f)
virtual bool soundUpdate (unsigned int sound, float volumeL, float volumeR, float disparity=0.0f, float pitch=1.0f)
virtual bool soundStop (unsigned int sound)
virtual void soundStop ()
virtual unsigned int soundActive () const

Static Public Member Functions

static DeviceAudiocreate (unsigned int nTracks=8, unsigned int frequency=22050, unsigned int chunkSize=1024)

Protected Member Functions

 DeviceAudioSdl (unsigned int nTracks, unsigned int frequency, unsigned int chunkSize)
virtual ~DeviceAudioSdl ()
void mixOutputFloat (signed short *outputBuffer, unsigned int nFrames)
void mixOutputSInt (Uint8 *stream, int len)

Static Protected Member Functions

static void cbOutput (void *userData, Uint8 *stream, int len)

Protected Attributes

SDL_AudioSpec m_spec
std::map< unsigned int, _AudioTrack > mm_sample
unsigned int m_sampleCounter
bool m_isDesiredFormat
_AudioTrack * ma_sound
unsigned int m_nSound

Detailed Description

SDL based stereo audio mixer/playback device.


Constructor & Destructor Documentation

DeviceAudioSdl::DeviceAudioSdl unsigned int  nTracks,
unsigned int  frequency,
unsigned int  chunkSize
[protected]
 

constructor. Use the create() method instead

virtual DeviceAudioSdl::~DeviceAudioSdl  )  [protected, virtual]
 

destructor. Use the destroy() method instead


Member Function Documentation

static void DeviceAudioSdl::cbOutput void *  userData,
Uint8 *  stream,
int  len
[static, protected]
 

output callback

static DeviceAudio* DeviceAudioSdl::create unsigned int  nTracks = 8,
unsigned int  frequency = 22050,
unsigned int  chunkSize = 1024
[static]
 

creates audio device

Use this method instead of a constructor.

Parameters:
nTracks (optional) the maximum number of sounds that are played parallely. Computation time is linearly correlated to this factor.
frequency (optional) sample frequency of the playback in Hz. 22050 corresponds to FM radio 44100 is CD quality. Computation time is linearly correlated to this factor.
chunkSize (optional) the number of bytes that are sent to the sound card at once. Low numbers lead to smaller latencies but need more computation time (thread switches). If a too small number is chosen, the sounds might not be played continuously. The default value 512 guarantees a good latency below 40 ms at 22050 Hz sample frequency.
Returns:
a pointer to an audio device object in case of success Note that the parameters are only handled when calling for the first time. Afterwards always the same object is returned until an explicit destroy() is called.

void DeviceAudioSdl::mixOutputFloat signed short *  outputBuffer,
unsigned int  nFrames
[protected]
 

advanced mixer method

void DeviceAudioSdl::mixOutputSInt Uint8 *  stream,
int  len
[protected]
 

fallback mixer method

virtual bool DeviceAudioSdl::sampleDestroy unsigned int  sample  )  [virtual]
 

deletes a previously created sound sample resource identified by its handle

Implements DeviceAudio.

virtual unsigned int DeviceAudioSdl::sampleFromMemory const AudioSample sample,
float  volume = 1.0f
[virtual]
 

converts a sound sample to internal audio format, returns handle

Implements DeviceAudio.

virtual unsigned int DeviceAudioSdl::soundActive  )  const [virtual]
 

returns number of currently active sounds

Implements DeviceAudio.

virtual unsigned int DeviceAudioSdl::soundLoop unsigned int  sample,
float  volumeL = 1.0f,
float  volumeR = 1.0f,
float  disparity = 0.0f,
float  pitch = 1.0f
[virtual]
 

plays a specified sample continuously and sets its parameters

Parameters:
sample a sample handle returned by a previous load() call
volumeL (optional) left volume
volumeR (optional) right volume
disparity (optional) time difference between left and right channel in seconds. Use negative values to specify a delay for the left channel, positive for the right.
pitch (optional) pitch factor for playback. 0.5 corresponds to one octave below, 2.0 to one above the original sample.
Returns:
a handle to the currently played sound or 0 in case of error

Implements DeviceAudio.

virtual unsigned int DeviceAudioSdl::soundPlay unsigned int  sample,
float  volumeL = 1.0f,
float  volumeR = 1.0f,
float  disparity = 0.0f,
float  pitch = 1.0f
[virtual]
 

plays a specified sample once and sets its parameters

Parameters:
sample a sample handle returned by a previous load() call
volumeL (optional) left volume
volumeR (optional) right volume
disparity (optional) time difference between left and right channel in seconds. Use negative values to specify a delay for the left channel, positive for the right.
pitch (optional) pitch factor for playback. 0.5 corresponds to one octave below, 2.0 to one above the original sample.
Returns:
a handle to the currently played sound or 0 in case of error

Implements DeviceAudio.

virtual void DeviceAudioSdl::soundStop  )  [virtual]
 

stops all sounds immediately

Implements DeviceAudio.

virtual bool DeviceAudioSdl::soundStop unsigned int  sound  )  [virtual]
 

stops a specified sound immediately

Implements DeviceAudio.

virtual bool DeviceAudioSdl::soundUpdate unsigned int  sound,
float  volumeL,
float  volumeR,
float  disparity = 0.0f,
float  pitch = 1.0f
[virtual]
 

updates parameters of a specified sound

Parameters:
sound handle of a currently active sound
volumeL left volume
volumeR right volume
disparity (optional) time difference between left and right channel in seconds. Use negative values to specify a delay for the left channel, positive for the right.
pitch (optional) pitch factor for playback. 0.5 corresponds to one octave below, 2.0 to one above the original sample.
Returns:
true in case the parameters have been updated successfully

Implements DeviceAudio.


Member Data Documentation

bool DeviceAudioSdl::m_isDesiredFormat [protected]
 

stores whether obtained audio format corresponds to expectations

unsigned int DeviceAudioSdl::m_nSound [protected]
 

stores number of parallel tracks

unsigned int DeviceAudioSdl::m_sampleCounter [protected]
 

stores maximum sample id

SDL_AudioSpec DeviceAudioSdl::m_spec [protected]
 

stores audio specification

_AudioTrack* DeviceAudioSdl::ma_sound [protected]
 

stores sounds to be mixed

std::map<unsigned int, _AudioTrack> DeviceAudioSdl::mm_sample [protected]
 

stores loaded sound samples


The documentation for this class was generated from the following file:
© 2009-02-04 by Gerald Franz, www.viremo.de impressum