Skip to content

Commit

Permalink
micd: don't update filtered sound level if playing sound (commaai#26652)
Browse files Browse the repository at this point in the history
* add is_sound_playing to hardware.py

* micd: don't update filtered sound level if playing sound
  • Loading branch information
incognitojam authored and krkeegan committed Jan 4, 2023
1 parent c1fa641 commit 73586a9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
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

0 comments on commit 73586a9

Please sign in to comment.