#### Archived

This topic is now archived and is closed to further replies.

# IDirectSound3DBuffer question...

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

## Recommended Posts

I got a quick question about the IDirectSound3DBuffer interface. I have everything setup fine using DirectMusic8...3D positional sounds work great, but the only problem is that I cannot figure out how to set the DSBCAPS_MUTE3DATMAXDISTANCE flag so that when I exceed the maximum distance set for the buffer the sound is muted and stops playing. I know that it is set in the DSBUFFERDESC structure, but I did not create the IDirectSound3DBuffer by calling IDirectSound8::CreateSoundBuffer. I got the buffer from the call to IDirectMusicAudioPath8::GetObjectInPath... I know I can always go back and rewrite the code to create the buffer the other way, but I would like to stick with what I got if it is possible. If anyone knows of a way I can set that flag when obtaining the 3DBuffer through IDirectMusicAudioPath8::GetObjectInPath or if there is another flag that does the same thing that I missed please let me know. Thanks in advanced!

##### Share on other sites
According to the DX SDK:

quote:

The maximum distance for a sound source is the distance beyond which the sound does not get any quieter. The default maximum distance for a DirectSound 3-D buffer (DS3D_DEFAULTMAXDISTANCE) is 1 billion, meaning that in most cases the attenuation will continue to be calculated long after the sound has moved out of hearing range. To avoid unnecessary processing, applications should set a reasonable maximum distance and include the DSBCAPS_MUTE3DATMAXDISTANCE flag when creating the buffer. This flag is automatically set on standard 3-D buffers created as part of an audiopath; see Standard Audiopaths.

So, it says that the flag is automatically used by default. I would assume that after grabbing the 3-D sound interface, you would call IDirectSound3DBuffer8::SetMaxDistance to your distance (as the default distance is infinite).

home.att.net/~rpgbook
Author, Programming Role-Playing Games with DirectX
and Focus On: Advanced Animation with DirectX

##### Share on other sites
Thanks for the quick reply! I saw that part about automatically setting it up when created that way, but I was not believing it because I would get everything setup using GetObjectInPath() and then set min and max distance to 1 and 10 respectively. It gets to the maximum distance and it seems to have gone away but if I turn up volume its still playing just REAL low volume... Here is the source I use when loading the sound then setting the distance.

     m_pLoader->LoadObjectFromFile(CLSID_DirectMusicSegment,                         IID_IDirectMusicSegment8,                         wstrFileName,                         (LPVOID*)&m_SoundFX[iNumSFX].pSegment);m_pPerformance->CreateStandardAudioPath(DMUS_APATH_DYNAMIC_3D,                                  64,                                                                       TRUE,                                                             &m_SoundFX[iNumSFX].p3DAudioPath);m_SoundFX[iNumSFX].p3DAudioPath->GetObjectInPath                             (DMUS_PCHANNEL_ALL,                         DMUS_PATH_BUFFER,                         0,                                                     GUID_NULL,                         0,                         IID_IDirectSound3DBuffer,                         (LPVOID*)&m_SoundF[iNumSFX].pDSBuffer);m_SoundFX[iNumSFX].pSegment->Download(                               m_SoundFX[iNumSFX].p3DAudioPath);m_SoundFX[iNumSFX].iSoundVolume = -1000;m_SoundFX[iNumSFX].p3DAudioPath->SetVolume(                            m_SoundFX[iNumSFX].iSoundVolume, 0);  That is what I use to load the sound effect then I call a SetDistance function and set Min and Max distance and another to set listener rolloff factor like this      m_SoundFX[SoundID].pDSBuffer->SetMinDistance(1.0f,                                                      DS3D_DEFERRED);m_SoundFX[SoundID].pDSBuffer->SetMaxDistance(10.0f,                                                      DS3D_DEFERRED);m_pListener->SetRolloffFactor(5.0f, DS3D_DEFERRED);    m_bUpdateSettings = true;  Then in my update function i have a check if anything has been updated and call       if(m_bUpdateSettings)   {    m_pListener->CommitDeferredSettings();    m_bUpdateSettings = false;}  And finally to play it I call something like this      m_pPerformance->PlaySegmentEx(m_SoundFX[iSoundID].pSegment,                              0,                              0,                              DMUS_SEGF_SECONDARY,                              0,                                                                  0,                              0,                                                                            m_SoundFX[iSoundID].p3DAudioPath);

Sorry for all the code I just wanted to show you how I was setting it up and seeing if maybe I have a flag set wrong somewhere and I am just not seeing it... Thanks again!

[edited by - Boomer58 on September 30, 2002 5:14:50 PM]

##### Share on other sites
Are you using a listener object or specifying a position? Also, have you tried immediate processing instead of deferred? What about lowering 10.0f to something like 2.0f and seeing if that does something. I think as it is, the sound is only half at 10, 1/4 at 20, etc.

home.att.net/~rpgbook
Author, Programming Role-Playing Games with DirectX
and Focus On: Advanced Animation with DirectX

##### Share on other sites
Yes I am using a listener, it''s position is what I am moving around in my test program. I have the 3dBuffer set at (0,0,0). I have also tried both immediate and deferred mode. I tried adjusting the distance values and the and the rolloff values and it still doesnt seem to change it from getting real low but not muting/stoping the sound... Any other ideas? According to the DXSDK what I really should be working...I just dont understand whats going on with it...

thanks

##### Share on other sites
It may not make a difference, but are you using debug libs? If so, does it also do the same w/retail libs?

##### Share on other sites
Alright I tried to change to release mode and same problem occurs... ill send you my code files to the email in your profile and see if you can tell whats wrong

##### Share on other sites
Sure - email to my profile''s address.

##### Share on other sites
I don''t know if you''re still having this problem, but if you are....

As Jim Adams quoted: "The maximum distance for a sound source is the distance beyond which the sound does not get any quieter."

This does not mean that the sound will stop playing if the position is greater than the maximum distance. It means that it will reach a certain volume, and stay at that volume until you stop the sound, or the position again becomes less than the maximum distance.

The following paragraph (Minimum and Maximum Distances in the DirectX 8.1 SDK, anyway) also says: "The maximum distance can also be used to prevent a sound from becoming inaudible."

In order to stop playing the sound after a certain distance, i think you have to actually stop the segment (at least, that''s what i''m doing....)

If, as the SDK documentation says, you set you''re minimum distance to be 1 (metre), then at 2, the sound will be halved, and thus at 10, will be 1/10th the loudest volume.

Hope that clears it up....