Simple question about DSound

Started by
1 comment, last by Marsc 21 years, 7 months ago
Hello developers. I guess this is very simple, As I allways did with DirectSound, I create the secondary buffers in a PCM Mono. (I''m not sure if you can create stereo buffers). Well, I''d like to give my new game stereo capabilities.... Of course playing the buffers individualy right or left dependind on its location on the screen. (Like the balance control in my audio amplifier). I know this can be done, but I think I missed something in documentation.... Please can anyone give me some help?.
Advertisement
Sure it is possible to create stereo buffer !

I hope it can help... Here is how I initialize my Sound Manager :


            HRESULT SoundManager::Init(HWND _hwnd){	HRESULT hr;	m_panCenterX = SCREEN_WIDTH/2; m_panCenterY = SCREEN_HEIGHT/2;	InitAllVolumes();	hr = DirectSoundCreate(NULL,&m_lpDSound,NULL); CheckFailed(hr,E_FAIL);	hr = m_lpDSound->SetCooperativeLevel(_hwnd,DSSCL_EXCLUSIVE); CheckFailed(hr,E_FAIL);	hr = m_lpDSound->SetSpeakerConfig(DSSPEAKER_COMBINED(DSSPEAKER_STEREO,DSSPEAKER_GEOMETRY_WIDE)); CheckFailed(hr,E_FAIL);	DSBUFFERDESC dsbdesc;	ZeroMemory(&dsbdesc,sizeof(DSBUFFERDESC));	dsbdesc.dwSize = sizeof(DSBUFFERDESC);	dsbdesc.dwFlags = DSBCAPS_PRIMARYBUFFER;	hr = m_lpDSound->CreateSoundBuffer(&dsbdesc,&m_lpDSBPrimary,NULL); CheckFailed(hr,E_FAIL);	WAVEFORMATEX wfx;	memset(&wfx,0,sizeof(xpWAVEFORMATEX));	wfx.wFormatTag = WAVE_FORMAT_PCM;	wfx.nChannels = 2;	wfx.nSamplesPerSec = 44100;	wfx.wBitsPerSample = 16;	wfx.nBlockAlign = wfx.wBitsPerSample / 8 * wfx.nChannels;	wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;	hr = m_lpDSBPrimary->SetFormat(&wfx); 	return S_OK;}  


with these delcaration inside the class SoundManager :

LPDIRECTSOUND m_lpDSound;
LPDIRECTSOUNDBUFFER m_lpDSBPrimary;


Then I use another class "Sound" to create my sounds fx, here is how I allocate my buffers :


        LPDIRECTSOUNDBUFFER Sound::AllocBuffer(){    LPDIRECTSOUNDBUFFER lpDSB = NULL;	DSBUFFERDESC dsbd;	Assert(gSoundManager,"DirectSound is not initialized!");	if (m_loadOK)	{		ZeroMemory(&dsbd,sizeof(dsbd));		dsbd.dwSize = sizeof(dsbd);		dsbd.dwFlags = DSBCAPS_STATIC | DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME;		dsbd.dwBufferBytes = m_cbWaveSize;		dsbd.dwReserved = 0;		dsbd.lpwfxFormat = &m_waveFormat;		gSoundManager->GetDirectSound()->CreateSoundBuffer( &dsbd, &lpDSB, NULL); 	}	return lpDSB;}            



You can then use the SetPan method of the buffer class to select the position of your sound in the space (left/right....)

__________________________



Bruno Wieckowski
Lead Programmer
Exood4 Studios



[edited by - brunow on August 15, 2002 12:17:20 PM]
quote:Original post by brunow
Sure it is possible to create stereo buffer !

I hope it can help... Here is how I initialize my Sound Manager :
12:17:20 PM]



Thank you very much....
I will start to work now on some stereo for my game.... :-)

This topic is closed to new replies.

Advertisement