USBD_Audio_DrvAS_SamplingFreqManage

Description

Get or set current sampling frequency for a particular Terminal (i.e. endpoint).

Files

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

Prototype

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.

terminal_id_link

AudioStreaming terminal link.

set_en

Flag indicating to get or set the sampling frequency.

p_sampling_freq

Pointer to the sampling frequency value to get or set.

Endianness

p_sampling_freq uses a little endian memory organization. Hence, you should use the µC/LIB macro MEM_VAL_SET_INT32U_LITTLE() when writing the sampling frequency to it. This will ensure data is accessed correctly regarding your CPU endianness.

Returned Value

DEF_OK, if NO error(s) occurred and request is supported.

DEF_FAIL, otherwise.

Callers

Audio Class.

Implementation guidelines

This listing shows an example usage of this function.

Listing - USBD_Audio_DrvCtrlAS_SamplingFreqGet() Example Usage
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)
}

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