mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-19 00:43:54 +08:00
infinite sound (#2372)
* make sound infinite loopable
* Update selfdrive/ui/android/sl_sound.cc
* fix loop
* fix test threshold
* more fix
Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
Co-authored-by: Comma Device <device@comma.ai>
old-commit-hash: 53bd3050ee
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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}"
|
||||
|
||||
@@ -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<int> repeat;
|
||||
};
|
||||
|
||||
@@ -57,8 +56,8 @@ bool SLSound::init() {
|
||||
|
||||
void SLAPIENTRY slplay_callback(SLPlayItf playItf, void *context, SLuint32 event) {
|
||||
SLSound::Player *s = reinterpret_cast<SLSound::Player *>(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");
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -11,7 +11,7 @@ static std::map<AudibleAlert, std::pair<const char *, int>> 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}}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user