Allow AUD file with sample rates other than 22050 Hz.

This commit is contained in:
RoosterDragon
2015-12-27 00:05:28 +00:00
parent 4660b7156d
commit da84f3d5ef

View File

@@ -45,7 +45,6 @@ namespace OpenRA.FileFormats
public class AudLoader : ISoundLoader public class AudLoader : ISoundLoader
{ {
static readonly int ExpectedSampleRate = 22050;
static readonly int[] IndexAdjust = { -1, -1, -1, -1, 2, 4, 6, 8 }; static readonly int[] IndexAdjust = { -1, -1, -1, -1, 2, 4, 6, 8 };
static readonly int[] StepTable = static readonly int[] StepTable =
{ {
@@ -119,19 +118,16 @@ namespace OpenRA.FileFormats
return samples / sampleRate; return samples / sampleRate;
} }
public static bool LoadSound(Stream s, out byte[] rawData) public static bool LoadSound(Stream s, out byte[] rawData, out int sampleRate)
{ {
rawData = null; rawData = null;
var 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();
var readFormat = s.ReadByte(); var readFormat = s.ReadByte();
if (sampleRate != ExpectedSampleRate)
return false;
if (!Enum.IsDefined(typeof(SoundFlags), readFlag)) if (!Enum.IsDefined(typeof(SoundFlags), readFlag))
return false; return false;
@@ -177,7 +173,7 @@ namespace OpenRA.FileFormats
try try
{ {
if (!LoadSound(stream, out rawData)) if (!LoadSound(stream, out rawData, out sampleRate))
return false; return false;
} }
catch (Exception e) catch (Exception e)
@@ -194,7 +190,6 @@ namespace OpenRA.FileFormats
channels = 1; channels = 1;
sampleBits = 16; sampleBits = 16;
sampleRate = ExpectedSampleRate;
return true; return true;
} }