summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndré de la Rocha <andre.rocha@qt.io>2022-05-06 13:08:06 +0200
committerAndré de la Rocha <andre.rocha@qt.io>2022-05-23 11:05:38 +0200
commit45f46ad6f6442ad9952d69cccd72d64ef7d053bf (patch)
tree619b3c5aef280db00bfae9f4099fc3344ba755cf
parent992a44e679cbbaa8c6f695df4c06afe92a765e15 (diff)
Windows: Fix audio buffer sizes
Audio buffer sizes were being calculated in a way that could result in buffer sizes that were not a multiple of the audio frame size. For instance, a buffer with an odd number of bytes could be used for holding 16-bit audio data, which would result in the audio data contained on half of buffers received by applications being shifted by half a sample, causing applications to misinterpret that audio data. Fixes: QTBUG-102843 Change-Id: I252384cb99fffca5e068b0b14e4be9b0469962ec Reviewed-by: Piotr Srebrny <piotr.srebrny@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io> (cherry picked from commit 88ab683b570f0d87ef609e262c3799059cee2107)
-rw-r--r--src/multimedia/platform/windows/audio/qwindowsaudiosource.cpp13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/multimedia/platform/windows/audio/qwindowsaudiosource.cpp b/src/multimedia/platform/windows/audio/qwindowsaudiosource.cpp
index d86b27157..8523f9982 100644
--- a/src/multimedia/platform/windows/audio/qwindowsaudiosource.cpp
+++ b/src/multimedia/platform/windows/audio/qwindowsaudiosource.cpp
@@ -305,14 +305,11 @@ bool QWindowsAudioSource::open()
if (!QWindowsAudioUtils::formatToWaveFormatExtensible(settings, wfx)) {
qWarning("QAudioSource: open error, invalid format.");
} else if (buffer_size == 0) {
- buffer_size
- = (settings.sampleRate()
- * settings.channelCount()
- * settings.bytesPerSample()
- + 39) / 5;
- period_size = buffer_size / 5;
+ period_size = settings.sampleRate() / 25 * settings.bytesPerFrame();
+ buffer_size = period_size * 5;
} else {
- period_size = buffer_size / 5;
+ if (int bpf = settings.bytesPerFrame())
+ period_size = bpf * (buffer_size / 5 / bpf);
}
if (period_size == 0) {
@@ -645,7 +642,7 @@ bool QWindowsAudioSource::deviceReady()
if(pullMode) {
// reads some audio data and writes it to QIODevice
- read(0, buffer_size);
+ read(0, period_size * (buffer_size / period_size));
} else {
// emits readyRead() so user will call read() on QIODevice to get some audio data
InputPrivate* a = qobject_cast<InputPrivate*>(audioSource);