fix(audio): support WAVE_FORMAT_EXTENSIBLE PCM WAVs, normalizing them to standard PCM on upload

This commit is contained in:
daniel-c-harvey
2026-06-10 15:20:34 -04:00
parent 0f5eaa42b5
commit 88ac5b2c88
2 changed files with 110 additions and 11 deletions
+18 -1
View File
@@ -59,7 +59,24 @@ class WavUtils {
// PCM only. The server's WavOffsetService synthesises PCM-shaped headers,
// and AudioProcessor rejects non-PCM at upload — accepting Float here would
// hand the decoder a header/payload mismatch that surfaces as garbled audio.
if (audioFormat !== 1) {
// WAVE_FORMAT_EXTENSIBLE (0xFFFE) is accepted only when its SubFormat GUID is
// PCM; the sample data is then byte-identical to standard PCM and every PCM
// field sits at the same offset. The vault normalizes uploads to plain PCM, so
// this is belt-and-suspenders for any EXTENSIBLE header that reaches the client.
if (audioFormat === 0xFFFE) {
// EXTENSIBLE needs the full extension: 16 base + 2 cbSize + 22 = 40 bytes.
if (chunkSize < 40) {
console.warn(`EXTENSIBLE fmt chunk too small: ${chunkSize} (need >= 40)`);
return null;
}
// SubFormat GUID at chunkOffset + 8 + 24; first two LE bytes are the format
// tag — 0x0001 == WAVE_FORMAT_PCM.
const subFormatTag = view.getUint16(chunkOffset + 8 + 24, true);
if (subFormatTag !== 1) {
console.warn(`Unsupported EXTENSIBLE SubFormat: ${subFormatTag} (only PCM supported)`);
return null;
}
} else if (audioFormat !== 1) {
console.warn(`Unsupported audio format: ${audioFormat} (only PCM=1 supported)`);
return null;
}