From 55c156dfb25d4cc594524d197a588a929a99f01f Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Wed, 23 Aug 2023 05:09:03 +0800 Subject: [PATCH] soundd: set volume on changes (#29389) * set volume on change * async set volumn * Revert "async set volumn" This reverts commit 7bc88c498353fff158b0de3d1923aa2c0f004a37. --- 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; };