From 22c89676b42f26dc50cfb3dd0ca1accfd3b946ab Mon Sep 17 00:00:00 2001 From: deanlee Date: Mon, 14 Aug 2023 22:38:43 +0800 Subject: [PATCH] set volume on change --- selfdrive/ui/soundd/sound.cc | 5 ++++- selfdrive/ui/soundd/sound.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/selfdrive/ui/soundd/sound.cc b/selfdrive/ui/soundd/sound.cc index 8d5b2b96b0..ae06e3e903 100644 --- a/selfdrive/ui/soundd/sound.cc +++ b/selfdrive/ui/soundd/sound.cc @@ -36,7 +36,10 @@ void Sound::update() { if (sm.updated("microphone")) { float volume = util::map_val(sm["microphone"].getMicrophone().getFilteredSoundPressureWeightedDb(), 30.f, 60.f, 0.f, 1.f); volume = QAudio::convertVolume(volume, QAudio::LogarithmicVolumeScale, QAudio::LinearVolumeScale); - Hardware::set_volume(volume); + // set volume on changes + if (std::exchange(current_volume, std::nearbyint(volume * 10)) != current_volume) { + Hardware::set_volume(volume); + } } setAlert(Alert::get(sm, 0)); diff --git a/selfdrive/ui/soundd/sound.h b/selfdrive/ui/soundd/sound.h index da9814c543..9cabd1c6bd 100644 --- a/selfdrive/ui/soundd/sound.h +++ b/selfdrive/ui/soundd/sound.h @@ -30,4 +30,5 @@ protected: SubMaster sm; Alert current_alert = {}; QMap> sounds; + int current_volume = -1; };