#include <AsyncAudioIO.h>
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 135 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 141 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 319 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 301 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.
Definition at line 272 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 310 of file AsyncAudioIO.h.
int Async::AudioIO::sampleRate | ( | void | ) | const [inline] |
Return the sample rate.
Definition at line 295 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 |
static int Async::AudioIO::setBufferCount | ( | int | count | ) | [static] |
Set the buffer count used when opening audio devices.
count | The buffer count to use |
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 |
void Async::AudioIO::setGain | ( | float | gain | ) | [inline] |
Set the gain to use.
gain | The new gain to set |
Definition at line 283 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 |
friend class AudioDevice [friend] |
Definition at line 368 of file AsyncAudioIO.h.