Make WAVE demuxer throw for format tags that it doesn't support (fixes #440), add support for reading & writing float64 PCM in WAVE

This commit is contained in:
Vanilagy
2026-07-14 17:30:50 +02:00
parent db75747533
commit 1183b542ee
2 changed files with 26 additions and 2 deletions
+1 -1
View File
@@ -799,7 +799,7 @@ export class WavOutputFormat extends OutputFormat {
getSupportedCodecs(): MediaCodec[] {
return [
...PCM_AUDIO_CODECS.filter(codec =>
['pcm-s16', 'pcm-s24', 'pcm-s32', 'pcm-f32', 'pcm-u8', 'ulaw', 'alaw'].includes(codec),
['pcm-s16', 'pcm-s24', 'pcm-s32', 'pcm-f32', 'pcm-f64', 'pcm-u8', 'ulaw', 'alaw'].includes(codec),
),
];
}
+25 -1
View File
@@ -173,6 +173,28 @@ export class WaveDemuxer extends Demuxer {
bitsPerSample = 8;
}
if (
formatTag !== WaveFormat.PCM
&& formatTag !== WaveFormat.IEEE_FLOAT
&& formatTag !== WaveFormat.ALAW
&& formatTag !== WaveFormat.MULAW
) {
throw new Error(
`Unsupported WAVE codec (format tag ${formatTag}). Only integer/float PCM, A-law, and μ-law are`
+ ` supported.`,
);
}
if (formatTag === WaveFormat.PCM && ![8, 16, 24, 32].includes(bitsPerSample)) {
throw new Error(
`Unsupported WAVE PCM bit depth (${bitsPerSample}). Only 8, 16, 24, and 32 bits are supported.`,
);
}
if (formatTag === WaveFormat.IEEE_FLOAT && ![32, 64].includes(bitsPerSample)) {
throw new Error(
`Unsupported WAVE float bit depth (${bitsPerSample}). Only 32 and 64 bits are supported.`,
);
}
this.audioInfo = {
format: formatTag,
numberOfChannels: numChannels,
@@ -322,10 +344,12 @@ export class WaveDemuxer extends Demuxer {
if (this.audioInfo.format === WaveFormat.IEEE_FLOAT) {
if (this.audioInfo.sampleSizeInBytes === 4) {
return 'pcm-f32';
} else if (this.audioInfo.sampleSizeInBytes === 8) {
return 'pcm-f64';
}
}
return null;
assert(false);
}
async getMimeType() {