Merge pull request #6459 from reaperrr/ima-aud-style
Renamed AdpcmLoader to ImaAdpcmLoader
This commit is contained in:
@@ -36,7 +36,7 @@ namespace OpenRA.FileFormats
|
|||||||
Chunk c;
|
Chunk c;
|
||||||
c.CompressedSize = s.ReadUInt16();
|
c.CompressedSize = s.ReadUInt16();
|
||||||
c.OutputSize = s.ReadUInt16();
|
c.OutputSize = s.ReadUInt16();
|
||||||
if (0xdeaf != s.ReadUInt32())
|
if (s.ReadUInt32() != 0xdeaf)
|
||||||
throw new InvalidDataException("Chunk header is bogus");
|
throw new InvalidDataException("Chunk header is bogus");
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
@@ -45,17 +45,19 @@ namespace OpenRA.FileFormats
|
|||||||
public static class AudLoader
|
public static class AudLoader
|
||||||
{
|
{
|
||||||
static int[] indexAdjust = { -1, -1, -1, -1, 2, 4, 6, 8 };
|
static int[] indexAdjust = { -1, -1, -1, -1, 2, 4, 6, 8 };
|
||||||
static int[] stepTable = {
|
static int[] stepTable =
|
||||||
7, 8, 9, 10, 11, 12, 13, 14, 16,
|
{
|
||||||
17, 19, 21, 23, 25, 28, 31, 34, 37,
|
7, 8, 9, 10, 11, 12, 13, 14, 16,
|
||||||
41, 45, 50, 55, 60, 66, 73, 80, 88,
|
17, 19, 21, 23, 25, 28, 31, 34, 37,
|
||||||
97, 107, 118, 130, 143, 157, 173, 190, 209,
|
41, 45, 50, 55, 60, 66, 73, 80, 88,
|
||||||
230, 253, 279, 307, 337, 371, 408, 449, 494,
|
97, 107, 118, 130, 143, 157, 173, 190, 209,
|
||||||
544, 598, 658, 724, 796, 876, 963, 1060, 1166,
|
230, 253, 279, 307, 337, 371, 408, 449, 494,
|
||||||
1282, 1411, 1552, 1707, 1878, 2066, 2272, 2499, 2749,
|
544, 598, 658, 724, 796, 876, 963, 1060, 1166,
|
||||||
3024, 3327, 3660, 4026, 4428, 4871, 5358, 5894, 6484,
|
1282, 1411, 1552, 1707, 1878, 2066, 2272, 2499, 2749,
|
||||||
7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, 15289,
|
3024, 3327, 3660, 4026, 4428, 4871, 5358, 5894, 6484,
|
||||||
16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767 };
|
7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, 15289,
|
||||||
|
16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
|
||||||
|
};
|
||||||
|
|
||||||
static short DecodeSample(byte b, ref int index, ref int current)
|
static short DecodeSample(byte b, ref int index, ref int current)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,14 +13,14 @@ using System.IO;
|
|||||||
|
|
||||||
namespace OpenRA.FileFormats
|
namespace OpenRA.FileFormats
|
||||||
{
|
{
|
||||||
struct AdpcmChunk
|
struct ImaAdpcmChunk
|
||||||
{
|
{
|
||||||
public int CompressedSize;
|
public int CompressedSize;
|
||||||
public int OutputSize;
|
public int OutputSize;
|
||||||
|
|
||||||
public static AdpcmChunk Read(Stream s)
|
public static ImaAdpcmChunk Read(Stream s)
|
||||||
{
|
{
|
||||||
AdpcmChunk c;
|
ImaAdpcmChunk c;
|
||||||
c.CompressedSize = s.ReadUInt16();
|
c.CompressedSize = s.ReadUInt16();
|
||||||
c.OutputSize = s.ReadUInt16();
|
c.OutputSize = s.ReadUInt16();
|
||||||
if (s.ReadUInt32() != 0xdeaf)
|
if (s.ReadUInt32() != 0xdeaf)
|
||||||
@@ -29,7 +29,7 @@ namespace OpenRA.FileFormats
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class AdpcmLoader
|
public static class ImaAdpcmLoader
|
||||||
{
|
{
|
||||||
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 =
|
||||||
@@ -46,7 +46,7 @@ namespace OpenRA.FileFormats
|
|||||||
16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
|
16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
|
||||||
};
|
};
|
||||||
|
|
||||||
static short DecodeAdpcmSample(byte b, ref int index, ref int current)
|
static short DecodeImaAdpcmSample(byte b, ref int index, ref int current)
|
||||||
{
|
{
|
||||||
var sb = (b & 8) != 0;
|
var sb = (b & 8) != 0;
|
||||||
b &= 7;
|
b &= 7;
|
||||||
@@ -65,13 +65,13 @@ namespace OpenRA.FileFormats
|
|||||||
return (short)current;
|
return (short)current;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] LoadAdpcmSound(byte[] raw, ref int index)
|
public static byte[] LoadImaAdpcmSound(byte[] raw, ref int index)
|
||||||
{
|
{
|
||||||
var currentSample = 0;
|
var currentSample = 0;
|
||||||
return LoadAdpcmSound(raw, ref index, ref currentSample);
|
return LoadImaAdpcmSound(raw, ref index, ref currentSample);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] LoadAdpcmSound(byte[] raw, ref int index, ref int currentSample)
|
public static byte[] LoadImaAdpcmSound(byte[] raw, ref int index, ref int currentSample)
|
||||||
{
|
{
|
||||||
var s = new MemoryStream(raw);
|
var s = new MemoryStream(raw);
|
||||||
var dataSize = raw.Length;
|
var dataSize = raw.Length;
|
||||||
@@ -84,11 +84,11 @@ namespace OpenRA.FileFormats
|
|||||||
{
|
{
|
||||||
var b = s.ReadUInt8();
|
var b = s.ReadUInt8();
|
||||||
|
|
||||||
var t = DecodeAdpcmSample(b, ref index, ref currentSample);
|
var t = DecodeImaAdpcmSample(b, ref index, ref currentSample);
|
||||||
output[offset++] = (byte)t;
|
output[offset++] = (byte)t;
|
||||||
output[offset++] = (byte)(t >> 8);
|
output[offset++] = (byte)(t >> 8);
|
||||||
|
|
||||||
t = DecodeAdpcmSample((byte)(b >> 4), ref index, ref currentSample);
|
t = DecodeImaAdpcmSample((byte)(b >> 4), ref index, ref currentSample);
|
||||||
output[offset++] = (byte)t;
|
output[offset++] = (byte)t;
|
||||||
output[offset++] = (byte)(t >> 8);
|
output[offset++] = (byte)(t >> 8);
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,7 @@ namespace OpenRA.FileFormats
|
|||||||
public readonly int DataSize;
|
public readonly int DataSize;
|
||||||
public readonly byte[] RawOutput;
|
public readonly byte[] RawOutput;
|
||||||
|
|
||||||
public enum WaveType { Pcm = 0x1, Adpcm = 0x11 };
|
public enum WaveType { Pcm = 0x1, ImaAdpcm = 0x11 };
|
||||||
public static WaveType Type { get; private set; }
|
public static WaveType Type { get; private set; }
|
||||||
|
|
||||||
public WavLoader(Stream s)
|
public WavLoader(Stream s)
|
||||||
@@ -53,7 +53,7 @@ namespace OpenRA.FileFormats
|
|||||||
FmtChunkSize = s.ReadInt32();
|
FmtChunkSize = s.ReadInt32();
|
||||||
AudioFormat = s.ReadInt16();
|
AudioFormat = s.ReadInt16();
|
||||||
Type = (WaveType)AudioFormat;
|
Type = (WaveType)AudioFormat;
|
||||||
if (Type != WaveType.Pcm && Type != WaveType.Adpcm)
|
if (Type != WaveType.Pcm && Type != WaveType.ImaAdpcm)
|
||||||
throw new NotSupportedException("Compression type is not supported.");
|
throw new NotSupportedException("Compression type is not supported.");
|
||||||
Channels = s.ReadInt16();
|
Channels = s.ReadInt16();
|
||||||
SampleRate = s.ReadInt32();
|
SampleRate = s.ReadInt32();
|
||||||
@@ -84,9 +84,9 @@ namespace OpenRA.FileFormats
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Type == WaveType.Adpcm)
|
if (Type == WaveType.ImaAdpcm)
|
||||||
{
|
{
|
||||||
RawOutput = DecodeAdpcmData();
|
RawOutput = DecodeImaAdpcmData();
|
||||||
BitsPerSample = 16;
|
BitsPerSample = 16;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,7 +110,7 @@ namespace OpenRA.FileFormats
|
|||||||
return length / (channels * sampleRate * bitsPerSample);
|
return length / (channels * sampleRate * bitsPerSample);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] DecodeAdpcmData()
|
public byte[] DecodeImaAdpcmData()
|
||||||
{
|
{
|
||||||
var s = new MemoryStream(RawOutput);
|
var s = new MemoryStream(RawOutput);
|
||||||
|
|
||||||
@@ -124,7 +124,7 @@ namespace OpenRA.FileFormats
|
|||||||
var predictor = new int[Channels];
|
var predictor = new int[Channels];
|
||||||
var index = new int[Channels];
|
var index = new int[Channels];
|
||||||
|
|
||||||
// Decode each block of ADPCM data in RawOutput
|
// Decode each block of IMA ADPCM data in RawOutput
|
||||||
for (var block = 0; block < numBlocks; block++)
|
for (var block = 0; block < numBlocks; block++)
|
||||||
{
|
{
|
||||||
// Each block starts with a initial state per-channel
|
// Each block starts with a initial state per-channel
|
||||||
@@ -150,7 +150,7 @@ namespace OpenRA.FileFormats
|
|||||||
{
|
{
|
||||||
// Decode 4 bytes (to 16 bytes of output) per channel
|
// Decode 4 bytes (to 16 bytes of output) per channel
|
||||||
var chunk = s.ReadBytes(4);
|
var chunk = s.ReadBytes(4);
|
||||||
var decoded = AdpcmLoader.LoadAdpcmSound(chunk, ref index[c], ref predictor[c]);
|
var decoded = ImaAdpcmLoader.LoadImaAdpcmSound(chunk, ref index[c], ref predictor[c]);
|
||||||
|
|
||||||
// Interleave output, one sample per channel
|
// Interleave output, one sample per channel
|
||||||
var outOffsetChannel = outOffset + (2 * c);
|
var outOffsetChannel = outOffset + (2 * c);
|
||||||
|
|||||||
@@ -261,7 +261,7 @@
|
|||||||
<Compile Include="InstallUtils.cs" />
|
<Compile Include="InstallUtils.cs" />
|
||||||
<Compile Include="Manifest.cs" />
|
<Compile Include="Manifest.cs" />
|
||||||
<Compile Include="Graphics\Vertex.cs" />
|
<Compile Include="Graphics\Vertex.cs" />
|
||||||
<Compile Include="FileFormats\AdpcmLoader.cs" />
|
<Compile Include="FileFormats\ImaAdpcmLoader.cs" />
|
||||||
<Compile Include="FileFormats\AudLoader.cs" />
|
<Compile Include="FileFormats\AudLoader.cs" />
|
||||||
<Compile Include="FileFormats\Blast.cs" />
|
<Compile Include="FileFormats\Blast.cs" />
|
||||||
<Compile Include="FileFormats\Blowfish.cs" />
|
<Compile Include="FileFormats\Blowfish.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user