audio_device
Overview
audio_device
represents individual audio interfaces on the host platform. There are typically one or more audio devices available. Each device has a name, device identifier, and specific capabilities, including sample rate and the number of input and output channels supported.
Declaration
class audio_device
{
public:
using device_list = std::vector<audio_device>;
static device_list list();
static audio_device get(int device_id);
int id() const;
std::string name() const;
std::size_t input_channels() const;
std::size_t output_channels() const;
double default_sample_rate() const;
};
Expressions
Notation
a
,b
-
Objects of type
audio_device
. ad
-
Object of type
audio_device
. id
-
A unique audio device ID (integer).
Constructors and Assignment
Expression | Semantics |
---|---|
|
Copy construct from |
|
Assign |
-
There are no public constructors. Instead, see
list()
andget(id)
below. -
`audio_device`s are lightweight handles that can be cheaply passed by value.
Instantiation
Expression | Semantics | Return Type |
---|---|---|
|
Get the list of available audio devices. |
|
|
Get the audio device with the given ID. |
|
-
To get an
audio_device
, first get list of currently available audio devices viaaudio_device::list()
, then choose, or let the user choose, the one suitable for your needs. -
Alternatively, if you know the unique
audio_device
ID, you can useaudio_device::get(id)
to obtain a specificaudio_device
.
Accessors
Expression | Semantics | Return Type |
---|---|---|
|
Get the unique ID. |
|
|
Get the unique name. |
|
|
Get the maximum number of input channels. |
|
|
Get the maximum number of output channels. |
|
|
Get the default sample rate. |
|
Example
List all available audio devices:
#include <q_io/audio_device.hpp>
#include <iostream>
#include <string>
namespace q = cycfi::q;
int main()
{
std::cout << "Available Audio Devices: " << std::endl;
for (auto const& device : q::audio_device::list())
{
std::cout
<< "id: " << device.id() << std:: endl
<< "name: \"" << device.name() << '"' << std:: endl
<< "number of input channels: " << device.input_channels() << std:: endl
<< "number of output channels: " << device.output_channels() << std:: endl
;
}
return 0;
}