From b629720675d9f25f264645595311107923e7053f Mon Sep 17 00:00:00 2001 From: Christopher Lees Date: Wed, 29 Mar 2023 10:25:29 +0100 Subject: [PATCH] Change: Make the wav parser handle some extensible WAV files --- .../Plugins/Sound.RiffWave/Plugin.Parser.cs | 59 ++++++++++++++----- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/source/Plugins/Sound.RiffWave/Plugin.Parser.cs b/source/Plugins/Sound.RiffWave/Plugin.Parser.cs index 8382d5192..b4e9e7f40 100644 --- a/source/Plugins/Sound.RiffWave/Plugin.Parser.cs +++ b/source/Plugins/Sound.RiffWave/Plugin.Parser.cs @@ -13,21 +13,30 @@ public partial class Plugin // --- structures and enumerations --- private abstract class WaveFormatEx { - internal ushort wFormatTag; + internal readonly ushort wFormatTag; internal ushort nChannels; internal uint nSamplesPerSec; internal uint nAvgBytesPerSec; internal ushort nBlockAlign; internal ushort wBitsPerSample; internal ushort cbSize; + + protected WaveFormatEx(ushort tag) + { + wFormatTag = tag; + } } private class WaveFormatPcm : WaveFormatEx { + public WaveFormatPcm(ushort tag) : base(tag) + { + } } private class WaveFormatAdPcm : WaveFormatEx { + internal struct CoefSet { internal short iCoef1; @@ -61,10 +70,24 @@ internal BlockData(int channels) 230, 230, 230, 230, 307, 409, 512, 614, 768, 614, 512, 409, 307, 230, 230, 230 }; + + public WaveFormatAdPcm(ushort tag) : base(tag) + { + } } private class WaveFormatMp3 : WaveFormatEx { + public WaveFormatMp3(ushort tag) : base(tag) + { + } + } + + private class WaveFormatExtensible : WaveFormatEx + { + public WaveFormatExtensible(ushort tag) : base(tag) + { + } } @@ -194,22 +217,25 @@ private static Sound WaveLoadFromStream(BinaryReader reader, BinaryReaderExtensi ushort wFormatTag = reader.ReadUInt16(endianness); - if (wFormatTag == 0x0001 || wFormatTag == 0x0003) - { - format = new WaveFormatPcm { wFormatTag = wFormatTag }; - } - else if (wFormatTag == 0x0002) - { - format = new WaveFormatAdPcm { wFormatTag = wFormatTag }; - } - else if (wFormatTag == 0x0050 || wFormatTag == 0x0055) - { - format = new WaveFormatMp3 { wFormatTag = wFormatTag }; - } - else + switch (wFormatTag) { - // unsupported format - throw new InvalidDataException("Unsupported wFormatTag"); + case 0x0001: + case 0x0003: + format = new WaveFormatPcm(wFormatTag); + break; + case 0x0002: + format = new WaveFormatAdPcm(wFormatTag); + break; + case 0x0050: + case 0x0055: + format = new WaveFormatMp3(wFormatTag); + break; + case 0xFFFE: + format = new WaveFormatExtensible(wFormatTag); + break; + default: + // unsupported format + throw new InvalidDataException("Unsupported wFormatTag"); } format.nChannels = reader.ReadUInt16(endianness); @@ -491,6 +517,7 @@ private static Sound ChangeBitDepth(ushort formatTag, int samplesPerSec, int byt switch (formatTag) { case 0x0001: + case 0xFFFE: switch (bytesPerSample) { case 3: