soundd: cleanup remnants from running while offroad (#29006)

cleanup
old-commit-hash: 0bacd98828
beeps
Adeeb Shihadeh 2 years ago committed by GitHub
parent 1ef7623ec7
commit e603ff3427
  1. 18
      selfdrive/ui/soundd/sound.cc
  2. 3
      selfdrive/ui/soundd/sound.h

@ -12,7 +12,7 @@
// TODO: detect when we can't play sounds
// TODO: detect when we can't display the UI
Sound::Sound(QObject *parent) : sm({"controlsState", "deviceState", "microphone"}) {
Sound::Sound(QObject *parent) : sm({"controlsState", "microphone"}) {
qInfo() << "default audio device: " << QAudioDeviceInfo::defaultOutputDevice().deviceName();
for (auto &[alert, fn, loops] : sound_list) {
@ -30,22 +30,8 @@ Sound::Sound(QObject *parent) : sm({"controlsState", "deviceState", "microphone"
};
void Sound::update() {
const bool started_prev = sm["deviceState"].getDeviceState().getStarted();
sm.update(0);
const bool started = sm["deviceState"].getDeviceState().getStarted();
if (started && !started_prev) {
started_frame = sm.frame;
}
// no sounds while offroad
// also no sounds if nothing is alive in case thermald crashes while offroad
const bool crashed = (sm.frame - std::max(sm.rcv_frame("deviceState"), sm.rcv_frame("controlsState"))) > 10*UI_FREQ;
if (!started || crashed) {
setAlert({});
return;
}
// scale volume using ambient noise level
if (sm.updated("microphone")) {
float volume = util::map_val(sm["microphone"].getMicrophone().getFilteredSoundPressureWeightedDb(), 30.f, 60.f, 0.f, 1.f);
@ -53,7 +39,7 @@ void Sound::update() {
Hardware::set_volume(volume);
}
setAlert(Alert::get(sm, started_frame));
setAlert(Alert::get(sm, 0));
}
void Sound::setAlert(const Alert &alert) {

@ -27,8 +27,7 @@ protected:
void update();
void setAlert(const Alert &alert);
SubMaster sm;
Alert current_alert = {};
QMap<AudibleAlert, QPair<QSoundEffect *, int>> sounds;
SubMaster sm;
uint64_t started_frame;
};

Loading…
Cancel
Save