Jump to content
  • Advertisement
Sign in to follow this  
zander

DirectSound SetVolume

This topic is 4862 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am using IDirectSoundBuffer8::SetVolume for Directx8 and whenever I try to use set the volume of the soundbuffer, it does nothing. It doesnt change the sound at all. The sound is playing fine, but I can not change the volume. For example: m_pSoundBuff->Play(0, 0, DSBPLAY_LOOPING); m_pSoundBuff->SetVolume(DSBVOLUME_MIN); when I put this in my code, the sound plays and loops, but the setVolume does not change the volume to silence like it should, or any other value that i put in there as a parameter. I tried switching the order of these two statements but that didn't work either. How do I change the volume of a sound loop or sound?

Share this post


Link to post
Share on other sites
Advertisement
Long time since I last directly worked with DirectSound... but have you checked the return code of the SetVolume call?

Share this post


Link to post
Share on other sites
How are you creating your Sound buffer? When you want to control the volume of the sound buffer you must specify a DSBCAPS_CTRLVOLUME flag when creating.
DSBUFFERDESC d;
d.lFlags = DSBCAPS_CTRLVOLUME; // | DSBCAPS_CTRLFREQUENCY | DSBCAPS_CTRLPAN
...
CreateSoundBufferFromFile("\Sample.wav", &d);

Share this post


Link to post
Share on other sites
wow thanks it works now! :) If I want to pause music, do I need to set more flags? because whenever I try to use the following code:

LPDWORD curPlayCursor = NULL;
static LPDWORD curWriteCursor = NULL;
LPDWORD curStatus = NULL;

if(playing)
{
HRESULT hResult = m_pSoundBuff->GetCurrentPosition(curPlayCursor,curWriteCursor);
if (hResult != DS_OK)
return hResult;
m_pSoundBuff->Stop();
}
else
{
//m_pSoundBuff->SetCurrentPosition(*curWriteCursor);
PlaySound(m_pSoundBuff, true);
}


i get errors using the curWriteCursor and curPlayCursor variables.

Share this post


Link to post
Share on other sites
as far as I know, the only thing you have to do to pause the sound is writing a single line of code:
buffer->Stop();

and if you want to stop the sound:

buffer->Stop();
buffer->SetCurrentPosition(0);

Share this post


Link to post
Share on other sites
Quote:
Original post by zander
wow thanks it works now! :) If I want to pause music, do I need to set more flags? because whenever I try to use the following code:

LPDWORD curPlayCursor = NULL;
static LPDWORD curWriteCursor = NULL;
LPDWORD curStatus = NULL;

if(playing)
{
HRESULT hResult = m_pSoundBuff->GetCurrentPosition(curPlayCursor,curWriteCursor);
if (hResult != DS_OK)
return hResult;
m_pSoundBuff->Stop();
}
else
{
//m_pSoundBuff->SetCurrentPosition(*curWriteCursor);
PlaySound(m_pSoundBuff, true);
}


i get errors using the curWriteCursor and curPlayCursor variables.

This is a common mistake. GetCurrentPosition() takes LPDWORD arguments, it is true, but LPDWORD is just a typedef for DWORD*. You passed it a couple of invalid addresses, whereas what it wanted was the addresses of two DWORD variables. What you should have done is like so:

DWORD curPlayCursor;
static DWORD curWriteCursor;
DWORD curStatus;

if(playing)
{
HRESULT hResult = m_pSoundBuff->GetCurrentPosition(&curPlayCursor,&curWriteCursor);
if (hResult != DS_OK)
return hResult;
m_pSoundBuff->Stop();
}
else
{
//m_pSoundBuff->SetCurrentPosition(curWriteCursor);
PlaySound(m_pSoundBuff, true);
}

That should run, although MePHyst0 is probably correct that you don't need the position stuff anyways (I didn't check that part).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!