Support 8 bit .aud files.

This commit is contained in:
Matthias Mailänder
2020-12-14 20:30:09 +01:00
committed by Paul Chote
parent d38fe542a2
commit 9a9f58d744
2 changed files with 6 additions and 11 deletions

View File

@@ -20,14 +20,10 @@ namespace OpenRA.Mods.Cnc.AudioLoaders
bool IsAud(Stream s) bool IsAud(Stream s)
{ {
var start = s.Position; var start = s.Position;
s.Position += 10; s.Position += 11;
var readFlag = s.ReadByte();
var readFormat = s.ReadByte(); var readFormat = s.ReadByte();
s.Position = start; s.Position = start;
if (!Enum.IsDefined(typeof(SoundFlags), readFlag))
return false;
return Enum.IsDefined(typeof(SoundFormat), readFormat); return Enum.IsDefined(typeof(SoundFormat), readFormat);
} }
@@ -54,7 +50,7 @@ namespace OpenRA.Mods.Cnc.AudioLoaders
public sealed class AudFormat : ISoundFormat public sealed class AudFormat : ISoundFormat
{ {
public int Channels { get { return 1; } } 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 int SampleRate { get { return sampleRate; } }
public float LengthInSeconds { get { return AudReader.SoundLength(sourceStream); } } public float LengthInSeconds { get { return AudReader.SoundLength(sourceStream); } }
public Stream GetPCMInputStream() { return audStreamFactory(); } public Stream GetPCMInputStream() { return audStreamFactory(); }
@@ -62,13 +58,14 @@ namespace OpenRA.Mods.Cnc.AudioLoaders
readonly Stream sourceStream; readonly Stream sourceStream;
readonly Func<Stream> audStreamFactory; readonly Func<Stream> audStreamFactory;
readonly int sampleBits;
readonly int sampleRate; readonly int sampleRate;
public AudFormat(Stream stream) public AudFormat(Stream stream)
{ {
sourceStream = stream; sourceStream = stream;
if (!AudReader.LoadSound(stream, out audStreamFactory, out sampleRate)) if (!AudReader.LoadSound(stream, out audStreamFactory, out sampleRate, out sampleBits))
throw new InvalidDataException(); throw new InvalidDataException();
} }
} }

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Cnc.FileFormats
return (float)samples / sampleRate; return (float)samples / sampleRate;
} }
public static bool LoadSound(Stream s, out Func<Stream> result, out int sampleRate) public static bool LoadSound(Stream s, out Func<Stream> result, out int sampleRate, out int sampleBits)
{ {
result = null; result = null;
var startPosition = s.Position; var startPosition = s.Position;
@@ -58,10 +58,8 @@ namespace OpenRA.Mods.Cnc.FileFormats
sampleRate = s.ReadUInt16(); sampleRate = s.ReadUInt16();
var dataSize = s.ReadInt32(); var dataSize = s.ReadInt32();
var outputSize = s.ReadInt32(); var outputSize = s.ReadInt32();
var readFlag = s.ReadByte(); var readFlag = s.ReadByte();
if (!Enum.IsDefined(typeof(SoundFlags), readFlag)) sampleBits = (readFlag & (int)SoundFlags._16Bit) == 0 ? 8 : 16;
return false;
var readFormat = s.ReadByte(); var readFormat = s.ReadByte();
if (!Enum.IsDefined(typeof(SoundFormat), readFormat)) if (!Enum.IsDefined(typeof(SoundFormat), readFormat))