Support 8 bit .aud files.
This commit is contained in:
committed by
Paul Chote
parent
d38fe542a2
commit
9a9f58d744
@@ -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<Stream> 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Cnc.FileFormats
|
||||
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;
|
||||
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))
|
||||
|
||||
Reference in New Issue
Block a user