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. | |
#define DAC_FLAG_16BIT (0x1) |
#define DAC_FLAG_8BIT (0x0) |
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.
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.
[in] | dac | The DAC to initialize |
[in] | sample_rate | The sample rate in Hz |
[in] | flags | Optional flags (DAC_FLAG_16BIT) |
[in] | cb | Will be called when the next buffer can be queued |
[in] | cb_arg | Callback argument |
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.
[in] | dac | The DAC to play the sample on |
[in] | buf | A buffer with (audio) samples |
[in] | len | Number of bytes to be played |
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. 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.
[in] | dac | The DAC to configure |
[in] | cb | Called when the played buffer is done |
[in] | cb_arg | Callback argument |
void dac_dds_stop | ( | dac_dds_t | dac | ) |
Stop playback of the current sample buffer.
[in] | dac | The DAC to stop |