soundd: set volume on changes (#29389)

* set volume on change

* async set volumn

* Revert "async set volumn"

This reverts commit 7bc88c4983.
pull/29536/head
Dean Lee 2 years ago committed by GitHub
parent 65ad8fd8e7
commit 55c156dfb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      selfdrive/ui/soundd/sound.cc
  2. 1
      selfdrive/ui/soundd/sound.h

@ -36,8 +36,11 @@ 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);
// 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