Rename Adpcm to ImaAdpcm everywhere.

To avoid confusion with Microsoft ADPCM and other ADPCMs.
This commit is contained in:
reaperrr
2014-09-14 13:27:46 +02:00
parent c7c816f22e
commit fec5eb178c
3 changed files with 18 additions and 18 deletions

View File

@@ -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);
} }

View File

@@ -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);

View File

@@ -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" />