libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
daisy::AudioHandle Class Reference

Audio Engine Handle. More...

Detailed Description

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

#include <audio.h>

Classes

struct  Config
 

Public Types

enum class  Result { OK , ERR }
 
typedef const float *constInputBuffer
 
typedef float ** OutputBuffer
 
typedef void(* AudioCallback) (InputBuffer in, OutputBuffer out, size_t size)
 
typedef const floatInterleavingInputBuffer
 
typedef floatInterleavingOutputBuffer
 
typedef void(* InterleavingAudioCallback) (InterleavingInputBuffer in, InterleavingOutputBuffer out, size_t size)
 

Public Member Functions

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

Member Typedef Documentation

◆ 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

◆ InputBuffer

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

◆ 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

◆ InterleavingInputBuffer

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

◆ InterleavingOutputBuffer

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

◆ OutputBuffer

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

Member Enumeration Documentation

◆ Result

Enumerator
OK 
ERR 

Constructor & Destructor Documentation

◆ AudioHandle() [1/2]

daisy::AudioHandle::AudioHandle ( )
inline

◆ ~AudioHandle()

daisy::AudioHandle::~AudioHandle ( )
inline

◆ AudioHandle() [2/2]

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

Member Function Documentation

◆ ChangeCallback() [1/2]

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

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

◆ ChangeCallback() [2/2]

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

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

◆ DeInit()

Result daisy::AudioHandle::DeInit ( )

Stops and deinitializes audio.

◆ 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

◆ GetConfig()

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

Returns the Global Configuration struct for the Audio

◆ GetSampleRate()

float daisy::AudioHandle::GetSampleRate ( )

Returns the Samplerate as a float

◆ Init() [1/2]

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

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

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

◆ operator=()

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

◆ 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

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

◆ 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
valGain adjustment amount. The hardware will clip at the reciprical of this value.

◆ SetSampleRate()

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

Sets the samplerate, and reinitializes the sai as needed.

◆ Start() [1/2]

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

Starts the Audio using the non-interleaving callback.

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

◆ Stop()

Result daisy::AudioHandle::Stop ( )

Stop the Audio


The documentation for this class was generated from the following file: