Async 1.8.0
|
A class for handling audio input/output to an audio device. More...
#include <AsyncAudioIO.h>
Public Types | |
enum | Mode { MODE_NONE , MODE_RD , MODE_WR , MODE_RDWR } |
The different modes to open a device in. More... | |
Public Member Functions | |
size_t | readBlocksize (void) |
Find out what the read (recording) blocksize is set to. | |
size_t | writeBlocksize (void) |
Find out what the write (playback) blocksize is set to. | |
AudioIO (const std::string &dev_name, size_t channel) | |
Constructor. | |
~AudioIO (void) | |
Destructor. | |
bool | isFullDuplexCapable (void) |
Check if the audio device is capable of full duplex operation. | |
bool | open (Mode mode) |
Open the audio device in the specified mode. | |
void | close (void) |
Close the adio device. | |
Mode | mode (void) const |
Find out how many samples there are in the output buffer. | |
void | setGain (float gain) |
Set the gain to use. | |
float | gain (void) const |
Return the gain. | |
int | sampleRate (void) const |
Return the sample rate. | |
size_t | channel (void) const |
Return the audio channel used. | |
void | resumeOutput (void) |
Resume audio output to the sink. | |
void | allSamplesFlushed (void) |
The registered sink has flushed all samples. | |
![]() | |
AudioSource (void) | |
Default constuctor. | |
virtual | ~AudioSource (void) |
Destructor. | |
bool | registerSink (AudioSink *sink, bool managed=false) |
Register an audio sink to provide samples to. | |
void | unregisterSink (void) |
Unregister the previously registered audio sink. | |
bool | isRegistered (void) const |
Check if an audio sink has been registered. | |
AudioSink * | sink (void) const |
Get the registered audio sink. | |
bool | sinkManaged (void) const |
Check if the sink is managed or not. | |
void | handleAllSamplesFlushed (void) |
The registered sink has flushed all samples. | |
![]() | |
AudioSink (void) | |
Default constuctor. | |
virtual | ~AudioSink (void) |
Destructor. | |
bool | registerSource (AudioSource *source) |
Register an audio source to provide samples to this sink. | |
void | unregisterSource (void) |
Unregister the previously registered audio source. | |
bool | isRegistered (void) const |
Check if an audio source has been registered. | |
AudioSource * | source (void) const |
Get the registered audio source. | |
virtual int | writeSamples (const float *samples, int count) |
Write samples into this audio sink. | |
virtual void | flushSamples (void) |
Tell the sink to flush the previously written samples. | |
Static Public Member Functions | |
static void | setSampleRate (int rate) |
Set the sample rate used when doing future opens. | |
static void | setBlocksize (size_t size) |
Set the blocksize used when opening audio devices. | |
static void | setBlockCount (size_t count) |
Set the block count used when opening audio devices. | |
static void | setChannels (size_t channels) |
Set the number of channels used when doing future opens. | |
Friends | |
class | AudioDevice |
Additional Inherited Members | |
![]() | |
int | sinkWriteSamples (const float *samples, int len) |
void | sinkFlushSamples (void) |
bool | setHandler (AudioSource *handler) |
Setup another source to handle the outgoing audio. | |
AudioSource * | handler (void) const |
void | clearHandler (void) |
Clear a handler that was previously setup with setHandler. | |
![]() | |
void | sourceResumeOutput (void) |
Tell the source that we are ready to accept more samples. | |
void | sourceAllSamplesFlushed (void) |
Tell the source that all samples have been flushed. | |
bool | setHandler (AudioSink *handler) |
Setup another sink to handle the incoming audio. | |
void | clearHandler (void) |
Clear a handler that was previously setup with setHandler. | |
AudioSink * | handler (void) const |
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.
Definition at line 134 of file AsyncAudioIO.h.
enum Async::AudioIO::Mode |
The different modes to open a device in.
Enumerator | |
---|---|
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, |
size_t | 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.
|
inlinevirtual |
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 322 of file AsyncAudioIO.h.
|
inline |
Return the audio channel used.
Definition at line 304 of file AsyncAudioIO.h.
void Async::AudioIO::close | ( | void | ) |
Close the adio device.
|
inline |
Return the gain.
Definition at line 292 of file AsyncAudioIO.h.
Referenced by setGain().
bool Async::AudioIO::isFullDuplexCapable | ( | void | ) |
Check if the audio device is capable of full duplex operation.
|
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 275 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 |
size_t Async::AudioIO::readBlocksize | ( | void | ) |
Find out what the read (recording) blocksize is set to.
|
inlinevirtual |
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 313 of file AsyncAudioIO.h.
|
inline |
Return the sample rate.
Definition at line 298 of file AsyncAudioIO.h.
|
static |
Set the block count used when opening audio devices.
count | The block 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 |
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 |
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.
|
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 286 of file AsyncAudioIO.h.
References gain().
|
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.
size_t Async::AudioIO::writeBlocksize | ( | void | ) |
Find out what the write (playback) blocksize is set to.
|
friend |
Definition at line 360 of file AsyncAudioIO.h.