Use a DAC to play a buffer of samples. More...
Use a DAC to play a buffer of samples.
A buffer of (audio) samples can be played on a DAC with a given sample rate. To supply a steady stream of samples, a double buffer is used. While buffer A is played on the DAC the user can fill buffer B with the next batch of samples by calling @ref dac_dds_play again. Once buffer A has finished playing, buffer B will automatically be used instead. A callback can be registered that signals when the next buffer is ready to be filled. Do not do the actual buffer filling inside the callback as this is called from the timer context that is used to play the samples. Instead, use it to wake a thread that then provides the samples and calls @ref dac_dds_play. If the next sample buffer is already prepared, you can also call `dac_dds_play` within the callback, just don't do any I/O or heavy processing.
Definition in file dac_dds.h.
#include <stddef.h>
#include <stdint.h>
#include <limits.h>
#include "periph/dac.h"
#include "periph/timer.h"
Go to the source code of this file.
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. | |