void Sound::InitializeSound(HWND hWnd)
{
HRESULT snd = DirectSoundCreate8(NULL, &d3dSound, NULL);
if (FAILED(snd))
MessageBox(NULL, "failed to create sound device", "FAIL!", MB_ICONEXCLAMATION | MB_OK);
HRESULT spr = d3dSound->SetCooperativeLevel(hWnd, DSSCL_NORMAL);
if (FAILED(spr))
MessageBox(NULL, "failed to set sound priority", "FAIL!", MB_ICONEXCLAMATION | MB_OK);
WAVEFORMATEX wfx;
memset(&wfx, 0, sizeof(WAVEFORMATEX));
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nChannels = dwPrimaryChannels;
wfx.nSamplesPerSec = dwPrimaryFreq;
wfx.nBlockAlign = (wfx.wBitsPerSample / 8 * wfx.nChannels);
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
wfx.wBitsPerSample = dwPrimaryBitRate;
LPDIRECTSOUNDBUFFER pDSBPrimary = NULL;
DSBUFFERDESC dsbd;
memset( &dsbd, 0, sizeof(DSBUFFERDESC) );
dsbd.dwSize = sizeof(DSBUFFERDESC);
dsbd.dwFlags = DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY | DSBCAPS_PRIMARYBUFFER;
dsbd.dwBufferBytes = 0;
dsbd.lpwfxFormat = &wfx
HRESULT csb = d3dSound->CreateSoundBuffer( &dsbd, &pDSBPrimary, NULL );
if (FAILED(csb))
MessageBox(NULL, "failed to create sound buffer", "FAIL!", MB_ICONEXCLAMATION | MB_OK);
if(pDSBPrimary)
pDSBPrimary->Release();
}
thanks in advance for any help you can give
CreateSoundBuffer returning DSERR_INVALIDPARAM
Im making a simple 2D game for a university project and when I try to create a sound buffer its returning the error DSERR_INVALIDPARAM and I cant figure out why. I know direct sound is pretty much dead but its what we were told to use so I have to stick with it. Any help would be greatly appreciated.
change this:
memset(&wfx, 0, sizeof(WAVEFORMATEX));
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nChannels = dwPrimaryChannels;
wfx.nSamplesPerSec = dwPrimaryFreq;
wfx.nBlockAlign = (wfx.wBitsPerSample / 8 * wfx.nChannels);
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
wfx.wBitsPerSample = dwPrimaryBitRate;
whit this:
memset(&wfx, 0, sizeof(WAVEFORMATEX));
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nChannels = dwPrimaryChannels;
wfx.nSamplesPerSec = dwPrimaryFreq;
wfx.wBitsPerSample = dwPrimaryBitRate;
wfx.nBlockAlign = (wfx.wBitsPerSample / 8 * wfx.nChannels);
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
bye...
memset(&wfx, 0, sizeof(WAVEFORMATEX));
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nChannels = dwPrimaryChannels;
wfx.nSamplesPerSec = dwPrimaryFreq;
wfx.nBlockAlign = (wfx.wBitsPerSample / 8 * wfx.nChannels);
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
wfx.wBitsPerSample = dwPrimaryBitRate;
whit this:
memset(&wfx, 0, sizeof(WAVEFORMATEX));
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nChannels = dwPrimaryChannels;
wfx.nSamplesPerSec = dwPrimaryFreq;
wfx.wBitsPerSample = dwPrimaryBitRate;
wfx.nBlockAlign = (wfx.wBitsPerSample / 8 * wfx.nChannels);
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
bye...
you used this assignment
wfx.nBlockAlign = (wfx.wBitsPerSample / 8 * wfx.nChannels);
before this
wfx.BitsPerSample = dwPrimaryBitRate;
wfx.nBlockAlign = (wfx.wBitsPerSample / 8 * wfx.nChannels);
before this
wfx.BitsPerSample = dwPrimaryBitRate;
I think that you cannot create a primary sound buffer with DSSCL_NORMAL. Try using DSSCL_PRIORITY.
Anyway you shouldn't be using the primary sound buffer. You should use secondary buffers only...can I ask you why are you doing this?
Anyway you shouldn't be using the primary sound buffer. You should use secondary buffers only...can I ask you why are you doing this?
Changing the cooperative level didnt seem to work unless theres even more problems.
Im just trying to follow a my university notes and a tutorial in Game Coding 2nd ed. My notes are a bit dis-jointed and hard to follow (I didnt write them, I get lazy in class but Im paying for it now :/ and the tutorial in Game Coding is way more complicated than I need but I havent been able to find anything better so Im trying to piece together the information. If Im not supposed to use the primary buffer its a mistake made out of ignorance.
Im just trying to follow a my university notes and a tutorial in Game Coding 2nd ed. My notes are a bit dis-jointed and hard to follow (I didnt write them, I get lazy in class but Im paying for it now :/ and the tutorial in Game Coding is way more complicated than I need but I havent been able to find anything better so Im trying to piece together the information. If Im not supposed to use the primary buffer its a mistake made out of ignorance.
You should always use secondary buffers as explained here:http://msdn.microsoft.com/en-us/library/bb174729%28VS.85%29.aspx.
Try this:
void Sound::InitializeSound(HWND hWnd)
{
HRESULT snd = DirectSoundCreate8(NULL, &d3dSound, NULL);
if (FAILED(snd))
MessageBox(NULL, "failed to create sound device", "FAIL!", MB_ICONEXCLAMATION | MB_OK);
HRESULT spr = d3dSound->SetCooperativeLevel(hWnd, DSSCL_PRIORITY);
if (FAILED(spr))
MessageBox(NULL, "failed to set sound priority", "FAIL!", MB_ICONEXCLAMATION | MB_OK);
WAVEFORMATEX wfx;
memset(&wfx, 0, sizeof(WAVEFORMATEX));
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nChannels = dwPrimaryChannels;
wfx.nSamplesPerSec = dwPrimaryFreq;
wfx.wBitsPerSample = dwPrimaryBitRate;
wfx.nBlockAlign = (wfx.wBitsPerSample / 8 * wfx.nChannels);
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
LPDIRECTSOUNDBUFFER pDSBPrimary = NULL;
DSBUFFERDESC dsbd;
memset( &dsbd, 0, sizeof(DSBUFFERDESC) );
dsbd.dwSize = sizeof(DSBUFFERDESC);
dsbd.dwFlags = DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY;
dsbd.dwBufferBytes = wfx.nAvgBytesPerSec;
dsbd.lpwfxFormat = &wfx
HRESULT csb = d3dSound->CreateSoundBuffer( &dsbd, &pDSBPrimary, NULL );
if (FAILED(csb))
MessageBox(NULL, "failed to create sound buffer", "FAIL!", MB_ICONEXCLAMATION | MB_OK);
if(pDSBPrimary)
pDSBPrimary->Release();
}
This creates a secondary buffer whose length is of exactly 1 second of audio. You can change this by assigning a different value to dsbd.dwBufferBytes
Bye! ;)
Try this:
void Sound::InitializeSound(HWND hWnd)
{
HRESULT snd = DirectSoundCreate8(NULL, &d3dSound, NULL);
if (FAILED(snd))
MessageBox(NULL, "failed to create sound device", "FAIL!", MB_ICONEXCLAMATION | MB_OK);
HRESULT spr = d3dSound->SetCooperativeLevel(hWnd, DSSCL_PRIORITY);
if (FAILED(spr))
MessageBox(NULL, "failed to set sound priority", "FAIL!", MB_ICONEXCLAMATION | MB_OK);
WAVEFORMATEX wfx;
memset(&wfx, 0, sizeof(WAVEFORMATEX));
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nChannels = dwPrimaryChannels;
wfx.nSamplesPerSec = dwPrimaryFreq;
wfx.wBitsPerSample = dwPrimaryBitRate;
wfx.nBlockAlign = (wfx.wBitsPerSample / 8 * wfx.nChannels);
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
LPDIRECTSOUNDBUFFER pDSBPrimary = NULL;
DSBUFFERDESC dsbd;
memset( &dsbd, 0, sizeof(DSBUFFERDESC) );
dsbd.dwSize = sizeof(DSBUFFERDESC);
dsbd.dwFlags = DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY;
dsbd.dwBufferBytes = wfx.nAvgBytesPerSec;
dsbd.lpwfxFormat = &wfx
HRESULT csb = d3dSound->CreateSoundBuffer( &dsbd, &pDSBPrimary, NULL );
if (FAILED(csb))
MessageBox(NULL, "failed to create sound buffer", "FAIL!", MB_ICONEXCLAMATION | MB_OK);
if(pDSBPrimary)
pDSBPrimary->Release();
}
This creates a secondary buffer whose length is of exactly 1 second of audio. You can change this by assigning a different value to dsbd.dwBufferBytes
Bye! ;)
sorry its taken me so long to get back, thanks very much for the help although there were many more problems after that one. a friend of mine tracked them all down for me and it is now working. mmioopen and mmioread seemed to be causing most of the follow up issues, not sure why yet.
anyway, thanks again for your help.
anyway, thanks again for your help.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement