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.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 | 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











