Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

usbd_audio_drv_<codec-name>.h / usbd_audio_drv_<codec-name>.c

Prototype

Code Block
languagecpp
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.

...

This listing shows an example usage of this function.

Anchor
Listing - USBD_Audio_DrvStreamPlaybackTx() Example Usage
Listing - USBD_Audio_DrvStreamPlaybackTx() Example Usage

Code Block
languagecpp
titleListing - USBD_Audio_DrvStreamPlaybackTx() Example Usage
linenumberstrue
#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)
}


Panel
bgColor#f0f0f0

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

Tip

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.

Tip

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.