diff --git a/selfdrive/ui/soundd.cc b/selfdrive/ui/soundd.cc index 02065499ba..014ceb2c5e 100644 --- a/selfdrive/ui/soundd.cc +++ b/selfdrive/ui/soundd.cc @@ -18,7 +18,7 @@ class Sound : public QObject { public: explicit Sound(QObject *parent = 0) { // TODO: merge again and add EQ in the amp config - const QString sound_asset_path = Hardware::TICI ? "../assets/sounds_tici/" : "../assets/sounds/"; + const QString sound_asset_path = Hardware::TICI() ? "../assets/sounds_tici/" : "../assets/sounds/"; std::tuple sound_list[] = { {AudibleAlert::CHIME_DISENGAGE, sound_asset_path + "disengaged.wav", false}, {AudibleAlert::CHIME_ENGAGE, sound_asset_path + "engaged.wav", false}, @@ -30,9 +30,10 @@ public: {AudibleAlert::CHIME_PROMPT, sound_asset_path + "error.wav", false} }; for (auto &[alert, fn, loops] : sound_list) { - sounds[alert].first.setSource(QUrl::fromLocalFile(fn)); - sounds[alert].second = loops ? QSoundEffect::Infinite : 0; - QObject::connect(&sounds[alert].first, &QSoundEffect::statusChanged, this, &Sound::checkStatus); + QSoundEffect *s = new QSoundEffect(this); + QObject::connect(s, &QSoundEffect::statusChanged, this, &Sound::checkStatus); + s->setSource(QUrl::fromLocalFile(fn)); + sounds[alert] = {s, loops ? QSoundEffect::Infinite : 0}; } sm = new SubMaster({"carState", "controlsState"}); @@ -47,9 +48,8 @@ public: private slots: void checkStatus() { - for (auto &[alert, kv] : sounds) { - assert(kv.first.status() != QSoundEffect::Error); - } + QSoundEffect *s = qobject_cast(sender()); + assert(s->status() != QSoundEffect::Error); } void update() { @@ -75,20 +75,19 @@ private slots: if (!alert.equal(a)) { alert = a; // stop sounds - for (auto &kv : sounds) { + for (auto &[s, loops] : sounds) { // Only stop repeating sounds - auto &[sound, loops] = kv.second; - if (sound.loopsRemaining() == QSoundEffect::Infinite) { - sound.stop(); + if (s->loopsRemaining() == QSoundEffect::Infinite) { + s->stop(); } } // play sound if (alert.sound != AudibleAlert::NONE) { - auto &[sound, loops] = sounds[alert.sound]; - sound.setLoopCount(loops); - sound.setVolume(volume); - sound.play(); + auto &[s, loops] = sounds[alert.sound]; + s->setLoopCount(loops); + s->setVolume(volume); + s->play(); } } } @@ -96,7 +95,7 @@ private slots: private: Alert alert; float volume = Hardware::MIN_VOLUME; - std::map> sounds; + QMap> sounds; SubMaster *sm; };