Welcome to Audijo’s documentation!

Audijo repository: https://github.com/KaixoCode/Audijo

Documentation

Stream

template<Api api = Unspecified>
class Audijo::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(Api api)

Constructor

Parameters
  • api: Api

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...>
void Callback(Callback<Args...> callback)

Set the callback. A valid callback signare is: void(Format**, Format**, CallbackInfo, UserObject) where Format is one of int8_t, int16_t, int32_t, float, double and UserObject is 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>
void Callback(Lambda callback)

Set the callback. A valid callback signare is: void(Format**, Format**, CallbackInfo, UserObject) where Format is one of int8_t, int16_t, int32_t, float, double and UserObject is 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

template<typename T>
void UserData(T &data)

Set the userdata

Parameters
  • data: userdata

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<Api api>
Stream<api> &Get()

Get this Stream object as a specific api, to expose api specific functions.

Return

this as a stream object for a specific api

void Api(Api api)

Set the api.

Parameters
  • api: api

Audijo::Api Api() const

Get the current api of this stream.

Return

api

template<>
class Audijo::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

Audijo::Api Api() const override

Get the current api of this stream.

Return

api

template<>
class Audijo::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

Audijo::Api Api() const override

Get the current api of this stream.

Return

api

Buffer

template<typename T>
class Audijo::Buffer

Audio buffer.

Template Parameters
  • T: sample type

Public Functions

Buffer()

Constructor.

Buffer(Type **data, int channels, int size)

Constructor.

Parameters
  • data: buffer

  • channels: amount of channels in the buffer

  • size: 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

Frame operator[](int index) const

Get frame at index.

Return

frame at index

Parameters
  • index: index

struct Frame

Holds a single frame of the buffer.

Public Functions

Frame(Buffer &data, int index)

Constructor.

Parameters
  • data: buffer object this frame belongs to

  • index: 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

struct Iterator

Frame iterator.

struct Iterator

Buffer iterator.

template<typename T1, typename T2>
class Audijo::Parallel

Parallel class for parallel iteration of 2 buffers.

Template Parameters
  • T1: sample type of input buffer

  • T2: sample type of output buffer

Public Functions

Parallel(Buffer<T1> &input, Buffer<T2> &output)

Constructor.

Parameters
  • input: input buffer

  • output: 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

Frame operator[](int index) const

Get a specific frame from this parallel buffer.

Return

frame

Parameters
  • index: frame index

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

struct Iterator

Frame iterator.

struct Iterator

Parallel iterator.

Structs

struct Audijo::CallbackInfo

Information given inside of the callback.

Public Members

int inputChannels

Amount of input channels.

int outputChannels

Amount of output channels.

int bufferSize

Buffer size

double sampleRate

Sample rate

struct Audijo::ChannelInfo

Public Members

std::string name

Channel name

long group

Part of group

bool active

Channel is active

bool input

Channel is input

struct Audijo::StreamParameters

Public Members

int input = Default

Parameters for the input device

int output = Default

Parameters for the output device

int bufferSize = Default

Buffer size

double sampleRate = Default

Sample rate

bool resampling = true

Allow resampling when chosen samplerate is not available

Device Information

template<Api api = Unspecified>
struct Audijo::DeviceInfo

Subclassed by Audijo::DeviceInfo< Asio >, Audijo::DeviceInfo< Wasapi >

Public Members

int id

Device id

std::string name

Device name

int inputChannels

Amount of input channels

int outputChannels

Amount of output channels

std::vector<double> sampleRates

Supported sample rates

bool defaultDevice

Default device

Api api = Unspecified

From which api is this device

template<>
struct Audijo::DeviceInfo<Asio> : public Audijo::DeviceInfo<>

Public Functions

ChannelInfo &Channel(int index, bool input) const

Get channel information

Return

channel info

Parameters
  • index: channel index

  • input: is input

std::vector<ChannelInfo> &Channels() const

Get list of channel information

Return

vector of ChannelInfo

template<>
struct DeviceInfo<Wasapi> : public Audijo::DeviceInfo<>

Enums

enum Audijo::SettingValues

Values:

enumerator Default
enumerator NoDevice
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
enum Audijo::Api

Values:

enumerator Unspecified
enumerator Asio
enumerator Wasapi
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

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();
}