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  CPU_BOOLEAN  USBD_Audio_DrvAS_SamplingFreqManage (USBD_AUDIO_DRV  *p_audio_drv,
                                                          CPU_INT08U       terminal_id_link,
                                                          CPU_BOOLEAN      set_en,
                                                          CPU_INT32U      *p_sampling_freq);


Arguments

p_audio_drv

Pointer to audio driver structure.

...

This listing shows an example usage of this function.

Anchor
Listing - USBD_Audio_DrvCtrlAS_SamplingFreqGet() Example Usage
Listing - USBD_Audio_DrvCtrlAS_SamplingFreqGet() Example Usage

Code Block
languagecpp
titleListing - USBD_Audio_DrvCtrlAS_SamplingFreqGet() Example Usage
linenumberstrue
static  CPU_INT32U  ActualSamplingFreq = USBD_AUDIO_FMT_TYPE_I_SAMFREQ_48KHZ;
 
static  CPU_BOOLEAN  USBD_Audio_DrvAS_SamplingFreqManage (USBD_AUDIO_DRV  *p_audio_drv,
                                                          CPU_INT08U       terminal_id_link,
                                                          CPU_BOOLEAN      set_en,
                                                          CPU_INT32U      *p_sampling_freq)
{
    CPU_BOOLEAN  req_ok = DEF_FAIL;


    (void)&p_audio_drv;
    (void)&terminal_id_link;

                                                                /* ----------------------- GET ------------------------ */
    if (set_en == DEF_FALSE) {                                                 (1)
       *p_sampling_freq = ActualSamplingFreq;                                  (2)
        req_ok = DEF_OK;
                                                                /* ----------------------- SET ------------------------ */
    } else {
        if ((*p_sampling_freq == USBD_AUDIO_FMT_TYPE_I_SAMFREQ_44_1KHZ) ||     (3)
            (*p_sampling_freq == USBD_AUDIO_FMT_TYPE_I_SAMFREQ_48KHZ)) {
            ActualSamplingFreq = *p_cur_sampling_freq;                         (4)
            req_ok = DEF_OK;
        }
    }
    return (req_ok);                                                           (5)
}


Panel
bgColor#f0f0f0

(1) Based on argument set_en, determine if the function is called to get or set the current sampling frequency.

(2) If set_en is DEF_FALSE, the actual sampling frequency is given and set the flag indicating that the request has been correctly processed is set to DEF_OK.

(3) If set_en is DEF_TRUE, the sampling frequency currently in use needs to be changed. Make sure the requested sampling frequency is supported by the codec used.

(4) If the sampling frequency is supported, update the sampling frequency used and set the flag indicating that the request has been correctly processed is set to DEF_OK. More actions may be required to actually change the sampling frequency of the codec, such as writing to registers or sending various commands to the codec.

(5) Return status of the function.