[multimedia/kwave] /: codec_audiofile: parallelized decoding

Thomas Eschenbacher <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 5182fe9cc47832c33391dea8b54f593d848af282 by Thomas Eschenbacher.
Committed on 18/08/2026 at 14:53.
Pushed by eschenbacher into branch 'master'.

codec_audiofile: parallelized decoding

M  +1    -0    CHANGES
M  +31   -17   plugins/codec_audiofile/AudiofileDecoder.cpp

https://invent.kde.org/multimedia/kwave/-/commit/5182fe9cc47832c33391dea8b54f593d848af282

diff --git a/CHANGES b/CHANGES
index ae964744..c95d3b79 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,5 @@
 26.11.70 [2026-08-18]
+ * codec_audiofile: parallelized decoding
  * codec_flac: parallelized decoding + added check for > 8 channels
  * codec_mp3: workaround for broken MBS conversion in ID3LIB
  * codec_mp3: do no longer explicitly link against libstdc++ and libz
diff --git a/plugins/codec_audiofile/AudiofileDecoder.cpp b/plugins/codec_audiofile/AudiofileDecoder.cpp
index 73ff42c1..a5ca1c20 100644
--- a/plugins/codec_audiofile/AudiofileDecoder.cpp
+++ b/plugins/codec_audiofile/AudiofileDecoder.cpp
@@ -22,7 +22,9 @@
 
 #include <audiofile.h>
 
+#include <QFutureSynchronizer>
 #include <QIODevice>
+#include <QtConcurrentRun>
 #include <QtGlobal>
 
 #include <KLocalizedString>
@@ -246,7 +248,7 @@ bool Kwave::AudiofileDecoder::decode(QWidget */*widget*/,
         afGetVirtualFrameSize(fh, AF_DEFAULT_TRACK, 1));
 
     // allocate a buffer for input data
-    const unsigned int buffer_frames = (8 * 1024);
+    const unsigned int buffer_frames = (64 * 1024);
     sample_storage_t *buffer =
         static_cast<sample_storage_t *>(malloc(buffer_frames * frame_size));
     Q_ASSERT(buffer);
@@ -265,24 +267,36 @@ bool Kwave::AudiofileDecoder::decode(QWidget */*widget*/,
         if (buffer_used <= 0) break;
         rest -= buffer_used;
 
-        // split into the tracks
-        const sample_storage_t *p = buffer;
-        unsigned int count = buffer_used;
-        while (count) {
-            for (unsigned int track = 0; track < tracks; track++) {
-                sample_storage_t s = *p++;
-
-                // adjust precision
-                if (SAMPLE_STORAGE_BITS != SAMPLE_BITS) {
-                    s /= (1 << (SAMPLE_STORAGE_BITS - SAMPLE_BITS));
+        // parallel deinterleaving and writing directly per track
+        unsigned int step  = tracks;
+        QFutureSynchronizer<void> synchronizer;
+
+        for (unsigned int track = 0; track < tracks; ++track) {
+            Kwave::Writer          *writer = dst[track];
+            const sample_storage_t *in     = buffer + track;
+            if (!writer) continue;
+
+            synchronizer.addFuture(QtConcurrent::run(
+                [in, buffer_used, step, writer]() {
+                    unsigned int remaining = buffer_used;
+                    const sample_storage_t *src = in;
+                    while (remaining-- > 0) {
+                        sample_storage_t s = *src;
+                        src += step;
+
+                        // adjust precision
+                        if (SAMPLE_STORAGE_BITS != SAMPLE_BITS) {
+                            s /= (1 << (SAMPLE_STORAGE_BITS - SAMPLE_BITS));
+                        }
+
+                        // the following cast is only necessary if
+                        // sample_t is not equal to a quint32
+                        *(writer) << static_cast<sample_t>(s);
+                    }
                 }
-
-                // the following cast is only necessary if
-                // sample_t is not equal to a quint32
-                *(dst[track]) << static_cast<sample_t>(s);
-            }
-            --count;
+            ));
         }
+        synchronizer.waitForFinished();
 
         // abort if the user pressed cancel
         if (dst.isCanceled()) break;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.