From 95215eefc82cedb2aac84b5719caf854e2fd9ce0 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Thu, 18 Sep 2025 23:23:08 -0400 Subject: [PATCH] I think sound is as good as I can get it. --- display.py | 4 ++-- sound.py | 12 +++++++----- utils.py | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/display.py b/display.py index c1caf1b..eaf438b 100644 --- a/display.py +++ b/display.py @@ -48,8 +48,8 @@ def initialize_gui(gameTitle): if not pygame.mixer.get_init(): pygame.mixer.pre_init(44100, -16, 2, 4096, allowedchanges=0) pygame.mixer.init() - pygame.mixer.set_num_channels(64) - pygame.mixer.set_reserved(16) # Reserve channels 0-15 for priority sounds (cutscenes, obj_play) + pygame.mixer.set_num_channels(48) + pygame.mixer.set_reserved(1) # Reserve channel 0 for cutscenes only # Enable key repeat for volume controls pygame.key.set_repeat(500, 100) diff --git a/sound.py b/sound.py index 86f98d3..1c055c0 100644 --- a/sound.py +++ b/sound.py @@ -93,8 +93,8 @@ class Sound: if not pygame.mixer.get_init(): pygame.mixer.pre_init(44100, -16, 2, 4096, allowedchanges=0) pygame.mixer.init() - pygame.mixer.set_num_channels(64) - pygame.mixer.set_reserved(16) # Reserve channels 0-15 for priority sounds (cutscenes, obj_play) + pygame.mixer.set_num_channels(48) + pygame.mixer.set_reserved(1) # Reserve channel 0 for cutscenes only self.load_sounds() @@ -537,7 +537,9 @@ def obj_update(channel, playerPos, objPos): def obj_stop(channel): """Stop a sound channel.""" if channel: - try: channel.stop() + try: + channel.stop() + pygame.event.pump() # Force pygame to update channel state immediately except: pass return None @@ -578,8 +580,8 @@ def play_priority_sound(sound_or_name, volume=1.0, loop=False, playerPos=None, o return None # Extremely concise lambda definitions for legacy functions -obj_play = lambda sounds, soundName, playerPos, objPos, loop=True: play_priority_sound( - soundName, 1.0, loop, playerPos, objPos, None, sounds) +obj_play = lambda sounds, soundName, playerPos, objPos, loop=True: play_sound( + soundName, 1.0, loop, playerPos, objPos, None, False, False, False, False, sounds) play_ambiance = lambda sounds, soundNames, probability, randomLocation=False: play_sound( random.choice(soundNames) if random.randint(1, 100) <= probability and not any( diff --git a/utils.py b/utils.py index 0b96c57..d293087 100644 --- a/utils.py +++ b/utils.py @@ -151,8 +151,8 @@ class Game: # Set up audio system pygame.mixer.pre_init(44100, -16, 2, 1024, allowedchanges=0) pygame.mixer.init() - pygame.mixer.set_num_channels(64) - pygame.mixer.set_reserved(16) # Reserve channels 0-15 for priority sounds (cutscenes, obj_play) + pygame.mixer.set_num_channels(48) + pygame.mixer.set_reserved(1) # Reserve channel 0 for cutscenes only # Enable key repeat for volume controls pygame.key.set_repeat(500, 100)