• Create Account

## DirectSound, volume, and distance

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1 Anonymous Poster_Anonymous Poster_*   Guests

Likes

Posted 04 October 1999 - 09:02 AM

What's a good equation (using DirectSound, not 3D) to calculate
volume dB based on the x,y distance of a sound that is off the
player's screen for a 2D scrolling game? So as I scrolled closer
to where the sound was coming found, it would get louder until
the source appears on the screen.

Also, could anyone point me to a DirectSound example where
they use 2D panning as well?

-Placid

### #2 Anonymous Poster_Anonymous Poster_*   Guests

Likes

Posted 02 October 1999 - 04:20 PM

I'm sure somebody out there must have done something like
this similiar. Am I wrong to try to use equations to calculate
panning and sound volume based on distance for a 2D scrolling game?
I don't see how D3D Sound would help me with this. Anyone

### #3Hw  Members

122
Like
Likes
Like

Posted 03 October 1999 - 10:29 PM

Hmm. Panning should be fairly easy; you just compare object's screen x-coordinate to midpoint of screen and set pan accordingly...
(-10000dB when object's far enough at left)

dB level is quite basic physics, but I don't have my physics book with me, so I can give only hunches;

dB = 20 * log ( I / I0 )

I = Intensity; If I remember correctly, it is is something like B/(r^3), where B is "baselevel" of volume, and I0 is intensity of basic scale, our previous value of B would do just fine. And r of course is range from sound source.

Formula 'dB = 20*log( B/r^3 )' might do fairly well most of the time, but you just have to find good values for B...

And of course, since we're dealing with computers here, you might want to alter
the formula a bit if [when?] this sounds bad...

As a reminder, -96dB is practically silence, since that's near the theoretical limit of 16-bit audio!

### #4 Anonymous Poster_Anonymous Poster_*   Guests

Likes

Posted 04 October 1999 - 09:02 AM

The wouldn't work well with panning, since this is a large
2D map and what the player sees on the screen is only a small
portion of the map. So if you place the player at the center
of a circle, the x,y coords. of a distant sound source from an
angle should somehow convert to panning dBs and volume dBs.

I also don't have any physics books lying around, so I can't
really look up equations. I can take the easy approach and
map distance and volume using a simple ratio based on the
max/min boundaries of my map, but this isn't using real physics,