Content¶
Documentation¶
Stream¶
-
template<Api
api= Unspecified>
classAudijo::Stream¶ Main stream object, with unspecified Api, so it can be dynamically set. To access api specific functions you need to cast to an api specific Stream object.
Subclassed by Audijo::Stream< Asio >, Audijo::Stream< Wasapi >
Public Functions
-
Stream() Constructor
-
const DeviceInfo &
Device(int id) const¶ Returns device with the given id.
- Return
device with id
- Parameters
id: device id
-
int
DeviceCount() const¶ Get the device count.
- Return
device count
-
const StreamInformation &
Information() const¶ Get stream information. This call only returns useful information after the stream has been opened.
- Return
stream information
-
template<typename ...
Args>
requires ValidCallback<int, Args...>
voidCallback(Callback<Args...> callback)¶ Set the callback. A valid callback signare is:
void(Format**, Format**, CallbackInfo, UserObject)whereFormatis one ofint8_t, int16_t, int32_t, float, doubleandUserObjectis a reference or a pointer to any type. The UserObject is optional and can be left out.- Parameters
callback:
-
template<typename
Lambda>
requires LambdaConstraint<Lambda>
voidCallback(Lambda callback)¶ Set the callback. A valid callback signare is:
void(Format**, Format**, CallbackInfo, UserObject)whereFormatis one ofint8_t, int16_t, int32_t, float, doubleandUserObjectis a reference or a pointer to any type. The UserObject is optional and can be left out.- Parameters
callback:
-
Error
Open(const StreamParameters &settings = StreamParameters{})¶ Open the stream. The StreamSettings are optional, when they are left out a default device with a default buffer size and sample rate will be opened.
- Return
AlreadyOpen - If the stream is already opened
NoApi - If no Api was specified
InvalidDuplex - If the combination of input and output devices is invalid
Fail - If the device failed to open
NotPresent - If the input/output is not present
InvalidSampleRate - If the sample rate is not supported
NoCallback - If no callback has been set
NoMemory - If it failed to allocate the necessary memory
InvalidBufferSize - If the buffer size is not supported
NoError - If stream started successfully
- Parameters
settings:StreamSettings
-
Error
Start()¶ Starts the flow of audio through the opened stream. Does nothing if the stream has not been opened yet.
- Return
NotOpen - If the stream wasn’t opened
AlreadyRunning - If the stream is already running
Fail - If device failed to start
NoError - If stream started successfully
-
Error
Stop()¶ Stop the flow of audio through the stream. Does nothing if the stream hasn’t been started or opened yet.
- Return
NotOpen - If the stream wasn’t opened
NotRunning - If the stream is not running
Fail - If device failed to stop
NoError - If stream stopped successfully
-
Error
Close()¶ Close the stream. Also stops the stream if it hasn’t been stopped yet. Does nothing if the stream hasn’t been opened yet.
- Return
NotOpen - If the stream wasn’t opened
Fail - If device failed to close
NoError - If stream stopped successfully
-
Error
SetSampleRate(double srate)¶ Set the sample rate of the stream.
- Return
NotOpen - If no device is open. InvalidSampleRate - If the sample rate is not supported Fail - If changing the sample rate at this time is not supported, or general fail. NoError - If sample rate successfully changed
- Parameters
srate: sample rate
-
-
template<>
classAudijo::Stream<Asio> : public Audijo::Stream<>¶ Asio specific Stream object, for when api is decided at compiletime, exposes api specific functions directly.
Public Functions
-
Error
OpenControlPanel()¶ Opens the ASIO control panel.
- Return
NotOpen - if no device has been opened yet
NoError - On success
-
const std::vector<DeviceInfo<Asio>> &
Devices() const¶ Search for all available devices. When called more than once, the list will be updated.
- Return
all available devices given the chosen api.
-
const DeviceInfo<Asio> &
Device(int id) const¶ Returns device with the given id.
- Return
device with id
- Parameters
id: device id
-
Error
-
template<>
classAudijo::Stream<Wasapi> : public Audijo::Stream<>¶ Wasapi specific Stream object, for when api is decided at compiletime, exposes api specific functions directly.
Public Functions
-
const std::vector<DeviceInfo<Wasapi>> &
Devices() const¶ Search for all available devices. When called more than once, the list will be updated.
- Return
all available devices given the chosen api.
-
const DeviceInfo<Wasapi> &
Device(int id) const¶ Returns device with the given id.
- Return
device with id
- Parameters
id: device id
-
const std::vector<DeviceInfo<Wasapi>> &
Buffer¶
-
template<typename
T>
classAudijo::Buffer¶ Audio buffer.
- Template Parameters
T: sample type
Public Functions
-
Buffer()¶ Constructor.
-
Buffer(Type **data, int channels, int size)¶ Constructor.
- Parameters
data: bufferchannels: amount of channels in the buffersize: amount of frames in the buffer
-
int
Channels() const¶ Amount of channels in this buffer.
- Return
channel count
-
int
Frames() const¶ Amount of frames in this buffer.
- Return
frame count
-
struct
Frame¶ Holds a single frame of the buffer.
Public Functions
-
Frame(Buffer &data, int index)¶ Constructor.
- Parameters
data: buffer object this frame belongs toindex: index of this frame in the buffer
-
int
Channels() const¶ Amount of channels in this frame.
- Return
channel count
-
int
Index() const¶ Index of this frame in the buffer.
- Return
index of this frame
-
Type &
operator[](int index)¶ Get the sample in this frame at the given channel index.
- Return
sample
- Parameters
index: channel index
-
-
template<typename
T1, typenameT2>
classAudijo::Parallel¶ Parallel class for parallel iteration of 2 buffers.
- Template Parameters
T1: sample type of input bufferT2: sample type of output buffer
Public Functions
-
Parallel(Buffer<T1> &input, Buffer<T2> &output)¶ Constructor.
- Parameters
input: input bufferoutput: output buffer
-
int
Channels() const¶ Amount of channels in this parallel buffer. Equals the smallest number of channels out of the 2 buffers.
- Return
channel count
-
int
Frames() const¶ Amount of frames in this parallel buffer. Equals the smallest number of frames out of the 2 buffers.
- Return
frame count
-
struct
Frame¶ Public Functions
-
int
Channels() const¶ Amount of channels in this frame.
- Return
channel count
-
int
Index() const¶ Index of this frame in the buffer.
- Return
index of this frame
-
std::pair<InType&, OutType&>
operator[](int index)¶ Get the samples in this parallel frame at the given channel index.
- Return
pair of samples
- Parameters
index: channel index
-
int
Structs¶
-
struct
Audijo::CallbackInfo¶ Information given inside of the callback.
-
struct
Audijo::ChannelInfo¶
-
struct
Audijo::StreamParameters¶
Device Information¶
-
template<Api
api= Unspecified>
structAudijo::DeviceInfo¶ Subclassed by Audijo::DeviceInfo< Asio >, Audijo::DeviceInfo< Wasapi >
-
template<>
structAudijo::DeviceInfo<Asio> : public Audijo::DeviceInfo<>¶ Public Functions
-
ChannelInfo &
Channel(int index, bool input) const¶ Get channel information
- Return
channel info
- Parameters
index: channel indexinput: is input
-
std::vector<ChannelInfo> &
Channels() const¶ Get list of channel information
- Return
vector of ChannelInfo
-
ChannelInfo &
-
template<>
structDeviceInfo<Wasapi> : public Audijo::DeviceInfo<>¶
Enums¶
-
enum
Audijo::SampleFormat¶ Values:
-
enumerator
None¶
-
enumerator
Int8¶
-
enumerator
Int16¶
-
enumerator
Int32¶
-
enumerator
Float32¶
-
enumerator
Float64¶
-
enumerator
SInt8¶
-
enumerator
SInt16¶
-
enumerator
SInt32¶
-
enumerator
SFloat32¶
-
enumerator
SFloat64¶
-
enumerator
Swap¶
-
enumerator
Floating¶
-
enumerator
Bytes¶
-
enumerator
-
enum
Audijo::Error¶ Values:
-
enumerator
NoError¶
-
enumerator
NoMemory¶
-
enumerator
NotPresent¶
-
enumerator
NoApi¶
-
enumerator
InvalidSampleRate¶
-
enumerator
InvalidBufferSize¶
-
enumerator
UnsupportedSampleFormat¶
-
enumerator
NoCallback¶
-
enumerator
NotOpen¶
-
enumerator
NotRunning¶
-
enumerator
AlreadyOpen¶
-
enumerator
AlreadyRunning¶
-
enumerator
Fail¶
-
enumerator
InvalidDuplex¶
-
enumerator
Examples¶
Play noise¶
#include "Audijo.hpp"
using namespace Audijo;
int main()
{
// Make a Wasapi Stream object
Stream<Wasapi> _stream;
// Set the callback, this can be a (capturing) lambda, but also a function pointer
_stream.Callback([&](Buffer<float>& input, Buffer<float>& output, CallbackInfo info) {
for (auto& _frame : output) // Loop through all frames in the output
for (auto& _channel : _frame) // Loop through all the channels in the frame
_channel = 0.5 * ((std::rand() % 10000) / 10000. - 0.5); // Generate noise
});
// Open the stream with default settings, and then start the stream
_stream.Open({
.input = NoDevice,
.output = Default,
.bufferSize = Default,
.sampleRate = Default
});
// Start the stream
_stream.Start();
// Wait until we get an input from the console.
std::cin.get();
// Close the stream
_stream.Close();
}