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

📄 wav.cpp

📁 CIRRUS 公司EP93XX系列CPU的WINCE下的BSP
💻 CPP
📖 第 1 页 / 共 3 页
字号:



// -----------------------------------------------------------------------------
//
//  @doc    WDEV_EXT
//
//  @func   BOOL | WAV_Close | Device close routine
//
//  @parm   DWORD | dwOpenData | Value returned from WAV_Open call
//
//  @rdesc  Returns TRUE for success, FALSE for failure
//
// -----------------------------------------------------------------------------
extern "C" BOOL WAV_Close(
    DWORD dwData
    )
{
    DEBUGMSG (ZONE_FUNCTION, (TEXT("WAV_Close(0x%X)\r\n"), dwData));

    delete (AudioDriver **)dwData;
    return TRUE;
}



// -----------------------------------------------------------------------------
//
//  @doc    WDEV_EXT
//
//  @func   DWORD | WAV_Read | Device read routine
//
//  @parm   DWORD | dwOpenData | Value returned from WAV_Open call (ignored)
//
//  @parm   LPVOID | pBuf | Buffer to receive data (ignored)
//
//  @parm   DWORD | len | Maximum length to read (ignored)
//
//  @rdesc  Returns 0 always. WAV_Read should never get called and does
//          nothing. Required DEVICE.EXE function, but all data communication
//          is handled by <f WAV_IOControl>.
//
// -----------------------------------------------------------------------------
extern "C" DWORD WAV_Read
(
    DWORD dwData, 
    LPVOID pBuf, 
    DWORD Len
)
{
    DEBUGMSG (ZONE_FUNCTION, (TEXT("WAV_Read(0x%X, 0x%X, %d)\r\n"),
                       dwData, pBuf, Len));

    // Return length read
    return 0;
}




// -----------------------------------------------------------------------------
//
//  @doc    WDEV_EXT
//
//  @func   DWORD | WAV_Write | Device write routine
//
//  @parm   DWORD | dwOpenData | Value returned from WAV_Open call (ignored)
//
//  @parm   LPCVOID | pBuf | Buffer containing data (ignored)
//
//  @parm   DWORD | len | Maximum length to write (ignored)
//
//  @rdesc  Returns 0 always. WAV_Write should never get called and does
//          nothing. Required DEVICE.EXE function, but all data communication
//          is handled by <f WAV_IOControl>.
//
// -----------------------------------------------------------------------------
extern "C" DWORD WAV_Write
(
    DWORD dwData, 
    LPCVOID pBuf, 
    DWORD Len
)
{
    DEBUGMSG (ZONE_FUNCTION, (TEXT("WAV_Write(0x%X, 0x%X, %d)\r\n"),
                  dwData, pBuf, Len));

    // return number of bytes written (or -1 for error)
    return 0;
}



// -----------------------------------------------------------------------------
//
//  @doc    WDEV_EXT
//
//  @func   DWORD | WAV_Seek | Device seek routine
//
//  @parm   DWORD | dwOpenData | Value returned from WAV_Open call (ignored)
//
//  @parm   long | pos | Position to seek to (relative to type) (ignored)
//
//  @parm   DWORD | type | FILE_BEGIN, FILE_CURRENT, or FILE_END (ignored)
//
//  @rdesc  Returns -1 always. WAV_Seek should never get called and does
//          nothing. Required DEVICE.EXE function, but all data communication
//          is handled by <f WAV_IOControl>.
//
// -----------------------------------------------------------------------------
extern "C" DWORD WAV_Seek
(
    DWORD dwData, 
    long pos, 
    DWORD type
)
{
    DEBUGMSG (ZONE_FUNCTION, (TEXT("WAV_Seek(0x%X, %d, %d)\r\n"), dwData,
                           pos, type));

    // return an error
    return (DWORD)-1;
}




// -----------------------------------------------------------------------------
//
//  @doc    WDEV_EXT
//
//  @func   void | WAV_PowerUp | Device powerup routine
//
//  @comm   Called to restore device from suspend mode.  Cannot call any
//          routines aside from those in the dll in this call.
//
// -----------------------------------------------------------------------------
extern "C" VOID WAV_PowerUp(VOID)
{
	AudioDriver * pAudio=g_pAudioDriverHead;

	for(; pAudio; )
	{
		pAudio->PowerUp( );
		pAudio=pAudio->pNext;
	}
    //WMDD_PowerHandler(FALSE);
}



// -----------------------------------------------------------------------------
//
//  @doc    WDEV_EXT
//
//  @func   void | WAV_PowerDown | Device powerdown routine
//
//  @comm   Called to suspend device.  Cannot call any routines aside from
//          those in the dll in this call.
//
// -----------------------------------------------------------------------------
extern "C" VOID WAV_PowerDown( VOID )
{
	AudioDriver * pAudio=g_pAudioDriverHead;

	for(; pAudio; ) 
	{
		pAudio->PowerDown( );
		pAudio=pAudio->pNext;
	}
    //WMDD_PowerHandler(TRUE);
}

// -----------------------------------------------------------------------------
//
//  @doc    WDEV_EXT
//
//  @func   BOOL | WAV_IOControl | Device IO control routine
//
//  @parm   DWORD | dwOpenData | Value returned from WAV_Open call
//
//  @parm   DWORD | dwCode | 
//          IO control code for the function to be performed. WAV_IOControl only
//          supports one IOCTL value (IOCTL_WAV_MESSAGE)
//
//  @parm   PBYTE | pBufIn | 
//          Pointer to the input parameter structure (<t MMDRV_MESSAGE_PARAMS>).
//
//  @parm   DWORD | dwLenIn | 
//          Size in bytes of input parameter structure (sizeof(<t MMDRV_MESSAGE_PARAMS>)).
//
//  @parm   PBYTE | pBufOut | Pointer to the return value (DWORD).
//
//  @parm   DWORD | dwLenOut | Size of the return value variable (sizeof(DWORD)).
//
//  @parm   PDWORD | pdwActualOut | Unused
//
//  @rdesc  Returns TRUE for success, FALSE for failure
//
//  @xref   <t Wave Input Driver Messages> (WIDM_XXX) <nl>
//          <t Wave Output Driver Messages> (WODM_XXX)
//
// -----------------------------------------------------------------------------
extern "C" BOOL WAV_IOControl
(
    DWORD  dwOpenData, 
    DWORD  dwCode, 
    PBYTE  pBufIn,
    DWORD  dwLenIn, 
    PBYTE  pBufOut, 
    DWORD  dwLenOut,
    PDWORD pdwActualOut
)
{
    DWORD dwRet;
    PMMDRV_MESSAGE_PARAMS pParams = (PMMDRV_MESSAGE_PARAMS) pBufIn;
    AudioDriver *pAudioDrv;    


    //  set the error code to be no error first
    SetLastError(MMSYSERR_NOERROR);

    __try 
    {
        pAudioDrv = *(AudioDriver **)dwOpenData;
        if(dwCode == IOCTL_WAV_MESSAGE)
        {
            dwRet = pAudioDrv->WaveMessage((PMMDRV_MESSAGE_PARAMS) pBufIn);
        }
        else if(dwCode == IOCTL_MIX_MESSAGE && pAudioDrv->MixerEnabled())
        {
            dwRet = pAudioDrv->MixerMessage((PMMDRV_MESSAGE_PARAMS) pBufIn);
        }
        else if( dwCode == IOCTL_DSHAL_MESSAGE)
        {
            PRINTMSG(ZONE_IOCTL, (TEXT("WAV_IOControl: dwCode == IOCTL_DSHAL_MESSAGE.\r\n")));
            return(FALSE);
        }
        
        else
        {
            PRINTMSG
            (
                ZONE_IOCTL, 
                (
                    TEXT("Unsupported dwCode = 0x%08x in WAV_IOControl()\r\n"),
                    dwCode
                )
            );
            return(FALSE);
        }    

        //
        // Pass the return code back via pBufOut
        //
        if (pBufOut != NULL) 
        {
            *((DWORD*) pBufOut) = dwRet;
        }   


    } __except (GetExceptionCode() == STATUS_ACCESS_VIOLATION ?
            EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) 
    {

        RETAILMSG(1, (TEXT("EXCEPTION IN WAV_IOControl!!!!\r\n")));
    }   

    return TRUE;
}

void AudioDriver::PowerDown( void )
{
	if( m_pCodec == &m_I2S )
	{//I2S
		m_WaveOut.PowerDown( );
		m_bPowerDown=TRUE;
	}
}

void AudioDriver::PowerUp( void )
{
	if( m_pCodec == &m_I2S )
	{//I2S
		m_WaveOut.PowerUp( );
	}
}


//****************************************************************************
// AudioDriver::Initialize
//****************************************************************************
// Audio Driver Initialation routine.
// 
//

MMRESULT AudioDriver::Initialize(void)
{
    BOOL    bUseAC97;
    BOOL    bSetGPIO1;
    BOOL    bUsePIO;

    HKEY    hKey;
    DWORD   dwRet;

    //
    // Open the WaveDev driver key.
    //
    RegOpenKeyEx
    ( 
        HKEY_LOCAL_MACHINE,
        TEXT("\\Drivers\\BuiltIn\\WaveDev"),
        0,
        0,
        &hKey
    ); 


    //
    // Check to see if we are using I2S or AC97.
    //
    bUseAC97  = ReadRegistryValue(hKey, TEXT("UseAC97"), 0);

    //
    // Check to see if we need to set GPIO 1 for the external unmute.
    //
    bSetGPIO1 = ReadRegistryValue(hKey, TEXT("SetGPIO1"), 0);

    //
    // Check to see if we are using PIO for the 
    //
    bUsePIO   = ReadRegistryValue(hKey, TEXT("UsePIO"), 0);


    //
    // The EDB9315 boards need GPIO8 to be cleared for I2S.
    //
    // bClearGPIO8 = ReadRegistryValue(hKey, TEXT("ClearGPIO8"), 0);


    //
    // Close the registry key.
    //
    RegCloseKey( hKey);


    //
    // Initializes the proper codec type
    //
    if(bUseAC97)
    {
        //
        // Initialize the AC97 codec
        //
        dwRet = m_AC97.Initialize();
        if(MMSUCCESS(dwRet))
        {
            dwRet = m_AC97Mixer.Initialize(&m_AC97);
            m_pCodec = &m_AC97;
            m_pMixer = &m_AC97Mixer;
        }        
        if(!MMSUCCESS(dwRet))
        {
            ERRORMSG(ZONE_ERROR, (L"AudioDriver::Initialize: Failed to initialize AC97Codec\n" )) ;
        }
    }

⌨️ 快捷键说明

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