Cleanup AudioFlinger

This commit is contained in:
Thomas Farstrike
2026-01-14 11:03:00 +01:00
parent 76be9fd968
commit 63f4c1c257
2 changed files with 6 additions and 62 deletions
@@ -3,57 +3,3 @@
# Simple routing: play_wav() -> I2S, play_rtttl() -> buzzer, record_wav() -> I2S mic
from .audioflinger import AudioFlinger
# Create singleton instance
_instance = AudioFlinger.get()
# Re-export stream type constants for convenience
STREAM_MUSIC = AudioFlinger.STREAM_MUSIC
STREAM_NOTIFICATION = AudioFlinger.STREAM_NOTIFICATION
STREAM_ALARM = AudioFlinger.STREAM_ALARM
# Re-export main API from singleton instance for backward compatibility
init = _instance.init
play_wav = _instance.play_wav
play_rtttl = _instance.play_rtttl
stop = _instance.stop
pause = _instance.pause
resume = _instance.resume
set_volume = _instance.set_volume
get_volume = _instance.get_volume
is_playing = _instance.is_playing
record_wav = _instance.record_wav
is_recording = _instance.is_recording
has_i2s = _instance.has_i2s
has_buzzer = _instance.has_buzzer
has_microphone = _instance.has_microphone
__all__ = [
# Class
'AudioFlinger',
# Stream types
'STREAM_MUSIC',
'STREAM_NOTIFICATION',
'STREAM_ALARM',
# Playback functions
'init',
'play_wav',
'play_rtttl',
'stop',
'pause',
'resume',
'set_volume',
'get_volume',
'is_playing',
# Recording functions
'record_wav',
'is_recording',
# Hardware checks
'has_i2s',
'has_buzzer',
'has_microphone',
]
@@ -37,7 +37,7 @@ class AudioFlinger:
if AudioFlinger._instance:
return
AudioFlinger._instance = self
self._i2s_pins = None # I2S pin configuration dict (created per-stream)
self._buzzer_instance = None # PWM buzzer instance
self._current_stream = None # Currently playing stream
@@ -377,12 +377,11 @@ class AudioFlinger:
bool: True if recording active, False otherwise
"""
return self._current_recording is not None and self._current_recording.is_recording()
# ============================================================================
# Class methods that delegate to singleton instance
# Class method forwarding to singleton instance
# ============================================================================
# Store original instance methods BEFORE we replace them with class methods
# Store original instance methods before replacing them
_original_methods = {}
_methods_to_delegate = [
'init', 'play_wav', 'play_rtttl', 'record_wav', 'stop', 'pause', 'resume',
@@ -393,10 +392,9 @@ _methods_to_delegate = [
for method_name in _methods_to_delegate:
_original_methods[method_name] = getattr(AudioFlinger, method_name)
# Helper function to create delegating class methods
# Helper to create delegating class methods
def _make_class_method(method_name):
"""Create a class method that delegates to the singleton instance."""
# Capture the original method in the closure
original_method = _original_methods[method_name]
@classmethod
@@ -406,7 +404,7 @@ def _make_class_method(method_name):
return class_method
# Attach class methods to AudioFlinger
for method_name in _methods_to_delegate:
setattr(AudioFlinger, method_name, _make_class_method(method_name))