summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Olav Tvete <paul.tvete@qt.io>2022-06-16 14:59:48 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-06-16 20:03:54 +0000
commitbd675effe17e014890a8f0ed3a1eb93b0b46baa7 (patch)
tree125ab881257113c2be37acf5a465f117ed7fc606
parent67fbf7f2e18f75fc71b97576a501a8c5b7b3070f (diff)
Update spatial audio example
Always loop the sound, and add an option to animate the position. Change-Id: Ib5b4fd230af27b74ce15285625e4c9bbf5ef3f7a Reviewed-by: Lars Knoll <lars.knoll@qt.io> (cherry picked from commit 995376a8894c59d29b27c0b80f0adb91486d954e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--examples/spatialaudio/audiopanning/main.cpp21
1 files changed, 21 insertions, 0 deletions
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 <QtWidgets/QtWidgets>
#include <QtSpatialAudio/QtSpatialAudio>
+#include <QtCore/QPropertyAnimation>
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;