Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

micd: don't update filtered sound level if playing sound #26652

Merged
merged 2 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions system/hardware/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def get_device_type(self):
def get_sound_card_online(self):
pass

@abstractmethod
def is_sound_playing(self):
pass

@abstractmethod
def get_imei(self, slot) -> str:
pass
Expand Down
4 changes: 4 additions & 0 deletions system/hardware/pc/hardware.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import random
import subprocess

from cereal import log
from system.hardware.base import HardwareBase, ThermalConfig
Expand All @@ -17,6 +18,9 @@ def get_device_type(self):
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!")

Expand Down
3 changes: 3 additions & 0 deletions system/hardware/tici/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ def get_sound_card_online(self):
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"])

Expand Down
4 changes: 3 additions & 1 deletion system/micd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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
Expand All @@ -27,7 +28,8 @@ def update(self):
# 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
Expand Down