diff --git a/selfdrive/controls/lib/events.py b/selfdrive/controls/lib/events.py index b1a4c27396..be23d3b0f9 100644 --- a/selfdrive/controls/lib/events.py +++ b/selfdrive/controls/lib/events.py @@ -739,7 +739,7 @@ EVENTS: Dict[int, Dict[str, Union[Alert, Callable[[Any, messaging.SubMaster, boo "Speed Too High", "Slow down to resume operation", AlertStatus.normal, AlertSize.mid, - Priority.HIGH, VisualAlert.steerRequired, AudibleAlert.chimeWarning2Repeat, 2.2, 3., 4.), + Priority.HIGH, VisualAlert.steerRequired, AudibleAlert.none, 2.2, 3., 4.), ET.NO_ENTRY: Alert( "Speed Too High", "Slow down to engage", diff --git a/selfdrive/test/test_sounds.py b/selfdrive/test/test_sounds.py index 2ee7b0826c..da6419ef61 100755 --- a/selfdrive/test/test_sounds.py +++ b/selfdrive/test/test_sounds.py @@ -19,8 +19,8 @@ SOUNDS = { AudibleAlert.chimePrompt: 85, AudibleAlert.chimeWarning1: 80, AudibleAlert.chimeWarning2: 107, - AudibleAlert.chimeWarningRepeat: 134, AudibleAlert.chimeWarning2Repeat: 177, + AudibleAlert.chimeWarningRepeat: 240, } def get_total_writes(): @@ -67,5 +67,6 @@ def test_alert_sounds(): pm.send('controlsState', msg) time.sleep(DT_CTRL) + tolerance = (expected_writes % 100) * 2 actual_writes = get_total_writes() - start_writes - assert abs(expected_writes - actual_writes) <= 2, f"{alert_sounds[sound]}: expected {expected_writes} writes, got {actual_writes}" + assert abs(expected_writes - actual_writes) <= tolerance, f"{alert_sounds[sound]}: expected {expected_writes} writes, got {actual_writes}" diff --git a/selfdrive/ui/android/sl_sound.cc b/selfdrive/ui/android/sl_sound.cc index 95cebab9c4..52604df937 100644 --- a/selfdrive/ui/android/sl_sound.cc +++ b/selfdrive/ui/android/sl_sound.cc @@ -15,7 +15,6 @@ struct SLSound::Player { SLObjectItf player; SLPlayItf playItf; - // slplay_callback runs on a background thread,use atomic to ensure thread safe. std::atomic repeat; }; @@ -57,8 +56,8 @@ bool SLSound::init() { void SLAPIENTRY slplay_callback(SLPlayItf playItf, void *context, SLuint32 event) { SLSound::Player *s = reinterpret_cast(context); - if (event == SL_PLAYEVENT_HEADATEND && s->repeat > 1) { - --s->repeat; + if (event == SL_PLAYEVENT_HEADATEND && s->repeat != 0) { + if (s->repeat > 0) --s->repeat; (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); (*playItf)->SetMarkerPosition(playItf, 0); (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_PLAYING); @@ -69,10 +68,13 @@ bool SLSound::play(AudibleAlert alert) { if (currentSound_ != AudibleAlert::NONE) { stop(); } + auto player = player_.at(alert); SLPlayItf playItf = player->playItf; - player->repeat = sound_map[alert].second; - if (player->repeat > 0) { + + int loops = sound_map[alert].second; + player->repeat = loops > 0 ? loops - 1 : loops; + if (player->repeat != 0) { ReturnOnError((*playItf)->RegisterCallback(playItf, slplay_callback, player), "Failed to register callback"); ReturnOnError((*playItf)->SetCallbackEventsMask(playItf, SL_PLAYEVENT_HEADATEND), "Failed to set callback event mask"); } diff --git a/selfdrive/ui/qt/qt_sound.cc b/selfdrive/ui/qt/qt_sound.cc index 76842c67ef..c44e27ec97 100644 --- a/selfdrive/ui/qt/qt_sound.cc +++ b/selfdrive/ui/qt/qt_sound.cc @@ -9,7 +9,7 @@ QtSound::QtSound() { } bool QtSound::play(AudibleAlert alert) { - sounds[alert].setLoopCount(sound_map[alert].second); + sounds[alert].setLoopCount(sound_map[alert].second>-1 ? sound_map[alert].second : QSoundEffect::Infinite); sounds[alert].setVolume(0.9); sounds[alert].play(); return true; diff --git a/selfdrive/ui/sound.hpp b/selfdrive/ui/sound.hpp index 9315783066..bdb8590801 100644 --- a/selfdrive/ui/sound.hpp +++ b/selfdrive/ui/sound.hpp @@ -11,7 +11,7 @@ static std::map> sound_map { {AudibleAlert::CHIME_WARNING1, {"../assets/sounds/warning_1.wav", 0}}, {AudibleAlert::CHIME_WARNING2, {"../assets/sounds/warning_2.wav", 0}}, {AudibleAlert::CHIME_WARNING2_REPEAT, {"../assets/sounds/warning_2.wav", 3}}, - {AudibleAlert::CHIME_WARNING_REPEAT, {"../assets/sounds/warning_repeat.wav", 3}}, + {AudibleAlert::CHIME_WARNING_REPEAT, {"../assets/sounds/warning_repeat.wav", -1}}, {AudibleAlert::CHIME_ERROR, {"../assets/sounds/error.wav", 0}}, {AudibleAlert::CHIME_PROMPT, {"../assets/sounds/error.wav", 0}} };