USBD_Audio_AS_IF_Cfg

Description

Configure AudioStreaming interface settings by:

  1. Allocating an AudioStreaming Settings structure.
  2. Initializing this structure with the stream information.
  3. Allocating buffers that will be used by the given AudioStreaming interface.

Files

usbd_audio.h / usbd_audio.c

Prototype

USBD_AUDIO_AS_IF_HANDLE  USBD_Audio_AS_IF_Cfg (const  USBD_AUDIO_STREAM_CFG          *p_stream_cfg,
                                               const  USBD_AUDIO_AS_IF_CFG           *p_as_if_cfg,
                                               const  USBD_AUDIO_DRV_AS_API          *p_as_api,
                                                      MEM_SEG                        *p_seg,
                                                      CPU_INT08U                      terminal_ID,
                                                      USBD_AUDIO_PLAYBACK_CORR_FNCT   corr_callback,
                                                      USBD_ERR                       *p_err);


Arguments

p_stream_cfg

Pointer to general stream configuration.

p_as_if_cfg

Pointer to the AudioStreaming interface configuration structure.

p_as_api

Pointer to AudioStreaming interface API.

p_seg

Pointer to memory segment used for buffers allocation. If null pointer, buffers are allocated from the heap. Otherwise, buffers are allocated from a memory region created by the application.

terminal_ID

Terminal ID associated to this AudioStreaming interface.

corr_callback

Application callback for user-defined correction algorithm.

p_err

Pointer to variable that will receive the return error code from this function.

USBD_ERR_NONE
USBD_ERR_NULL_PTR
USBD_ERR_INVALID_ARG
USBD_ERR_ALLOC

Returned Value

Handle to AudioStreaming interface, if NO error(s).

0, otherwise.

Callers

Application.

Notes / Warnings


The Listing - USBD_Audio_AS_IF_Cfg() Example Usage presents an example of usage using a memory segment to allocate the stream buffers. Listing Listing - Audio Class Initialization Example shows the same function using a general heap for the stream buffers.

Listing - USBD_Audio_AS_IF_Cfg() Example Usage
#define  APP_CFG_USBD_AUDIO_PLAYBACK_NBR_BUF               20u  

#define  APP_CFG_USBD_AUDIO_BUF_EXTRA_BYTE          (USBD_AUDIO_STEREO * USBD_AUDIO_FMT_TYPE_I_SUBFRAME_SIZE_2)

#define  APP_CFG_USBD_AUDIO_DEMO_MEM_SEG_SIZE      (APP_CFG_USBD_AUDIO_PLAYBACK_NBR_BUF            \
                                                   * (USBD_AUDIO_FMT_TYPE_I_SAMFREQ_48KHZ / 1000u) \
                                                   * USBD_AUDIO_STEREO                             \
                                                   * USBD_AUDIO_FMT_TYPE_I_SUBFRAME_SIZE_2         \
                                                   * APP_CFG_USBD_AUDIO_BUF_EXTRA_BYTE)

static  CPU_INT08U  App_USBD_Audio_MemSegData[APP_CFG_USBD_AUDIO_DEMO_MEM_SEG_SIZE];
static  MEM_SEG     App_USBD_Audio_MemSegInfo;

USBD_AUDIO_AS_IF_HANDLE  speaker_playback_as_if_handle;


Mem_SegCreate(         "Audio Data Memory Segment",                                     (1)
                       &App_USBD_Audio_MemSegInfo,
              (CPU_ADDR)App_USBD_Audio_MemSegData,
                        APP_CFG_USBD_AUDIO_DEMO_MEM_SEG_SIZE,
                        LIB_MEM_PADDING_ALIGN_NONE,
                       &err_lib);
if (err_lib!= LIB_MEM_ERR_NONE) {
    /* $$$$ Handle the error. */
}               
        
speaker_playback_as_if_handle =  USBD_Audio_AS_IF_Cfg(&USBD_SpeakerStreamCfg,
                                                      &USBD_AS_IF1_SpeakerCfg,
                                                      &USBD_Audio_DrvAS_API_Simulation,
                                                      &App_USBD_Audio_MemSegInfo,       (2)
                                                       Speaker_IT_USB_OUT_ID,
                                                       DEF_NULL,
                                                      &err);
if (err != USBD_ERR_NONE) {
    /* $$$$ Handle the error. */
}

(1) Create the memory segment. The memory segment will be created on a statically allocated buffer whose size will fit the necessary number of playback buffers. The base address of the memory segment data can also point to a controller dedicated memory. In that case, you may define the memory segment size to the the available dedicated memory size. Other stream buffers may be allocated from the same memory. In this example, the constant LIB_MEM_PADDING_ALIGN_NONE is passed to the function. This argument relates to the buffer padding done internally by µC/LIB when getting a buffer from the memory segment. The padding is done only if the argument is different from LIB_MEM_PADDING_ALIGN_NONE. Padding may be useful to avoid cache incoherence when audio buffers are allocated from a cacheable memory region accessible to a DMA engine. Refer to page Memory Segments for more details about this function.

(2) Pass the memory segment structure to the function USBD_Audio_AS_IF_Cfg(). The audio class will create a memory pool into the given memory segment from which the audio class will get audio buffers while performing streaming.