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

📄 wmaudio.c

📁 pxa270平台 windows mobile 5.2 wm9713 触摸屏+音频驱动
💻 C
📖 第 1 页 / 共 4 页
字号:
                                                    isMaster,
                                                    format,
                                                    width,
                                                    flags
                                                  );
    if ( WM_ERROR( status ) )
    {
        goto error;
    }

    /*
     * Save our settings.
     */
    if ( pDeviceContext->v_pWMData )
    {
        /*
         * Lock our global data.
         */
        if ( WMLockGlobalData( hDevice ) )
        {
            if ( WM_AUDIOIF_HIFI == audioIF )
            {
                pDeviceContext->v_pWMData->audioData.flags |= WM_AUDIO_HIFI_CONFIGURED;
                if ( isMaster )
                    pDeviceContext->v_pWMData->audioData.flags |= WM_AUDIO_HIFI_MASTER;
                else
                    pDeviceContext->v_pWMData->audioData.flags &= ~WM_AUDIO_HIFI_MASTER;
            }
#if WM_VOICE
            else /* Voice */
            {
                pDeviceContext->v_pWMData->audioData.flags |= WM_AUDIO_VOICE_CONFIGURED;
                if ( isMaster )
                    pDeviceContext->v_pWMData->audioData.flags |= WM_AUDIO_VOICE_MASTER;
                else
                    pDeviceContext->v_pWMData->audioData.flags &= ~WM_AUDIO_VOICE_MASTER;
            }
#endif /* WM_VOICE */

            /* Let other threads in again */
            WMUnlockGlobalData( hDevice );
        }
	}

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

/*-----------------------------------------------------------------------------
 * Function:    WMAudioUnconfigureInterface
 *
 * Unconfigures the streaming format for the link for the given interface.
 * Note: this is not required for AC'97 streams - HIFI and MONO on AC'97
 * codecs.
 *
 * Parameters:
 *      hDevice         handle to the device (from WMOpenDevice)
 *      audioIF         the interface to configure
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h.
 *---------------------------------------------------------------------------*/
WMSTATUS WMAudioUnconfigureInterface( WM_DEVICE_HANDLE     hDevice,
                                      WM_AUDIO_INTERFACE   audioIF
									)
{
    WM_DEVICE_CONTEXT   *pDeviceContext = WMHANDLE_TO_DEVICE( hDevice );
    WMSTATUS            status = WMS_UNSUPPORTED;
    const WM_CHIPDEF    *pChipDef;

    /*
     * Check the device supports the interface.
     */
    if ( WM_IS_AC97( hDevice ) ||!WMAudioIsInterfaceSupported( hDevice, audioIF ) )
    {
        status = WMS_UNSUPPORTED;
        goto error;
    }
    
    /*
     * Check we've got a function to call.
     */
    pChipDef = WMGetChipDef( hDevice );
    WM_ASSERT( hDevice, pChipDef );
    if ( !pChipDef )
    {
        status = WMS_NO_SUPPORTED_DEVICE;
        goto error;
    }
    
    if ( !pChipDef->vtable.fnUnconfigureInterface )
    {
        status = WMS_UNSUPPORTED;
        goto error;
    }
    
    /*
     * And call the codec-specific function.
     */
    status = pChipDef->vtable.fnUnconfigureInterface( hDevice, audioIF );
    if ( WM_ERROR( status ) )
    {
        goto error;
    }

    /*
     * Save our settings.
     */
    if ( pDeviceContext->v_pWMData )
    {
        /*
         * Lock our global data.
         */
        if ( WMLockGlobalData( hDevice ) )
        {
            if ( WM_AUDIOIF_HIFI == audioIF )
            {
                pDeviceContext->v_pWMData->audioData.flags &= ~WM_AUDIO_HIFI_CONFIGURED;
            }
#           if WM_VOICE
                else    /* Voice */
                {
                    pDeviceContext->v_pWMData->audioData.flags &= ~WM_AUDIO_VOICE_CONFIGURED;
                }
#           endif /* WM_VOICE */

            /* Let other threads in again */
            WMUnlockGlobalData( hDevice );
        }
	}

    /*
     * We're done.
     */
    return WMS_SUCCESS;

error:
    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    WMAudioIsInterfaceConfigured
 *
 * Queries whether the given interface has been configured.
 * Note: this requires global data.  If there is no global data, this
 * function will return WMS_UNSUPPORTED.
 *
 * Parameters:
 *      hDevice         handle to the device (from WMOpenDevice)
 *      audioIF         the interface to query
 *
 * Returns:     WMSTATUS
 *      WMS_RETURN_TRUE     - interface is configured
 *      WMS_RETURN_FALSE    - interface is not configured
 *      WMS_UNSUPPORTED     - no global data, or interface not supported
 *---------------------------------------------------------------------------*/
WMSTATUS WMAudioIsInterfaceConfigured( WM_DEVICE_HANDLE     hDevice,
                                       WM_AUDIO_INTERFACE   audioIF
                                     )
{
    WM_DEVICE_CONTEXT   *pDeviceContext = WMHANDLE_TO_DEVICE( hDevice );
    WMSTATUS            status = WMS_UNSUPPORTED;
    
    /*
     * Query our settings.
     */
    if ( pDeviceContext->v_pWMData )
    {
        /*
         * Lock our global data.
         */
        if ( WMLockGlobalData( hDevice ) )
        {
            switch ( audioIF )
            {
                case WM_AUDIOIF_HIFI:
                    if ( pDeviceContext->v_pWMData->audioData.flags & WM_AUDIO_HIFI_CONFIGURED )
                    {
                        status = WMS_RETURN_TRUE;
                    }
                    else
                    {
                        status = WMS_RETURN_FALSE;
                    }
                    break;

#           if WM_VOICE
                case WM_AUDIOIF_VOICE:
                    if ( pDeviceContext->v_pWMData->audioData.flags & WM_AUDIO_VOICE_CONFIGURED )
                    {
                        status = WMS_RETURN_TRUE;
                    }
                    else
                    {
                        status = WMS_RETURN_FALSE;
                    }
                    break;
#           endif /* WM_VOICE */

                default:
                    status = WMS_UNSUPPORTED;
                    break;
            }

            /* Let other threads in again */
            WMUnlockGlobalData( hDevice );
        }
    }
    
    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    WMAudioIsStreamSupported
 *
 * Queries whether the given stream is supported by the WDCL for this device.
 *
 * Parameters:
 *      hDevice         handle to the device (from WMOpenDevice)
 *      stream          The stream to query
 *
 * Returns:     WM_BOOL
 *      TRUE     - stream is supported
 *      FALSE    - stream is not supported
 *---------------------------------------------------------------------------*/
WM_BOOL WMAudioIsStreamSupported( WM_DEVICE_HANDLE hDevice,
                                  WM_STREAM_ID     stream
                                 )
{
    WM_BOOL             supported;
    WM_AUDIO_INTERFACE  audioIF;
    WM_BOOL             checkInterface = FALSE;

    switch ( stream )
    {
        /* The default streams are always supported */
        case WM_STREAM_DEFAULT_INPUT:
        case WM_STREAM_DEFAULT_OUTPUT:
            supported = TRUE;
            break;

        /* For HiFi we should check the table */
        case WM_STREAM_HIFI_IN:
        case WM_STREAM_HIFI_OUT:
            audioIF = WM_AUDIOIF_HIFI;
            checkInterface = TRUE;
            break;
            
        /* For Voice we should check the table */
        case WM_STREAM_VOICE_IN:
        case WM_STREAM_VOICE_OUT:
            audioIF = WM_AUDIOIF_VOICE;
            checkInterface = TRUE;
            break;

        /* Mono uses the HiFi interface at present - check the macro */
        case WM_STREAM_MONO_OUT:
            supported = WM_HAS_MONO_DAC( hDevice ) ? TRUE : FALSE;
            break;

        default:
            supported = FALSE;
    }

    /*
     * If we've got to check our interface table, run through it now.
     */
    if ( checkInterface )
    {
        const WM_CHIPDEF    *pChipDef;
        unsigned int        i;
        WM_BOOL             checkFlag;

        pChipDef = WMGetChipDef( hDevice );
        WM_ASSERT( hDevice, pChipDef );
		if ( !pChipDef )
		{
			supported = FALSE;
			goto finish;
		}

        if ( WM_IS_INPUT_STREAM( stream ) )
            checkFlag = WM_IF_RECORD;
        else
            checkFlag = WM_IF_PLAYBACK;

        supported = FALSE;
        
        for ( i = 0; i < pChipDef->nInterfaces; i++ )
        {
            if ( audioIF == pChipDef->pInterfaces[i].audioIF &&
                 pChipDef->pInterfaces[i].flags & checkFlag
               )
            {
                supported = TRUE;
                break;
            }
        }
    }
    
finish:
    return supported;
}

/*-----------------------------------------------------------------------------
 * Function:    WMAudioIsInterfaceSupported
 *
 * Queries whether the given audio interface is supported by the WDCL for
 * this device.
 *
 * Parameters:
 *      hDevice         handle to the device (from WMOpenDevice)
 *      audioIF         The interface to query
 *
 * Returns:     WM_BOOL
 *      TRUE     - interface is supported
 *      FALSE    - interface is not supported
 *---------------------------------------------------------------------------*/
WM_BOOL WMAudioIsInterfaceSupported( WM_DEVICE_HANDLE   hDevice,
                                     WM_AUDIO_INTERFACE audioIF
                                    )
{
    WM_BOOL             supported;
    const WM_CHIPDEF    *pChipDef;
    unsigned int        i;

    pChipDef = WMGetChipDef( hDevice );
    WM_ASSERT( hDevice, pChipDef );
    if ( !pChipDef )
    {
        supported = FALSE;
        goto finish;
    }

    supported = FALSE;
    
    for ( i = 0; i < pChipDef->nInterfaces; i++ )
    {
        if ( audioIF == pChipDef->pInterfaces[i].audioIF )
        {
            supported = TRUE;
            break;
        }
    }
    
finish:
    return supported;
}

/*-----------------------------------------------------------------------------
 * Function:    WMAudioEnableStream
 *
 * Called to enable the device to handle the given stream.  This powers up
 * and configures the interface according to the default values.
 *
 * Parameters:
 *      hDevice         handle to the device (from WMOpenDevice)
 *      stream          The stream to enable
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h.
 *---------------------------------------------------------------------------*/
WMSTATUS WMAudioEnableStream( WM_DEVICE_HANDLE hDevice,
                              WM_STREAM_ID     ifStream
                            )
{
    WM_DEVICE_CONTEXT   *pDeviceContext = WMHANDLE_TO_DEVICE( hDevice );
    WMSTATUS            status;
    WM_POWERFLAG        powerSections;
    const WM_CHIPDEF    *pChipDef;
    WM_AUDIO_INTERFACE  audioIF;
    WM_STREAM_ID        stream = _WMAudioGetRealStream( hDevice, ifStream );

    /*
     * Check our stream.
     */
    if ( !WMAudioIsStreamSupported( hDevice, stream ) )
    {
        status = WMS_UNSUPPORTED;
        goto error0;
    }
               
    /*
     * Power up.
     */
    switch ( stream )
    {
        case WM_STREAM_HIFI_IN:
            powerSections = WM_POWER_AUDIO_HIFI_ADC;
            audioIF = WM_AUDIOIF_HIFI;
            break;
        case WM_STREAM_VOICE_IN:
            powerSections = WM_POWER_AUDIO_ADCS;
            audioIF = WM_AUDIOIF_VOICE;
            break;

        case WM_STREAM_HIFI_OUT:
            powerSections = WM_POWER_AUDIO_HIFI_DAC;

⌨️ 快捷键说明

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