Skip to content

daisy::AudioHandle

Module: LIBDAISY / HUMAN_INTERFACE / AUDIO

Audio Engine Handle. More...

#include <audio.h>

Public Classes

Name
struct Config

Public Types

Name
enum class Result
typedef const float *const * InputBuffer
typedef float ** OutputBuffer
typedef void(*)(InputBuffer in, OutputBuffer out, size_t size) AudioCallback
typedef const float * InterleavingInputBuffer
typedef float * InterleavingOutputBuffer
typedef void(*)(InterleavingInputBuffer in, InterleavingOutputBuffer out, size_t size) InterleavingAudioCallback

Public Functions

Detailed Description

class daisy::AudioHandle;

Audio Engine Handle.

This class allows for higher level access to an audio engine. If you're using a SOM like the DaisySeed or DaisyPatchSM (or any board that includes one of those objects) then the intialization is already taken care of. If you're setting up your own custom hardware, or need to make changes you will have to take the following steps:

  1. Create and Initialize an SaiHandle or two depending on your requirements
  2. Initialize the Audio Handle with the desired settings and the Initialized SaiHandle
  3. If the connected codec requires special configuration or initialization, do so
  4. Write a callback method using either the AudioCallback or the InterleavingAudioCallback format
  5. Start the Audio using one of the StartAudio function

Public Types Documentation

enum Result

Enumerator Value Description
OK
ERR

typedef InputBuffer

typedef const float* const* daisy::AudioHandle::InputBuffer;

Non-Interleaving input buffer Buffer arranged by float[chn][sample] const so that the user can't modify the input

typedef OutputBuffer

typedef float** daisy::AudioHandle::OutputBuffer;

Non-Interleaving output buffer Arranged by float[chn][sample]

typedef AudioCallback

typedef void(* daisy::AudioHandle::AudioCallback) (InputBuffer in, OutputBuffer out, size_t size);

Type for a Non-Interleaving audio callback Non-Interleaving audio callbacks in daisy will be of this type

typedef InterleavingInputBuffer

typedef const float* daisy::AudioHandle::InterleavingInputBuffer;

Interleaving Input buffer audio is prepared as { L0, R0, L1, R1, . . . LN, RN }] this is const, as the user shouldn't modify it

typedef InterleavingOutputBuffer

typedef float* daisy::AudioHandle::InterleavingOutputBuffer;

Interleaving Output buffer audio is prepared as { L0, R0, L1, R1, . . . LN, RN }

typedef InterleavingAudioCallback

typedef void(* daisy::AudioHandle::InterleavingAudioCallback) (InterleavingInputBuffer in, InterleavingOutputBuffer out, size_t size);

Interleaving Audio Callback Interleaving audio callbacks in daisy must be of this type

Public Functions Documentation

function AudioHandle

inline AudioHandle()

function ~AudioHandle

inline ~AudioHandle()

function AudioHandle

AudioHandle(
    const AudioHandle & other
) =default

function operator=

AudioHandle & operator=(
    const AudioHandle & other
) =default

function Init

Result Init(
    const Config & config,
    SaiHandle sai
)

Initializes audio to run using a single SAI configured in Stereo I2S mode.


function Init

Result Init(
    const Config & config,
    SaiHandle sai1,
    SaiHandle sai2
)

Initializes audio to run using two SAI, each configured in Stereo I2S mode.


function DeInit

Result DeInit()

Stops and deinitializes audio.


function GetConfig

const Config & GetConfig() const

Returns the Global Configuration struct for the Audio


function GetChannels

size_t GetChannels() const

Returns the number of channels of audio. When using a single SAI this returns 2, when using two SAI it returns 4 If no SAI is initialized this returns 0

Eventually when we add non-standard I2S for each SAI this will be work differently


function GetSampleRate

float GetSampleRate()

Returns the Samplerate as a float


function SetSampleRate

Result SetSampleRate(
    SaiHandle::Config::SampleRate samplerate
)

Sets the samplerate, and reinitializes the sai as needed.


function SetBlockSize

Result SetBlockSize(
    size_t size
)

Sets the block size after initialization, and updates the internal configuration struct. Get BlockSize and other details via the GetConfig


function SetPostGain

Result SetPostGain(
    float val
)

Parameters:

  • val Gain adjustment amount. The hardware will clip at the reciprical of this value.

Sets the amount of gain adjustment to perform before and after callback. useful if the hardware has additional headroom, and the nominal value shouldn't be 1.0


function SetOutputCompensation

Result SetOutputCompensation(
    float val
)

Parameters:

  • val To calcuate the value, measure the input signal, then measure the output signal (with this set to default value of 1.0). Then calculate val as: val = 1 / (vout / vin);

Sets an additional amount of gain compensation to perform at the end of the callback Useful if the hardware input/output levels are not equal.


function Start

Result Start(
    AudioCallback callback
)

Starts the Audio using the non-interleaving callback.


function Start

Result Start(
    InterleavingAudioCallback callback
)

Starts the Audio using the interleaving callback. For now only two channels are supported via this method.


function Stop

Result Stop()

Stop the Audio


function ChangeCallback

Result ChangeCallback(
    AudioCallback callback
)

Immediatley changes the audio callback to the non-interleaving callback passed in.


function ChangeCallback

Result ChangeCallback(
    InterleavingAudioCallback callback
)

Immediatley changes the audio callback to the interleaving callback passed in.

---

Updated on 2024-01-03 at 19:41:01 +0000