Async 1.8.0
AsyncAudioIO_demo.cpp

An example of how to use the Async::AudioIO class

#include <AsyncAudioIO.h>
#include <AsyncAudioSink.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("alsa:default", 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);
// Create a sine generator
sine_gen = new AudioGenerator;
sine_gen->setFq(1000);
sine_gen->setPower(-24);
// Create an audio device for the sine generator
AudioIO *sine_io = new AudioIO("alsa:default", 1);
sine_io->open(AudioIO::MODE_WR);
sine_gen->registerSink(sine_io, true);
// Enable the sine generator
sine_gen->enable(true);
}
~MyClass(void)
{
delete audio_io;
delete sine_gen;
}
// AudioSink functions
int writeSamples(const float *samples, int count)
{
// Just loop incoming samples back to the audio device
// We could do some processing here if we wanted to.
return sinkWriteSamples(samples, count);
}
void flushSamples(void)
{
}
// AudioSource functions
void resumeOutput(void)
{
}
void allSamplesFlushed(void)
{
}
private:
AudioIO * audio_io;
AudioGenerator * sine_gen;
};
int main(int argc, char **argv)
{
MyClass my_class;
app.exec();
}
An audio generator.
Contains a class for handling audio input/output to an audio device.
This file contains the base class for an audio sink.
This file contains the base class for an audio source.
The core class for writing asyncronous cpp applications.
A class for generating periodic audio signals.
void setFq(float tone_fq)
Set the audio frequency.
A class for handling audio input/output to an audio device.
bool open(Mode mode)
Open the audio device in the specified mode.
The base class for an audio sink.
void sourceAllSamplesFlushed(void)
Tell the source that all samples have been flushed.
bool registerSource(AudioSource *source)
Register an audio source to provide samples to this sink.
virtual int writeSamples(const float *samples, int count)
Write samples into this audio sink.
void sourceResumeOutput(void)
Tell the source that we are ready to accept more samples.
virtual void flushSamples(void)
Tell the sink to flush the previously written samples.
The base class for an audio source.
virtual void allSamplesFlushed(void)
The registered sink has flushed all samples.
void sinkFlushSamples(void)
virtual void resumeOutput(void)
Resume audio output to the sink.
int sinkWriteSamples(const float *samples, int len)
An application class for writing non GUI applications.
void exec(void)
Execute the application main loop.
Namespace for the asynchronous programming classes.