⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wmaudio.c

📁 pxa270平台 windows mobile 5.2 wm9713 触摸屏+音频驱动
💻 C
📖 第 1 页 / 共 4 页
字号:
 *
 * Returns:     WMSTATUS
 *		See WMStatus.h.
 *---------------------------------------------------------------------------*/
WMSTATUS WMAudioSetSampleRate( WM_DEVICE_HANDLE hDevice,
							   WM_STREAM_ID     ifStream, 
							   WM_SAMPLE_RATE   sampleRate
							 )
{
    WM_DEVICE_CONTEXT   *pDeviceContext = WMHANDLE_TO_DEVICE( hDevice );
    WMSTATUS            status			= WMS_UNSUPPORTED;
    const WM_CHIPDEF    *pChipDef;
    WM_STREAM_ID        stream = _WMAudioGetRealStream( hDevice, ifStream );

    /*
     * Check our stream.
     */
    if ( !WMAudioIsStreamSupported( hDevice, stream ) )
    {
        status = WMS_UNSUPPORTED;
        goto error;
    }
               
    /*
     * Look up our chipdef.
     */
    pChipDef = WMGetChipDef( hDevice );
    WM_ASSERT( hDevice, pChipDef );
    if ( !pChipDef )
    {
        status = WMS_NO_SUPPORTED_DEVICE;
        goto error;
    }

    WM_ASSERT( hDevice, pChipDef->vtable.fnSetSampleRate );
    if ( !pChipDef->vtable.fnSetSampleRate )
    {
        status = WMS_UNSUPPORTED;
        goto error;
    }
    
    /*
     * And set the sample rate.
     */
    status = pChipDef->vtable.fnSetSampleRate( hDevice, 
                                               stream,
                                               sampleRate
                                             );
    if ( WM_ERROR( status ) )
    {
        goto error;
    }

    /*
     * Update our settings.
     */
    if ( pDeviceContext->v_pWMData )
    {
        /*
         * Lock our global data.
         */
        if ( WMLockGlobalData( hDevice ) )
        {
            switch ( stream )
            {
            case WM_STREAM_HIFI_OUT:
                pDeviceContext->v_pWMData->audioData.hifiDACRate = sampleRate;
                break;

#if WM_VOICE
            case WM_STREAM_VOICE_OUT:
                pDeviceContext->v_pWMData->audioData.voiceDACRate = sampleRate;
                break;

#endif /* WM_VOICE */
#if WM_MONODAC
            case WM_STREAM_MONO_OUT:
                pDeviceContext->v_pWMData->audioData.monoDACRate = sampleRate;
                break;

#endif /* WM_MONODAC */
            case WM_STREAM_HIFI_IN:
#if WM_VOICE
            case WM_STREAM_VOICE_IN:
#endif /* WM_VOICE */
                pDeviceContext->v_pWMData->audioData.ADCRate = sampleRate;
                break;

            default:
                status = WMS_UNSUPPORTED;
                goto error;
            }
            
            /*
             * Let other threads in.
             */
            WMUnlockGlobalData( hDevice );
        }
    }
    
    /*
     * We're done.
     */
    return WMS_SUCCESS;
    
error:
    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    WMAudioGetSampleRate
 *
 * Returns the sample rate in the audio-specific sections of the chip. 
 *
 * Parameters:
 *      hDevice      handle to the device (from WMOpenDevice)
 *      stream       The stream for which to get the sample rate
 *      pSampleRate  Variable to receive the sample rate
 *
 * Returns:     WMSTATUS
 *       See WMStatus.h.
 *---------------------------------------------------------------------------*/
WMSTATUS WMAudioGetSampleRate( WM_DEVICE_HANDLE hDevice,
                               WM_STREAM_ID     ifStream, 
                               WM_SAMPLE_RATE   *pSampleRate
                             )
{
    WMSTATUS            status			= WMS_UNSUPPORTED;
    WM_DEVICE_CONTEXT   *pDeviceContext = WMHANDLE_TO_DEVICE( hDevice );
    WM_SAMPLE_RATE      sampleRate      = 0;
    const WM_CHIPDEF    *pChipDef;
    WM_STREAM_ID        stream = _WMAudioGetRealStream( hDevice, ifStream );

    /*
     * Check our stream.
     */
    if ( !WMAudioIsStreamSupported( hDevice, stream ) )
    {
        status = WMS_UNSUPPORTED;
        goto error;
    }

    /*
     * Use our cached rate if we can.
     */
    if ( pDeviceContext->v_pWMData )
    {
        switch ( stream )
        {
            case WM_STREAM_HIFI_OUT:
                sampleRate = pDeviceContext->v_pWMData->audioData.hifiDACRate;
                break;

#if WM_VOICE
            case WM_STREAM_VOICE_OUT:
                sampleRate = pDeviceContext->v_pWMData->audioData.voiceDACRate;
                break;
            
#endif /* WM_VOICE */
#if WM_MONODAC
            case WM_STREAM_MONO_OUT:
                sampleRate = pDeviceContext->v_pWMData->audioData.monoDACRate;
                break;
            
#endif /* WM_MONODAC */
            case WM_STREAM_HIFI_IN:
#if WM_VOICE
            case WM_STREAM_VOICE_IN:
#endif /* WM_VOICE */
                sampleRate = pDeviceContext->v_pWMData->audioData.ADCRate;
                break;

            default:
                status = WMS_UNSUPPORTED;
                goto error;
        }
    }

    /*
     * If we've got a sample rate of 0 we didn't know it.
     */
    if ( 0 == sampleRate )
    {
        /*
         * Look up our chipdef and check we've got the function.
         */
        pChipDef = WMGetChipDef( hDevice );
        WM_ASSERT( hDevice, pChipDef );
        if ( !pChipDef )
        {
            status = WMS_NO_SUPPORTED_DEVICE;
            goto error;
        }
        
        if ( !pChipDef->vtable.fnGetSampleRate )
        {
            status = WMS_UNSUPPORTED;
            goto error;
        }
    
        /*
         * Now get the sample rate.
         */
        status = pChipDef->vtable.fnGetSampleRate( hDevice, 
                                                   stream,
                                                   &sampleRate
                                                 );

        /*
         * Update our settings.
         */
        if ( pDeviceContext->v_pWMData )
        {
            /*
             * Lock our global data.
             */
            if ( WMLockGlobalData( hDevice ) )
            {
                switch ( stream )
                {
                case WM_STREAM_HIFI_OUT:
                    pDeviceContext->v_pWMData->audioData.hifiDACRate = sampleRate;
                    break;
    
#if WM_VOICE
                case WM_STREAM_VOICE_OUT:
                    pDeviceContext->v_pWMData->audioData.voiceDACRate = sampleRate;
                    break;
    
#endif /* WM_VOICE */
#if WM_MONODAC
                case WM_STREAM_MONO_OUT:
                    pDeviceContext->v_pWMData->audioData.monoDACRate = sampleRate;
                    break;
    
#endif /* WM_MONODAC */
                case WM_STREAM_HIFI_IN:
#if WM_VOICE
                case WM_STREAM_VOICE_IN:
#endif /* WM_VOICE */
                    pDeviceContext->v_pWMData->audioData.ADCRate = sampleRate;
                    break;

                default:
                    status = WMS_UNSUPPORTED;
                    goto error;
                }
                
                /*
                 * Let other threads in.
                 */
                WMUnlockGlobalData( hDevice );
            }
        }
    }

    /*
     * We're done.
     */
    *pSampleRate = sampleRate;
    return WMS_SUCCESS;
    
error:
    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    WMAudioIsSampleRateSupported
 *
 * Returns whether the sample rate is supported by the given stream. 
 *
 * Parameters:
 *      hDevice      handle to the device (from WMOpenDevice)
 *      stream       The stream for which to check the sample rate
 *      sampleRate   The sample rate to check.
 *
 * Returns:     WMSTATUS
 *      WMS_RETURN_TRUE     - sample rate is supported.
 *      WMS_RETURN_FALSE    - sample rate is not supported.
 *      WMS_UNSUPPORTED     - stream is not supported on this device.
 *---------------------------------------------------------------------------*/
WMSTATUS WMAudioIsSampleRateSupported( WM_DEVICE_HANDLE hDevice,
                                       WM_STREAM_ID     ifStream, 
                                       WM_SAMPLE_RATE   sampleRate
                                     )
{
    WMSTATUS                    status = WMS_RETURN_FALSE;
    const WM_CHIPDEF            *pChipDef;
    WM_STREAM_ID                stream = _WMAudioGetRealStream( hDevice, ifStream );
    WM_AUDIO_INTERFACE          audioIF;
    const WM_INTERFACE_DETAILS  *pInterface;
    unsigned int                i;

    /*
     * Check our stream.
     */
    if ( !WMAudioIsStreamSupported( hDevice, stream ) )
    {
        status = WMS_UNSUPPORTED;
        goto exit;
    }

    if ( WM_IS_HIFI_STREAM( stream ) || WM_IS_MONO_STREAM( stream ) )
    {
        /*
         * HiFi interface - currently all MONO DACs are AC'97 so use the
         * same interface as HiFi.
         */
        audioIF = WM_AUDIOIF_HIFI;
    }
    else if ( WM_IS_VOICE_STREAM( stream ) )
    {
        audioIF = WM_AUDIOIF_VOICE;
    }
    else
    {
        status = WMS_UNSUPPORTED;
        goto exit;
    }
    
    /*
     * Look up our chipdef.
     */
    pChipDef = WMGetChipDef( hDevice );
    WM_ASSERT( hDevice, pChipDef );
    if ( !pChipDef )
    {
        status = WMS_NO_SUPPORTED_DEVICE;
        goto exit;
    }
    WM_ASSERT( hDevice, pChipDef->nInterfaces > 0 );
    if ( pChipDef->nInterfaces <= 0 )
    {
        status = WMS_UNSUPPORTED;
        goto exit;
    }
    
    /*
     * Now run through the interfaces, looking for the right table.
     */
    for ( i = 0; i < pChipDef->nInterfaces; i++ )
    {
        pInterface = &pChipDef->pInterfaces[ i ];
        if ( pInterface->audioIF == audioIF )
        {
            break;
        }
    }
    
    /*
     * If we didn't find it, bomb out.
     */
    if ( pInterface->audioIF != audioIF )
    {
        status = WMS_UNSUPPORTED;
        goto exit;
    }
    
    /*
     * If it doesn't support this direction, bomb out.
     */
    if ( WM_IS_INPUT_STREAM( stream ) && !(pInterface->flags & WM_IF_RECORD) )
    {
        status = WMS_UNSUPPORTED;
        goto exit;
    }
    if ( WM_IS_OUTPUT_STREAM( stream ) && !(pInterface->flags & WM_IF_PLAYBACK) )
    {
        status = WMS_UNSUPPORTED;
        goto exit;
    }
    
    /*
     * Now run through the table, looking for the interface.
     */
    for ( i = 0; i < pInterface->nSupportedRates; i++ )
    {
        if ( WM_IS_INPUT_STREAM( stream ) &&
             pInterface->pSupportedRates[i].adcRate == sampleRate
           )
        {
            status = WMS_RETURN_TRUE;
            break;
        }
        if ( WM_IS_OUTPUT_STREAM( stream ) &&
             pInterface->pSupportedRates[i].dacRate == sampleRate
           )
        {
            status = WMS_RETURN_TRUE;
            break;
        }
    }

exit:
    return status;
}

#endif  /* WM_AUDIO */

/*------------------------------ END OF FILE ---------------------------------*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -