soundd: set volume on changes (#29389)

* set volume on change

* async set volumn

* Revert "async set volumn"

This reverts commit 7bc88c498353fff158b0de3d1923aa2c0f004a37.
old-commit-hash: 55c156dfb25d4cc594524d197a588a929a99f01f
This commit is contained in:
Dean Lee
2023-08-23 05:09:03 +08:00
committed by GitHub
parent ce7008c70c
commit 4f7e9268e8
2 changed files with 5 additions and 1 deletions

View File

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

View File

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