From db655c381d80fae60fb9b9dbd7ef0a7538da8df4 Mon Sep 17 00:00:00 2001 From: oberon Date: Mon, 16 Feb 2026 21:53:09 +0100 Subject: [PATCH] fixxed buffer --- app/__init__.py | 9 +++++++-- app/routes/api.py | 9 +++++++-- config.py | 7 +++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index bc28b1e..d0325a8 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -31,8 +31,13 @@ def create_app(): init_bluetooth() # pygame initialisieren (einmalig) - pygame.mixer.init(frequency=44100, size=-16, channels=2, buffer=512) - pygame.mixer.set_num_channels(16) # genug parallele Kanäle für BG + Effekte + from config import Config + pygame.mixer.pre_init(frequency=Config.AUDIO_FREQ, + size=Config.AUDIO_SIZE, + channels=Config.AUDIO_CHANNELS, + buffer=Config.AUDIO_BUFFER) + pygame.mixer.init() + pygame.mixer.set_num_channels(Config.AUDIO_NUM_CHANNELS) # genug parallele Kanäle für BG + Effekte pygame.mixer.music.set_volume(0.8) # Standard-Lautstärke (für Legacy-Fälle) app.logger.info("pygame initialisiert") diff --git a/app/routes/api.py b/app/routes/api.py index f115950..fff10e6 100644 --- a/app/routes/api.py +++ b/app/routes/api.py @@ -18,9 +18,14 @@ audio_lock = threading.Lock() loaded_sounds = {} def _ensure_mixer(): + from config import Config if not pygame.mixer.get_init(): - pygame.mixer.init(frequency=44100, size=-16, channels=2, buffer=512) - pygame.mixer.set_num_channels(16) + pygame.mixer.pre_init(frequency=Config.AUDIO_FREQ, + size=Config.AUDIO_SIZE, + channels=Config.AUDIO_CHANNELS, + buffer=Config.AUDIO_BUFFER) + pygame.mixer.init() + pygame.mixer.set_num_channels(Config.AUDIO_NUM_CHANNELS) def _load_sound(file_path): if file_path in loaded_sounds: diff --git a/config.py b/config.py index a40ad79..7dcc683 100644 --- a/config.py +++ b/config.py @@ -13,5 +13,12 @@ class Config: LOG_DIR = os.path.join(BASE_DIR, 'logs') SOUNDS_DIR = os.path.join(BASE_DIR, 'sounds') + # Audio-Parameter (für pygame.mixer) + AUDIO_FREQ = 44100 + AUDIO_SIZE = -16 + AUDIO_CHANNELS = 2 + AUDIO_BUFFER = 2048 # größerer Buffer reduziert Knacksen + AUDIO_NUM_CHANNELS = 16 + # Optional: absolute Pfade, falls du später Docker o.ä. nutzt # CONFIG_DIR = os.path.join(os.path.dirname(__file__), 'configs')