Beispiel #1
0
//-----------------------------------------------------------------------------
// Name: Reset()
// Desc: Resets the internal m_ckIn pointer so reading starts from the 
//       beginning of the file again 
//-----------------------------------------------------------------------------
HRESULT CWaveSoundRead::Reset()
{
    return WaveStartDataRead( &m_hmmioIn, &m_ckIn, &m_ckInRiff );
}
Beispiel #2
0
int WaveLoadFile(
            TCHAR*pszFileName,                      // (IN)
            UINT *cbSize,                           // (OUT)
            WAVEFORMATEX **ppwfxInfo,       // (OUT)
            BYTE **ppbData                          // (OUT)
            )
{

    HMMIO                           hmmioIn;        
    MMCKINFO                        ckInRiff;
    MMCKINFO                        ckIn;
    int                                     nError;
    UINT                            cbActualRead;

    *ppbData = NULL;
    *ppwfxInfo = NULL;
    *cbSize = 0;
    
    if ((nError = WaveOpenFile(pszFileName, &hmmioIn, ppwfxInfo, &ckInRiff)) != 0)
        {
        goto ERROR_LOADING;
        }

    if ((nError = WaveStartDataRead(&hmmioIn, &ckIn, &ckInRiff)) != 0)
        {
        goto ERROR_LOADING;
        }

    // Ok, size of wave data is in ckIn, allocate that buffer.
    if ((*ppbData = (BYTE *)GlobalAlloc(GMEM_FIXED, ckIn.cksize)) == NULL)
        {
        nError = ER_MEM;
        goto ERROR_LOADING;
        }

    if ((nError = WaveReadFile(hmmioIn, ckIn.cksize, *ppbData, &ckIn, &cbActualRead)) != 0)
        {
        goto ERROR_LOADING;
        }        
    
    *cbSize = cbActualRead;
    goto DONE_LOADING;

ERROR_LOADING:
    if (*ppbData != NULL)
        {
        GlobalFree(*ppbData);
        *ppbData = NULL;
        }
    if (*ppwfxInfo != NULL)
        {
        GlobalFree(*ppwfxInfo);
        *ppwfxInfo = NULL;
        }
            
DONE_LOADING:
    // Close the wave file. 
    if (hmmioIn != NULL)
        {
        mmioClose(hmmioIn, 0);
        hmmioIn = NULL;
        }

    return(nError);

}
Beispiel #3
0
//================================================================================================================
bool Sound::LoadSound(char* filename)
{
	char* path = new char[strlen(m_gd->m_music_path.c_str()) + 1];
	strcpy(path, m_gd->m_music_path.c_str());
	strcat(path, "\\");
	strcat(path, filename);

	WAVEFORMATEX  *pwfx;
	HMMIO         hmmio;
	MMCKINFO      mmckinfo;
	MMCKINFO      mmckinfoParent;

	TCHAR szName[512];

	int path_len = strlen(m_gd->m_music_path.c_str()) + 1;
	int filename_len = strlen(filename) + 1;
	int size = path_len + filename_len;

	ZShadeSandboxGlobal::Convert::ConvertCharPointerToTChar(path, szName, size);

	//Open the file
	if (WaveOpenFile(szName, &hmmio, &pwfx, &mmckinfoParent) != 0)
	{
		ZShadeMessageCenter::MsgBoxError(NULL, "LoadSound: failed to open wave file");
		return false;
	}

	//Read the file
	if (WaveStartDataRead(&hmmio, &mmckinfo, &mmckinfoParent) != 0)
	{
		ZShadeMessageCenter::MsgBoxError(NULL, "LoadSound: failed to read wave file");
		return false;
	}

	DSBUFFERDESC dsbdesc;

	//Get buffer Info
	memset( &dsbdesc, 0, sizeof(DSBUFFERDESC) );
	dsbdesc.dwSize = sizeof(DSBUFFERDESC);
	dsbdesc.dwFlags = DSBCAPS_STATIC;
	dsbdesc.dwBufferBytes = mmckinfo.cksize;
	dsbdesc.lpwfxFormat = pwfx;

	//Create the buffer
	if (FAILED(m_DirectSound->CreateSoundBuffer(&dsbdesc, &m_primaryBuffer, NULL)))
	{
		ZShadeMessageCenter::MsgBoxError(NULL, "LoadSound: failed to create wave sound buffer");
		WaveCloseReadFile(&hmmio, &pwfx);
		return false;
	}

	LPVOID lpvAudio1;
	DWORD dwBytes1;

	//Lock the buffer
	if (FAILED(m_primaryBuffer->Lock(0, 0, &lpvAudio1, &dwBytes1, NULL, NULL, DSBLOCK_ENTIREBUFFER)))
	{
		ZShadeMessageCenter::MsgBoxError(NULL, "LoadSound: failed to lock wave sound buffer");
		WaveCloseReadFile(&hmmio, &pwfx);
		return false;
	}

	UINT cbBytesRead;

	if (WaveReadFile(hmmio, dwBytes1, (BYTE*)lpvAudio1, &mmckinfo, &cbBytesRead))
	{
		ZShadeMessageCenter::MsgBoxError(NULL, "LoadSound: failed to read wave sound buffer");
		WaveCloseReadFile(&hmmio, &pwfx);
		return false;
	}

	//Unlock the buffer
	m_primaryBuffer->Unlock(lpvAudio1, dwBytes1, NULL, 0);

	//Close the file
	WaveCloseReadFile(&hmmio, &pwfx);

	m_soundLoaded = true;

	return true;
}