diff --git a/selfdrive/test/test_onroad.py b/selfdrive/test/test_onroad.py index 3c8e848fda..d7c5c58280 100755 --- a/selfdrive/test/test_onroad.py +++ b/selfdrive/test/test_onroad.py @@ -46,13 +46,13 @@ PROCS = { "selfdrive.thermald.thermald": 3.87, "selfdrive.locationd.calibrationd": 2.0, "selfdrive.locationd.torqued": 5.0, - "selfdrive.ui.soundd": 5.8, + "selfdrive.ui.soundd": 3.5, "selfdrive.monitoring.dmonitoringd": 4.0, "./proclogd": 1.54, "system.logmessaged": 0.2, "selfdrive.tombstoned": 0, "./logcatd": 0, - "system.micd": 10.0, + "system.micd": 6.0, "system.timezoned": 0, "selfdrive.boardd.pandad": 0, "selfdrive.statsd": 0.4, diff --git a/selfdrive/ui/soundd.py b/selfdrive/ui/soundd.py index dc1b7061e1..5ac503aadf 100644 --- a/selfdrive/ui/soundd.py +++ b/selfdrive/ui/soundd.py @@ -16,6 +16,7 @@ from openpilot.common.realtime import Ratekeeper from openpilot.common.swaglog import cloudlog SAMPLE_RATE = 48000 +SAMPLE_BUFFER = 4096 # (approx 100ms) MAX_VOLUME = 1.0 MIN_VOLUME = 0.1 CONTROLS_TIMEOUT = 5 # 5 seconds @@ -133,11 +134,11 @@ class Soundd: if TICI: micd.wait_for_devices(sd) # wait for alsa to be initialized on device - with sd.OutputStream(channels=1, samplerate=SAMPLE_RATE, callback=self.callback) as stream: + with sd.OutputStream(channels=1, samplerate=SAMPLE_RATE, callback=self.callback, blocksize=SAMPLE_BUFFER) as stream: rk = Ratekeeper(20) sm = messaging.SubMaster(['controlsState', 'microphone']) - cloudlog.info(f"soundd stream started: {stream.samplerate=} {stream.channels=} {stream.dtype=} {stream.device=}") + cloudlog.info(f"soundd stream started: {stream.samplerate=} {stream.channels=} {stream.dtype=} {stream.device=}, {stream.blocksize=}") while True: sm.update(0) diff --git a/system/micd.py b/system/micd.py index f4085becd4..baf75c17b9 100755 --- a/system/micd.py +++ b/system/micd.py @@ -11,6 +11,7 @@ RATE = 10 FFT_SAMPLES = 4096 REFERENCE_SPL = 2e-5 # newtons/m^2 SAMPLE_RATE = 44100 +SAMPLE_BUFFER = 4096 # (approx 100ms) @retry(attempts=7, delay=3) @@ -98,8 +99,8 @@ class Mic: if TICI: wait_for_devices(sd) # wait for alsa to be initialized on device - with sd.InputStream(channels=1, samplerate=SAMPLE_RATE, callback=self.callback) as stream: - cloudlog.info(f"micd stream started: {stream.samplerate=} {stream.channels=} {stream.dtype=} {stream.device=}") + with sd.InputStream(channels=1, samplerate=SAMPLE_RATE, callback=self.callback, blocksize=SAMPLE_BUFFER) as stream: + cloudlog.info(f"micd stream started: {stream.samplerate=} {stream.channels=} {stream.dtype=} {stream.device=}, {stream.blocksize=}") while True: self.update()