| Troubles with Direct Sound |
|
 |
|
 |
|
 |
|
 |
Group: microsoft.public.win32.programmer.directx.audio · Group Profile
Author: Kostikov StanislavKostikov Stanislav Date: Mar 30, 2008 20:27
I have strange problem with Direct Sound.
- On start application i set sound in silence (DSBVOLUME_MIN)
- Before it finished loading i switch to another window (make my inactive)
- After it finish loading ( wait some time ) i return to my application
- Sound is playing with maximum volume, but if i ask sound buffer sound
volume it's return DSBVOLUME_MIN and if i try change sound volume in
DSBVOLUME_MIN
it's do nothing.
I change sound volume of secondary buffer and never change sound volume of
primary buffers (it's done becourse i play sound and music by direct sound so
i must have separate sound and music volume control)
there code for initialization DirectSound:
cSoundImpl::cSoundImpl( )
{
HRESULT hr = DirectSoundCreate(NULL, &m_pDirectSound, NULL);
assert( !FAILED(hr) );
hr = m_pDirectSound->SetCooperativeLevel(cApplication::instance()->hwnd(),
DSSCL_PRIORITY );
assert( !FAILED(hr) );
DSBUFFERDESC dsbdesc;
ZeroMemory(&dsbdesc, sizeof(DSBUFFERDESC));
dsbdesc.dwSize = sizeof(DSBUFFERDESC);
dsbdesc.dwFlags = DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME |
DSBCAPS_CTRL3D;
m_pDirectSound->CreateSoundBuffer(&dsbdesc, &m_pPrimary, NULL);
m_pPrimary->QueryInterface(IID_IDirectSound3DListener,
(void**)&m_listener_3d);
m_pPrimary->Play( 0, 0, DSBPLAY_LOOPING );
}
And there code for create direct sound buffer:
LPDIRECTSOUNDBUFFER cSoundImpl::createBuffer ( const WAVEFORMATEX & wfx )
{
WAVEFORMATEX wf = wfx;
DWORD nBlockAlign = wfx.nBlockAlign;
INT nSamplesPerSec = wfx.nSamplesPerSec;
DSBUFFERDESC dsbdesc;
memset(&dsbdesc, 0, sizeof(DSBUFFERDESC));
dsbdesc.dwSize = sizeof(DSBUFFERDESC);
dsbdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLVOLUME ;
dsbdesc.dwBufferBytes = nSamplesPerSec * 3 * nBlockAlign;
dsbdesc.lpwfxFormat = &wf;
LPDIRECTSOUNDBUFFER buf;
m_pDirectSound->CreateSoundBuffer(&dsbdesc, &buf, NULL);
return buf;
}
|