summaryrefslogtreecommitdiffstats
path: root/src/multimedia/windows
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-08 23:36:33 +0200
commit88ab683b570f0d87ef609e262c3799059cee2107 (patch)
tree4a1aceff0a2930e876bfcdf5418ec9eb2a78ec23 /src/multimedia/windows
parentd0f21f14e973944d412ff41ab982a7a210dbef71 (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. Pick-to: 6.3 6.2 Fixes: QTBUG-102843 Change-Id: I252384cb99fffca5e068b0b14e4be9b0469962ec Reviewed-by: Piotr Srebrny <piotr.srebrny@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/multimedia/windows')
-rw-r--r--src/multimedia/windows/qwindowsaudiosource.cpp13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/multimedia/windows/qwindowsaudiosource.cpp b/src/multimedia/windows/qwindowsaudiosource.cpp
index d86b27157..8523f9982 100644
--- a/src/multimedia/windows/qwindowsaudiosource.cpp
+++ b/src/multimedia/windows/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);