A class for handling audio input/output to an audio device. More...
#include <AsyncAudioIO.h>
The different modes to open a device in.
More...A class for handling audio input/output to an audio device.
This is a class for handling audio input and output to an audio device. For now, the AudioIO class only works with 16 bit stereo samples. An example usage is shown below.
Multiple AudioIO objects can use the same audio device as long as the device name is exactly the same.
#include <iostream> #include <AsyncCppApplication.h> #include <AsyncAudioIO.h> #include <AsyncAudioSink.h> #include <AsyncAudioSource.h> using namespace std; using namespace Async; class MyClass : public Async::AudioSink, public Async::AudioSource { public: MyClass(void) { // Create a new audio IO object audio_io = new AudioIO("/dev/dsp", 0); // Open it for both reading and writing audio_io->open(AudioIO::MODE_RDWR); // Register this object as the audio source for sound output audio_io->registerSource(this); // Register the audio device as the audio source for this object registerSource(audio_io); } ~MyClass(void) { delete audio_io; } // AudioSink functions int writeSamples(const float *samples, int count) { // Just loop incoming samples back to the audio device return sinkWriteSamples(samples, count); } void flushSamples(void) { sinkFlushSamples(); } // AudioSource functions void resumeOutput(void) { sourceResumeOutput(); } void allSamplesFlushed(void) { sourceAllSamplesFlushed(); } private: AudioIO *audio_io; }; int main(int argc, char **argv) { CppApplication app; MyClass my_class; app.exec(); }
Definition at line 134 of file AsyncAudioIO.h.
enum Async::AudioIO::Mode |
The different modes to open a device in.
MODE_NONE |
No mode. The same as close. |
MODE_RD |
Read. |
MODE_WR |
Write. |
MODE_RDWR |
Both read and write. |
Definition at line 140 of file AsyncAudioIO.h.
Async::AudioIO::AudioIO | ( | const std::string & | dev_name, | |
int | channel | |||
) |
Constructor.
dev_name | The name of the device to use | |
channel | The channel number (zero is the first channel) |
Async::AudioIO::~AudioIO | ( | void | ) |
Destructor.
void Async::AudioIO::allSamplesFlushed | ( | void | ) | [inline, virtual] |
The registered sink has flushed all samples.
This function will be called when all samples have been flushed in the registered sink. This function is normally only called from a connected sink object.
Reimplemented from Async::AudioSource.
Definition at line 318 of file AsyncAudioIO.h.
static int Async::AudioIO::blocksize | ( | void | ) | [static] |
Find out what the blocksize is set to.
int Async::AudioIO::channel | ( | void | ) | const [inline] |
Return the audio channel used.
Definition at line 300 of file AsyncAudioIO.h.
void Async::AudioIO::close | ( | void | ) |
Close the adio device.
float Async::AudioIO::gain | ( | void | ) | const [inline] |
bool Async::AudioIO::isFullDuplexCapable | ( | void | ) |
Check if the audio device is capable of full duplex operation.
Mode Async::AudioIO::mode | ( | void | ) | const [inline] |
Find out how many samples there are in the output buffer.
This function can be used to find out how many samples there are in the output buffer at the moment. This can for example be used to find out how long it will take before the output buffer has been flushed.
Definition at line 271 of file AsyncAudioIO.h.
bool Async::AudioIO::open | ( | Mode | mode | ) |
Open the audio device in the specified mode.
mode | The mode to open the audio device in. See Async::AudioIO::Mode for more information |
void Async::AudioIO::resumeOutput | ( | void | ) | [inline, virtual] |
Resume audio output to the sink.
This function will be called when the registered audio sink is ready to accept more samples. This function is normally only called from a connected sink object.
Reimplemented from Async::AudioSource.
Definition at line 309 of file AsyncAudioIO.h.
int Async::AudioIO::sampleRate | ( | void | ) | const [inline] |
Return the sample rate.
Definition at line 294 of file AsyncAudioIO.h.
static int Async::AudioIO::setBlocksize | ( | int | size | ) | [static] |
Set the blocksize used when opening audio devices.
size | The blocksize, in samples per channel, to use |
Use this function to set the block size used when opening audio devices. The block size is the size of the blocks used when reading and writing audio to/from the sound card. Smaller blocks give less delay but could cause choppy audio if the computer is too slow. The blocksize is set as samples per channel. For example, a blocksize of 256 samples at 8kHz sample rate will give a delay of 256/8000 = 32ms. This is a global setting so all sound cards will be affected. Already opened sound cards will not be affected.
static int Async::AudioIO::setBufferCount | ( | int | count | ) | [static] |
Set the buffer count used when opening audio devices.
count | The buffer count to use |
Use this function to set the buffer count used when opening audio devices. The buffer count is the maximum number of blocks the driver will buffer when reading and writing audio to/from the sound card. Lower numbers give less delay but could cause choppy audio if the computer is too slow. This is a global setting so all sound cards will be affected. Already opened sound cards will not be affected.
static void Async::AudioIO::setChannels | ( | int | channels | ) | [static] |
Set the number of channels used when doing future opens.
channels | The number of channels to use |
Use this function to set the number of channels used when opening audio devices. This is a global setting so all sound cards will be affected. Already opened sound cards will not be affected.
void Async::AudioIO::setGain | ( | float | gain | ) | [inline] |
Set the gain to use.
gain | The new gain to set |
This function will setup the gain to use for this audio stream. The default gain is 1.0, that is no amplification or attenuation. A value < 1.0 will attenuate the audio stream and a value > 1.0 will result in an amplification of the audio stream.
Definition at line 282 of file AsyncAudioIO.h.
static void Async::AudioIO::setSampleRate | ( | int | rate | ) | [static] |
Set the sample rate used when doing future opens.
rate | The sampling rate to use |
Use this function to set the sample rate used when opening audio devices. This is a global setting so all sound cards will be affected. Already opened sound cards will not be affected.
friend class AudioDevice [friend] |
Definition at line 356 of file AsyncAudioIO.h.