problem loading wav resource in DSound
There''s problem when I tried to load wave resource in DSound. I wrote the code according to the directx documentation:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dx8_c/hh/dx8_c/audio_using_9jxr.asp
Here''s what I''ve written:
//////////////////////////////////////////////////////////////
CWaveFile waveFile;
if (FAILED(waveFile.Open("mywave", NULL, WAVEFILE_READ)))
// where "mywave" is the name of wave resource file
{
waveFile.Close();
}
LPDIRECTSOUNDBUFFER lpdsbStatic;
DSBUFFERDESC dsbdesc;
memset(&dsbdesc, 0, sizeof(DSBUFFERDESC));
dsbdesc.dwSize = sizeof(DSBUFFERDESC);
dsbdesc.dwFlags = 0;
dsbdesc.dwBufferBytes = waveFile.GetSize();
dsbdesc.lpwfxFormat = waveFile.m_pwfx;
if FAILED(lpds->CreateSoundBuffer(&dsbdesc, &lpdsbStatic, NULL))
{
// Error handling.
}
LPVOID lpvAudio1;
DWORD dwBytes1;
if FAILED(lpdsbStatic->Lock(
0, // Offset of lock start.
0, // Size of lock; ignored in this case.
&lpvAudio1, // Address of lock start.
&dwBytes1, // Number of bytes locked.
NULL, // Wraparound start; not used.
NULL, // Wraparound size; not used.
DSBLOCK_ENTIREBUFFER))
{
// Error handling.
}
DWORD dwBytesRead;
waveFile.Read((BYTE*)lpvAudio1, dwBytes1, &dwBytesRead);
lpdsbStatic->Unlock(lpvAudio1, dwBytes1, NULL, 0);
waveFile.Close();
///////////////////////////////////////////////////////////////
The problem is that the resource "mywave" failed to open and cannot create the buffer.("mywave" was imported as type "WAVE" in the resource.rc)
However, when I replace "mywave" with a file name, say "wave1.wav", the routine works properly.
Can anyone tell me what''s going wrong?
Thanks!!
You can use CMusicManager (find in DMUtil.cpp)
CMusicManager* g_pMusicManager = NULL;
g_pMusicManager = new CMusicManager();
if( FAILED( g_pMusicManager->Initialize( hWnd ) ) )
return E_FAIL;
g_pMusicManager->CreateSegmentFromResource(&g_pSound,_T("MYSOUND"), _T("WAV") );
<<>>
MYSOUND WAV MOVEABLE PURE "level.wav"
CMusicManager* g_pMusicManager = NULL;
g_pMusicManager = new CMusicManager();
if( FAILED( g_pMusicManager->Initialize( hWnd ) ) )
return E_FAIL;
g_pMusicManager->CreateSegmentFromResource(&g_pSound,_T("MYSOUND"), _T("WAV") );
<<>>
MYSOUND WAV MOVEABLE PURE "level.wav"
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement