diff --git a/OpenRA.Mods.Cnc/AudioLoaders/AudLoader.cs b/OpenRA.Mods.Cnc/AudioLoaders/AudLoader.cs index 0cadd71142..c72ed35f0c 100644 --- a/OpenRA.Mods.Cnc/AudioLoaders/AudLoader.cs +++ b/OpenRA.Mods.Cnc/AudioLoaders/AudLoader.cs @@ -20,14 +20,10 @@ namespace OpenRA.Mods.Cnc.AudioLoaders bool IsAud(Stream s) { var start = s.Position; - s.Position += 10; - var readFlag = s.ReadByte(); + s.Position += 11; var readFormat = s.ReadByte(); s.Position = start; - if (!Enum.IsDefined(typeof(SoundFlags), readFlag)) - return false; - return Enum.IsDefined(typeof(SoundFormat), readFormat); } @@ -54,7 +50,7 @@ namespace OpenRA.Mods.Cnc.AudioLoaders public sealed class AudFormat : ISoundFormat { public int Channels { get { return 1; } } - public int SampleBits { get { return 16; } } + public int SampleBits { get { return sampleBits; } } public int SampleRate { get { return sampleRate; } } public float LengthInSeconds { get { return AudReader.SoundLength(sourceStream); } } public Stream GetPCMInputStream() { return audStreamFactory(); } @@ -62,13 +58,14 @@ namespace OpenRA.Mods.Cnc.AudioLoaders readonly Stream sourceStream; readonly Func audStreamFactory; + readonly int sampleBits; readonly int sampleRate; public AudFormat(Stream stream) { sourceStream = stream; - if (!AudReader.LoadSound(stream, out audStreamFactory, out sampleRate)) + if (!AudReader.LoadSound(stream, out audStreamFactory, out sampleRate, out sampleBits)) throw new InvalidDataException(); } } diff --git a/OpenRA.Mods.Cnc/FileFormats/AudReader.cs b/OpenRA.Mods.Cnc/FileFormats/AudReader.cs index dd6ab438a6..467defdc36 100644 --- a/OpenRA.Mods.Cnc/FileFormats/AudReader.cs +++ b/OpenRA.Mods.Cnc/FileFormats/AudReader.cs @@ -49,7 +49,7 @@ namespace OpenRA.Mods.Cnc.FileFormats return (float)samples / sampleRate; } - public static bool LoadSound(Stream s, out Func result, out int sampleRate) + public static bool LoadSound(Stream s, out Func result, out int sampleRate, out int sampleBits) { result = null; var startPosition = s.Position; @@ -58,10 +58,8 @@ namespace OpenRA.Mods.Cnc.FileFormats sampleRate = s.ReadUInt16(); var dataSize = s.ReadInt32(); var outputSize = s.ReadInt32(); - var readFlag = s.ReadByte(); - if (!Enum.IsDefined(typeof(SoundFlags), readFlag)) - return false; + sampleBits = (readFlag & (int)SoundFlags._16Bit) == 0 ? 8 : 16; var readFormat = s.ReadByte(); if (!Enum.IsDefined(typeof(SoundFormat), readFormat))