soundd: cleanup remnants from running while offroad (#29006)
cleanup old-commit-hash: 0bacd9882875b4b0c3ad206dbc365ccae5464564
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user