Versions Compared

Key

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

Description

Configure AudioStreaming interface settings by:

...

usbd_audio.h / usbd_audio.c

Prototype

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

...

Application.

Notes / Warnings


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

Anchor
Listing - USBD_Audio_AS_IF_Cfg() Example Usage
Listing - USBD_Audio_AS_IF_Cfg() Example Usage

Code Block
languagecpp
titleListing - USBD_Audio_AS_IF_Cfg() Example Usage
linenumberstrue
#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. */
}


Panel
bgColor#f0f0f0

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