* ui:move c-capnp to c++ * move Subsockets into vector * rename reader to msg include cereal/gen/cpp/log.capnp * fix some errors restore some changes restore previous * cleanup codes cleanup codes * remove unused variable alert_size * handle capnproto's enum in a robust way add break to default * switch -> std:map * use static std::map instead of switch do cleanup * fix wrong variable name * use FlatArrayMessageReader instead of custom MessageReader remove messagehelp.h Revert "use FlatArrayMessageReader instead of custom MessageReader" This reverts commit 57d8b6b1e2b4bad908246f35eb068535b1627167. use FlatArrayMessageReader instead of custom MessageReader add header file remove capnp_c lib,add kj lib include serialize.h fix remove duplicate includes old-commit-hash: ee725534bb1ae2335705562e9f1eb176e5cd91fd
92 lines
2.5 KiB
C++
92 lines
2.5 KiB
C++
#include <stdlib.h>
|
|
#include "sound.hpp"
|
|
|
|
#include "common/swaglog.h"
|
|
|
|
typedef struct {
|
|
AudibleAlert alert;
|
|
const char* uri;
|
|
bool loop;
|
|
} sound_file;
|
|
|
|
extern "C"{
|
|
#include "slplay.h"
|
|
}
|
|
|
|
int last_volume = 0;
|
|
|
|
void set_volume(int volume) {
|
|
if (last_volume != volume) {
|
|
char volume_change_cmd[64];
|
|
sprintf(volume_change_cmd, "service call audio 3 i32 3 i32 %d i32 1 &", volume);
|
|
|
|
// 5 second timeout at 60fps
|
|
int volume_changed = system(volume_change_cmd);
|
|
last_volume = volume;
|
|
}
|
|
}
|
|
|
|
|
|
sound_file sound_table[] = {
|
|
{ cereal::CarControl::HUDControl::AudibleAlert::CHIME_DISENGAGE, "../assets/sounds/disengaged.wav", false },
|
|
{ cereal::CarControl::HUDControl::AudibleAlert::CHIME_ENGAGE, "../assets/sounds/engaged.wav", false },
|
|
{ cereal::CarControl::HUDControl::AudibleAlert::CHIME_WARNING1, "../assets/sounds/warning_1.wav", false },
|
|
{ cereal::CarControl::HUDControl::AudibleAlert::CHIME_WARNING2, "../assets/sounds/warning_2.wav", false },
|
|
{ cereal::CarControl::HUDControl::AudibleAlert::CHIME_WARNING2_REPEAT, "../assets/sounds/warning_2.wav", true },
|
|
{ cereal::CarControl::HUDControl::AudibleAlert::CHIME_WARNING_REPEAT, "../assets/sounds/warning_repeat.wav", true },
|
|
{ cereal::CarControl::HUDControl::AudibleAlert::CHIME_ERROR, "../assets/sounds/error.wav", false },
|
|
{ cereal::CarControl::HUDControl::AudibleAlert::CHIME_PROMPT, "../assets/sounds/error.wav", false },
|
|
{ cereal::CarControl::HUDControl::AudibleAlert::NONE, NULL, false },
|
|
};
|
|
|
|
sound_file* get_sound_file(AudibleAlert alert) {
|
|
for (sound_file *s = sound_table; s->alert != cereal::CarControl::HUDControl::AudibleAlert::NONE; s++) {
|
|
if (s->alert == alert) {
|
|
return s;
|
|
}
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
void play_alert_sound(AudibleAlert alert) {
|
|
sound_file* sound = get_sound_file(alert);
|
|
char* error = NULL;
|
|
|
|
slplay_play(sound->uri, sound->loop, &error);
|
|
if(error) {
|
|
LOGW("error playing sound: %s", error);
|
|
}
|
|
}
|
|
|
|
void stop_alert_sound(AudibleAlert alert) {
|
|
sound_file* sound = get_sound_file(alert);
|
|
char* error = NULL;
|
|
|
|
slplay_stop_uri(sound->uri, &error);
|
|
if(error) {
|
|
LOGW("error stopping sound: %s", error);
|
|
}
|
|
}
|
|
|
|
void ui_sound_init() {
|
|
char *error = NULL;
|
|
slplay_setup(&error);
|
|
if (error) goto fail;
|
|
|
|
for (sound_file *s = sound_table; s->alert != cereal::CarControl::HUDControl::AudibleAlert::NONE; s++) {
|
|
slplay_create_player_for_uri(s->uri, &error);
|
|
if (error) goto fail;
|
|
}
|
|
return;
|
|
|
|
fail:
|
|
LOGW(error);
|
|
exit(1);
|
|
}
|
|
|
|
void ui_sound_destroy() {
|
|
slplay_destroy();
|
|
}
|
|
|