From e042ec84be57d026b674aa37454d97fe23318857 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Fri, 22 Oct 2021 17:47:46 -0700 Subject: [PATCH] little sound tester old-commit-hash: 474981541960c9f27e70ff0db69e1ac40d7d8bbe --- selfdrive/ui/.gitignore | 1 + selfdrive/ui/SConscript | 2 ++ selfdrive/ui/tests/playsound.cc | 30 ++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 selfdrive/ui/tests/playsound.cc diff --git a/selfdrive/ui/.gitignore b/selfdrive/ui/.gitignore index 5d656f889e..9e529b5d0c 100644 --- a/selfdrive/ui/.gitignore +++ b/selfdrive/ui/.gitignore @@ -3,6 +3,7 @@ moc_* watch3 installer/installers/* +tests/playsound replay/replay replay/tests/test_replay qt/text diff --git a/selfdrive/ui/SConscript b/selfdrive/ui/SConscript index be7d95372c..3a1e406682 100644 --- a/selfdrive/ui/SConscript +++ b/selfdrive/ui/SConscript @@ -45,6 +45,8 @@ asset_obj = qt_env.Object("assets", assets) # build soundd qt_env.Program("_soundd", "soundd.cc", LIBS=base_libs) +if GetOption('test'): + qt_env.Program("tests/playsound", "tests/playsound.cc", LIBS=base_libs) # spinner and text window qt_env.Program("qt/text", ["qt/text.cc"], LIBS=qt_libs) diff --git a/selfdrive/ui/tests/playsound.cc b/selfdrive/ui/tests/playsound.cc new file mode 100644 index 0000000000..6487d04790 --- /dev/null +++ b/selfdrive/ui/tests/playsound.cc @@ -0,0 +1,30 @@ +#include +#include +#include +#include + +int main(int argc, char **argv) { + + QApplication a(argc, argv); + + QTimer::singleShot(0, [=]{ + QSoundEffect s; + const char *vol = getenv("VOLUME"); + s.setVolume(vol ? atof(vol) : 1.0); + for (int i = 1; i < argc; i++) { + QString fn = argv[i]; + qDebug() << "playing" << fn; + + QEventLoop loop; + s.setSource(QUrl::fromLocalFile(fn)); + QEventLoop::connect(&s, &QSoundEffect::loadedChanged, &loop, &QEventLoop::quit); + loop.exec(); + s.play(); + QEventLoop::connect(&s, &QSoundEffect::playingChanged, &loop, &QEventLoop::quit); + loop.exec(); + } + QCoreApplication::exit(); + }); + + return a.exec(); +}