diff options
author | Pavel Dubsky <pavel.dubsky@qt.io> | 2023-05-26 12:51:02 +0200 |
---|---|---|
committer | Pavel Dubsky <pavel.dubsky@qt.io> | 2023-05-30 20:08:41 +0200 |
commit | 5aa899abb67ebdbcc9d0feb994385f1ab12656f7 (patch) | |
tree | b66a5a27b8c38d154edd2abbe06cc0c5e0dfbcbf /src/multimedia/audio | |
parent | cfc5b97daee9ac38b6fa8ec52be292e0790220ce (diff) |
Add audio engine warm-up on Windows
Current implementation has the following audio problem on Windows: if
any of the classes that support audio playback are used (QMediaPlayer
or QSoundEffect) sound is cutting off (part of the sound is missing
usually beginning). If there're some other applications playing sounds
in the system while we try to play our sound then everyting works fine.
Apparently this happens due to warm up delays for system audio engine
and if there're other applications available they're simply keeping it
alive and it's already fully initialized and ready to be used by us
when we need it.
As a workaround to this problem an unused audio device is created that
is fully initialized and set to play (nothing) but is actually present
for any subsequently created audio devices that are ready from the
start without any delays.
Pick-to: 6.5
Task-number: QTBUG-112512
Change-Id: I660a48e8ac1a1ebd1cfb6a9ff76605c3b4742e17
Reviewed-by: Artem Dyomin <artem.dyomin@qt.io>
Reviewed-by: Lars Knoll <lars@knoll.priv.no>
Reviewed-by: Jøger Hansegård <joger.hansegard@qt.io>
Diffstat (limited to 'src/multimedia/audio')
-rw-r--r-- | src/multimedia/audio/qaudiosystem.cpp | 7 | ||||
-rw-r--r-- | src/multimedia/audio/qsoundeffect.cpp | 3 |
2 files changed, 9 insertions, 1 deletions
diff --git a/src/multimedia/audio/qaudiosystem.cpp b/src/multimedia/audio/qaudiosystem.cpp index ef7552492..b052b78a6 100644 --- a/src/multimedia/audio/qaudiosystem.cpp +++ b/src/multimedia/audio/qaudiosystem.cpp @@ -3,9 +3,14 @@ #include "qaudiosystem_p.h" +#include <private/qplatformmediadevices_p.h> + QT_BEGIN_NAMESPACE -QPlatformAudioSink::QPlatformAudioSink(QObject *parent) : QObject(parent) { } +QPlatformAudioSink::QPlatformAudioSink(QObject *parent) : QObject(parent) +{ + QPlatformMediaDevices::instance()->prepareAudio(); +} qreal QPlatformAudioSink::volume() const { diff --git a/src/multimedia/audio/qsoundeffect.cpp b/src/multimedia/audio/qsoundeffect.cpp index b6b6f2d1f..d65df2502 100644 --- a/src/multimedia/audio/qsoundeffect.cpp +++ b/src/multimedia/audio/qsoundeffect.cpp @@ -8,6 +8,7 @@ #include "qaudiosink.h" #include "qmediadevices.h" #include <QtCore/qloggingcategory.h> +#include <private/qplatformmediadevices_p.h> static Q_LOGGING_CATEGORY(qLcSoundEffect, "qt.multimedia.soundeffect") @@ -72,6 +73,8 @@ QSoundEffectPrivate::QSoundEffectPrivate(QSoundEffect *q, const QAudioDevice &au , m_audioDevice(audioDevice) { open(QIODevice::ReadOnly); + + QPlatformMediaDevices::instance()->prepareAudio(); } void QSoundEffectPrivate::sampleReady() |