Skip to content

Class daisy::AudioHandle

ClassList > daisy > AudioHandle

Audio Engine Handle. More...

  • #include <audio.h>

Classes

Type Name
struct Config

Public Types

Type Name
typedef void(* AudioCallback
typedef const float *const * InputBuffer
typedef void(* InterleavingAudioCallback
typedef const float * InterleavingInputBuffer
typedef float * InterleavingOutputBuffer
typedef float ** OutputBuffer
enum Result

Public Functions

Type Name
AudioHandle ()
AudioHandle (const AudioHandle & other) = default
Result ChangeCallback (AudioCallback callback)
Result ChangeCallback (InterleavingAudioCallback callback)
Result DeInit ()
size_t GetChannels () const
const Config & GetConfig () const
float GetSampleRate ()
Result Init (const Config & config, SaiHandle sai)
Result Init (const Config & config, SaiHandle sai1, SaiHandle sai2)
Result SetBlockSize (size_t size)
Result SetOutputCompensation (float val)
Result SetPostGain (float val)
Result SetSampleRate (SaiHandle::Config::SampleRate samplerate)
Result Start (AudioCallback callback)
Result Start (InterleavingAudioCallback callback)
Result Stop ()
AudioHandle & operator= (const AudioHandle & other) = default
~AudioHandle ()

Detailed Description

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: * Create and Initialize an SaiHandle or two depending on your requirements * Initialize the Audio Handle with the desired settings and the Initialized SaiHandle * If the connected codec requires special configuration or initialization, do so * Write a callback method using either the AudioCallback or the InterleavingAudioCallback format * Start the Audio using one of the StartAudio function

Public Types Documentation

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 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 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


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 OutputBuffer

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

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


enum Result

enum daisy::AudioHandle::Result {
    OK,
    ERR
};

Public Functions Documentation

function AudioHandle [½]

inline daisy::AudioHandle::AudioHandle () 

function AudioHandle [2/2]

daisy::AudioHandle::AudioHandle (
    const  AudioHandle & other
) = default

function ChangeCallback [½]

Result daisy::AudioHandle::ChangeCallback (
    AudioCallback callback
) 

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


function ChangeCallback [2/2]

Result daisy::AudioHandle::ChangeCallback (
    InterleavingAudioCallback callback
) 

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


function DeInit

Result daisy::AudioHandle::DeInit () 

Stops and deinitializes audio.


function GetChannels

size_t daisy::AudioHandle::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 GetConfig

const  Config & daisy::AudioHandle::GetConfig () const

Returns the Global Configuration struct for the Audio


function GetSampleRate

float daisy::AudioHandle::GetSampleRate () 

Returns the Samplerate as a float


function Init [½]

Result daisy::AudioHandle::Init (
    const  Config & config,
    SaiHandle sai
) 

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


function Init [2/2]

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

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


function SetBlockSize

Result daisy::AudioHandle::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 SetOutputCompensation

Result daisy::AudioHandle::SetOutputCompensation (
    float val
) 

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.

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

function SetPostGain

Result daisy::AudioHandle::SetPostGain (
    float val
) 

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

Parameters:

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

function SetSampleRate

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

Sets the samplerate, and reinitializes the sai as needed.


function Start [½]

Result daisy::AudioHandle::Start (
    AudioCallback callback
) 

Starts the Audio using the non-interleaving callback.


function Start [2/2]

Result daisy::AudioHandle::Start (
    InterleavingAudioCallback callback
) 

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


function Stop

Result daisy::AudioHandle::Stop () 

Stop the Audio


function operator=

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

function ~AudioHandle

inline daisy::AudioHandle::~AudioHandle () 


The documentation for this class was generated from the following file external-docs/libDaisy/src/hid/audio.h