AudioSystem Class Reference

#include <taptaudio.h>

Collaboration diagram for AudioSystem:

Collaboration graph
[legend]
List of all members.

Detailed Description

The audio system.

Only one of these may exist at a time. You may delete the old copy and make a new one if you wish.

Examples:

loopmix.cpp, mixing.cpp, record.cpp, record_basic.cpp, and volumes.cpp.

Definition at line 100 of file taptaudio.h.

Public Member Functions

 AudioSystem (AUDIO_FORMAT format=AF_Default, double sampleRate=0.0, int inputChannels=2, int outputChannels=2, int deviceIDin=-1, int deviceIDout=-1, const AUDIO_BACKEND backends[]=NULL)
 Create the audio system.
bool freeSample (ASSample *samp)
 Free all resources used by a sample, ONLY IF THE REFERENCE COUNT IS ZERO.
float inputVU () const
 Get the current VU level of the input buffer between 0 and 1.0.
bool isRecording ()
 Returns true if we are currently recording.
ASSampleloadRawSample (const std::string &name, void *data, unsigned long size)
ASSampleloadRawSample (const char *name, void *data, unsigned long size)
 Load a raw sample from memory.
ASSampleloadSample (const std::string &name)
ASSampleloadSample (const char *name)
 Load a sample that will be managed by the AudioSystem.
bool loopSample (ASSample *samp, float vol=1.0f, unsigned *trackno=0)
 Loop a sample.
bool mixSample (ASSample *samp, float vol=1.0f, unsigned *trackno=0)
bool mixSample (ASSample *samp, bool record_after, double record_size=30.0, float vol=1.0f, unsigned *trackno=0)
 Mix a loaded sample into the output audio stream.
bool pauseRec ()
 Pause the recording.
unsigned pauseSample (ASSample *samp, int trackno=-1, bool setpause=true)
 Pause playing instances of a sample.
bool previewRec (float vol=1.0, unsigned *trackno=0)
 Preview the current recording (i.e.
bool resumeRec ()
 Resume the recording.
unsigned setVolume (ASSample *samp, float vol=1.0f, int trackno=-1)
 Adjust the volume of all playing instances of a sample.
bool startRec (double secondsMax=30.0)
 Start buffering data from the audio input (microphone) into the (single) recording buffer.
void stop ()
 Stop *ALL* audio operations.
ASSamplestopRec (const std::string &name, bool save=false, bool save_in_thread=false, FILE_ENCODING enc=AF_ENC_WAV, float quality=2.0)
ASSamplestopRec (const char *name="", bool save=false, bool save_in_thread=false, FILE_ENCODING enc=AF_ENC_WAV, float quality=2.0)
 Stop buffering and create a sample from the recorded audio.
unsigned stopSample (ASSample *samp, int trackno=-1)
 Stop playing instances of a sample.
unsigned unpauseSample (ASSample *samp, int trackno=-1)
 Unpause paused instances of a sample.
 ~AudioSystem ()
 Destructor destroys the singleton, allowing another to be made.

Static Public Member Functions

static AudioSystemget ()
 Get the singleton instance.
static bool isRunning ()
 Returns true if the AudioSystem is running.
static void listDevices ()
 Lists the device IDs to stderr.
static void setDebugFile (void *FILESTAR)
 Set the FILE* at which debugging output is sent.
static void setDebugLevel (unsigned level)
 Set the debugging level for the audio system.

Static Public Attributes

static unsigned AUDIO_TRACKS
 Number of audio tracks in mixer.

Protected Member Functions

 AudioSystem (const AudioSystem &)
 no copying - we are a Singleton
AudioSystemoperator= (const AudioSystem &)
 no assignment - we are a Singleton

Protected Attributes

AudioSystemImpl * impl
 The pointer implementation.

Static Protected Attributes

static AudioSysteminstance
 The singleton.


Constructor & Destructor Documentation

AudioSystem const AudioSystem  )  [protected]
 

no copying - we are a Singleton

AudioSystem AUDIO_FORMAT  format = AF_Default,
double  sampleRate = 0.0,
int  inputChannels = 2,
int  outputChannels = 2,
int  deviceIDin = -1,
int  deviceIDout = -1,
const AUDIO_BACKEND  backends[] = NULL
 

Create the audio system.

Parameters:
format The format to try and mix audio in (some backends may force a particular format)
sampleRate The sample rate to run the AudioSystem in
inputChannels The number of input channels (i.e. mono/stereo microphone)
outputChannels The number of output channels (i.e. mono/stereo/surround)
deviceIDin The input device identifier (usually backend-dependent, -1 is default/best, use listDevices() for a list)
deviceIDout The input output identifier
backends A fallback list of backends to attempt to initialize THIS MUST BE TERMINATED BY AF_NOAUDIO (or NULL/0)

~AudioSystem  ) 
 

Destructor destroys the singleton, allowing another to be made.


Member Function Documentation

bool freeSample ASSample samp  ) 
 

Free all resources used by a sample, ONLY IF THE REFERENCE COUNT IS ZERO.

Will also remove itself from the sample registry. Only ever use this to free a sample -- never delete() your reference.

Parameters:
samp the sample to free
Returns:
true if the reference count was zero and the sample was freed (i.e. success)

static AudioSystem* get  )  [static]
 

Get the singleton instance.

Returns NULL if it has not been created, or it has been destroyed.

Examples:
loopmix.cpp, mixing.cpp, and volumes.cpp.

float inputVU  )  const
 

Get the current VU level of the input buffer between 0 and 1.0.

bool isRecording  ) 
 

Returns true if we are currently recording.

static bool isRunning  )  [static]
 

Returns true if the AudioSystem is running.

static void listDevices  )  [static]
 

Lists the device IDs to stderr.

ASSample* loadRawSample const char *  name,
void *  data,
unsigned long  size
 

Load a raw sample from memory.

Must match the format of the loaded AudioSystem.

ASSample* loadSample const char *  name  ) 
 

Load a sample that will be managed by the AudioSystem.

Client code will just use the return value as a pointer to pass back into the audio system. Most of this can occur in a background thread .. but maybe not two at once.

Note:
If name is not registered, it must refer to a file AND the file must be in a format convertible to the audio system.
Parameters:
name A filename, or the name of a sample "known" to the AudioSystem
Returns:
a loaded sample, that can be passed back to the AudioSystem
Examples:
loopmix.cpp, mixing.cpp, rbtests.rb, and volumes.cpp.

bool loopSample ASSample samp,
float  vol = 1.0f,
unsigned *  trackno = 0
 

Loop a sample.

Stop it with stopSample.

Note:
it makes no sense to record after one of these
Parameters:
samp the sample to play
vol the volume at which to mix the sample
trackno if non-null, this will be set to the track number assigned to the sample
Returns:
true if our mixer supports looping and there is a free track in which to play the sample
Examples:
loopmix.cpp.

bool mixSample ASSample samp,
bool  record_after,
double  record_size = 30.0,
float  vol = 1.0f,
unsigned *  trackno = 0
 

Mix a loaded sample into the output audio stream.

Note:
if samp is NULL, we return false

if DEBUG_LEVEL > WARNING (2, i.e. 3 or more), we check to see if samp is registered before playing (otherwise we assume it is valid)

Parameters:
samp the sample to play
record_after if true, we will start recording when the sample is finished
record_size the size of the record buffer in seconds
vol the volume at which to mix the (output) sample
trackno if non-null, this will be set to the track number assigned to the sample
Returns:
true if there is a free track in which to play the sample
Examples:
mixing.cpp, rbtests.rb, record.cpp, record_basic.cpp, and volumes.cpp.

AudioSystem& operator= const AudioSystem  )  [protected]
 

no assignment - we are a Singleton

bool pauseRec  ) 
 

Pause the recording.

Returns:
true if there is a current recording that was not already paused (and is now paused)

unsigned pauseSample ASSample samp,
int  trackno = -1,
bool  setpause = true
 

Pause playing instances of a sample.

Parameters:
samp the sample to pause
trackno the track (holding a playing samp) to pause; -1 for all
setpause true to pause, false to unpause
Returns:
the number of samples paused

bool previewRec float  vol = 1.0,
unsigned *  trackno = 0
 

Preview the current recording (i.e.

mix it into the output stream). It doesn't need to be paused.

Parameters:
vol the volume at which to mix the recording
trackno if non-null, set to the track number where the recording will be previewed
Returns:
true if there is a current recording

bool resumeRec  ) 
 

Resume the recording.

Returns:
true if there is a currently a paused recording that has now resumed

static void setDebugFile void *  FILESTAR  )  [static]
 

Set the FILE* at which debugging output is sent.

static void setDebugLevel unsigned  level  )  [static]
 

Set the debugging level for the audio system.

0 for none, higher means more messages

Examples:
record.cpp, and volumes.cpp.

unsigned setVolume ASSample samp,
float  vol = 1.0f,
int  trackno = -1
 

Adjust the volume of all playing instances of a sample.

Parameters:
samp the sample to adjust
vol the volume to set
trackno the track (holding a playing samp) to adjust; -1 for all
Returns:
the number of samples adjusted

bool startRec double  secondsMax = 30.0  ) 
 

Start buffering data from the audio input (microphone) into the (single) recording buffer.

Parameters:
secondsMax the maximum amount of time we will record for (we will trim the buffer if we record less)
Returns:
true if we were able to start recording (false if we are already recording)
Examples:
record.cpp, and record_basic.cpp.

void stop  ) 
 

Stop *ALL* audio operations.

ASSample* stopRec const char *  name = "",
bool  save = false,
bool  save_in_thread = false,
FILE_ENCODING  enc = AF_ENC_WAV,
float  quality = 2.0
 

Stop buffering and create a sample from the recorded audio.

Parameters:
name if non-null use name to identify the sample in the registry if null, a name will be generated based on the current time
save if true, the sample will be saved to disk, using name as the filename
save_in_thread if true, we will start a thread to save the data
enc file encoding to use (defaults to WAV)
quality encoding quality, where relevant
Examples:
record.cpp, and record_basic.cpp.

unsigned stopSample ASSample samp,
int  trackno = -1
 

Stop playing instances of a sample.

Parameters:
samp the sample to stop playing.
trackno the track (holding a playing samp) to stop; -1 for all
Returns:
the number of samples stopped
Examples:
loopmix.cpp.

unsigned unpauseSample ASSample samp,
int  trackno = -1
 

Unpause paused instances of a sample.


Member Data Documentation

unsigned AUDIO_TRACKS [static]
 

Number of audio tracks in mixer.

  • 0 will disable audio (singleton will never be created)
  • 1 will use a super-fast non-mixer version
  • >1 will use a stereo/mono N-track mixer default: 32
    Note:
    track overhead (i.e. >2) is negligible (i.e. vs 2)

Definition at line 111 of file taptaudio.h.

AudioSystemImpl* impl [protected]
 

The pointer implementation.

Definition at line 126 of file taptaudio.h.

AudioSystem* instance [static, protected]
 

The singleton.

Definition at line 127 of file taptaudio.h.


The documentation for this class was generated from the following file:
Generated on Thu Mar 16 11:30:43 2006 for TaptAudio by  doxygen 1.4.6