From bd675effe17e014890a8f0ed3a1eb93b0b46baa7 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Thu, 16 Jun 2022 14:59:48 +0200 Subject: Update spatial audio example Always loop the sound, and add an option to animate the position. Change-Id: Ib5b4fd230af27b74ce15285625e4c9bbf5ef3f7a Reviewed-by: Lars Knoll (cherry picked from commit 995376a8894c59d29b27c0b80f0adb91486d954e) Reviewed-by: Qt Cherry-pick Bot --- examples/spatialaudio/audiopanning/main.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/examples/spatialaudio/audiopanning/main.cpp b/examples/spatialaudio/audiopanning/main.cpp index 434aabe6a..b0a1f616f 100644 --- a/examples/spatialaudio/audiopanning/main.cpp +++ b/examples/spatialaudio/audiopanning/main.cpp @@ -49,6 +49,7 @@ ****************************************************************************/ #include #include +#include class AudioWidget : public QWidget { @@ -108,6 +109,9 @@ public: grid->addWidget(new QLabel(tr("Output mode:")), 8, 0); grid->addWidget(mode, 8, 1); + animateButton = new QCheckBox(tr("Animate sound position")); + grid->addWidget(animateButton, 9, 0); + connect(fileEdit, &QLineEdit::textChanged, this, &AudioWidget::fileChanged); connect(fileDialogButton, &QPushButton::clicked, this, &AudioWidget::openFileDialog); @@ -138,6 +142,13 @@ public: sound = new QSpatialSound(&engine); updatePosition(); + + animation = new QPropertyAnimation(azimuth, "value"); + animation->setDuration(10000); + animation->setStartValue(-180); + animation->setEndValue(180); + animation->setLoopCount(-1); + connect(animateButton, &QCheckBox::toggled, this, &AudioWidget::animateChanged); } void setFile(const QString &file) { fileEdit->setText(file); } private slots: @@ -164,6 +175,7 @@ private slots: { sound->setSource(QUrl::fromLocalFile(file)); sound->setSize(5); + sound->setLoops(QSpatialSound::Infinite); } void openFileDialog() { @@ -177,6 +189,13 @@ private slots: room->setReflectionGain(float(reflectionGain->value())/100); room->setReverbGain(float(reverbGain->value())/100); } + void animateChanged() + { + if (animateButton->isChecked()) + animation->start(); + else + animation->stop(); + } QLineEdit *fileEdit = nullptr; QPushButton *fileDialogButton = nullptr; @@ -188,6 +207,8 @@ private slots: QSlider *reverbGain = nullptr; QSlider *reflectionGain = nullptr; QComboBox *mode = nullptr; + QCheckBox *animateButton = nullptr; + QPropertyAnimation *animation = nullptr; QAudioEngine engine; QAudioListener *listener = nullptr; -- cgit v1.2.3