Jump to content
  • Advertisement
Sign in to follow this  
Evil Steve

3D Sound Woes

This topic is 3786 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

Hi all, I'm trying to add support for 3D sound to my engine, but I'm having "issues" with DirectSound. I'm using DirectSound 8 in C++, and I can't seem to get the sounds volume to fade correctly. In my world, I'd like sound to be completely silent after around 1000 units, and for the volume to fall off linearly (I think, I'm not entirely sure). Setting the min and max distance for my sound buffer to 250 and 1,000 respectively still has the sound pretty loud at 20,000 units away, but setting them to 250 and 100,000 causes the sound to be quiet (but still audible) at 20,000 units away. So, my questions are: 1. Is there anything obvious I'm doing wrong here? I'm moving the listener around and leaving the sound at the origin. 2. Why isn't the sound silent past the max distance 3. If all else fails, is there any problem with setting the min and max distances to infinity, and adjusting the volume of all 3D sounds every frame? That seems horrible to me though :(

Share this post


Link to post
Share on other sites
Advertisement
DirectSound was one of the biggest pains I have had to work with in DirectX...

There's an article in the DirectX 8.1 documentation that explains max and min values, which may not be like you expected...
Quote:
As a listener approaches a sound source, the sound gets louder; the volume doubles when the distance is halved. Past a certain point, however, it is not reasonable for the volume to continue to increase. This is the minimum distance for the sound source.

The minimum distance is especially useful when an application must compensate for the difference in absolute volume levels of different sounds. Although a jet engine is much louder than a bee, for practical reasons these sounds must be recorded at similar absolute volumes. An application might use a minimum distance of 100 meters for the jet engine and 2 centimeters for the bee. With these settings, the jet engine would be at half volume when the listener was 200 meters away, but the bee would be at half volume when the listener was 4 centimeters away.

The default minimum distance for a sound buffer, DS3D_DEFAULTMINDISTANCE, is defined as 1 unit, or 1 meter at the default distance factor. Unless you change this value, the sound is at full volume when it is 1 meter away from the listener, half as loud at 2 meters, a quarter as loud at 4 meters, and so on. For most sounds you will probably want to set a larger minimum distance so that the sound does not fade so rapidly as it moves away.

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.

The maximum distance can also be used to prevent a sound from becoming inaudible. For example, if you have set the minimum distance for a sound at 100 meters, that sound might become effectively inaudible at 1,000 meters or less. By setting the maximum distance at 800 meters, you ensure that the sound always has at least one-eighth of its maximum volume regardless of the distance. In this case, of course, you would not set the DSBCAPS_MUTE3DATMAXDISTANCE flag.
It seems if you're using an audio path, the DSBCAPS_MUTE3DATMAXDISTANCE flag should be set and you'd be good. If you're creating sound buffers yourself, then you might want include this flag.

Share this post


Link to post
Share on other sites
Quote:
Original post by BNY
It seems if you're using an audio path, the DSBCAPS_MUTE3DATMAXDISTANCE flag should be set and you'd be good. If you're creating sound buffers yourself, then you might want include this flag.
Ah ha, that looks exactly like what I want. I'm creating the sound buffer myself, not using audiopaths.

I'll give that a go at lunch time today. Thanks [smile]

Share this post


Link to post
Share on other sites
Hmm. Well, using that flag does mute the sound at maximum distance, but it clips in and out because the sound is still quite loud just before max distance.

Currently I'm doing my own volume adjustment based on the distance to the listener, but this seems horrible to me. Anyone got any idea what's going on?

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!