USBD_Audio_DrvStreamPlaybackTx
Description
Provide a ready playback buffer to codec.
Files
usbd_audio_drv_<codec-name>.h / usbd_audio_drv_<codec-name>.c
Prototype
static void USBD_Audio_DrvStreamPlaybackTx (USBD_AUDIO_DRV *p_audio_drv, CPU_INT08U terminal_id_link, void *p_buf, CPU_INT16U buf_len, USBD_ERR *p_err);
Arguments
p_audio_drv
Pointer to audio driver structure.
terminal_id_link
Terminal ID associated to this stream.
p_buf
Pointer to ready playback buffer.
buf_len
Buffer length in bytes.
p_err
Pointer to variable that will receive the return error code from this function.
USBD_ERR_NONE
USBD_ERR_TX
Returned Value
DEF_OK
, if NO error(s) occurred and request is supported.
DEF_FAIL
, otherwise.
Callers
Audio Class.
Implementation guidelines
This listing shows an example usage of this function.
#define DMA_CH_0 0u #define DMA_MAX_NBR_CH_USED 2u static CPU_INT08U DMA_AsHandleTbl[DMA_MAX_NBR_CH_USED]; static void USBD_Audio_DrvStreamPlaybackTx (USBD_AUDIO_DRV *p_audio_drv, CPU_INT08U terminal_id_link, void *p_buf, CPU_INT16U buf_len, USBD_ERR *p_err) { /* $$$$ Store ready playback buffer. */ (1) /* $$$$ Prepare DMA transfer for initial buffer. */ (2) }
(1) The ready buffer provided by the audio class could be stored internally into the codec driver using any buffer memory management method (for example a circular buffer). Then the stored ready buffer could be retrieved by the audio peripheral ISR.
The Audio Peripheral Driver should support at least double-buffering to optimize the playback streaming.
(2) If the Audio Peripheral driver support buffer queuing, you may accumulate a certain number of ready buffers (for instance, 2 buffers should be enough). When the buffers accumulation is done, you should prepare the initial DMA transfer. When the stream is launched, the next DMA transfer may be prepared in an interrupt context when the current DMA transfer completes.
If the peripheral managing audio data transfer can work with a DMA controller, we recommend using DMA transfers. It will improve overall audio performance by offloading the CPU. As opposed to CPU copies involved for FIFO transfers that would be time-consuming.
(3) In case of error, you may return the error code USBD_ERR_TX
.