ImmursionAudio(TM)
This commit is contained in:
+117
-38
@@ -1,4 +1,47 @@
|
||||
/proc/playsound(atom/source, soundin, vol as num, vary, extrarange as num, falloff, frequency = null, channel = 0, pressure_affected = TRUE, ignore_walls = TRUE, soundenvwet = -10000, soundenvdry = 0)
|
||||
|
||||
///Default override for echo
|
||||
/sound
|
||||
echo = list(
|
||||
0, // Direct
|
||||
0, // DirectHF
|
||||
-10000, // Room, -10000 means no low frequency sound reverb
|
||||
-10000, // RoomHF, -10000 means no high frequency sound reverb
|
||||
0, // Obstruction
|
||||
0, // ObstructionLFRatio
|
||||
0, // Occlusion
|
||||
0.25, // OcclusionLFRatio
|
||||
1.5, // OcclusionRoomRatio
|
||||
1.0, // OcclusionDirectRatio
|
||||
0, // Exclusion
|
||||
1.0, // ExclusionLFRatio
|
||||
0, // OutsideVolumeHF
|
||||
0, // DopplerFactor
|
||||
0, // RolloffFactor
|
||||
0, // RoomRolloffFactor
|
||||
1.0, // AirAbsorptionFactor
|
||||
0, // Flags (1 = Auto Direct, 2 = Auto Room, 4 = Auto RoomHF)
|
||||
)
|
||||
environment = SOUND_ENVIRONMENT_NONE //Default to none so sounds without overrides dont get reverb
|
||||
|
||||
/*! playsound
|
||||
|
||||
playsound is a proc used to play a 3D sound in a specific range. This uses SOUND_RANGE + extra_range to determine that.
|
||||
|
||||
source - Origin of sound
|
||||
soundin - Either a file, or a string that can be used to get an SFX
|
||||
vol - The volume of the sound, excluding falloff and pressure affection.
|
||||
vary - bool that determines if the sound changes pitch every time it plays
|
||||
extrarange - modifier for sound range. This gets added on top of SOUND_RANGE
|
||||
falloff_exponent - Rate of falloff for the audio. Higher means quicker drop to low volume. Should generally be over 1 to indicate a quick dive to 0 rather than a slow dive.
|
||||
frequency - playback speed of audio
|
||||
channel - The channel the sound is played at
|
||||
pressure_affected - Whether or not difference in pressure affects the sound (E.g. if you can hear in space)
|
||||
ignore_walls - Whether or not the sound can pass through walls.
|
||||
falloff_distance - Distance at which falloff begins. Sound is at peak volume (in regards to falloff) aslong as it is in this range.
|
||||
|
||||
*/
|
||||
|
||||
/proc/playsound(atom/source, soundin, vol as num, vary, extrarange as num, falloff_exponent = SOUND_FALLOFF_EXPONENT, frequency = null, channel = 0, pressure_affected = TRUE, ignore_walls = TRUE, falloff_distance = SOUND_DEFAULT_FALLOFF_DISTANCE, use_reverb = TRUE)
|
||||
if(isarea(source))
|
||||
CRASH("playsound(): source is an area")
|
||||
|
||||
@@ -10,26 +53,60 @@
|
||||
//allocate a channel if necessary now so its the same for everyone
|
||||
channel = channel || SSsounds.random_available_channel()
|
||||
|
||||
// Looping through the player list has the added bonus of working for mobs inside containers
|
||||
// Looping through the player list has the added bonus of working for mobs inside containers
|
||||
var/sound/S = sound(get_sfx(soundin))
|
||||
var/maxdistance = (world.view + extrarange)
|
||||
var/z = turf_source.z
|
||||
var/list/listeners = SSmobs.clients_by_zlevel[z]
|
||||
var/maxdistance = SOUND_RANGE + extrarange
|
||||
var/source_z = turf_source.z
|
||||
var/list/listeners = SSmobs.clients_by_zlevel[source_z].Copy()
|
||||
|
||||
var/turf/above_turf = SSmapping.get_turf_above(turf_source)
|
||||
var/turf/below_turf = SSmapping.get_turf_below(turf_source)
|
||||
|
||||
if(!ignore_walls) //these sounds don't carry through walls
|
||||
listeners = listeners & hearers(maxdistance,turf_source)
|
||||
|
||||
if(above_turf && istransparentturf(above_turf))
|
||||
listeners += hearers(maxdistance,above_turf)
|
||||
|
||||
if(below_turf && istransparentturf(turf_source))
|
||||
listeners += hearers(maxdistance,below_turf)
|
||||
|
||||
else
|
||||
if(above_turf && istransparentturf(above_turf))
|
||||
listeners += SSmobs.clients_by_zlevel[above_turf.z]
|
||||
|
||||
if(below_turf && istransparentturf(turf_source))
|
||||
listeners += SSmobs.clients_by_zlevel[below_turf.z]
|
||||
|
||||
for(var/P in listeners)
|
||||
var/mob/M = P
|
||||
if(get_dist(M, turf_source) <= maxdistance)
|
||||
M.playsound_local(turf_source, soundin, vol, vary, frequency, falloff, channel, pressure_affected, S, soundenvwet, soundenvdry)
|
||||
for(var/P in SSmobs.dead_players_by_zlevel[z])
|
||||
M.playsound_local(turf_source, soundin, vol, vary, frequency, falloff_exponent, channel, pressure_affected, S, maxdistance, falloff_distance)
|
||||
for(var/P in SSmobs.dead_players_by_zlevel[source_z])
|
||||
var/mob/M = P
|
||||
if(get_dist(M, turf_source) <= maxdistance)
|
||||
M.playsound_local(turf_source, soundin, vol, vary, frequency, falloff, channel, pressure_affected, S, soundenvwet, soundenvdry)
|
||||
M.playsound_local(turf_source, soundin, vol, vary, frequency, falloff_exponent, channel, pressure_affected, S, maxdistance, falloff_distance)
|
||||
|
||||
/mob/proc/playsound_local(turf/turf_source, soundin, vol as num, vary, frequency, falloff, channel = 0, pressure_affected = TRUE, sound/S, envwet = -10000, envdry = 0, manual_x, manual_y, distance_multiplier = 1)
|
||||
if(audiovisual_redirect)
|
||||
var/turf/T = get_turf(src)
|
||||
audiovisual_redirect.playsound_local(turf_source, soundin, vol, vary, frequency, falloff, channel, pressure_affected, S, 0, -1000, turf_source.x - T.x, turf_source.y - T.y, distance_multiplier)
|
||||
/*! playsound
|
||||
|
||||
playsound_local is a proc used to play a sound directly on a mob from a specific turf.
|
||||
This is called by playsound to send sounds to players, in which case it also gets the max_distance of that sound.
|
||||
|
||||
turf_source - Origin of sound
|
||||
soundin - Either a file, or a string that can be used to get an SFX
|
||||
vol - The volume of the sound, excluding falloff
|
||||
vary - bool that determines if the sound changes pitch every time it plays
|
||||
frequency - playback speed of audio
|
||||
falloff_exponent - Rate of falloff for the audio. Higher means quicker drop to low volume. Should generally be over 1 to indicate a quick dive to 0 rather than a slow dive.
|
||||
channel - The channel the sound is played at
|
||||
pressure_affected - Whether or not difference in pressure affects the sound (E.g. if you can hear in space)
|
||||
max_distance - The peak distance of the sound, if this is a 3D sound
|
||||
falloff_distance - Distance at which falloff begins, if this is a 3D sound
|
||||
distance_multiplier - Can be used to multiply the distance at which the sound is heard
|
||||
|
||||
*/
|
||||
|
||||
/mob/proc/playsound_local(turf/turf_source, soundin, vol as num, vary, frequency, falloff_exponent = SOUND_FALLOFF_EXPONENT, channel = 0, pressure_affected = TRUE, sound/S, max_distance, falloff_distance = SOUND_DEFAULT_FALLOFF_DISTANCE, distance_multiplier = 1, use_reverb = TRUE)
|
||||
if(!client || !can_hear())
|
||||
return
|
||||
|
||||
@@ -39,7 +116,6 @@
|
||||
S.wait = 0 //No queue
|
||||
S.channel = channel || SSsounds.random_available_channel()
|
||||
S.volume = vol
|
||||
S.environment = 7
|
||||
|
||||
if(vary)
|
||||
if(frequency)
|
||||
@@ -51,13 +127,13 @@
|
||||
var/turf/T = get_turf(src)
|
||||
|
||||
//sound volume falloff with distance
|
||||
var/distance = 0
|
||||
if(!manual_x && !manual_y)
|
||||
distance = get_dist(T, turf_source)
|
||||
var/distance = get_dist(T, turf_source)
|
||||
|
||||
distance *= distance_multiplier
|
||||
|
||||
S.volume -= max(distance - world.view, 0) * 2 //multiplicative falloff to add on top of natural audio falloff.
|
||||
if(max_distance) //If theres no max_distance we're not a 3D sound, so no falloff.
|
||||
S.volume -= (max(distance - falloff_distance, 0) ** (1 / falloff_exponent)) / ((max(max_distance, distance) - falloff_distance) ** (1 / falloff_exponent)) * S.volume
|
||||
//https://www.desmos.com/calculator/sqdfl8ipgf
|
||||
|
||||
if(pressure_affected)
|
||||
//Atmosphere affects sound
|
||||
@@ -72,8 +148,6 @@
|
||||
else //space
|
||||
pressure_factor = 0
|
||||
|
||||
S.echo = list(envdry, null, envwet, null, null, null, null, null, null, null, null, null, null, 1, 1, 1, null, null)
|
||||
|
||||
if(distance <= 1)
|
||||
pressure_factor = max(pressure_factor, 0.15) //touching the source of the sound
|
||||
|
||||
@@ -83,31 +157,36 @@
|
||||
if(S.volume <= 0)
|
||||
return //No sound
|
||||
|
||||
var/dx = 0 // Hearing from the right/left
|
||||
if(!manual_x)
|
||||
dx = turf_source.x - T.x
|
||||
else
|
||||
dx = manual_x
|
||||
var/dx = turf_source.x - T.x // Hearing from the right/left
|
||||
S.x = dx * distance_multiplier
|
||||
var/dz = 0 // Hearing from infront/behind
|
||||
if(!manual_x)
|
||||
dz = turf_source.y - T.y
|
||||
else
|
||||
dz = manual_y
|
||||
var/dz = turf_source.y - T.y // Hearing from infront/behind
|
||||
S.z = dz * distance_multiplier
|
||||
// The y value is for above your head, but there is no ceiling in 2d spessmens.
|
||||
S.y = 1
|
||||
S.falloff = (falloff ? falloff : FALLOFF_SOUNDS)
|
||||
var/dy = (turf_source.z - T.z) * 5 * distance_multiplier // Hearing from above / below, multiplied by 5 because we assume height is further along coords.
|
||||
S.y = dy
|
||||
|
||||
S.falloff = max_distance || 1 //use max_distance, else just use 1 as we are a direct sound so falloff isnt relevant.
|
||||
|
||||
if(S.environment == SOUND_ENVIRONMENT_NONE)
|
||||
if(sound_environment_override != SOUND_ENVIRONMENT_NONE)
|
||||
S.environment = sound_environment_override
|
||||
else
|
||||
var/area/A = get_area(src)
|
||||
if(A.sound_environment != SOUND_ENVIRONMENT_NONE)
|
||||
S.environment = A.sound_environment
|
||||
|
||||
if(use_reverb && S.environment != SOUND_ENVIRONMENT_NONE) //We have reverb, reset our echo setting
|
||||
S.echo[3] = 0 //Room setting, 0 means normal reverb
|
||||
S.echo[4] = 0 //RoomHF setting, 0 means normal reverb.
|
||||
|
||||
SEND_SOUND(src, S)
|
||||
|
||||
/proc/sound_to_playing_players(soundin, volume = 100, vary = FALSE, frequency = 0, falloff = FALSE, channel = 0, pressure_affected = FALSE, sound/S)
|
||||
/proc/sound_to_playing_players(soundin, volume = 100, vary = FALSE, frequency = 0, channel = 0, pressure_affected = FALSE, sound/S)
|
||||
if(!S)
|
||||
S = sound(get_sfx(soundin))
|
||||
for(var/m in GLOB.player_list)
|
||||
if(ismob(m) && !isnewplayer(m))
|
||||
var/mob/M = m
|
||||
M.playsound_local(M, null, volume, vary, frequency, falloff, channel, pressure_affected, S)
|
||||
M.playsound_local(M, null, volume, vary, frequency, null, channel, pressure_affected, S)
|
||||
|
||||
/mob/proc/stop_sound_channel(chan)
|
||||
SEND_SOUND(src, sound(null, repeat = 0, wait = 0, channel = chan))
|
||||
@@ -130,14 +209,14 @@
|
||||
/proc/get_sfx(soundin)
|
||||
if(istext(soundin))
|
||||
switch(soundin)
|
||||
if ("explosion_creaking") // from skyrat-ss13/skyrat13/pull/3295
|
||||
soundin = pick('sound/effects/explosioncreak1.ogg', 'sound/effects/explosioncreak2.ogg')
|
||||
if ("hull_creaking") // from skyrat-ss13/skyrat13/pull/3295
|
||||
soundin = pick('sound/effects/creak1.ogg', 'sound/effects/creak2.ogg', 'sound/effects/creak3.ogg')
|
||||
if ("shatter")
|
||||
soundin = pick('sound/effects/glassbr1.ogg','sound/effects/glassbr2.ogg','sound/effects/glassbr3.ogg')
|
||||
if ("explosion")
|
||||
soundin = pick('sound/effects/explosion1.ogg','sound/effects/explosion2.ogg')
|
||||
if ("explosion_creaking")
|
||||
soundin = pick('sound/effects/explosioncreak1.ogg', 'sound/effects/explosioncreak2.ogg')
|
||||
if ("hull_creaking")
|
||||
soundin = pick('sound/effects/creak1.ogg', 'sound/effects/creak2.ogg', 'sound/effects/creak3.ogg')
|
||||
if ("sparks")
|
||||
soundin = pick('sound/effects/sparks1.ogg','sound/effects/sparks2.ogg','sound/effects/sparks3.ogg','sound/effects/sparks4.ogg')
|
||||
if ("rustle")
|
||||
|
||||
Reference in New Issue
Block a user