Base class for handling audio devices.
More...
#include <AsyncAudioDevice.h>
|
virtual size_t | readBlocksize (void)=0 |
| Find out what the read (recording) blocksize is set to.
|
|
virtual size_t | writeBlocksize (void)=0 |
| Find out what the write (playback) blocksize is set to.
|
|
virtual bool | isFullDuplexCapable (void)=0 |
| Check if the audio device has full duplex capability.
|
|
bool | open (Mode mode) |
| Open the audio device.
|
|
void | close (void) |
| Close the audio device.
|
|
Mode | mode (void) const |
| Get the current operating mode of this audio device.
|
|
virtual void | audioToWriteAvailable (void)=0 |
| Tell the audio device handler that there are audio to be written in the buffer.
|
|
virtual void | flushSamples (void)=0 |
|
virtual int | samplesToWrite (void) const =0 |
| Find out how many samples there are in the output buffer.
|
|
int | sampleRate (void) const |
| Return the sample rate.
|
|
const std::string & | devName (void) const |
| Return the device name.
|
|
|
static AudioDevice * | registerAudioIO (const std::string &dev_designator, AudioIO *audio_io) |
| Register an AudioIO object with the given device name.
|
|
static void | unregisterAudioIO (AudioIO *audio_io) |
| Unregister a previously registered AudioIO object.
|
|
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 buffer count used when opening audio devices.
|
|
static void | setChannels (size_t channels) |
| Set the number of channels used when doing future opens.
|
|
static size_t | getChannels (void) |
| Get the number of channels used for future opens.
|
|
|
| AudioDevice (const std::string &dev_name) |
| Constuctor.
|
|
virtual | ~AudioDevice (void) |
| Destructor.
|
|
virtual bool | openDevice (Mode mode)=0 |
| Open the audio device.
|
|
virtual void | closeDevice (void)=0 |
| Close the audio device.
|
|
void | putBlocks (int16_t *buf, size_t frame_cnt) |
| Write samples read from audio device to upper layers.
|
|
size_t | getBlocks (int16_t *buf, size_t block_cnt) |
| Read samples from upper layers to write to audio device.
|
|
void | setDeviceError (void) |
| Called by the device object to indicate an error condition.
|
|
Base class for handling audio devices.
- Author
- Tobias Blomberg / SM0SVX
- Date
- 2004-03-20
This class implements a base class for supporting different audio devices. This class is not intended to be used by the end user of the Async library. It is used by the Async::AudioIO class, which is the Async API frontend for using audio in an application.
Definition at line 123 of file AsyncAudioDevice.h.
◆ 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 129 of file AsyncAudioDevice.h.
◆ AudioDevice()
Async::AudioDevice::AudioDevice |
( |
const std::string & | dev_name | ) |
|
|
explicitprotected |
Constuctor.
- Parameters
-
dev_name | The name of the device to associate this object with |
◆ ~AudioDevice()
virtual Async::AudioDevice::~AudioDevice |
( |
void | | ) |
|
|
protectedvirtual |
◆ audioToWriteAvailable()
virtual void Async::AudioDevice::audioToWriteAvailable |
( |
void | | ) |
|
|
pure virtual |
Tell the audio device handler that there are audio to be written in the buffer.
◆ close()
void Async::AudioDevice::close |
( |
void | | ) |
|
◆ closeDevice()
virtual void Async::AudioDevice::closeDevice |
( |
void | | ) |
|
|
protectedpure virtual |
◆ devName()
const std::string & Async::AudioDevice::devName |
( |
void | | ) |
const |
|
inline |
◆ flushSamples()
virtual void Async::AudioDevice::flushSamples |
( |
void | | ) |
|
|
pure virtual |
◆ getBlocks()
size_t Async::AudioDevice::getBlocks |
( |
int16_t * | buf, |
|
|
size_t | block_cnt ) |
|
protected |
Read samples from upper layers to write to audio device.
buf Buffer which will be filled with frames of samples
block_cnt The size of the buffer counted in blocks
- Returns
- The number of blocks actually stored in the buffer
This function is used by an audio device implementation to get samples from upper layers to write to the actual audio device. The count is given in blocks. The buffer must be able to store the number given in block_cnt. Fewer blocks may be returned if the requested block count is not available. The number of samples a block contain is ret_blocks * writeBlocksize() * channels.
◆ getChannels()
static size_t Async::AudioDevice::getChannels |
( |
void | | ) |
|
|
inlinestatic |
Get the number of channels used for future opens.
- Returns
- Returns the number of channels used for future opens
Definition at line 235 of file AsyncAudioDevice.h.
References channels.
◆ isFullDuplexCapable()
virtual bool Async::AudioDevice::isFullDuplexCapable |
( |
void | | ) |
|
|
pure virtual |
Check if the audio device has full duplex capability.
- Returns
- Returns true if the device has full duplex capability or else false
◆ mode()
Mode Async::AudioDevice::mode |
( |
void | | ) |
const |
|
inline |
◆ open()
bool Async::AudioDevice::open |
( |
Mode | mode | ) |
|
Open the audio device.
- Parameters
-
- Returns
- Returns true on success or else false
◆ openDevice()
virtual bool Async::AudioDevice::openDevice |
( |
Mode | mode | ) |
|
|
protectedpure virtual |
Open the audio device.
- Parameters
-
- Returns
- Returns true on success or else false
◆ putBlocks()
void Async::AudioDevice::putBlocks |
( |
int16_t * | buf, |
|
|
size_t | frame_cnt ) |
|
protected |
Write samples read from audio device to upper layers.
- Parameters
-
buf | Buffer containing frames of samples to write |
frame_cnt | The number of frames of samples in the buffer |
This function is used by an audio device implementation to write audio samples recorded from the actual audio device to the upper software layers, for further processing. The number of samples is given as frames. A frame contains one sample per channel starting with channel 0. Frames are put in the buffer one after the other. Thus, the sample buffer should contain frame_cnt * channels samples.
◆ readBlocksize()
virtual size_t Async::AudioDevice::readBlocksize |
( |
void | | ) |
|
|
pure virtual |
Find out what the read (recording) blocksize is set to.
- Returns
- Returns the currently set blocksize in samples per channel
◆ registerAudioIO()
static AudioDevice * Async::AudioDevice::registerAudioIO |
( |
const std::string & | dev_designator, |
|
|
AudioIO * | audio_io ) |
|
static |
Register an AudioIO object with the given device name.
- Parameters
-
dev_designator | The name of the audio device |
audio_io | A previously created AudioIO object |
- Returns
- Returns an AudioDevice object associated with the given device
This function is used to register an AudioIO object with the given audio device. If an AudioDevice object already exist for the given device, it is returned. If there is no AudioDevice object for the given device, a new one is created.
◆ sampleRate()
int Async::AudioDevice::sampleRate |
( |
void | | ) |
const |
|
inline |
◆ samplesToWrite()
virtual int Async::AudioDevice::samplesToWrite |
( |
void | | ) |
const |
|
pure virtual |
Find out how many samples there are in the output buffer.
- Returns
- Returns the number of samples in the output buffer on success or -1 on failure.
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.
◆ setBlockCount()
static void Async::AudioDevice::setBlockCount |
( |
size_t | count | ) |
|
|
inlinestatic |
Set the buffer count used when opening audio devices.
- Parameters
-
count | The buffer count to use |
- Returns
- Returns the buffer count actually set
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.
Definition at line 212 of file AsyncAudioDevice.h.
References block_count_hint.
◆ setBlocksize()
static void Async::AudioDevice::setBlocksize |
( |
size_t | size | ) |
|
|
inlinestatic |
Set the blocksize used when opening audio devices.
- Parameters
-
size | The blocksize, in samples per channel, to use |
- Returns
- Returns the blocksize actually set
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.
Definition at line 182 of file AsyncAudioDevice.h.
References block_size_hint.
◆ setChannels()
static void Async::AudioDevice::setChannels |
( |
size_t | channels | ) |
|
|
inlinestatic |
Set the number of channels used when doing future opens.
- Parameters
-
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.
Definition at line 226 of file AsyncAudioDevice.h.
References channels.
◆ setDeviceError()
void Async::AudioDevice::setDeviceError |
( |
void | | ) |
|
|
protected |
Called by the device object to indicate an error condition.
◆ setSampleRate()
static void Async::AudioDevice::setSampleRate |
( |
int | rate | ) |
|
|
inlinestatic |
Set the sample rate used when doing future opens.
- Parameters
-
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.
Definition at line 166 of file AsyncAudioDevice.h.
References sample_rate.
◆ unregisterAudioIO()
static void Async::AudioDevice::unregisterAudioIO |
( |
AudioIO * | audio_io | ) |
|
|
static |
Unregister a previously registered AudioIO object.
- Parameters
-
audio_io | A previously registered AudioIO object |
◆ writeBlocksize()
virtual size_t Async::AudioDevice::writeBlocksize |
( |
void | | ) |
|
|
pure virtual |
Find out what the write (playback) blocksize is set to.
- Returns
- Returns the currently set blocksize in samples per channel
◆ block_count_hint
size_t Async::AudioDevice::block_count_hint |
|
staticprotected |
◆ block_size_hint
size_t Async::AudioDevice::block_size_hint |
|
staticprotected |
◆ channels
size_t Async::AudioDevice::channels |
|
staticprotected |
◆ dev_name
std::string Async::AudioDevice::dev_name |
|
protected |
◆ sample_rate
int Async::AudioDevice::sample_rate |
|
staticprotected |
The documentation for this class was generated from the following file: