From 8843b7f75774bfcd74b45eb62286641f42e8ec3a Mon Sep 17 00:00:00 2001 From: mwerezak Date: Mon, 28 Jul 2014 14:09:16 -0400 Subject: [PATCH] Sound fixes Conflicts: code/game/sound.dm --- code/game/sound.dm | 56 +++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/code/game/sound.dm b/code/game/sound.dm index 4459cd88b96..cd188eef878 100644 --- a/code/game/sound.dm +++ b/code/game/sound.dm @@ -1,4 +1,3 @@ - var/list/shatter_sound = list('sound/effects/Glassbr1.ogg','sound/effects/Glassbr2.ogg','sound/effects/Glassbr3.ogg') var/list/explosion_sound = list('sound/effects/Explosion1.ogg','sound/effects/Explosion2.ogg') var/list/spark_sound = list('sound/effects/sparks1.ogg','sound/effects/sparks2.ogg','sound/effects/sparks3.ogg','sound/effects/sparks4.ogg') @@ -9,7 +8,7 @@ var/list/jackboot_sound = list('sound/effects/jackboot1.ogg','sound/effects/jack var/list/swing_hit_sound = list('sound/weapons/genhit1.ogg', 'sound/weapons/genhit2.ogg', 'sound/weapons/genhit3.ogg') var/list/hiss_sound = list('sound/voice/hiss1.ogg','sound/voice/hiss2.ogg','sound/voice/hiss3.ogg','sound/voice/hiss4.ogg') var/list/page_sound = list('sound/effects/pageturn1.ogg', 'sound/effects/pageturn2.ogg','sound/effects/pageturn3.ogg') -var/list/gun_sound = list('sound/weapons/Gunshot.ogg', 'sound/weapons/Gunshot2.ogg','sound/weapons/Gunshot3.ogg','sound/weapons/Gunshot4.ogg') +//var/list/gun_sound = list('sound/weapons/Gunshot.ogg', 'sound/weapons/Gunshot2.ogg','sound/weapons/Gunshot3.ogg','sound/weapons/Gunshot4.ogg') /proc/playsound(var/atom/source, soundin, vol as num, vary, extrarange as num, falloff, var/is_global) @@ -33,17 +32,7 @@ var/list/gun_sound = list('sound/weapons/Gunshot.ogg', 'sound/weapons/Gunshot2.o var/turf/T = get_turf(M) if(T && T.z == turf_source.z) - //check that the air can transmit sound - var/datum/gas_mixture/environment = T.return_air() - if (!environment || environment.return_pressure() < SOUND_MINIMUM_PRESSURE) - if (distance > 1) - continue - - var/new_frequency = 32000 + (frequency - 32000)*0.125 //lower the frequency. very rudimentary - var/new_volume = vol*0.15 //muffle the sound, like we're hearing through contact - M.playsound_local(turf_source, soundin, new_volume, vary, new_frequency, falloff, is_global) - else - M.playsound_local(turf_source, soundin, vol, vary, frequency, falloff, is_global) + M.playsound_local(turf_source, soundin, vol, vary, frequency, falloff, is_global) var/const/FALLOFF_SOUNDS = 0.5 @@ -65,12 +54,34 @@ var/const/FALLOFF_SOUNDS = 0.5 if(isturf(turf_source)) // 3D sounds, the technology is here! var/turf/T = get_turf(src) - S.volume -= get_dist(T, turf_source) * 2 //multiplicative falloff to add on top of natural audio falloff. - var/datum/gas_mixture/environment = T.return_air() - if(get_dist(T, turf_source) > 2) - S.volume -= environment.return_pressure()/100 + 1 - if (S.volume < 0) - S.volume = 0 + + //sound volume falloff with distance + var/distance = get_dist(T, turf_source) + + S.volume -= max(distance - world.view, 0) * 2 //multiplicative falloff to add on top of natural audio falloff. + + //sound volume falloff with pressure + var/pressure_factor = 1.0 + + var/datum/gas_mixture/hearer_env = T.return_air() + var/datum/gas_mixture/source_env = turf_source.return_air() + + if (hearer_env && source_env) + var/pressure = min(hearer_env.return_pressure(), source_env.return_pressure()) + + if (pressure < ONE_ATMOSPHERE) + pressure_factor = max((pressure - SOUND_MINIMUM_PRESSURE)/(ONE_ATMOSPHERE - SOUND_MINIMUM_PRESSURE), 0) + else //in space + pressure_factor = 0 + + if (distance <= 1) + pressure_factor = max(pressure_factor, 0.15) //hearing through contact + + S.volume *= pressure_factor + + if (S.volume <= 0) + return //no volume means no sound + var/dx = turf_source.x - T.x // Hearing from the right/left S.x = dx var/dz = turf_source.y - T.y // Hearing from infront/behind @@ -82,6 +93,11 @@ var/const/FALLOFF_SOUNDS = 0.5 S.environment = 2 src << S +/client/proc/playtitlemusic() + if(!ticker || !ticker.login_music) return + if(prefs.toggles & SOUND_LOBBY) + src << sound(ticker.login_music, repeat = 0, wait = 0, volume = 85, channel = 1) // MAD JAMS + /proc/get_rand_frequency() return rand(32000, 55000) //Frequency stuff only works with 45kbps oggs. @@ -98,5 +114,5 @@ var/const/FALLOFF_SOUNDS = 0.5 if ("swing_hit") soundin = pick(swing_hit_sound) if ("hiss") soundin = pick(hiss_sound) if ("pageturn") soundin = pick(page_sound) - if ("gunshot") soundin = pick(gun_sound) + //if ("gunshot") soundin = pick(gun_sound) return soundin