-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.9.2
-
None
Even after pre-load, QSoundEffect introduces a short, but noticable freeze of the GUI when played. In earlier Qt versions, e.g. 6.8.2, it had low latency as expected. This regression makes QSoundEffect not suitable for games anymore.
Code to reproduce (expects ":/bin/audio/test.wav"):
#include <QApplication> #include <QPushButton> #include <QProgressBar> #include <QVBoxLayout> #include <QSoundEffect> #include <QElapsedTimer> #include <QTimer> class TestWidget : public QWidget { Q_OBJECT public: TestWidget(QWidget *parent = nullptr) : QWidget(parent) { auto *layout{new QVBoxLayout(this)}; auto *progress{new QProgressBar(this)}; auto *btnPlay{new QPushButton(tr("Play sound"), this)}; auto *timer{new QTimer(this)}; auto *effect{new QSoundEffect(this)}; timer->start(100); btnPlay->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); layout->addWidget(progress); layout->addWidget(btnPlay); resize(300, 200); effect->setSource(QUrl::fromLocalFile(":/bin/audio/test.wav")); effect->setVolume(0.8f); connect(btnPlay, &QPushButton::clicked, this, [effect](){ QElapsedTimer timer; timer.start(); effect->play(); qDebug() << "Delay in ms:" << timer.elapsed(); }); connect(timer, &QTimer::timeout, this, [progress](){ progress->setValue(progress->value() + 1); if (progress->value() != progress->maximum()) return; bool isInverted{progress->invertedAppearance()}; progress->setInvertedAppearance(!isInverted); progress->setValue(progress->minimum()); }); } }; int main(int argc, char *argv[]) { QApplication app(argc, argv); TestWidget w; w.show(); return app.exec(); } #include "main.moc"
Console output:
qt.multimedia.ffmpeg: Using Qt multimedia with FFmpeg version 7.1.1 LGPL version 2.1 or later Delay in ms: 454 Delay in ms: 492