USBD_Audio_DrvStreamStart
Description
Start record or playback stream.
Files
usbd_audio_drv_<codec-name>.h / usbd_audio_drv_<codec-name>.c
Prototype
static CPU_BOOLEAN USBD_Audio_DrvStreamStart (USBD_AUDIO_DRV *p_audio_drv, USBD_AUDIO_AS_HANDLE as_handle, CPU_INT08U terminal_id_link);
Arguments
p_audio_drv
Pointer to audio driver structure.
as_handle
AudioStreaming handle.
terminal_id_link
AudioStreaming terminal link.
Returned Value
DEF_OK
, if NO error(s) occurred.
DEF_FAIL
, otherwise.
Callers
Audio Class.
Implementation guidelines
This listing shows an example usage of this function for a record stream.
#define DMA_CH_1 1u #define DMA_MAX_NBR_CH_USED 2u static CPU_INT08U DMA_AsHandleTbl[DMA_MAX_NBR_CH_USED]; static CPU_BOOLEAN USBD_Audio_DrvStreamStart (USBD_AUDIO_DRV *p_audio_drv, CPU_INT08U as_handle, CPU_INT08U terminal_id_link) { CPU_INT16U buf_len; CPU_INT08U *p_buf; (void)&p_audio_drv; if (terminal_id_link != Mic_OT_USB_IN_ID) { (1) return (DEF_FAIL); } DMA_AsHandleTbl[DMA_CH_1] = as_handle; (2) /* $$$$ Enable record operations on audio chip if needed. */ (3) p_buf = (CPU_INT08U *)USBD_Audio_RecordBufGet(as_handle, (4) &buf_len); if (p_buf == (CPU_INT08U *)0) { return (DEF_FAIL); } /* $$$$ Prepare initial DMA transfer. */ (5) return (DEF_OK); }
(1) You can verify if the stream processing is intended for the record path by checking the terminal ID associated to this stream. The function may be used to process also a playback stream. In that case, the terminal ID will differentiate the different streams.
(2) You should save the AudioStreaming interface handle locally to be used by the ISR managing audio data transfer. This handle is used by the functions USBD_Audio_RecordBufGet()
, USBD_Audio_RecordRxCmpl
and USBD_Audio_RecordBufFree()
.
(3) You may have to enable the record operations on the audio chip. It could be enabling some clocks, enabling some modules, etc. It may require sending a series of I2C commands for registers access,
(4) Call USBD_Audio_RecordBufGet()
to get an empty record buffer.
(5) With this buffer, prepare the initial DMA transfer.
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.
This listing shows an example usage of this function for a playback stream.
#define DMA_CH_0 0u #define DMA_MAX_NBR_CH_USED 2u static CPU_INT08U DMA_AsHandleTbl[DMA_MAX_NBR_CH_USED]; static CPU_BOOLEAN USBD_Audio_DrvStreamStart (USBD_AUDIO_DRV *p_audio_drv, CPU_INT08U as_handle, CPU_INT08U terminal_id_link) { CPU_INT16U buf_len; CPU_INT08U *p_buf; (void)&p_audio_drv; if (terminal_id_link != Speaker_IT_USB_OUT_ID) { (1) return (DEF_FAIL); } DMA_AsHandleTbl[DMA_CH_0] = as_handle; (2) /* $$$$ Enable playback operations on audio chip if needed. */ (3) USBD_Audio_PlaybackTxCmpl(as_handle); (4) USBD_Audio_PlaybackTxCmpl(as_handle); return (DEF_OK); }
(1) You can verify if the stream processing is intended for the playback path by checking the terminal ID associated to this stream. The function may be used to process also a record stream. In that case, the terminal ID will differentiate the different streams.
(2) You should save the AudioStreaming interface handle locally to be used by the ISR managing audio data transfer. This handle is used by the functions USBD_Audio_PlaybackTxCmpl
and USBD_Audio_PlaybackBufFree()
.
(3) You may have to enable the playback operations on the audio chip. It could be enabling some clocks, enabling some modules, etc. It may require sending a series of I2C commands for registers access,
(4) Signal to the playback task the number of ready buffers that can be queued by calling USBD_Audio_PlaybackTxCmpl()
. In this example, 2 playback buffers ready to be consumed can be queued. The playback task will receive 2 events CODEC XFER CMPL and will call USBD_Audio_DrvStreamPlaybackTx
to provide to the code driver ready buffers. The codec driver could initiate for instance a DMA transfer from USBD_Audio_DrvStreamPlaybackTx()
to start the streaming.