[Scummvm-git-logs] scummvm master -> 641374b5ed274c39b3ddf52045901648eb0c5b00

bluegr noreply at scummvm.org
Sat Oct 21 13:13:24 UTC 2023


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
641374b5ed AUDIO: Detect and skip BFW chunks in WAV files


Commit: 641374b5ed274c39b3ddf52045901648eb0c5b00
    https://github.com/scummvm/scummvm/commit/641374b5ed274c39b3ddf52045901648eb0c5b00
Author: Walter Agazzi (walter.agazzi at protonmail.com)
Date: 2023-10-21T16:13:20+03:00

Commit Message:
AUDIO: Detect and skip BFW chunks in WAV files

Modern WAV files may contain extra chunks before the FMT header,
as specified in the Broadcast Wave Format extension.
These chunks must be skipped to properly read the header.

Changed paths:
    audio/decoders/wave.cpp


diff --git a/audio/decoders/wave.cpp b/audio/decoders/wave.cpp
index a247ab82880..556fb65557f 100644
--- a/audio/decoders/wave.cpp
+++ b/audio/decoders/wave.cpp
@@ -32,6 +32,8 @@
 #include "audio/decoders/raw.h"
 #include "audio/decoders/g711.h"
 
+#define EXT_CHUNKS 8
+
 namespace Audio {
 
 bool loadWAVFromStream(Common::SeekableReadStream &stream, int &size, int &rate, byte &flags, uint16 *wavType, int *blockAlign_, int *samplesPerBlock_) {
@@ -40,6 +42,17 @@ bool loadWAVFromStream(Common::SeekableReadStream &stream, int &size, int &rate,
 
 	buf[4] = 0;
 
+	const char *extensionChunks[EXT_CHUNKS] = {
+		"JUNK",
+		"bext",
+		"iXML",
+		"qlty",
+		"mext",
+		"levl",
+		"link",
+		"axml"
+	};
+
 	stream.read(buf, 4);
 	if (memcmp(buf, "RIFF", 4) != 0) {
 		warning("getWavInfo: No 'RIFF' header");
@@ -62,15 +75,22 @@ bool loadWAVFromStream(Common::SeekableReadStream &stream, int &size, int &rate,
 		stream.read(buf, 4);
 	}
 
-	if (memcmp(buf, "JUNK", 4) == 0) {
-		uint32 junksize = stream.readUint32LE();
-		// skip junk padding (add 1 byte if odd)
-		stream.skip(junksize + (junksize % 2));
-		stream.read(buf, 4);
+	while (1) { // skip junk/bext... chunks
+		int i;
+		for (i = 0; (i < EXT_CHUNKS) && (memcmp(buf, extensionChunks[i], 4) != 0); i++)
+			;
+		if (i != EXT_CHUNKS) { // found a known chunk
+			uint32 chunkSize = stream.readUint32LE();
+			// skip junk/ext chunk (add 1 byte if odd)
+			stream.skip(chunkSize + (chunkSize % 2));
+			stream.read(buf, 4);
+			debug(0, "Skipped %s chunk in wav file!", extensionChunks[i]);
+		} else // skipped all chunks, or found something unexpected
+			break;
 	}
 
 	if (memcmp(buf, "fmt ", 4) != 0) {
-		warning("getWavInfo: No 'fmt' header");
+		warning("getWavInfo: No 'fmt' header! Found %s", buf);
 		return false;
 	}
 




More information about the Scummvm-git-logs mailing list