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, pytests.py, record.cpp, record_basic.cpp, and volumes.cpp.

Definition at line 36 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=0, int deviceIDout=0)
 Create the audio system.
bool freeSample (ASSample *samp)
 Free all resources used by a sample, ONLY IF THE REFERENCE COUNT IS ZERO.
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.
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)
ASSamplestopRec (const char *name="", bool save=false, bool save_in_thread=false)
 Stop buffering and create a sample from the recorded audio.
unsigned stopSample (ASSample *samp, int trackno=-1)
 Stop playing 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 = 32
 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

AudioSystemImplimpl
 The pointer implementation.

Static Protected Attributes

static AudioSysteminstance = 0
 The singleton.


Constructor & Destructor Documentation

AudioSystem const AudioSystem  )  [inline, protected]
 

no copying - we are a Singleton

Definition at line 52 of file taptaudio.h.

AudioSystem AUDIO_FORMAT  format = AF_Default,
double  sampleRate = 0.0,
int  inputChannels = 2,
int  outputChannels = 2,
int  deviceIDin = 0,
int  deviceIDout = 0
 

Create the audio system.

Definition at line 18 of file taptaudio.cpp.

References AF_Default, AF_Float32, AF_Int16, AF_Int32, AF_Int8, AudioSystemImpl::as_mutex, AUDIO_TRACKS, DODEBUG, impl, and instance.

~AudioSystem  ) 
 

Destructor destroys the singleton, allowing another to be made.

Definition at line 84 of file taptaudio.cpp.

References impl, instance, AudioSystemImpl::stop(), and AudioSystemImpl::waitstop().

Here is the call graph for this function:


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)

Definition at line 113 of file taptaudio.cpp.

References AudioSystemImpl::freeSample(), and impl.

Here is the call graph for this function:

static AudioSystem* get  )  [inline, 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.

Definition at line 74 of file taptaudio.h.

References instance.

bool isRecording  ) 
 

Returns true if we are currently recording.

Definition at line 129 of file taptaudio.cpp.

References impl, and AudioSystemImpl::isRecording().

Here is the call graph for this function:

static bool isRunning  )  [inline, static]
 

Returns true if the AudioSystem is running.

Definition at line 79 of file taptaudio.h.

References instance.

void listDevices  )  [static]
 

Lists the device IDs to stderr.

Definition at line 166 of file taptaudio.cpp.

References AudioSystemImpl::listDevices().

Here is the call graph for this function:

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

Load a raw sample from memory.

Must match the format of the loaded AudioSystem.

Definition at line 150 of file taptaudio.cpp.

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, and volumes.cpp.

Definition at line 146 of file taptaudio.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.

Definition at line 109 of file taptaudio.cpp.

References impl, and AudioSystemImpl::loopSample().

Here is the call graph for this function:

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.

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, record_basic.cpp, and volumes.cpp.

Definition at line 101 of file taptaudio.cpp.

References impl, and AudioSystemImpl::mixSample().

Here is the call graph for this function:

AudioSystem& operator= const AudioSystem  )  [inline, protected]
 

no assignment - we are a Singleton

Definition at line 54 of file taptaudio.h.

void setDebugFile void *  FILESTAR  )  [static]
 

Set the FILE* at which debugging output is sent.

Definition at line 162 of file taptaudio.cpp.

References taptaudio_debug_file.

void setDebugLevel unsigned  level  )  [static]
 

Set the debugging level for the audio system.

0 for none, higher means more messages

Definition at line 158 of file taptaudio.cpp.

References SETDEBUG.

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

Definition at line 133 of file taptaudio.cpp.

References impl, and AudioSystemImpl::setVolume().

Here is the call graph for this function:

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_basic.cpp.

Definition at line 121 of file taptaudio.cpp.

References impl, and AudioSystemImpl::startRec().

Here is the call graph for this function:

void stop  ) 
 

Stop *ALL* audio operations.

Definition at line 137 of file taptaudio.cpp.

References impl, and AudioSystemImpl::stop().

Here is the call graph for this function:

ASSample * stopRec const char *  name = "",
bool  save = false,
bool  save_in_thread = false
 

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
Examples:
record_basic.cpp.

Definition at line 154 of file taptaudio.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.

Definition at line 117 of file taptaudio.cpp.

References impl, and AudioSystemImpl::stopSample().

Here is the call graph for this function:


Member Data Documentation

unsigned AUDIO_TRACKS = 32 [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 is negligible

Definition at line 142 of file taptaudio.cpp.

Referenced by AudioSystem().

AudioSystemImpl* impl [protected]
 

The pointer implementation.

Definition at line 56 of file taptaudio.h.

Referenced by AudioSystem(), freeSample(), isRecording(), loadRawSample(), loadSample(), loopSample(), mixSample(), setVolume(), startRec(), stop(), stopRec(), stopSample(), and ~AudioSystem().

AudioSystem * instance = 0 [static, protected]
 

The singleton.

Definition at line 143 of file taptaudio.cpp.

Referenced by AudioSystem(), get(), isRunning(), and ~AudioSystem().


The documentation for this class was generated from the following files:
Generated on Fri Aug 5 19:43:29 2005 for TaptAudio by  doxygen 1.4.3