Extensible wave format support
btx opened this issue · comments
I'm trying to identify a WAVE PCM audio file with multiple channels (3 and more) and it seems it's not identified correctly.
Mutagen gives me invalid WAVE encoding (it returns -2
instead of 1
which is PCM).
I was using sample files downloaded here https://www.mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/Samples.html.
import mutagen
files = [
"M1F1-int16-AFsp.wav",
"addf8-Alaw-GW.wav",
"8_Channel_ID.wav",
"M1F1-float64WE-AFsp.wav",
]
for fn in files:
with open(fn, "rb") as f:
info = mutagen.File(f).info
print(f'{fn.rpartition("/")[-1]:25} encoding {info.audio_format:2}, channels {info.channels}, bits_per_sample {info.bits_per_sample:2}, sample_rate {info.sample_rate:5}')
M1F1-int16-AFsp.wav encoding 1, channels 2, bits_per_sample 12, sample_rate 8000
addf8-Alaw-GW.wav encoding 6, channels 1, bits_per_sample 8, sample_rate 8000
8_Channel_ID.wav encoding -2, channels 8, bits_per_sample 24, sample_rate 48000
M1F1-float64WE-AFsp.wav encoding -2, channels 2, bits_per_sample 64, sample_rate 8000
I have looked into mutagen code and it indeed does not seem to support extensible wave format.
I am not fluent in audio formats, so thanks a lot for any insight :)
The value is kind of correct, just that I think mutagen should read the values unsigned, and currently reads it signed. For WAVE_FORMAT_EXTENSIBLE this format info is supposed to be FFFE (65534), which if you read this as a signed value is -2.
See https://learn.microsoft.com/en-us/windows/win32/api/mmreg/ns-mmreg-waveformatextensible and https://github.com/tpn/winsdk-10/blob/master/Include/10.0.16299.0/shared/mmreg.h
#596 fixes the issue. With the patch these files properly return info.audio_format == 65534