From 8b0bcae27a60e6768d8c9834e6f2abe3d299bd09 Mon Sep 17 00:00:00 2001 From: Batrachophreno Date: Wed, 11 Feb 2026 11:53:52 -0500 Subject: [PATCH] Sound channel assignment stuff (#21845) Fixes https://github.com/Aurorastation/Aurora.3/issues/21806 Headphones using the PlayNonloopingSound proc meant that in datum/sound_token/New(), it wasnt being dynamically assigned its own channel and so the associated sound.channel was defaulting to zero. This broke a bunch of stupid sound stuff when the headphones were A.) playing while onscreen but not within range of a listener and B.) stopping songs while other SFX happened to be playing and C.) probably other cases. PlayNonloopingSound is not used anywhere else in the repo at this time. --- code/datums/sound_player.dm | 2 + code/modules/clothing/ears/earphones.dm | 29 +++++-------- html/changelogs/Bat-HeadphonesSound.yml | 58 +++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 18 deletions(-) create mode 100644 html/changelogs/Bat-HeadphonesSound.yml diff --git a/code/datums/sound_player.dm b/code/datums/sound_player.dm index ee4b4699d62..0e110e33625 100644 --- a/code/datums/sound_player.dm +++ b/code/datums/sound_player.dm @@ -35,6 +35,8 @@ GLOBAL_DATUM_INIT(sound_player, /singleton/sound_player, new) return PlaySoundDatum(source, sound_id, S, range, prefer_mute, sound_type) +/// The 'repeat = FALSE' here seems to cause scattered sound cutoff issues due to any /sounds created reverting to the default channel zero. Refer to https://github.com/Aurorastation/Aurora.3/pull/21845. +/// This suggests that further work needs to be done with managing channels when a sound gets assigned default channel 0. /singleton/sound_player/proc/PlayNonloopingSound(atom/source, sound_id, sound, volume, range, falloff = 1, echo, frequency, prefer_mute, sound_type = ASFX_AMBIENCE) var/sound/S = istype(sound, /sound) ? sound : new(sound) S.environment = 0 // Ensures a 3D effect even if x/y offset happens to be 0 the first time it's played diff --git a/code/modules/clothing/ears/earphones.dm b/code/modules/clothing/ears/earphones.dm index d7c4c0def12..cb218a74a2c 100644 --- a/code/modules/clothing/ears/earphones.dm +++ b/code/modules/clothing/ears/earphones.dm @@ -1,20 +1,13 @@ -/* - Earphones that use our sound_player system to play sounds from a music cartridge to their wearer. - - Current Features: - - All earphones have a cartridge slot. Cartridges can be inserted by clicking an earphone, and removed via an eject_music_cartridge() verb. - - Inserting a cartridge will load a playlist containing /datum/tracks, where track names and sound files are loaded. - - Alt+Clicking will Start/Stop a playlist, creating or deleting an active sound_player token. - - attack_self will eject the music cartridge. Ejecting a music cartridge also terminates the sound_player token. - - Volume controllable via verb. - - Missing features i am too weak to figure out: - - There is no auto—next song, and a user must manually use next_song() or previous_song() verbs to iterate through a playlist. - - Part and parcel with no auto-next: Tracks automatically loop due to using the PlayLoopingSound() proc. Ideally, tracks should not loop. - - There is no accomodation for user-uploaded sound files. - - There are no UI implementations of earphone controls, which could be more user friendly. -*/ - +/** + * Earphones that use our sound_player system to play sounds from a music cartridge to their wearer. + * + * Current Features: + * - All earphones have a cartridge slot. Cartridges can be inserted by clicking an earphone, and removed via an eject_music_cartridge() verb. + * - Inserting a cartridge will load a playlist containing /datum/tracks, where track names and sound files are loaded. + * - Alt+Clicking will Start/Stop a playlist, creating or deleting an active sound_player token. + * - attack_self will eject the music cartridge. Ejecting a music cartridge also terminates the sound_player token. + * - Volume controllable via verb. + */ /obj/item/clothing/ears/earphones name = "earphones" desc = "A pair of wireless earphones. Includes a little slot for a music cartridge." @@ -135,7 +128,7 @@ if(!soundplayer_token) if(current_playlist && (current_playlist.len > 0)) var/sound/sound_to_play = current_playlist[playlist_index].song_path - soundplayer_token = GLOB.sound_player.PlayNonloopingSound(src, src, sound_to_play, volume, range, 20, prefer_mute = FALSE, sound_type = ASFX_MUSIC) + soundplayer_token = GLOB.sound_player.PlayLoopingSound(src, src, sound_to_play, volume, range, 20, prefer_mute = FALSE, sound_type = ASFX_MUSIC) // Queue the next_song() proc when the current song ends. Clean up handled under next_song() which also calls stopplaying() to end this token autoplay_timeleft = current_playlist[playlist_index].song_length diff --git a/html/changelogs/Bat-HeadphonesSound.yml b/html/changelogs/Bat-HeadphonesSound.yml new file mode 100644 index 00000000000..8c9c0c1ce65 --- /dev/null +++ b/html/changelogs/Bat-HeadphonesSound.yml @@ -0,0 +1,58 @@ +################################ +# Example Changelog File +# +# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb. +# +# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.) +# When it is, any changes listed below will disappear. +# +# Valid Prefixes: +# bugfix +# - (fixes bugs) +# wip +# - (work in progress) +# qol +# - (quality of life) +# soundadd +# - (adds a sound) +# sounddel +# - (removes a sound) +# rscadd +# - (adds a feature) +# rscdel +# - (removes a feature) +# imageadd +# - (adds an image or sprite) +# imagedel +# - (removes an image or sprite) +# spellcheck +# - (fixes spelling or grammar) +# experiment +# - (experimental change) +# balance +# - (balance changes) +# code_imp +# - (misc internal code change) +# refactor +# - (refactors code) +# config +# - (makes a change to the config files) +# admin +# - (makes changes to administrator tools) +# server +# - (miscellaneous changes to server) +################################# + +# Your name. +author: Batrachophrenoboocosmomachia + +# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again. +delete-after: True + +# Any changes you've made. See valid prefix list above. +# INDENT WITH TWO SPACES. NOT TABS. SPACES. +# SCREW THIS UP AND IT WON'T WORK. +# Also, this gets changed to [] after reading. Just remove the brackets when you add new shit. +# Please surround your changes in double quotes ("). It works without them, but if you use certain characters it screws up compiling. The quotes will not show up in the changelog. +changes: + - bugfix: "Fixes headphones/earbuds from causing early cutoffs in other nearby sounds in several configurations."