Loading...
Searching...
No Matches
DAC Direct Digital Synthesis

Detailed Description

Files

file  dac_dds.h
 Use a DAC to play a buffer of samples.
 

Data Structures

struct  dac_dds_params_t
 Configuration struct for a DAC DDS channel. More...
 

Macros

#define DAC_FLAG_8BIT   (0x0)
 A sample has a resolution of 8 bit.
 
#define DAC_FLAG_16BIT   (0x1)
 A sample has a resolution of 16 bit.
 

Typedefs

typedef void(* dac_dds_cb_t) (void *arg)
 The callback that will be called when the end of the current sample buffer has been reached.
 
typedef uint8_t dac_dds_t
 Index of the DAC DDS channel.
 

Functions

void dac_dds_init (dac_dds_t dac, uint16_t sample_rate, uint8_t flags, dac_dds_cb_t cb, void *cb_arg)
 Initialize a DAC for playing audio samples A user defined callback can be provided that will be called when the next buffer can be queued.
 
void dac_dds_set_cb (dac_dds_t dac, dac_dds_cb_t cb, void *cb_arg)
 Change the 'buffer done' callback.
 
bool dac_dds_play (dac_dds_t dac, const void *buf, size_t len)
 Play a buffer of (audio) samples on a DAC.
 
void dac_dds_stop (dac_dds_t dac)
 Stop playback of the current sample buffer.
 

Macro Definition Documentation

◆ DAC_FLAG_16BIT

#define DAC_FLAG_16BIT   (0x1)

A sample has a resolution of 16 bit.

Definition at line 90 of file dac_dds.h.

◆ DAC_FLAG_8BIT

#define DAC_FLAG_8BIT   (0x0)

A sample has a resolution of 8 bit.

Definition at line 83 of file dac_dds.h.

Typedef Documentation

◆ dac_dds_cb_t

typedef void(* dac_dds_cb_t) (void *arg)

The callback that will be called when the end of the current sample buffer has been reached.

Should be used to start filling the next sample buffer with dac_dds_play.

Note
Will be called in interrupt context. Only use the callback to signal a thread. Don't directly fill the sample buffer in the callback.

Definition at line 61 of file dac_dds.h.

◆ dac_dds_t

typedef uint8_t dac_dds_t

Index of the DAC DDS channel.

Definition at line 77 of file dac_dds.h.

Function Documentation

◆ dac_dds_init()

void dac_dds_init ( dac_dds_t  dac,
uint16_t  sample_rate,
uint8_t  flags,
dac_dds_cb_t  cb,
void *  cb_arg 
)

Initialize a DAC for playing audio samples A user defined callback can be provided that will be called when the next buffer can be queued.

Warning
This feature is experimental!
Parameters
[in]dacThe DAC to initialize
[in]sample_rateThe sample rate in Hz
[in]flagsOptional flags (DAC_FLAG_16BIT)
[in]cbWill be called when the next buffer can be queued
[in]cb_argCallback argument

◆ dac_dds_play()

bool dac_dds_play ( dac_dds_t  dac,
const void *  buf,
size_t  len 
)

Play a buffer of (audio) samples on a DAC.

     If this function is called while another buffer is already
     being played, the new `buf` will be played when the current
     buffer has finished playing.

     The DAC implementations allows one buffer to be queued
     (double buffering).

     Whenever a new buffer can be queued, the @ref dac_dds_cb_t
     callback function will be executed.
Warning
This feature is experimental!
Parameters
[in]dacThe DAC to play the sample on
[in]bufA buffer with (audio) samples
[in]lenNumber of bytes to be played
Returns
true if the buffer was queued while another buffer is currently playing. false if the new buffer is played immediately. That means playing was just started or an underrun occurred.

◆ dac_dds_set_cb()

void dac_dds_set_cb ( dac_dds_t  dac,
dac_dds_cb_t  cb,
void *  cb_arg 
)

Change the 'buffer done' callback.

A user defined callback can be provided that will be called when the next buffer can be queued. This function can be used to change the callback on the fly.

Passing in a cb of NULL can be used to only update the arg without updating the cb. Conversely, to clear the callback, both cb and cb_arg need to be passed in as NULL.

Warning
This feature is experimental!
Parameters
[in]dacThe DAC to configure
[in]cbCalled when the played buffer is done
[in]cb_argCallback argument

◆ dac_dds_stop()

void dac_dds_stop ( dac_dds_t  dac)

Stop playback of the current sample buffer.

Parameters
[in]dacThe DAC to stop