mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-03 13:53:53 +02:00
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:
@@ -799,7 +799,7 @@ export class WavOutputFormat extends OutputFormat {
|
|||||||
getSupportedCodecs(): MediaCodec[] {
|
getSupportedCodecs(): MediaCodec[] {
|
||||||
return [
|
return [
|
||||||
...PCM_AUDIO_CODECS.filter(codec =>
|
...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),
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,6 +173,28 @@ export class WaveDemuxer extends Demuxer {
|
|||||||
bitsPerSample = 8;
|
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 = {
|
this.audioInfo = {
|
||||||
format: formatTag,
|
format: formatTag,
|
||||||
numberOfChannels: numChannels,
|
numberOfChannels: numChannels,
|
||||||
@@ -322,10 +344,12 @@ export class WaveDemuxer extends Demuxer {
|
|||||||
if (this.audioInfo.format === WaveFormat.IEEE_FLOAT) {
|
if (this.audioInfo.format === WaveFormat.IEEE_FLOAT) {
|
||||||
if (this.audioInfo.sampleSizeInBytes === 4) {
|
if (this.audioInfo.sampleSizeInBytes === 4) {
|
||||||
return 'pcm-f32';
|
return 'pcm-f32';
|
||||||
|
} else if (this.audioInfo.sampleSizeInBytes === 8) {
|
||||||
|
return 'pcm-f64';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getMimeType() {
|
async getMimeType() {
|
||||||
|
|||||||
Reference in New Issue
Block a user