Original Post
In the directsound playsound example in directx 9 sdk, they have a class called CSoundManager that is called like this:
CSoundManager * g_pSoundManager;
g_pSoundManager = new CSoundManager();
g_pSoundManager->Initialize( hWnd ) ;
Ive been messing around with the sample code and making it much smaller. The problem is i dont want to declare the CSoundManager as a pointer.
But as such:
CSoundManager g_pSoundManager;
g_pSoundManager.Initialize( hWnd ) ;
But when I do this directsound will not initialise.
Heres my class code:
class CSoundManager
{
public:
static LPDIRECTSOUND8 m_pDS;
CSoundManager()
{
m_pDS = NULL;
}
~CSoundManager()
{
if(m_pDS)
{
(m_pDS)->Release();
(m_pDS)=NULL;
}
}
void Initialize( HWND hWnd )
{
DirectSoundCreate8( NULL, &m_pDS, NULL );
m_pDS->SetCooperativeLevel( hWnd, DSSCL_PRIORITY );
LPDIRECTSOUNDBUFFER pDSBPrimary = NULL;
DSBUFFERDESC dsbd;
ZeroMemory( &dsbd, sizeof(DSBUFFERDESC) );
dsbd.dwSize = sizeof(DSBUFFERDESC);
dsbd.dwFlags = DSBCAPS_PRIMARYBUFFER;
dsbd.dwBufferBytes = 0;
dsbd.lpwfxFormat = NULL;
m_pDS->CreateSoundBuffer( &dsbd, &pDSBPrimary, NULL ) ;
WAVEFORMATEX wfx;
ZeroMemory( &wfx, sizeof(WAVEFORMATEX) );
wfx.wFormatTag = (WORD) WAVE_FORMAT_PCM;
wfx.nChannels = 2;
wfx.nSamplesPerSec = 22050;
wfx.wBitsPerSample = (WORD) 16;
wfx.nBlockAlign = (WORD) (wfx.wBitsPerSample / 8 * wfx.nChannels);
wfx.nAvgBytesPerSec = (DWORD) (wfx.nSamplesPerSec * wfx.nBlockAlign);
pDSBPrimary->SetFormat(&wfx);
if(pDSBPrimary)
{
(pDSBPrimary)->Release();
(pDSBPrimary)=NULL;
}
}
};
LPDIRECTSOUND8 CSoundManager::m_pDS=NULL;
thanks
[edited by - johnnyBravo on November 26, 2003 11:12:38 PM]