set volume on change

pull/29389/head
deanlee 2 years ago
parent 29f2389cce
commit 22c89676b4
  1. 5
      selfdrive/ui/soundd/sound.cc
  2. 1
      selfdrive/ui/soundd/sound.h

@ -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));

@ -30,4 +30,5 @@ protected:
SubMaster sm;
Alert current_alert = {};
QMap<AudibleAlert, QPair<QSoundEffect *, int>> sounds;
int current_volume = -1;
};

Loading…
Cancel
Save