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

📄 hwctxt.cpp

📁 pxa270平台 windows mobile 5.2 wm9713 触摸屏+音频驱动
💻 CPP
📖 第 1 页 / 共 5 页
字号:
#endif  // WM_I2S

#if WM_AC97
    if ( WMS_CODEC_NOT_READY == status || WMS_NO_SUPPORTED_DEVICE == status )
    {
        //
        // Nothing responding on I2S secondary - try AC'97 instead...
        //
        status = WMOpenAudioDevice( WM_DEV_AC97_PRIMARY, &m_hAudioDevice );
        if ( WM_SUCCESS( status ) )
        {
            DEBUGMSG( ZONE_PDD, ( TEXT( "PDD_AudioInitialise - primary AC'97 device\r\n" ) ) );
        }
    }
    if ( WMS_CODEC_NOT_READY == status || WMS_NO_SUPPORTED_DEVICE == status )
    {
        //
        // Nothing responding on AC'97 primary - try secondary instead...
        //
        status = WMOpenAudioDevice( WM_DEV_AC97_SECONDARY, &m_hAudioDevice );
        if ( WM_SUCCESS( status ) )
        {
            DEBUGMSG( ZONE_PDD, ( TEXT( "PDD_AudioInitialise - secondary AC'97 device\r\n" ) ) );
        }
    }
#endif // WM_AC97

    if ( WM_ERROR( status ) )
    {
        //
        // Nothing responding on AC'97 or I2S, or something really went wrong
        // - nothing much we can do except tell the user...
        //
        RETAILMSG( ZONE_ALWAYS,
                   ( TEXT("InitCodec: WMOpenAudioDevice failed: %hs\r\n"),
                   WMStatusText( status ) ) );
        goto error0;
    }

    //
    // Get some information about the device.
    //
    WMGetDeviceType( m_hAudioDevice, &m_deviceType, NULL );

	//
	// Set up the record path parameters.
	// NOTE: see WMConfig.h for the definition of the default record paths.
	//       Each application will differ so this is the
	//       point at which the correct path parameters should be set
	//       up in the driver to record.
	//
	m_SignalL = WM_AUDIO_DEFAULT_RECORD_LEFT_PATH;
	m_SignalR = WM_AUDIO_DEFAULT_RECORD_RIGHT_PATH;

	// 
	// On the WM9713 AMR card WM_AUDIO_MIC2B is the default mic input
	// so change the value of Mic input used. 
	//
#if WM9713_AMR_CARD
	if ( WM_SIGNAL_IS_MIC( WM_AUDIO_DEFAULT_RECORD_LEFT_PATH ) )
	{
		if ( IS_WM9713_DEVICE( m_deviceType ) )
		{
			m_SignalL = WM_AUDIO_MIC2B;	// AMR MIC_IN
		}
	}

	if ( WM_SIGNAL_IS_MIC( WM_AUDIO_DEFAULT_RECORD_RIGHT_PATH ) )
	{
		if ( IS_WM9713_DEVICE( m_deviceType ) )
		{
			m_SignalR = WM_AUDIO_MIC2B;	// AMR MIC_IN
		}
	}
#endif // WM9713_AMR_CARD

    //
    // Open our streams - output
    //
    status = WMAudioOpenStream( m_hAudioDevice,
                                WM_STREAM_HIFI_OUT,
                                &m_hHiFiOutputStream,
                                m_HiFiOutputDeviceContext.SampleRate(),
                                BITSPERSAMPLE,
                                m_HiFiOutputDeviceContext.IsStereo()
                              );
    if ( WM_ERROR( status ) )
    {
        RETAILMSG( ZONE_ALWAYS,
                   ( TEXT("InitCodec: WMAudioOpenStream failed for HiFi output device: %hs\r\n"),
                     WMStatusText( status ) ) );
        goto error1;
    }

    //
    // Make sure everything is quiet.
    //
    retval = private_PrepareOutputPaths( WM_STREAM_HIFI_OUT, m_pWMAudioDeviceData, FALSE );
    if ( MMSYSERR_NOERROR != retval )
    {
        DEBUGMSG( ZONE_ERROR,
                   ( TEXT( "InitCodec - disabling HiFi output paths failed\r\n") ) );

        goto error1;
    }

    //
    // ... and input
    //
    status = WMAudioOpenStream( m_hAudioDevice,
                                WM_STREAM_HIFI_IN,
                                &m_hHiFiInputStream,
                                m_HiFiInputDeviceContext.SampleRate(),
                                BITSPERSAMPLE,
                                m_HiFiInputDeviceContext.IsStereo()
                              );
    if ( WM_ERROR( status )  && ( status != WMS_UNSUPPORTED ) )
    {
        if ( WMS_UNSUPPORTED == status )
        {
            m_hHiFiInputStream = WM_HANDLE_INVALID;
        }
        else
        {
			RETAILMSG( ZONE_ALWAYS,
					   ( TEXT("InitCodec: WMAudioOpenStream failed for HiFi input device: %hs\r\n"),
						 WMStatusText( status ) ) );
			goto error2;
        }
    }

    //
    // Check that we have a valid pointer to the global audio data.
    //
    if ( !m_pWMAudioDeviceData )
    {
        ASSERT( 0 );
        retval = MMSYSERR_ERROR;
        goto error2;
    }

    //
    // Make sure everything is quiet.
    //
    retval = private_PrepareInputPaths( WM_STREAM_HIFI_IN, m_pWMAudioDeviceData, FALSE );
    if ( MMSYSERR_NOERROR != retval )
    {
        DEBUGMSG( ZONE_ERROR,
                   ( TEXT( "InitCodec - disabling HiFi input paths failed\r\n") ) );

        goto error2;
    }

#if WM_VOICE
	if ( WM_IS_VOICE_SUPPORTED( m_hAudioDevice ) )
	{
        status = WMAudioOpenStream( m_hAudioDevice,
                                    WM_STREAM_VOICE_OUT,
                                    &m_hVoiceOutputStream,
                                    m_VoiceOutputDeviceContext.SampleRate(),
                                    BITSPERSAMPLE,
                                    m_VoiceOutputDeviceContext.IsStereo()
                                   );
        if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
	    {
            if ( WMS_UNSUPPORTED == status )
            {
                m_hVoiceOutputStream = WM_HANDLE_INVALID;
            }
            else
            {
	            RETAILMSG( ZONE_ALWAYS,
	                       ( TEXT("InitCodec: WMAudioOpenStream failed for voice output device: %hs\r\n"),
	                         WMStatusText( status ) ) );
	            goto error3;
            }
	    }

        //
        // Make sure everything is quiet.
        //
        retval = private_PrepareOutputPaths( WM_STREAM_VOICE_OUT, m_pWMAudioDeviceData, FALSE );
        if ( MMSYSERR_NOERROR != retval )
        {
            DEBUGMSG( ZONE_ERROR,
                       ( TEXT( "InitCodec - disabling voice output paths failed\r\n") ) );

            goto error3;
        }

        //
        // ... and input
        //
        status = WMAudioOpenStream( m_hAudioDevice,
                                    WM_STREAM_VOICE_IN,
                                    &m_hVoiceInputStream,
                                    m_VoiceInputDeviceContext.SampleRate(),
                                    BITSPERSAMPLE,
                                    m_VoiceInputDeviceContext.IsStereo()
                                  );
        if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
	    {
            if ( WMS_UNSUPPORTED == status )
            {
                m_hVoiceInputStream = WM_HANDLE_INVALID;
            }
            else
            {
	            RETAILMSG( ZONE_ALWAYS,
	                       ( TEXT("InitCodec: WMAudioOpenStream failed for voice input device: %hs\r\n"),
	                         WMStatusText( status ) ) );
	            goto error4;
            }
	    }

        //
        // Make sure everything is quiet.
        //
        retval = private_PrepareInputPaths( WM_STREAM_VOICE_IN, m_pWMAudioDeviceData, FALSE );
        if ( MMSYSERR_NOERROR != retval )
        {
            DEBUGMSG( ZONE_ERROR,
                       ( TEXT( "InitCodec - disabling voice input paths failed\r\n") ) );

            goto error4;
        }

	}
#endif // WM_VOICE

#if WM_MONODAC
	if ( WM_IS_MONO_SUPPORTED( m_hAudioDevice ) )
	{
        status = WMAudioOpenStream( m_hAudioDevice,
                                    WM_STREAM_MONO_OUT,
                                    &m_hMonoOutputStream,
                                    m_MonoOutputDeviceContext.SampleRate(),
                                    BITSPERSAMPLE,
                                    m_MonoOutputDeviceContext.IsStereo()
                                   );
        if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
	    {
            if ( WMS_UNSUPPORTED == status )
            {
                m_hMonoOutputStream = WM_HANDLE_INVALID;
            }
            else
            {
	            RETAILMSG( ZONE_ALWAYS,
	                       ( TEXT("InitCodec: WMAudioOpenStream failed for mono output device: %hs\r\n"),
	                         WMStatusText( status ) ) );
	            goto error5;
            }
	    }

        //
        // Make sure everything is quiet.
        //
        retval = private_PrepareOutputPaths( WM_STREAM_MONO_OUT, m_pWMAudioDeviceData, FALSE );
        if ( MMSYSERR_NOERROR != retval )
        {
            DEBUGMSG( ZONE_ERROR,
                       ( TEXT( "InitCodec - disabling mono output paths failed\r\n") ) );

            goto error5;
        }
	}
#endif // WM_MONODAC

    return ( TRUE );

	// Error Clean up
error5:

#if WM_VOICE
    if ( WM_HANDLE_INVALID != m_hVoiceInputStream )
	{
		WMAudioCloseStream( m_hAudioDevice, m_hVoiceInputStream );
		m_hVoiceInputStream = WM_HANDLE_INVALID;
	}
error4:
    if ( WM_HANDLE_INVALID != m_hVoiceOutputStream )
	{
		WMAudioCloseStream( m_hAudioDevice, m_hVoiceOutputStream );
		m_hVoiceOutputStream = WM_HANDLE_INVALID;
	}

error3:
#endif // WM_VOICE
	WMAudioCloseStream( m_hAudioDevice, m_hHiFiInputStream );
    m_hHiFiInputStream = WM_HANDLE_INVALID;

error2:
	WMAudioCloseStream( m_hAudioDevice, m_hHiFiOutputStream );
    m_hHiFiOutputStream = WM_HANDLE_INVALID;

error1:
	WMCloseDevice( m_hAudioDevice, WM_DRIVER_AUDIO );

error0:
	return ( FALSE );
}

//-----------------------------------------------------------------------------
// Member function:    HandleDriverMessage
//
// Checks to see if this is a hardware-specific message, and handles it if
// it is.
//
// Parameters:
//      uDeviceId   device number
//      uMsg        message ID
//      dwParam1    first parameter
//      dwParam2    second parameter
//
// Returns:     DWORD
//      Return status value
//-----------------------------------------------------------------------------
DWORD HardwareContext::HandleDriverMessage( UINT uDeviceId,
                                            UINT uMsg,
                                            DWORD dwParam1,
                                            DWORD dwParam2
                                          )
{
    DWORD dwRet = MMSYSERR_NOTSUPPORTED;
    WMSTATUS wmStatus;

	//
	// The Audio drivers make a local copy or the record inputs
	// This causes communication problems for the WDCL when it 
	// tries to change the record settings - how does it inform the deiver ?
	// This is only a temporary solution.
	//
	if  ( WMMSG_SELECT_RECORD_PATHS == uMsg )
	{
		WM_AUDIO_SIGNAL leftInput;
		WM_AUDIO_SIGNAL rightInput;

		leftInput  = (WM_AUDIO_SIGNAL) dwParam1;
		rightInput = (WM_AUDIO_SIGNAL) dwParam2;

	   // Ensure that the supplied parameters are valid
	   if ( !WM_SIGNAL_IS_RECORDABLE( leftInput ) || !WM_SIGNAL_IS_RECORDABLE( rightInput ) )
	   {
			dwRet = MMSYSERR_INVALPARAM;
	   }
	   else
	   {
			dwRet = MMSYSERR_NOERROR;
			// 
			// We make the call to WMAudioSetRecPaths so that
			// we can check that the signals are valid for the codec.
			// We then call WMAudioClearRecPaths .
			//
			if ( WM_SUCCESS( (wmStatus = WMAudioSetRecPaths( m_hAudioDevice, leftInput, rightInput ) ) ) )
			{
				wmStatus = WMAudioClearRecPaths( m_hAudioDevice, leftInput, rightInput );
			}
			if ( WMS_UNKNOWN_MESSAGE != wmStatus )
			{
				dwRet = wmStatus;
			}
		}
		// Set up our global signal variables
		m_SignalL = leftInput;
		m_SignalR = rightInput;
	}
	else
	{
	    // Pass it on to the API, in case it's a private message.
		wmStatus = WMDriverMessage( m_hAudioDevice, uMsg, dwParam1, dwParam2 );
		if ( WMS_UNKNOWN_MESSAGE != wmStatus )
		{
			dwRet = wmStatus;
		}
	}    if ( WMS_UNKNOWN_MESSAGE != wmStatus )
    {
        dwRet = wmStatus;
    }
    
    return dwRet;
}

//-----------------------------------------------------------------------------
// Member function:    StartHiFiOutputDMA
//
// Makes sure DMA is running for the HiFi output stream, and transmits the first
// buffer-fulls of data.
//
// Parameters:
//      none
//
// Returns:     void
//-----------------------------------------------------------------------------
void HardwareContext::StartHiFiOutputDMA()
{
    DWORD    retval = MMSYSERR_NOERROR;
    WMSTATUS status = WMS_SUCCESS;

    //
    // Check that we have a valid pointer to the global audio data.
    //
    if ( !m_pWMAudioDeviceData )
    {
        ASSERT( 0 );
        retval = MMSYSERR_ERROR;
        goto exit;
    }
    
    //
    // Lock our global data access
    //
    UnlockGlobalData( m_hGlobalDataDeviceMutex );

    if ( !m_pWMAudioDeviceData->HiFiOutputDMARunning )
    {
        ULONG OutputTransferred = 0;
        
        // For now, pretend output dma is running in case we accidentally get reentered
        m_pWMAudioDeviceData->HiFiOutputDMARunning = TRUE;

        m_HiFiOutBytes[0]      = m_HiFiOutBytes[1]=0;
        m_nextHiFiOutputBuf    = 0;
        m_HiFiOutputStarted    = FALSE;

#if WM_OUTPUT_MUTE_DELAY
        if ( m_pWMAudioDeviceData->HiFiOutputMuted )
#endif
        {            
            //
            // Enable the output paths.
            //
            retval = private_PrepareOutputPaths( WM_STREAM_HIFI_OUT, m_pWMAudioDeviceData, TRUE );
            if ( MMSYSERR_NOERROR != retval )
            {
                DEBUGMSG( ZONE_ERROR,

⌨️ 快捷键说明

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