Sign in to follow this  
RoyChen204

Direct Sound 3D help!

Recommended Posts

I got a problem with DirectSound. heres how it goes, I created an Audio class to store any music files I loaded. When its just background music, its fine, but when I insert a listener, things become problematic. I can change the values of the sound position to no effect, while if I change the listener, even the background music becomes "dropped off"
void AudioManager::PlaySegment(unsigned int value, int times)
{
	for(std::vector<Sound *>::iterator g2 = Audio.begin(); g2 != Audio.end();g2++)
	{
		if((*g2)->id == value)
		{
			if(times > -1)
			{
				(*g2)->m_pSegment->SetRepeats(times);
				m_pPerformance->PlaySegmentEx((*g2)->m_pSegment,NULL,NULL, DMUS_SEGF_DEFAULT, 0, NULL,NULL, (*g2)->m_p3DAudioPath);
			}
			else
			{
				(*g2)->m_pSegment->SetRepeats(DMUS_SEG_REPEAT_INFINITE);
				m_pPerformance->PlaySegmentEx((*g2)->m_pSegment,NULL,NULL, DMUS_SEGF_SECONDARY, 0, NULL,NULL, (*g2)->m_p3DAudioPath);
			}

			
			return;
		}
	}
}
void AudioManager::SetListener(Vector *position)
{
	m_pListener->SetPosition(position->x,position->y,position->z ,DS3D_IMMEDIATE);
}
void AudioManager::SetPosition(unsigned int value, Vector *position)
{
	for(std::vector<Sound *>::iterator g2 = Audio.begin(); g2 != Audio.end();g2++)
	{
		if((*g2)->id == value)
		{
			if((*g2)->m_pDirectSoundBuffer3D != NULL)
			{
				(*g2)->m_pDirectSoundBuffer3D->SetPosition(position->x, position->y, position->z, DS3D_DEFERRED);
			}
		}
	}
}

p.s: How to I post blocks of codes neatly like how some of the other guys do it? [Edited by - RoyChen204 on July 29, 2008 1:07:31 PM]

Share this post


Link to post
Share on other sites
If you change any parameter of the listener or a 3D soundbuffer and pass DS3D_IMMEDIATE, those changes will be applied immediately. If you pass DS3D_DEFERRED, your changes will not be applied until you call IDirectSound3DListener::CommitDeferredSettings().

I guess your error is that you're not calling this function.
Since you change the position of your 3D sound using DS3D_DEFERRED, those changes won't be applied.

Quote:
Original post by RoyChen204
p.s: How to I post blocks of codes neatly like how some of the other guys do it?


Read the FAQ.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this