ID:259906
 
Will there be some kind of "depth" setting that, when on, will decrease the volume of a sound played?

Let's say sound "gunshot.wav" is fired in a view of 10, and "depth" is set to 1, will it be that at view(0) volume = 100, view(1) volume = 95 (etc.) ?

If not, it'd be a great feature.
Phoenix Man wrote:
Will there be some kind of "depth" setting that, when on, will decrease the volume of a sound played?

Let's say sound "gunshot.wav" is fired in a view of 10, and "depth" is set to 1, will it be that at view(0) volume = 100, view(1) volume = 95 (etc.) ?

If not, it'd be a great feature.

When BYOND gets volume control, you will be able to send the sound at a different volume to each client so you can produce your "depth" functionality easily with DM. We should even be able to pan the sound (making it sound like it comes from the left or the right of the player.)
In response to Shadowdarke
Will I be able to see the datum where a sound has been sent from?

Like if I do

turf/wall/Enter(mob/M)M<<sound('ouch-my-toe.wav')


Will I be able to see the /turf/wall which it came from?
I could use this to make music, and I can decrease the volume as the player goes farther away from the source of the sound/music.
In response to Phoenix Man
The first FMOD version of BYOND supports many new file types for sound. Then there will be overhaul of the sound datum to include the basic features: volume, panning, and a few other fundamentals. With these, you would be able to DM code the functionality you're requesting with some work on your part.

FMOD does support 3D sound and I agree that it is a very exciting feature. Tom and I have discussed making it a part of BYOND since I first read the FMOD feature list. 3D sound and many other of the more exciting FMOD features (I'm really interested in the reverb settings too) are low on the list though. The top priority is stabilty. It is better to have a solid package that doesn't crash rather than a buggy package with tons of glitzy features that operate poorly.

BYOND may never get built in positional sound support. It's a terrific feature, but it's just glitz. I hope that it does. Fortunately it will get the key features you need to implement it through your own creativity.

If you don't know how to do positional sound, remind me when the volume control becomes part of BYOND and I'll whip up a library for it.
In response to Shadowdarke
Shadowdarke wrote:
FMOD does support 3D sound and I agree that it is a very exciting feature.

What is 3D sound?
In response to GokuDBZ3128
Sound that comes at you from a particular side and decreased in volume the farther away you are. You know, "real" sound.
In response to Shadowdarke
He did remind me! :)


Well, the good news is that positional sound and even all the fancy reverb features are in BYOND now. I've already whipped up a soundtool library/demo available at http://developer.byond.com/hub/Shadowdarke/soundtool that lets you play with all the sound features. Still, it would probably be a good idea to provide a detailed tutorial.

Until I write one, here are the basics:

sound vars x, y, and z are the position of the sound relative to the listener. Negative values of x are left, positive is right. Negative y is down, positive is up. Negative z is behind the listener and positive z is in front. (I may have the z values reversed. You can experiment in the soundtool and see.) We decided this was the best way as it keeps sound values in the same plane as the BYOND map on the screen.

The sound falloff var determines how quickly the sound attenuates. Small values will make sounds inaudible at shorter distances, so soft noises like flies buzzing should have a small falloff value. A jumbo jet should have a huge falloff value. Within a distance equal to falloff, the sound will play at full volume set by the sound.volume var.

Finally, the reverb is implimented by the environment and echo vars. This is truly nifty, but really complex too. For simple scenarios, you can ignore echo and use the 25 environmental presets. BYOND will also allow you to fully control most of the features of EAX reverb. (We didn't impliment the EAX4 multiple reverb environments.) You can get detailed documentation on EAX from http://developer.creative.com. Most of the reverb stuff is detailed in the EAX2 specs which are available without their painful registration process.

In BYOND, sending a sound with environment set to anything other than -1 will change the environmental reverb for ALL 3D sounds from that point until you set a different environment. sound.echo is for sound specific reverb information, such as how direct a path there is between the sound source and the listener.

Now for some usable code:
atom/proc/SoundSource(Who, soundfile, falloff, environment, echo)
/* Plays a 3D sound heard from a specific source.
src is the atom source the sound is coming from. (Areas will cause unreliable
results, but a turf, obj, or mob will work great as a sound src.)
ARGS:
Who - The mob or list of mobs hearing the sound
soundfile - The file of the sound to play
falloff - OPTIONAL: How quickly the sound attenuates.
environment - OPTIONAL: Sets the environmental reverb for ALL 3D sounds. See the
BYOND reference entry on sound vars for more info.
echo - OPTIONAL: Sets sound specific reverb information. See the BYOND
reference entry on sound vars for more info.
RETURNS:
List of player mobs who hear the sound or null if none hear it. (This does not
take inaudibility due to distance and volume into account.) */


// fail conditions: nothing to play, no mob to hear it, or source is off the map
if(!(soundfile && Who && src.x)) return

var/list/listeners
if(istype(Who, /list))
// copy list so we can change listeners without modifying the incoming list
var/list/L = Who
listeners = L.Copy()
else if(ismob(Who)) listeners = list(Who)
else return // no valid listeners

var/sound/S = sound(soundfile)
if(!isnull(falloff)) S.falloff = falloff
if(!isnull(environment)) S.environment = environment
if(!isnull(echo)) S.echo = echo

for(var/mob/M in listeners)
if(!(M.client && M.x)) // non-player mob or mob is off the map
listeners -= M
continue
// set relative position
S.x = M.x - src.x
S.y = M.y - src.y
S.z = M.z - src.z
// send the sound to this mob
M << S

if(!listeners.len) return // so it never returns a list unless at least one player heard it
return listeners