diff --git a/cereal b/cereal index aa349f6c31..12162ac4de 160000 --- a/cereal +++ b/cereal @@ -1 +1 @@ -Subproject commit aa349f6c314b1fcc7f5a42e6f4bfe0d466335634 +Subproject commit 12162ac4dee9537611ee6d075e4b9b2873c6e741 diff --git a/selfdrive/controls/lib/events.py b/selfdrive/controls/lib/events.py index 0335ddbdea..bc5d6a0b10 100644 --- a/selfdrive/controls/lib/events.py +++ b/selfdrive/controls/lib/events.py @@ -156,7 +156,7 @@ class SoftDisableAlert(Alert): super().__init__("TAKE CONTROL IMMEDIATELY", alert_text_2, AlertStatus.critical, AlertSize.full, Priority.MID, VisualAlert.steerRequired, - AudibleAlert.chimeWarningRepeat, .1, 2., 2.), + AudibleAlert.chimeWarningRepeatInfinite, .1, 2., 2.), class ImmediateDisableAlert(Alert): @@ -164,7 +164,7 @@ class ImmediateDisableAlert(Alert): super().__init__(alert_text_1, alert_text_2, AlertStatus.critical, AlertSize.full, Priority.HIGHEST, VisualAlert.steerRequired, - AudibleAlert.chimeWarningRepeat, 2.2, 3., 4.), + AudibleAlert.chimeWarningRepeatInfinite, 2.2, 3., 4.), class EngagementAlert(Alert): @@ -350,7 +350,7 @@ EVENTS: Dict[int, Dict[str, Union[Alert, Callable[[Any, messaging.SubMaster, boo "BRAKE!", "Risk of Collision", AlertStatus.critical, AlertSize.full, - Priority.HIGHEST, VisualAlert.fcw, AudibleAlert.chimeWarningRepeat, 1., 2., 2.), + Priority.HIGHEST, VisualAlert.fcw, AudibleAlert.chimeWarningRepeatInfinite, 1., 2., 2.), }, EventName.ldw: { @@ -410,7 +410,7 @@ EVENTS: Dict[int, Dict[str, Union[Alert, Callable[[Any, messaging.SubMaster, boo "KEEP EYES ON ROAD", "Driver Distracted", AlertStatus.userPrompt, AlertSize.mid, - Priority.MID, VisualAlert.steerRequired, AudibleAlert.chimeWarning2Repeat, .1, .1, .1), + Priority.MID, VisualAlert.steerRequired, AudibleAlert.chimeWarning2RepeatInfinite, .1, .1, .1), }, EventName.driverDistracted: { @@ -418,7 +418,7 @@ EVENTS: Dict[int, Dict[str, Union[Alert, Callable[[Any, messaging.SubMaster, boo "DISENGAGE IMMEDIATELY", "Driver Distracted", AlertStatus.critical, AlertSize.full, - Priority.HIGH, VisualAlert.steerRequired, AudibleAlert.chimeWarningRepeat, .1, .1, .1), + Priority.HIGH, VisualAlert.steerRequired, AudibleAlert.chimeWarningRepeatInfinite, .1, .1, .1), }, EventName.preDriverUnresponsive: { @@ -434,7 +434,7 @@ EVENTS: Dict[int, Dict[str, Union[Alert, Callable[[Any, messaging.SubMaster, boo "TOUCH STEERING WHEEL", "Driver Unresponsive", AlertStatus.userPrompt, AlertSize.mid, - Priority.MID, VisualAlert.steerRequired, AudibleAlert.chimeWarning2Repeat, .1, .1, .1), + Priority.MID, VisualAlert.steerRequired, AudibleAlert.chimeWarning2RepeatInfinite, .1, .1, .1), }, EventName.driverUnresponsive: { @@ -442,7 +442,7 @@ EVENTS: Dict[int, Dict[str, Union[Alert, Callable[[Any, messaging.SubMaster, boo "DISENGAGE IMMEDIATELY", "Driver Unresponsive", AlertStatus.critical, AlertSize.full, - Priority.HIGH, VisualAlert.steerRequired, AudibleAlert.chimeWarningRepeat, .1, .1, .1), + Priority.HIGH, VisualAlert.steerRequired, AudibleAlert.chimeWarningRepeatInfinite, .1, .1, .1), }, EventName.manualRestart: { @@ -849,7 +849,7 @@ EVENTS: Dict[int, Dict[str, Union[Alert, Callable[[Any, messaging.SubMaster, boo "Speed Too High", "Model uncertain at this speed", AlertStatus.userPrompt, AlertSize.mid, - Priority.HIGH, VisualAlert.steerRequired, AudibleAlert.chimeWarning2Repeat, 2.2, 3., 4.), + Priority.HIGH, VisualAlert.steerRequired, AudibleAlert.chimeWarning2RepeatInfinite, 2.2, 3., 4.), ET.NO_ENTRY: Alert( "Speed Too High", "Slow down to engage", diff --git a/selfdrive/ui/soundd/sound.cc b/selfdrive/ui/soundd/sound.cc index dec46cbea8..d004d0dd2e 100644 --- a/selfdrive/ui/soundd/sound.cc +++ b/selfdrive/ui/soundd/sound.cc @@ -13,9 +13,9 @@ Sound::Sound(QObject *parent) : sm({"carState", "controlsState"}) { QObject::connect(s, &QSoundEffect::statusChanged, [=]() { assert(s->status() != QSoundEffect::Error); }); - s->setSource(QUrl::fromLocalFile(sound_asset_path + fn)); s->setVolume(Hardware::MIN_VOLUME); - sounds[alert] = {s, loops ? QSoundEffect::Infinite : 0}; + s->setSource(QUrl::fromLocalFile(sound_asset_path + fn)); + sounds[alert] = {s, loops}; } QTimer *timer = new QTimer(this); @@ -25,8 +25,9 @@ Sound::Sound(QObject *parent) : sm({"carState", "controlsState"}) { void Sound::update() { sm.update(0); + + // scale volume with speed if (sm.updated("carState")) { - // scale volume with speed float volume = util::map_val(sm["carState"].getCarState().getVEgo(), 0.f, 20.f, Hardware::MIN_VOLUME, Hardware::MAX_VOLUME); for (auto &[s, loops] : sounds) { @@ -43,7 +44,7 @@ void Sound::setAlert(const Alert &alert) { // stop sounds for (auto &[s, loops] : sounds) { // Only stop repeating sounds - if (s->loopsRemaining() == QSoundEffect::Infinite) { + if (s->loopsRemaining() > 1 || s->loopsRemaining() == QSoundEffect::Infinite) { s->stop(); } } diff --git a/selfdrive/ui/soundd/sound.h b/selfdrive/ui/soundd/sound.h index 0fb1dd5b4a..e9f186de5d 100644 --- a/selfdrive/ui/soundd/sound.h +++ b/selfdrive/ui/soundd/sound.h @@ -5,15 +5,16 @@ #include "selfdrive/hardware/hw.h" #include "selfdrive/ui/ui.h" -const std::tuple sound_list[] = { - {AudibleAlert::CHIME_DISENGAGE, "disengaged.wav", false}, - {AudibleAlert::CHIME_ENGAGE, "engaged.wav", false}, - {AudibleAlert::CHIME_WARNING1, "warning_1.wav", false}, - {AudibleAlert::CHIME_WARNING2, "warning_2.wav", false}, - {AudibleAlert::CHIME_WARNING2_REPEAT, "warning_2.wav", true}, - {AudibleAlert::CHIME_WARNING_REPEAT, "warning_repeat.wav", true}, - {AudibleAlert::CHIME_ERROR, "error.wav", false}, - {AudibleAlert::CHIME_PROMPT, "error.wav", false}, +const std::tuple sound_list[] = { + // AudibleAlert, file name, loop count + {AudibleAlert::CHIME_DISENGAGE, "disengaged.wav", 0}, + {AudibleAlert::CHIME_ENGAGE, "engaged.wav", 0}, + {AudibleAlert::CHIME_WARNING1, "warning_1.wav", 0}, + {AudibleAlert::CHIME_WARNING_REPEAT, "warning_repeat.wav", 10}, + {AudibleAlert::CHIME_WARNING_REPEAT_INFINITE, "warning_repeat.wav", QSoundEffect::Infinite}, + {AudibleAlert::CHIME_WARNING2_REPEAT_INFINITE, "warning_2.wav", QSoundEffect::Infinite}, + {AudibleAlert::CHIME_ERROR, "error.wav", 0}, + {AudibleAlert::CHIME_PROMPT, "error.wav", 0}, }; class Sound : public QObject { diff --git a/selfdrive/ui/tests/test_sound.cc b/selfdrive/ui/tests/test_sound.cc index 579867ad2b..62aa35cb2b 100644 --- a/selfdrive/ui/tests/test_sound.cc +++ b/selfdrive/ui/tests/test_sound.cc @@ -11,8 +11,6 @@ public: for (auto i = sounds.constBegin(); i != sounds.constEnd(); ++i) { QObject::connect(i.value().first, &QSoundEffect::playingChanged, [=, s = i.value().first, a = i.key()]() { if (s->isPlaying()) { - bool repeat = a == AudibleAlert::CHIME_WARNING_REPEAT || a == AudibleAlert::CHIME_WARNING2_REPEAT; - REQUIRE((s->loopsRemaining() == repeat ? QSoundEffect::Infinite : 1)); sound_stats[a].first++; } else { sound_stats[a].second++; @@ -40,23 +38,31 @@ void controls_thread(int loop_cnt) { } } } + + // send no alert sound + for (int j = 0; j < 1000 / DT_CTRL; ++j) { + MessageBuilder msg; + msg.initEvent().initControlsState(); + pm.send("controlsState", msg); + QThread::msleep(DT_CTRL); + } + QThread::currentThread()->quit(); } -TEST_CASE("test sound") { +TEST_CASE("test soundd") { QEventLoop loop; - TestSound test_sound; - const int test_loop_cnt = 2; + QThread t; QObject::connect(&t, &QThread::started, [=]() { controls_thread(test_loop_cnt); }); QObject::connect(&t, &QThread::finished, [&]() { loop.quit(); }); t.start(); - loop.exec(); - for (auto [play, stop] : test_sound.sound_stats) { + for (const AudibleAlert alert : test_sound.sound_stats.keys()) { + auto [play, stop] = test_sound.sound_stats[alert]; REQUIRE(play == test_loop_cnt); REQUIRE(stop == test_loop_cnt); } diff --git a/selfdrive/ui/tests/test_soundd.py b/selfdrive/ui/tests/test_soundd.py index 80302faa9a..ad07f86303 100755 --- a/selfdrive/ui/tests/test_soundd.py +++ b/selfdrive/ui/tests/test_soundd.py @@ -20,9 +20,9 @@ SOUNDS = { AudibleAlert.chimeError: 173, AudibleAlert.chimePrompt: 173, AudibleAlert.chimeWarning1: 163, - AudibleAlert.chimeWarning2: 216, - AudibleAlert.chimeWarning2Repeat: 470, AudibleAlert.chimeWarningRepeat: 468, + AudibleAlert.chimeWarningRepeatInfinite: 468, + AudibleAlert.chimeWarning2RepeatInfinite: 470, } def get_total_writes():