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; };