From 8242a86d969db11ad9e21c8827cc3958d94985d3 Mon Sep 17 00:00:00 2001 From: Cameron Clough Date: Thu, 1 Dec 2022 12:52:06 -0800 Subject: [PATCH] micd: don't update filtered sound level if playing sound (#26652) * add is_sound_playing to hardware.py * micd: don't update filtered sound level if playing sound old-commit-hash: 86cd919a57be22fa0ccf324a8767999309df60e4 --- system/hardware/base.py | 4 ++++ system/hardware/pc/hardware.py | 4 ++++ system/hardware/tici/hardware.py | 3 +++ system/micd.py | 4 +++- 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/system/hardware/base.py b/system/hardware/base.py index 31df1babe0..16ed9621c1 100644 --- a/system/hardware/base.py +++ b/system/hardware/base.py @@ -43,6 +43,10 @@ class HardwareBase(ABC): def get_sound_card_online(self): pass + @abstractmethod + def is_sound_playing(self): + pass + @abstractmethod def get_imei(self, slot) -> str: pass diff --git a/system/hardware/pc/hardware.py b/system/hardware/pc/hardware.py index 564f9e483a..2c83eb35f4 100644 --- a/system/hardware/pc/hardware.py +++ b/system/hardware/pc/hardware.py @@ -1,4 +1,5 @@ import random +import subprocess from cereal import log from system.hardware.base import HardwareBase, ThermalConfig @@ -17,6 +18,9 @@ class Pc(HardwareBase): def get_sound_card_online(self): return True + def is_sound_playing(self): + return "RUNNING" in subprocess.check_output(["pactl", "list", "short", "sinks"]).decode('utf8') + def reboot(self, reason=None): print("REBOOT!") diff --git a/system/hardware/tici/hardware.py b/system/hardware/tici/hardware.py index b5f5e00410..8371d6ef70 100644 --- a/system/hardware/tici/hardware.py +++ b/system/hardware/tici/hardware.py @@ -96,6 +96,9 @@ class Tici(HardwareBase): return (os.path.isfile('/proc/asound/card0/state') and open('/proc/asound/card0/state').read().strip() == 'ONLINE') + def is_sound_playing(self): + return "RUNNING" in subprocess.check_output(["pactl", "list", "short", "sinks"]).decode('utf8') + def reboot(self, reason=None): subprocess.check_output(["sudo", "reboot"]) diff --git a/system/micd.py b/system/micd.py index d2a5a2849f..27b6cb5f19 100755 --- a/system/micd.py +++ b/system/micd.py @@ -5,6 +5,7 @@ import numpy as np from cereal import messaging from common.filter_simple import FirstOrderFilter from common.realtime import Ratekeeper +from system.hardware import HARDWARE from system.swaglog import cloudlog RATE = 10 @@ -27,7 +28,8 @@ class Mic: # https://www.engineeringtoolbox.com/sound-pressure-d_711.html sound_pressure = np.sqrt(np.mean(self.measurements ** 2)) # RMS of amplitudes sound_pressure_level = 20 * np.log10(sound_pressure / REFERENCE_SPL) if sound_pressure > 0 else 0 # dB - self.spl_filter.update(sound_pressure_level) + if not HARDWARE.is_sound_playing(): + self.spl_filter.update(sound_pressure_level) else: sound_pressure = 0 sound_pressure_level = 0