mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-07 22:52:06 +08:00
Soundd: Give each alert a volume (#29767)
* Give each alert a volume * Update sound.h old-commit-hash: 75ead2c38980437c617fbb8c02bf0e53cfbe9682
This commit is contained in:
@@ -15,12 +15,13 @@
|
||||
Sound::Sound(QObject *parent) : sm({"controlsState", "microphone"}) {
|
||||
qInfo() << "default audio device: " << QAudioDeviceInfo::defaultOutputDevice().deviceName();
|
||||
|
||||
for (auto &[alert, fn, loops] : sound_list) {
|
||||
for (auto &[alert, fn, loops, volume] : sound_list) {
|
||||
QSoundEffect *s = new QSoundEffect(this);
|
||||
QObject::connect(s, &QSoundEffect::statusChanged, [=]() {
|
||||
assert(s->status() != QSoundEffect::Error);
|
||||
});
|
||||
s->setSource(QUrl::fromLocalFile("../../assets/sounds/" + fn));
|
||||
s->setVolume(volume);
|
||||
sounds[alert] = {s, loops};
|
||||
}
|
||||
|
||||
|
||||
@@ -9,18 +9,21 @@
|
||||
#include "system/hardware/hw.h"
|
||||
#include "selfdrive/ui/ui.h"
|
||||
|
||||
const std::tuple<AudibleAlert, QString, int> sound_list[] = {
|
||||
|
||||
const float MAX_VOLUME = 1.0;
|
||||
|
||||
const std::tuple<AudibleAlert, QString, int, float> sound_list[] = {
|
||||
// AudibleAlert, file name, loop count
|
||||
{AudibleAlert::ENGAGE, "engage.wav", 0},
|
||||
{AudibleAlert::DISENGAGE, "disengage.wav", 0},
|
||||
{AudibleAlert::REFUSE, "refuse.wav", 0},
|
||||
{AudibleAlert::ENGAGE, "engage.wav", 0, MAX_VOLUME},
|
||||
{AudibleAlert::DISENGAGE, "disengage.wav", 0, MAX_VOLUME},
|
||||
{AudibleAlert::REFUSE, "refuse.wav", 0, MAX_VOLUME},
|
||||
|
||||
{AudibleAlert::PROMPT, "prompt.wav", 0},
|
||||
{AudibleAlert::PROMPT_REPEAT, "prompt.wav", QSoundEffect::Infinite},
|
||||
{AudibleAlert::PROMPT_DISTRACTED, "prompt_distracted.wav", QSoundEffect::Infinite},
|
||||
{AudibleAlert::PROMPT, "prompt.wav", 0, MAX_VOLUME},
|
||||
{AudibleAlert::PROMPT_REPEAT, "prompt.wav", QSoundEffect::Infinite, MAX_VOLUME},
|
||||
{AudibleAlert::PROMPT_DISTRACTED, "prompt_distracted.wav", QSoundEffect::Infinite, MAX_VOLUME},
|
||||
|
||||
{AudibleAlert::WARNING_SOFT, "warning_soft.wav", QSoundEffect::Infinite},
|
||||
{AudibleAlert::WARNING_IMMEDIATE, "warning_immediate.wav", QSoundEffect::Infinite},
|
||||
{AudibleAlert::WARNING_SOFT, "warning_soft.wav", QSoundEffect::Infinite, MAX_VOLUME},
|
||||
{AudibleAlert::WARNING_IMMEDIATE, "warning_immediate.wav", QSoundEffect::Infinite, MAX_VOLUME},
|
||||
};
|
||||
|
||||
class Sound : public QObject {
|
||||
|
||||
@@ -31,7 +31,7 @@ void controls_thread(int loop_cnt) {
|
||||
|
||||
const int DT_CTRL = 10; // ms
|
||||
for (int i = 0; i < loop_cnt; ++i) {
|
||||
for (auto &[alert, fn, loops] : sound_list) {
|
||||
for (auto &[alert, fn, loops, volume] : sound_list) {
|
||||
printf("testing %s\n", qPrintable(fn));
|
||||
for (int j = 0; j < 1000 / DT_CTRL; ++j) {
|
||||
MessageBuilder msg;
|
||||
|
||||
Reference in New Issue
Block a user