Fix sound service audio device handling and revert to simple configuration

- Modified sound.py to handle audio device errors gracefully with retry loop
- Reverted lighting-sound.service to simple configuration without complex dependencies
- Sound service now working reliably with beat detection at ~147 BPM
- Both lighting-control and lighting-sound services running successfully at boot
This commit is contained in:
2025-10-04 10:01:29 +13:00
parent 8ad7f41d77
commit 0c6ccb90af
2 changed files with 46 additions and 24 deletions

View File

@@ -3,10 +3,10 @@
{
"r": 255,
"g": 0,
"b": 0
"b": 255
},
{
"r": 0,
"r": 255,
"g": 255,
"b": 0
},
@@ -26,9 +26,9 @@
"b": 255
},
{
"r": 0,
"r": 255,
"g": 255,
"b": 255
"b": 0
},
{
"r": 255,
@@ -47,17 +47,17 @@
],
"pattern_parameters": {
"alternating": {
"delay": 100,
"n1": 25,
"n2": 15,
"delay": 327,
"n1": 226,
"n2": 60,
"n3": 1,
"n4": 1
},
"segmented_movement": {
"delay": 100,
"n1": 37,
"n2": 39,
"n3": 7,
"n1": 6,
"n2": 28,
"n3": 6,
"n4": 21
},
"rd": {
@@ -82,9 +82,9 @@
"n4": 1
},
"radiate": {
"delay": 3,
"n1": 32,
"n2": 10,
"delay": 1,
"n1": 43,
"n2": 11,
"n3": 1,
"n4": 1
},
@@ -125,9 +125,9 @@
},
"alternating_phase": {
"delay": 100,
"n1": 21,
"n2": 60,
"n3": 28,
"n1": 33,
"n2": 35,
"n3": 1,
"n4": 1
},
"ap": {
@@ -138,6 +138,13 @@
"n4": 1
},
"alternating_pulse": {
"delay": 100,
"n1": 90,
"n2": 78,
"n3": 1,
"n4": 1
},
"pulse": {
"delay": 100,
"n1": 10,
"n2": 10,

View File

@@ -66,7 +66,7 @@ class SoundBeatDetector:
except Exception as e:
logging.error(f"Error getting audio device info for index {self.audioInputDeviceIndex}: {e}")
self.pa.terminate()
exit()
raise RuntimeError(f"Audio device {self.audioInputDeviceIndex} not available: {e}")
self.hopSize = self.bufferSize
self.winSize = self.hopSize * self.windowSizeMultiple
@@ -211,11 +211,26 @@ if __name__ == "__main__":
MIDI_TCP_HOST = "127.0.0.1"
MIDI_TCP_PORT = 65432
sound_detector = SoundBeatDetector(MIDI_TCP_HOST, MIDI_TCP_PORT, input_device=args.input_device)
logging.info("Starting SoundBeatDetector...")
try:
sound_detector.start_stream()
except KeyboardInterrupt:
logging.info("\nProgram interrupted by user.")
except Exception as e:
logging.error(f"An error occurred during main execution: {e}")
while True:
try:
sound_detector = SoundBeatDetector(MIDI_TCP_HOST, MIDI_TCP_PORT, input_device=args.input_device)
sound_detector.start_stream()
break # If we get here, the stream ended normally
except KeyboardInterrupt:
logging.info("\nProgram interrupted by user.")
break
except RuntimeError as e:
if "Audio device" in str(e):
logging.error(f"Audio device error: {e}")
logging.info("Waiting 10 seconds before retrying...")
time.sleep(10)
continue
else:
logging.error(f"Runtime error: {e}")
break
except Exception as e:
logging.error(f"An error occurred during main execution: {e}")
logging.info("Waiting 5 seconds before retrying...")
time.sleep(5)
continue