add live select pannel

This commit is contained in:
CroakFang
2023-01-20 07:13:54 +08:00
parent 3b18268252
commit a4dc2516e3
1543 changed files with 107369 additions and 9227 deletions
@@ -0,0 +1,26 @@
namespace DereTore.Exchange.Audio.HCA {
public enum ActionResult {
HasMoreData = 1,
Ok = 0,
InvalidHandle = -1,
MagicNotMatch = -2,
AlreadyClosed = -3,
InvalidParameter = -4,
InvalidStage = -5,
FileOpFailed = -6,
InvalidFileProp = -7,
InvalidOperation = -8,
DecodeFailed = -9,
BufferTooSmall = -10,
ChecksumNotMatch = -11,
InvalidInternalState = -12,
AthInitFailed = -13,
CiphInitFailed = -14,
StateOutOfRange = -15,
NotImplemented = -16,
DecodeAlreadyCompleted = -17,
InvalidFieldValue = -18
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0be710beae9c6684f8b587f3e2906e3c
timeCreated: 1531897074
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,92 @@
using DereTore.Common;
namespace DereTore.Exchange.Audio.HCA {
internal sealed class Ath {
public bool Initialize(uint type, uint key) {
switch (type) {
case 0:
Init0();
break;
case 1:
Init1(key);
break;
default:
return false;
}
return true;
}
public byte[] Table
{
get
{
return _table;
}
}
private void Init0() {
_table.ZeroMem();
}
private void Init1(uint key) {
for (uint i = 0, v = 0; i < _table.Length; ++i, v += key) {
uint index = v >> 13;
if (index > 0x28e) {
for (; i < _table.Length; ++i) {
_table[i] = 0xff;
}
break;
}
_table[i] = AthInitList[index];
}
}
private readonly byte[] _table = new byte[0x80];
private static readonly byte[] AthInitList = new byte[] {
0x78, 0x5f, 0x56, 0x51, 0x4e, 0x4c, 0x4b, 0x49, 0x48, 0x48, 0x47, 0x46, 0x46, 0x45, 0x45, 0x45,
0x44, 0x44, 0x44, 0x44, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
0x42, 0x42, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
0x3f, 0x3f, 0x3f, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d,
0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c,
0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3f,
0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
0x3f, 0x3f, 0x3f, 0x3f, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x43, 0x43, 0x43,
0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x44, 0x44,
0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x45, 0x45, 0x45, 0x45,
0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46,
0x46, 0x46, 0x47, 0x47, 0x47, 0x47, 0x47, 0x47, 0x47, 0x47, 0x47, 0x47, 0x48, 0x48, 0x48, 0x48,
0x48, 0x48, 0x48, 0x48, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x4a, 0x4a, 0x4a, 0x4a,
0x4a, 0x4a, 0x4a, 0x4a, 0x4b, 0x4b, 0x4b, 0x4b, 0x4b, 0x4b, 0x4b, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,
0x4c, 0x4d, 0x4d, 0x4d, 0x4d, 0x4d, 0x4d, 0x4e, 0x4e, 0x4e, 0x4e, 0x4e, 0x4e, 0x4f, 0x4f, 0x4f,
0x4f, 0x4f, 0x4f, 0x50, 0x50, 0x50, 0x50, 0x50, 0x51, 0x51, 0x51, 0x51, 0x51, 0x52, 0x52, 0x52,
0x52, 0x52, 0x53, 0x53, 0x53, 0x53, 0x54, 0x54, 0x54, 0x54, 0x54, 0x55, 0x55, 0x55, 0x55, 0x56,
0x56, 0x56, 0x56, 0x57, 0x57, 0x57, 0x57, 0x57, 0x58, 0x58, 0x58, 0x59, 0x59, 0x59, 0x59, 0x5a,
0x5a, 0x5a, 0x5a, 0x5b, 0x5b, 0x5b, 0x5b, 0x5c, 0x5c, 0x5c, 0x5d, 0x5d, 0x5d, 0x5d, 0x5e, 0x5e,
0x5e, 0x5f, 0x5f, 0x5f, 0x60, 0x60, 0x60, 0x61, 0x61, 0x61, 0x61, 0x62, 0x62, 0x62, 0x63, 0x63,
0x63, 0x64, 0x64, 0x64, 0x65, 0x65, 0x66, 0x66, 0x66, 0x67, 0x67, 0x67, 0x68, 0x68, 0x68, 0x69,
0x69, 0x6a, 0x6a, 0x6a, 0x6b, 0x6b, 0x6b, 0x6c, 0x6c, 0x6d, 0x6d, 0x6d, 0x6e, 0x6e, 0x6f, 0x6f,
0x70, 0x70, 0x70, 0x71, 0x71, 0x72, 0x72, 0x73, 0x73, 0x73, 0x74, 0x74, 0x75, 0x75, 0x76, 0x76,
0x77, 0x77, 0x78, 0x78, 0x78, 0x79, 0x79, 0x7a, 0x7a, 0x7b, 0x7b, 0x7c, 0x7c, 0x7d, 0x7d, 0x7e,
0x7e, 0x7f, 0x7f, 0x80, 0x80, 0x81, 0x81, 0x82, 0x83, 0x83, 0x84, 0x84, 0x85, 0x85, 0x86, 0x86,
0x87, 0x88, 0x88, 0x89, 0x89, 0x8a, 0x8a, 0x8b, 0x8c, 0x8c, 0x8d, 0x8d, 0x8e, 0x8f, 0x8f, 0x90,
0x90, 0x91, 0x92, 0x92, 0x93, 0x94, 0x94, 0x95, 0x95, 0x96, 0x97, 0x97, 0x98, 0x99, 0x99, 0x9a,
0x9b, 0x9b, 0x9c, 0x9d, 0x9d, 0x9e, 0x9f, 0xa0, 0xa0, 0xa1, 0xa2, 0xa2, 0xa3, 0xa4, 0xa5, 0xa5,
0xa6, 0xa7, 0xa7, 0xa8, 0xa9, 0xaa, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xae, 0xaf, 0xb0, 0xb1, 0xb1,
0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
0xc0, 0xc1, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xc9, 0xca, 0xcb, 0xcc, 0xcd,
0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd,
0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xed, 0xee,
0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xff, 0xff,
};
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 40b066e970eebc54bbe874aae6921f4a
timeCreated: 1531897075
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,28 @@
namespace DereTore.Exchange.Audio.HCA {
public struct AudioParams {
/// <summary>
/// 0 = play as if it is a normal sequential audio.
/// </summary>
public uint SimulatedLoopCount { get; set; }
/// <summary>
/// </summary>
/// <remarks>
/// When applied to an HCA audio with a loop range, <see cref="OutputWaveHeader"/> must be set to <code>false</code>.
/// Otherwise an invalid wave header will be generated.
/// </remarks>
public bool InfiniteLoop { get; set; }
public bool OutputWaveHeader { get; set; }
public static AudioParams CreateDefault() {
return new AudioParams {
InfiniteLoop = false,
SimulatedLoopCount = 0,
OutputWaveHeader = true
};
}
public static readonly AudioParams Default = CreateDefault();
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4afe91a6d5d0cff4dbb131f20c16410b
timeCreated: 1531897075
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,299 @@
using System;
using System.Runtime.InteropServices;
using DereTore.Common;
using System.Linq.Expressions;
namespace DereTore.Exchange.Audio.HCA {
[StructLayout(LayoutKind.Sequential, Pack = 1)]
internal struct Channel {
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.R8, SizeConst = 0x80)]
public float[] Block;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.R8, SizeConst = 0x80)]
public float[] Base;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.U1, SizeConst = 0x80)]
public byte[] Value;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.U1, SizeConst = 0x80)]
public byte[] Scale;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.U1, SizeConst = 8)]
public byte[] Value2;
[MarshalAs(UnmanagedType.I4)]
public int Type;
// Original type: public char *
[MarshalAs(UnmanagedType.U4)]
public uint Value3;
public uint Count;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.R8, SizeConst = 0x80)]
public float[] Wav1;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.R8, SizeConst = 0x80)]
public float[] Wav2;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.R8, SizeConst = 0x80)]
public float[] Wav3;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.R8, SizeConst = 8 * 0x80)]
public float[] Wave;
public static string NameOf<T>(Expression<Func<T>> e)
{
return ((MemberExpression)e.Body).Member.Name;
}
public static Channel CreateDefault() {
var v = default(Channel);
v.Block = new float[0x80];
v.Base = new float[0x80];
v.Value = new byte[0x80];
v.Scale = new byte[0x80];
v.Value2 = new byte[8];
v.Type = 0;
v.Value3 = 0;
v.Count = 0;
v.Wav1 = new float[0x80];
v.Wav2 = new float[0x80];
v.Wav3 = new float[0x80];
v.Wave = new float[8 * 0x80];
return v;
}
public void Decode1(DataBits data, uint a, int b, byte[] ath) {
int v = data.GetBit(3);
if (v >= 6) {
for (uint i = 0; i < Count; ++i) {
Value[i] = (byte)data.GetBit(6);
}
} else if (v != 0) {
int v1 = data.GetBit(6);
int v2 = (1 << v) - 1;
int v3 = v2 >> 1;
Value[0] = (byte)v1;
for (uint i = 1; i < Count; ++i) {
int v4 = data.GetBit(v);
if (v4 != v2) {
v1 += v4 - v3;
} else {
v1 = data.GetBit(6);
}
Value[i] = (byte)v1;
}
} else {
Value.ZeroMem();
}
if (Type == 2) {
v = data.CheckBit(4);
Value2[0] = (byte)v;
if (v < 15) {
for (var i = 0; i < 8; ++i) {
Value2[i] = (byte)data.GetBit(4);
}
}
} else {
for (uint i = 0; i < a; ++i) {
//Value3[i] = (byte)data.GetBit(6);
SetValue3(i, (byte)data.GetBit(6));
}
}
for (uint i = 0; i < Count; ++i) {
v = Value[i];
if (v != 0) {
v = (int)(ath[i] + ((b + i) >> 8) - ((v * 5) >> 1) + 1);
if (v < 0) {
v = 15;
} else if (v >= 0x39) {
v = 1;
} else {
v = ChannelTables.Decode1ScaleList[v];
}
}
Scale[i] = (byte)v;
}
for (var i = Count; i < Scale.Length; ++i) {
Scale[i] = 0;
}
for (uint i = 0; i < Count; ++i) {
Base[i] = ChannelTables.Decode1ValueSingle[Value[i]] * ChannelTables.Decode1ScaleSingle[Scale[i]];
}
}
public void Decode2(DataBits data) {
for (uint i = 0; i < Count; ++i) {
float f;
int s = Scale[i];
int bitSize = ChannelTables.Decode2List1[s];
int v = data.GetBit(bitSize);
if (s < 8) {
v += s << 4;
data.AddBit(ChannelTables.Decode2List2[v] - bitSize);
f = ChannelTables.Decode2List3[v];
} else {
v = (1 - ((v & 1) << 1)) * (v >> 1);
if (v == 0) {
data.AddBit(-1);
}
f = v;
}
Block[i] = Base[i] * f;
}
for (var i = Count; i < Block.Length; ++i) {
Block[i] = 0;
}
}
public void Decode3(uint a, uint b, uint c, uint d) {
if (Type != 2 && b != 0) {
float[] listFloat = ChannelTables.Decode3ListSingle;
int offset = ChannelTables.Decode3ListOffset;
for (uint i = 0, k = c, l = c - 1; i < a; ++i) {
for (uint j = 0; j < b && k < d; ++j, --l) {
Block[k++] = listFloat[GetValue3(i) - Value[l] + offset] * Block[l];
}
}
Block[0x80 - 1] = 0;
}
}
public static void Decode4(ref Channel @this, ref Channel next, int index, uint a, uint b, uint c) {
if (@this.Type == 1 && c != 0) {
var f1 = ChannelTables.Decode4ListSingle[next.Value2[index]];
var f2 = f1 - 2f;
float[] s = @this.Block;
float[] d = next.Block;
int sIndex, dIndex;
sIndex = (int)b;
dIndex = (int)b;
for (uint i = 0; i < a; ++i) {
// Don't know why, but it just happened.
// See se_live_flic_perfect.hca
// original:
/*
* (no 'break')
* d[dIndex++] = s[sIndex] * f2;
* s[sIndex++] = s[sIndex] * f1;
*/
if (sIndex >= s.Length || dIndex >= d.Length) {
break;
}
d[dIndex] = s[sIndex] * f2;
dIndex++;
s[sIndex] = s[sIndex] * f1;
sIndex++;
}
}
}
public void Decode5(int index) {
float[] s;
float[] d;
s = Block;
d = Wav1;
int sIndex = 0, dIndex = 0;
int s1Index, s2Index;
for (int i = 0, count1 = 1, count2 = 0x40; i < 7; ++i, count1 <<= 1, count2 >>= 1) {
int dIndex1 = dIndex, dIndex2 = dIndex + count2;
for (int j = 0; j < count1; ++j) {
for (int k = 0; k < count2; ++k) {
float a = s[sIndex++];
float b = s[sIndex++];
d[dIndex1++] = b + a;
d[dIndex2++] = a - b;
}
dIndex1 += count2;
dIndex2 += count2;
}
sIndex -= 0x80;
HcaHelper.Exchange(ref sIndex, ref dIndex);
HcaHelper.Exchange(ref s, ref d);
}
s = Wav1;
d = Block;
sIndex = dIndex = 0;
for (int i = 0, count1 = 0x40, count2 = 1; i < 7; ++i, count1 >>= 1, count2 <<= 1) {
// The original array is a 2-rank array, [7][0x40].
int list1FloatIndex = i * 0x40;
// The original array is a 2-rank array, [7][0x40].
int list2FloatIndex = i * 0x40;
s1Index = sIndex;
s2Index = sIndex + count2;
int dIndex1 = dIndex;
int dIndex2 = dIndex + count2 * 2 - 1;
for (int j = 0; j < count1; ++j) {
for (int k = 0; k < count2; ++k) {
float fa = s[s1Index++];
float fb = s[s2Index++];
float fc = ChannelTables.Decode5List1Single[list1FloatIndex++];
float fd = ChannelTables.Decode5List2Single[list2FloatIndex++];
d[dIndex1++] = fa * fc - fb * fd;
d[dIndex2--] = fa * fd + fb * fc;
}
s1Index += count2;
s2Index += count2;
dIndex1 += count2;
dIndex2 += count2 * 3;
}
HcaHelper.Exchange(ref sIndex, ref dIndex);
HcaHelper.Exchange(ref s, ref d);
}
d = Wav2;
for (int i = 0; i < 0x80; ++i) {
d[i] = s[i];
}
s = ChannelTables.Decode5List3Single;
sIndex = 0;
d = Wave;
// The original array is [8][0x80].
dIndex = index * 0x80;
float[] s1 = Wav2;
s1Index = 0x40;
float[] s2 = Wav3;
s2Index = 0;
for (int i = 0; i < 0x40; ++i) {
d[dIndex++] = s1[s1Index++] * s[sIndex++] + s2[s2Index++];
}
for (int i = 0; i < 0x40; ++i) {
d[dIndex++] = s[sIndex++] * s1[--s1Index] - s2[s2Index++];
}
s1 = Wav2;
s2 = Wav3;
s1Index = 0x40 - 1;
s2Index = 0;
for (int i = 0; i < 0x40; ++i) {
s2[s2Index++] = s1[s1Index--] * s[--sIndex];
}
for (int i = 0; i < 0x40; ++i) {
s2[s2Index++] = s[--sIndex] * s1[++s1Index];
}
}
private byte GetValue3(int refIndex) {
int index = (int)(refIndex + Value3);
if (0 <= index && index < 0x80) {
return Value[index];
} else if (0x80 <= index && index < 0x80 + 0x80) {
return Scale[index - 0x80];
} else {
throw new ArgumentOutOfRangeException(NameOf(() => refIndex));
}
}
private byte GetValue3(uint refIndex) {
var index = refIndex + Value3;
if (index < 0x80) {
return Value[index];
} else if (index < 0x80 + 0x80) {
return Scale[index - 0x80];
} else {
throw new ArgumentOutOfRangeException(NameOf(() => refIndex));
}
}
private void SetValue3(int refIndex, byte value) {
Value[refIndex + Value3] = value;
}
private void SetValue3(uint refIndex, byte value) {
Value[refIndex + Value3] = value;
}
private void SetValue3(byte value) {
Value[Value3] = value;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 216edc83c8bc18847a421400ad346fce
timeCreated: 1531897074
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,333 @@
namespace DereTore.Exchange.Audio.HCA {
internal static class ChannelTables {
public static void TranslateTables() {
_decode1ValueSingle = new float[_decode1ValueUInt.Length];
for (var i = 0; i < _decode1ValueSingle.Length; ++i) {
_decode1ValueSingle[i] = HcaHelper.UInt32ToSingleBits(_decode1ValueUInt[i]);
}
_decode1ScaleSingle = new float[_decode1ScaleUInt.Length];
for (var i = 0; i < _decode1ScaleSingle.Length; ++i) {
_decode1ScaleSingle[i] = HcaHelper.UInt32ToSingleBits(_decode1ScaleUInt[i]);
}
_decode3ListSingle = new float[_decode3ListUInt[0].Length + _decode3ListUInt[1].Length];
for (var i = 0; i < _decode3ListUInt[0].Length; ++i) {
_decode3ListSingle[i] = HcaHelper.UInt32ToSingleBits(_decode3ListUInt[0][i]);
}
for (var i = 0; i < _decode3ListUInt[1].Length; ++i) {
_decode3ListSingle[i + _decode3ListOffset] = HcaHelper.UInt32ToSingleBits(_decode3ListUInt[1][i]);
}
_decode4ListSingle = new float[_decode4ListUInt.Length];
for (var i = 0; i < _decode4ListSingle.Length; ++i) {
_decode4ListSingle[i] = HcaHelper.UInt32ToSingleBits(_decode4ListUInt[i]);
}
_decode5List1Single = new float[_decode5List1UInt.Length];
for (var i = 0; i < _decode5List1Single.Length; ++i) {
_decode5List1Single[i] = HcaHelper.UInt32ToSingleBits(_decode5List1UInt[i]);
}
_decode5List2Single = new float[_decode5List2UInt.Length];
for (var i = 0; i < _decode5List2Single.Length; ++i) {
_decode5List2Single[i] = HcaHelper.UInt32ToSingleBits(_decode5List2UInt[i]);
}
_decode5List3Single = new float[_decode5List3UInt.Length];
for (var i = 0; i < _decode5List3Single.Length; ++i) {
_decode5List3Single[i] = HcaHelper.UInt32ToSingleBits(_decode5List3UInt[i]);
}
}
public static byte[] Decode1ScaleList { get { return _decode1ScaleList; } }
public static float[] Decode1ValueSingle { get { return _decode1ValueSingle; } }
public static float[] Decode1ScaleSingle { get { return _decode1ScaleSingle; } }
public static byte[] Decode2List1 { get { return _decode2List1; } }
public static byte[] Decode2List2 { get { return _decode2List2; } }
public static float[] Decode2List3 { get { return _decode2List3; } }
public static float[] Decode3ListSingle { get { return _decode3ListSingle; } }
public static int Decode3ListOffset { get { return _decode3ListOffset; } }
public static float[] Decode4ListSingle { get { return _decode4ListSingle; } }
public static float[] Decode5List1Single { get { return _decode5List1Single; } }
public static float[] Decode5List2Single { get { return _decode5List2Single; } }
public static float[] Decode5List3Single { get { return _decode5List3Single; } }
private static readonly byte[] _decode1ScaleList = {
// v2.0
0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0D, 0x0D,
0x0D, 0x0D, 0x0D, 0x0D, 0x0C, 0x0C, 0x0C, 0x0C,
0x0C, 0x0C, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B,
0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x09,
0x09, 0x09, 0x09, 0x09, 0x09, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x07, 0x06, 0x06, 0x05, 0x04,
0x04, 0x04, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// v1.3
//0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0D,0x0D,
//0x0D,0x0D,0x0D,0x0D,0x0C,0x0C,0x0C,0x0C,
//0x0C,0x0C,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,
//0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x0A,0x09,
//0x09,0x09,0x09,0x09,0x09,0x08,0x08,0x08,
//0x08,0x08,0x08,0x07,0x06,0x06,0x05,0x04,
//0x04,0x04,0x03,0x03,0x03,0x02,0x02,0x02,
//0x02,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
};
private static readonly uint[] _decode1ValueUInt = {
0x342A8D26, 0x34633F89, 0x3497657D, 0x34C9B9BE, 0x35066491, 0x353311C4, 0x356E9910, 0x359EF532,
0x35D3CCF1, 0x360D1ADF, 0x363C034A, 0x367A83B3, 0x36A6E595, 0x36DE60F5, 0x371426FF, 0x3745672A,
0x37838359, 0x37AF3B79, 0x37E97C38, 0x381B8D3A, 0x384F4319, 0x388A14D5, 0x38B7FBF0, 0x38F5257D,
0x3923520F, 0x39599D16, 0x3990FA4D, 0x39C12C4D, 0x3A00B1ED, 0x3A2B7A3A, 0x3A647B6D, 0x3A9837F0,
0x3ACAD226, 0x3B071F62, 0x3B340AAF, 0x3B6FE4BA, 0x3B9FD228, 0x3BD4F35B, 0x3C0DDF04, 0x3C3D08A4,
0x3C7BDFED, 0x3CA7CD94, 0x3CDF9613, 0x3D14F4F0, 0x3D467991, 0x3D843A29, 0x3DB02F0E, 0x3DEAC0C7,
0x3E1C6573, 0x3E506334, 0x3E8AD4C6, 0x3EB8FBAF, 0x3EF67A41, 0x3F243516, 0x3F5ACB94, 0x3F91C3D3,
0x3FC238D2, 0x400164D2, 0x402C6897, 0x4065B907, 0x40990B88, 0x40CBEC15, 0x4107DB35, 0x413504F3,
};
private static float[] _decode1ValueSingle;
private static readonly uint[] _decode1ScaleUInt = {
0x00000000, 0x3F2AAAAB, 0x3ECCCCCD, 0x3E924925, 0x3E638E39, 0x3E3A2E8C, 0x3E1D89D9, 0x3E088889,
0x3D842108, 0x3D020821, 0x3C810204, 0x3C008081, 0x3B804020, 0x3B002008, 0x3A801002, 0x3A000801,
};
private static float[] _decode1ScaleSingle;
private static readonly byte[] _decode2List1 = {
0, 2, 3, 3, 4, 4, 4, 4, 5, 6, 7, 8, 9, 10, 11, 12,
};
private static readonly byte[] _decode2List2 = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 2, 2, 2, 2, 2, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0,
2, 2, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4,
3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
};
private static readonly float[] _decode2List3 = {
+0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0,
+0, +0, +1, -1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0,
+0, +0, +1, +1, -1, -1, +2, -2, +0, +0, +0, +0, +0, +0, +0, +0,
+0, +0, +1, -1, +2, -2, +3, -3, +0, +0, +0, +0, +0, +0, +0, +0,
+0, +0, +1, +1, -1, -1, +2, +2, -2, -2, +3, +3, -3, -3, +4, -4,
+0, +0, +1, +1, -1, -1, +2, +2, -2, -2, +3, -3, +4, -4, +5, -5,
+0, +0, +1, +1, -1, -1, +2, -2, +3, -3, +4, -4, +5, -5, +6, -6,
+0, +0, +1, -1, +2, -2, +3, -3, +4, -4, +5, -5, +6, -6, +7, -7,
};
private static readonly uint[][] _decode3ListUInt = {
new uint[] {
0x00000000, 0x00000000, 0x32A0B051, 0x32D61B5E, 0x330EA43A, 0x333E0F68, 0x337D3E0C, 0x33A8B6D5,
0x33E0CCDF, 0x3415C3FF, 0x34478D75, 0x3484F1F6, 0x34B123F6, 0x34EC0719, 0x351D3EDA, 0x355184DF,
0x358B95C2, 0x35B9FCD2, 0x35F7D0DF, 0x36251958, 0x365BFBB8, 0x36928E72, 0x36C346CD, 0x370218AF,
0x372D583F, 0x3766F85B, 0x3799E046, 0x37CD078C, 0x3808980F, 0x38360094, 0x38728177, 0x38A18FAF,
0x38D744FD, 0x390F6A81, 0x393F179A, 0x397E9E11, 0x39A9A15B, 0x39E2055B, 0x3A16942D, 0x3A48A2D8,
0x3A85AAC3, 0x3AB21A32, 0x3AED4F30, 0x3B1E196E, 0x3B52A81E, 0x3B8C57CA, 0x3BBAFF5B, 0x3BF9295A,
0x3C25FED7, 0x3C5D2D82, 0x3C935A2B, 0x3CC4563F, 0x3D02CD87, 0x3D2E4934, 0x3D68396A, 0x3D9AB62B,
0x3DCE248C, 0x3E0955EE, 0x3E36FD92, 0x3E73D290, 0x3EA27043, 0x3ED87039, 0x3F1031DC, 0x3F40213B,
},
new uint[] {
0x3F800000, 0x3FAA8D26, 0x3FE33F89, 0x4017657D, 0x4049B9BE, 0x40866491, 0x40B311C4, 0x40EE9910,
0x411EF532, 0x4153CCF1, 0x418D1ADF, 0x41BC034A, 0x41FA83B3, 0x4226E595, 0x425E60F5, 0x429426FF,
0x42C5672A, 0x43038359, 0x432F3B79, 0x43697C38, 0x439B8D3A, 0x43CF4319, 0x440A14D5, 0x4437FBF0,
0x4475257D, 0x44A3520F, 0x44D99D16, 0x4510FA4D, 0x45412C4D, 0x4580B1ED, 0x45AB7A3A, 0x45E47B6D,
0x461837F0, 0x464AD226, 0x46871F62, 0x46B40AAF, 0x46EFE4BA, 0x471FD228, 0x4754F35B, 0x478DDF04,
0x47BD08A4, 0x47FBDFED, 0x4827CD94, 0x485F9613, 0x4894F4F0, 0x48C67991, 0x49043A29, 0x49302F0E,
0x496AC0C7, 0x499C6573, 0x49D06334, 0x4A0AD4C6, 0x4A38FBAF, 0x4A767A41, 0x4AA43516, 0x4ADACB94,
0x4B11C3D3, 0x4B4238D2, 0x4B8164D2, 0x4BAC6897, 0x4BE5B907, 0x4C190B88, 0x4C4BEC15, 0x00000000,
}
};
private static float[] _decode3ListSingle;
private static readonly int _decode3ListOffset = _decode3ListUInt[0].Length;
private static readonly uint[] _decode4ListUInt = {
// v2.0
0x40000000, 0x3FEDB6DB, 0x3FDB6DB7, 0x3FC92492, 0x3FB6DB6E, 0x3FA49249, 0x3F924925, 0x3F800000,
0x3F5B6DB7, 0x3F36DB6E, 0x3F124925, 0x3EDB6DB7, 0x3E924925, 0x3E124925, 0x00000000, 0x00000000,
0x00000000, 0x32A0B051, 0x32D61B5E, 0x330EA43A, 0x333E0F68, 0x337D3E0C, 0x33A8B6D5, 0x33E0CCDF,
0x3415C3FF, 0x34478D75, 0x3484F1F6, 0x34B123F6, 0x34EC0719, 0x351D3EDA, 0x355184DF, 0x358B95C2,
0x35B9FCD2, 0x35F7D0DF, 0x36251958, 0x365BFBB8, 0x36928E72, 0x36C346CD, 0x370218AF, 0x372D583F,
0x3766F85B, 0x3799E046, 0x37CD078C, 0x3808980F, 0x38360094, 0x38728177, 0x38A18FAF, 0x38D744FD,
0x390F6A81, 0x393F179A, 0x397E9E11, 0x39A9A15B, 0x39E2055B, 0x3A16942D, 0x3A48A2D8, 0x3A85AAC3,
0x3AB21A32, 0x3AED4F30, 0x3B1E196E, 0x3B52A81E, 0x3B8C57CA, 0x3BBAFF5B, 0x3BF9295A, 0x3C25FED7,
//↓この2行要らない?
0x3C5D2D82, 0x3C935A2B, 0x3CC4563F, 0x3D02CD87, 0x3D2E4934, 0x3D68396A, 0x3D9AB62B, 0x3DCE248C,
0x3E0955EE, 0x3E36FD92, 0x3E73D290, 0x3EA27043, 0x3ED87039, 0x3F1031DC, 0x3F40213B, 0x00000000,
// v1.3
//0x40000000,0x3FEDB6DB,0x3FDB6DB7,0x3FC92492,0x3FB6DB6E,0x3FA49249,0x3F924925,0x3F800000,
//0x3F5B6DB7,0x3F36DB6E,0x3F124925,0x3EDB6DB7,0x3E924925,0x3E124925,0x00000000,0x00000000,
};
private static float[] _decode4ListSingle;
private static readonly uint[] _decode5List1UInt = {
0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75,
0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75,
0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75,
0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75,
0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75,
0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75,
0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75,
0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75, 0x3DA73D75,
0x3F7B14BE, 0x3F54DB31, 0x3F7B14BE, 0x3F54DB31, 0x3F7B14BE, 0x3F54DB31, 0x3F7B14BE, 0x3F54DB31,
0x3F7B14BE, 0x3F54DB31, 0x3F7B14BE, 0x3F54DB31, 0x3F7B14BE, 0x3F54DB31, 0x3F7B14BE, 0x3F54DB31,
0x3F7B14BE, 0x3F54DB31, 0x3F7B14BE, 0x3F54DB31, 0x3F7B14BE, 0x3F54DB31, 0x3F7B14BE, 0x3F54DB31,
0x3F7B14BE, 0x3F54DB31, 0x3F7B14BE, 0x3F54DB31, 0x3F7B14BE, 0x3F54DB31, 0x3F7B14BE, 0x3F54DB31,
0x3F7B14BE, 0x3F54DB31, 0x3F7B14BE, 0x3F54DB31, 0x3F7B14BE, 0x3F54DB31, 0x3F7B14BE, 0x3F54DB31,
0x3F7B14BE, 0x3F54DB31, 0x3F7B14BE, 0x3F54DB31, 0x3F7B14BE, 0x3F54DB31, 0x3F7B14BE, 0x3F54DB31,
0x3F7B14BE, 0x3F54DB31, 0x3F7B14BE, 0x3F54DB31, 0x3F7B14BE, 0x3F54DB31, 0x3F7B14BE, 0x3F54DB31,
0x3F7B14BE, 0x3F54DB31, 0x3F7B14BE, 0x3F54DB31, 0x3F7B14BE, 0x3F54DB31, 0x3F7B14BE, 0x3F54DB31,
0x3F7EC46D, 0x3F74FA0B, 0x3F61C598, 0x3F45E403, 0x3F7EC46D, 0x3F74FA0B, 0x3F61C598, 0x3F45E403,
0x3F7EC46D, 0x3F74FA0B, 0x3F61C598, 0x3F45E403, 0x3F7EC46D, 0x3F74FA0B, 0x3F61C598, 0x3F45E403,
0x3F7EC46D, 0x3F74FA0B, 0x3F61C598, 0x3F45E403, 0x3F7EC46D, 0x3F74FA0B, 0x3F61C598, 0x3F45E403,
0x3F7EC46D, 0x3F74FA0B, 0x3F61C598, 0x3F45E403, 0x3F7EC46D, 0x3F74FA0B, 0x3F61C598, 0x3F45E403,
0x3F7EC46D, 0x3F74FA0B, 0x3F61C598, 0x3F45E403, 0x3F7EC46D, 0x3F74FA0B, 0x3F61C598, 0x3F45E403,
0x3F7EC46D, 0x3F74FA0B, 0x3F61C598, 0x3F45E403, 0x3F7EC46D, 0x3F74FA0B, 0x3F61C598, 0x3F45E403,
0x3F7EC46D, 0x3F74FA0B, 0x3F61C598, 0x3F45E403, 0x3F7EC46D, 0x3F74FA0B, 0x3F61C598, 0x3F45E403,
0x3F7EC46D, 0x3F74FA0B, 0x3F61C598, 0x3F45E403, 0x3F7EC46D, 0x3F74FA0B, 0x3F61C598, 0x3F45E403,
0x3F7FB10F, 0x3F7D3AAC, 0x3F7853F8, 0x3F710908, 0x3F676BD8, 0x3F5B941A, 0x3F4D9F02, 0x3F3DAEF9,
0x3F7FB10F, 0x3F7D3AAC, 0x3F7853F8, 0x3F710908, 0x3F676BD8, 0x3F5B941A, 0x3F4D9F02, 0x3F3DAEF9,
0x3F7FB10F, 0x3F7D3AAC, 0x3F7853F8, 0x3F710908, 0x3F676BD8, 0x3F5B941A, 0x3F4D9F02, 0x3F3DAEF9,
0x3F7FB10F, 0x3F7D3AAC, 0x3F7853F8, 0x3F710908, 0x3F676BD8, 0x3F5B941A, 0x3F4D9F02, 0x3F3DAEF9,
0x3F7FB10F, 0x3F7D3AAC, 0x3F7853F8, 0x3F710908, 0x3F676BD8, 0x3F5B941A, 0x3F4D9F02, 0x3F3DAEF9,
0x3F7FB10F, 0x3F7D3AAC, 0x3F7853F8, 0x3F710908, 0x3F676BD8, 0x3F5B941A, 0x3F4D9F02, 0x3F3DAEF9,
0x3F7FB10F, 0x3F7D3AAC, 0x3F7853F8, 0x3F710908, 0x3F676BD8, 0x3F5B941A, 0x3F4D9F02, 0x3F3DAEF9,
0x3F7FB10F, 0x3F7D3AAC, 0x3F7853F8, 0x3F710908, 0x3F676BD8, 0x3F5B941A, 0x3F4D9F02, 0x3F3DAEF9,
0x3F7FEC43, 0x3F7F4E6D, 0x3F7E1324, 0x3F7C3B28, 0x3F79C79D, 0x3F76BA07, 0x3F731447, 0x3F6ED89E,
0x3F6A09A7, 0x3F64AA59, 0x3F5EBE05, 0x3F584853, 0x3F514D3D, 0x3F49D112, 0x3F41D870, 0x3F396842,
0x3F7FEC43, 0x3F7F4E6D, 0x3F7E1324, 0x3F7C3B28, 0x3F79C79D, 0x3F76BA07, 0x3F731447, 0x3F6ED89E,
0x3F6A09A7, 0x3F64AA59, 0x3F5EBE05, 0x3F584853, 0x3F514D3D, 0x3F49D112, 0x3F41D870, 0x3F396842,
0x3F7FEC43, 0x3F7F4E6D, 0x3F7E1324, 0x3F7C3B28, 0x3F79C79D, 0x3F76BA07, 0x3F731447, 0x3F6ED89E,
0x3F6A09A7, 0x3F64AA59, 0x3F5EBE05, 0x3F584853, 0x3F514D3D, 0x3F49D112, 0x3F41D870, 0x3F396842,
0x3F7FEC43, 0x3F7F4E6D, 0x3F7E1324, 0x3F7C3B28, 0x3F79C79D, 0x3F76BA07, 0x3F731447, 0x3F6ED89E,
0x3F6A09A7, 0x3F64AA59, 0x3F5EBE05, 0x3F584853, 0x3F514D3D, 0x3F49D112, 0x3F41D870, 0x3F396842,
0x3F7FFB11, 0x3F7FD397, 0x3F7F84AB, 0x3F7F0E58, 0x3F7E70B0, 0x3F7DABCC, 0x3F7CBFC9, 0x3F7BACCD,
0x3F7A7302, 0x3F791298, 0x3F778BC5, 0x3F75DEC6, 0x3F740BDD, 0x3F721352, 0x3F6FF573, 0x3F6DB293,
0x3F6B4B0C, 0x3F68BF3C, 0x3F660F88, 0x3F633C5A, 0x3F604621, 0x3F5D2D53, 0x3F59F26A, 0x3F5695E5,
0x3F531849, 0x3F4F7A1F, 0x3F4BBBF8, 0x3F47DE65, 0x3F43E200, 0x3F3FC767, 0x3F3B8F3B, 0x3F373A23,
0x3F7FFB11, 0x3F7FD397, 0x3F7F84AB, 0x3F7F0E58, 0x3F7E70B0, 0x3F7DABCC, 0x3F7CBFC9, 0x3F7BACCD,
0x3F7A7302, 0x3F791298, 0x3F778BC5, 0x3F75DEC6, 0x3F740BDD, 0x3F721352, 0x3F6FF573, 0x3F6DB293,
0x3F6B4B0C, 0x3F68BF3C, 0x3F660F88, 0x3F633C5A, 0x3F604621, 0x3F5D2D53, 0x3F59F26A, 0x3F5695E5,
0x3F531849, 0x3F4F7A1F, 0x3F4BBBF8, 0x3F47DE65, 0x3F43E200, 0x3F3FC767, 0x3F3B8F3B, 0x3F373A23,
0x3F7FFEC4, 0x3F7FF4E6, 0x3F7FE129, 0x3F7FC38F, 0x3F7F9C18, 0x3F7F6AC7, 0x3F7F2F9D, 0x3F7EEA9D,
0x3F7E9BC9, 0x3F7E4323, 0x3F7DE0B1, 0x3F7D7474, 0x3F7CFE73, 0x3F7C7EB0, 0x3F7BF531, 0x3F7B61FC,
0x3F7AC516, 0x3F7A1E84, 0x3F796E4E, 0x3F78B47B, 0x3F77F110, 0x3F772417, 0x3F764D97, 0x3F756D97,
0x3F748422, 0x3F73913F, 0x3F7294F8, 0x3F718F57, 0x3F708066, 0x3F6F6830, 0x3F6E46BE, 0x3F6D1C1D,
0x3F6BE858, 0x3F6AAB7B, 0x3F696591, 0x3F6816A8, 0x3F66BECC, 0x3F655E0B, 0x3F63F473, 0x3F628210,
0x3F6106F2, 0x3F5F8327, 0x3F5DF6BE, 0x3F5C61C7, 0x3F5AC450, 0x3F591E6A, 0x3F577026, 0x3F55B993,
0x3F53FAC3, 0x3F5233C6, 0x3F5064AF, 0x3F4E8D90, 0x3F4CAE79, 0x3F4AC77F, 0x3F48D8B3, 0x3F46E22A,
0x3F44E3F5, 0x3F42DE29, 0x3F40D0DA, 0x3F3EBC1B, 0x3F3CA003, 0x3F3A7CA4, 0x3F385216, 0x3F36206C,
};
private static float[] _decode5List1Single;
private static readonly uint[] _decode5List2UInt = {
0xBD0A8BD4, 0x3D0A8BD4, 0x3D0A8BD4, 0xBD0A8BD4, 0x3D0A8BD4, 0xBD0A8BD4, 0xBD0A8BD4, 0x3D0A8BD4,
0x3D0A8BD4, 0xBD0A8BD4, 0xBD0A8BD4, 0x3D0A8BD4, 0xBD0A8BD4, 0x3D0A8BD4, 0x3D0A8BD4, 0xBD0A8BD4,
0x3D0A8BD4, 0xBD0A8BD4, 0xBD0A8BD4, 0x3D0A8BD4, 0xBD0A8BD4, 0x3D0A8BD4, 0x3D0A8BD4, 0xBD0A8BD4,
0xBD0A8BD4, 0x3D0A8BD4, 0x3D0A8BD4, 0xBD0A8BD4, 0x3D0A8BD4, 0xBD0A8BD4, 0xBD0A8BD4, 0x3D0A8BD4,
0x3D0A8BD4, 0xBD0A8BD4, 0xBD0A8BD4, 0x3D0A8BD4, 0xBD0A8BD4, 0x3D0A8BD4, 0x3D0A8BD4, 0xBD0A8BD4,
0xBD0A8BD4, 0x3D0A8BD4, 0x3D0A8BD4, 0xBD0A8BD4, 0x3D0A8BD4, 0xBD0A8BD4, 0xBD0A8BD4, 0x3D0A8BD4,
0xBD0A8BD4, 0x3D0A8BD4, 0x3D0A8BD4, 0xBD0A8BD4, 0x3D0A8BD4, 0xBD0A8BD4, 0xBD0A8BD4, 0x3D0A8BD4,
0x3D0A8BD4, 0xBD0A8BD4, 0xBD0A8BD4, 0x3D0A8BD4, 0xBD0A8BD4, 0x3D0A8BD4, 0x3D0A8BD4, 0xBD0A8BD4,
0xBE47C5C2, 0xBF0E39DA, 0x3E47C5C2, 0x3F0E39DA, 0x3E47C5C2, 0x3F0E39DA, 0xBE47C5C2, 0xBF0E39DA,
0x3E47C5C2, 0x3F0E39DA, 0xBE47C5C2, 0xBF0E39DA, 0xBE47C5C2, 0xBF0E39DA, 0x3E47C5C2, 0x3F0E39DA,
0x3E47C5C2, 0x3F0E39DA, 0xBE47C5C2, 0xBF0E39DA, 0xBE47C5C2, 0xBF0E39DA, 0x3E47C5C2, 0x3F0E39DA,
0xBE47C5C2, 0xBF0E39DA, 0x3E47C5C2, 0x3F0E39DA, 0x3E47C5C2, 0x3F0E39DA, 0xBE47C5C2, 0xBF0E39DA,
0x3E47C5C2, 0x3F0E39DA, 0xBE47C5C2, 0xBF0E39DA, 0xBE47C5C2, 0xBF0E39DA, 0x3E47C5C2, 0x3F0E39DA,
0xBE47C5C2, 0xBF0E39DA, 0x3E47C5C2, 0x3F0E39DA, 0x3E47C5C2, 0x3F0E39DA, 0xBE47C5C2, 0xBF0E39DA,
0xBE47C5C2, 0xBF0E39DA, 0x3E47C5C2, 0x3F0E39DA, 0x3E47C5C2, 0x3F0E39DA, 0xBE47C5C2, 0xBF0E39DA,
0x3E47C5C2, 0x3F0E39DA, 0xBE47C5C2, 0xBF0E39DA, 0xBE47C5C2, 0xBF0E39DA, 0x3E47C5C2, 0x3F0E39DA,
0xBDC8BD36, 0xBE94A031, 0xBEF15AEA, 0xBF226799, 0x3DC8BD36, 0x3E94A031, 0x3EF15AEA, 0x3F226799,
0x3DC8BD36, 0x3E94A031, 0x3EF15AEA, 0x3F226799, 0xBDC8BD36, 0xBE94A031, 0xBEF15AEA, 0xBF226799,
0x3DC8BD36, 0x3E94A031, 0x3EF15AEA, 0x3F226799, 0xBDC8BD36, 0xBE94A031, 0xBEF15AEA, 0xBF226799,
0xBDC8BD36, 0xBE94A031, 0xBEF15AEA, 0xBF226799, 0x3DC8BD36, 0x3E94A031, 0x3EF15AEA, 0x3F226799,
0x3DC8BD36, 0x3E94A031, 0x3EF15AEA, 0x3F226799, 0xBDC8BD36, 0xBE94A031, 0xBEF15AEA, 0xBF226799,
0xBDC8BD36, 0xBE94A031, 0xBEF15AEA, 0xBF226799, 0x3DC8BD36, 0x3E94A031, 0x3EF15AEA, 0x3F226799,
0xBDC8BD36, 0xBE94A031, 0xBEF15AEA, 0xBF226799, 0x3DC8BD36, 0x3E94A031, 0x3EF15AEA, 0x3F226799,
0x3DC8BD36, 0x3E94A031, 0x3EF15AEA, 0x3F226799, 0xBDC8BD36, 0xBE94A031, 0xBEF15AEA, 0xBF226799,
0xBD48FB30, 0xBE164083, 0xBE78CFCC, 0xBEAC7CD4, 0xBEDAE880, 0xBF039C3D, 0xBF187FC0, 0xBF2BEB4A,
0x3D48FB30, 0x3E164083, 0x3E78CFCC, 0x3EAC7CD4, 0x3EDAE880, 0x3F039C3D, 0x3F187FC0, 0x3F2BEB4A,
0x3D48FB30, 0x3E164083, 0x3E78CFCC, 0x3EAC7CD4, 0x3EDAE880, 0x3F039C3D, 0x3F187FC0, 0x3F2BEB4A,
0xBD48FB30, 0xBE164083, 0xBE78CFCC, 0xBEAC7CD4, 0xBEDAE880, 0xBF039C3D, 0xBF187FC0, 0xBF2BEB4A,
0x3D48FB30, 0x3E164083, 0x3E78CFCC, 0x3EAC7CD4, 0x3EDAE880, 0x3F039C3D, 0x3F187FC0, 0x3F2BEB4A,
0xBD48FB30, 0xBE164083, 0xBE78CFCC, 0xBEAC7CD4, 0xBEDAE880, 0xBF039C3D, 0xBF187FC0, 0xBF2BEB4A,
0xBD48FB30, 0xBE164083, 0xBE78CFCC, 0xBEAC7CD4, 0xBEDAE880, 0xBF039C3D, 0xBF187FC0, 0xBF2BEB4A,
0x3D48FB30, 0x3E164083, 0x3E78CFCC, 0x3EAC7CD4, 0x3EDAE880, 0x3F039C3D, 0x3F187FC0, 0x3F2BEB4A,
0xBCC90AB0, 0xBD96A905, 0xBDFAB273, 0xBE2F10A2, 0xBE605C13, 0xBE888E93, 0xBEA09AE5, 0xBEB8442A,
0xBECF7BCA, 0xBEE63375, 0xBEFC5D27, 0xBF08F59B, 0xBF13682A, 0xBF1D7FD1, 0xBF273656, 0xBF3085BB,
0x3CC90AB0, 0x3D96A905, 0x3DFAB273, 0x3E2F10A2, 0x3E605C13, 0x3E888E93, 0x3EA09AE5, 0x3EB8442A,
0x3ECF7BCA, 0x3EE63375, 0x3EFC5D27, 0x3F08F59B, 0x3F13682A, 0x3F1D7FD1, 0x3F273656, 0x3F3085BB,
0x3CC90AB0, 0x3D96A905, 0x3DFAB273, 0x3E2F10A2, 0x3E605C13, 0x3E888E93, 0x3EA09AE5, 0x3EB8442A,
0x3ECF7BCA, 0x3EE63375, 0x3EFC5D27, 0x3F08F59B, 0x3F13682A, 0x3F1D7FD1, 0x3F273656, 0x3F3085BB,
0xBCC90AB0, 0xBD96A905, 0xBDFAB273, 0xBE2F10A2, 0xBE605C13, 0xBE888E93, 0xBEA09AE5, 0xBEB8442A,
0xBECF7BCA, 0xBEE63375, 0xBEFC5D27, 0xBF08F59B, 0xBF13682A, 0xBF1D7FD1, 0xBF273656, 0xBF3085BB,
0xBC490E90, 0xBD16C32C, 0xBD7B2B74, 0xBDAFB680, 0xBDE1BC2E, 0xBE09CF86, 0xBE22ABB6, 0xBE3B6ECF,
0xBE541501, 0xBE6C9A7F, 0xBE827DC0, 0xBE8E9A22, 0xBE9AA086, 0xBEA68F12, 0xBEB263EF, 0xBEBE1D4A,
0xBEC9B953, 0xBED53641, 0xBEE0924F, 0xBEEBCBBB, 0xBEF6E0CB, 0xBF00E7E4, 0xBF064B82, 0xBF0B9A6B,
0xBF10D3CD, 0xBF15F6D9, 0xBF1B02C6, 0xBF1FF6CB, 0xBF24D225, 0xBF299415, 0xBF2E3BDE, 0xBF32C8C9,
0x3C490E90, 0x3D16C32C, 0x3D7B2B74, 0x3DAFB680, 0x3DE1BC2E, 0x3E09CF86, 0x3E22ABB6, 0x3E3B6ECF,
0x3E541501, 0x3E6C9A7F, 0x3E827DC0, 0x3E8E9A22, 0x3E9AA086, 0x3EA68F12, 0x3EB263EF, 0x3EBE1D4A,
0x3EC9B953, 0x3ED53641, 0x3EE0924F, 0x3EEBCBBB, 0x3EF6E0CB, 0x3F00E7E4, 0x3F064B82, 0x3F0B9A6B,
0x3F10D3CD, 0x3F15F6D9, 0x3F1B02C6, 0x3F1FF6CB, 0x3F24D225, 0x3F299415, 0x3F2E3BDE, 0x3F32C8C9,
0xBBC90F88, 0xBC96C9B6, 0xBCFB49BA, 0xBD2FE007, 0xBD621469, 0xBD8A200A, 0xBDA3308C, 0xBDBC3AC3,
0xBDD53DB9, 0xBDEE3876, 0xBE039502, 0xBE1008B7, 0xBE1C76DE, 0xBE28DEFC, 0xBE354098, 0xBE419B37,
0xBE4DEE60, 0xBE5A3997, 0xBE667C66, 0xBE72B651, 0xBE7EE6E1, 0xBE8586CE, 0xBE8B9507, 0xBE919DDD,
0xBE97A117, 0xBE9D9E78, 0xBEA395C5, 0xBEA986C4, 0xBEAF713A, 0xBEB554EC, 0xBEBB31A0, 0xBEC1071E,
0xBEC6D529, 0xBECC9B8B, 0xBED25A09, 0xBED8106B, 0xBEDDBE79, 0xBEE363FA, 0xBEE900B7, 0xBEEE9479,
0xBEF41F07, 0xBEF9A02D, 0xBEFF17B2, 0xBF0242B1, 0xBF04F484, 0xBF07A136, 0xBF0A48AD, 0xBF0CEAD0,
0xBF0F8784, 0xBF121EB0, 0xBF14B039, 0xBF173C07, 0xBF19C200, 0xBF1C420C, 0xBF1EBC12, 0xBF212FF9,
0xBF239DA9, 0xBF26050A, 0xBF286605, 0xBF2AC082, 0xBF2D1469, 0xBF2F61A5, 0xBF31A81D, 0xBF33E7BC,
};
private static float[] _decode5List2Single;
private static readonly uint[] _decode5List3UInt = {
0x3A3504F0, 0x3B0183B8, 0x3B70C538, 0x3BBB9268, 0x3C04A809, 0x3C308200, 0x3C61284C, 0x3C8B3F17,
0x3CA83992, 0x3CC77FBD, 0x3CE91110, 0x3D0677CD, 0x3D198FC4, 0x3D2DD35C, 0x3D434643, 0x3D59ECC1,
0x3D71CBA8, 0x3D85741E, 0x3D92A413, 0x3DA078B4, 0x3DAEF522, 0x3DBE1C9E, 0x3DCDF27B, 0x3DDE7A1D,
0x3DEFB6ED, 0x3E00D62B, 0x3E0A2EDA, 0x3E13E72A, 0x3E1E00B1, 0x3E287CF2, 0x3E335D55, 0x3E3EA321,
0x3E4A4F75, 0x3E56633F, 0x3E62DF37, 0x3E6FC3D1, 0x3E7D1138, 0x3E8563A2, 0x3E8C72B7, 0x3E93B561,
0x3E9B2AEF, 0x3EA2D26F, 0x3EAAAAAB, 0x3EB2B222, 0x3EBAE706, 0x3EC34737, 0x3ECBD03D, 0x3ED47F46,
0x3EDD5128, 0x3EE6425C, 0x3EEF4EFF, 0x3EF872D7, 0x3F00D4A9, 0x3F0576CA, 0x3F0A1D3B, 0x3F0EC548,
0x3F136C25, 0x3F180EF2, 0x3F1CAAC2, 0x3F213CA2, 0x3F25C1A5, 0x3F2A36E7, 0x3F2E9998, 0x3F32E705,
0xBF371C9E, 0xBF3B37FE, 0xBF3F36F2, 0xBF431780, 0xBF46D7E6, 0xBF4A76A4, 0xBF4DF27C, 0xBF514A6F,
0xBF547DC5, 0xBF578C03, 0xBF5A74EE, 0xBF5D3887, 0xBF5FD707, 0xBF6250DA, 0xBF64A699, 0xBF66D908,
0xBF68E90E, 0xBF6AD7B1, 0xBF6CA611, 0xBF6E5562, 0xBF6FE6E7, 0xBF715BEF, 0xBF72B5D1, 0xBF73F5E6,
0xBF751D89, 0xBF762E13, 0xBF7728D7, 0xBF780F20, 0xBF78E234, 0xBF79A34C, 0xBF7A5397, 0xBF7AF439,
0xBF7B8648, 0xBF7C0ACE, 0xBF7C82C8, 0xBF7CEF26, 0xBF7D50CB, 0xBF7DA88E, 0xBF7DF737, 0xBF7E3D86,
0xBF7E7C2A, 0xBF7EB3CC, 0xBF7EE507, 0xBF7F106C, 0xBF7F3683, 0xBF7F57CA, 0xBF7F74B6, 0xBF7F8DB6,
0xBF7FA32E, 0xBF7FB57B, 0xBF7FC4F6, 0xBF7FD1ED, 0xBF7FDCAD, 0xBF7FE579, 0xBF7FEC90, 0xBF7FF22E,
0xBF7FF688, 0xBF7FF9D0, 0xBF7FFC32, 0xBF7FFDDA, 0xBF7FFEED, 0xBF7FFF8F, 0xBF7FFFDF, 0xBF7FFFFC,
};
private static float[] _decode5List3Single;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 6dc44417a97e9374986bb79f1514e71f
timeCreated: 1531897075
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,139 @@
using System;
namespace DereTore.Exchange.Audio.HCA {
internal sealed class Cipher {
public bool Initialize(CipherType type, uint key1, uint key2) {
if (key1 == 0 && key2 == 0 && type == CipherType.CipherWithAKey) {
type = CipherType.NoChipher;
}
switch (type) {
case CipherType.NoChipher:
Init0();
break;
case CipherType.CipherWithoutKeys:
Init1();
break;
case CipherType.CipherWithAKey:
Init56(key1, key2);
break;
default:
return false;
}
InitEncryptTable();
return true;
}
public void Decrypt(byte[] data) {
Decrypt(data, data.Length);
}
public void Decrypt(byte[] data, int length) {
length = Math.Min(data.Length, length);
for (var i = 0; i < length; ++i) {
data[i] = _decryptTable[data[i]];
}
}
public void Encrypt(byte[] data) {
Encrypt(data, data.Length);
}
public void Encrypt(byte[] data, int length) {
length = Math.Min(data.Length, length);
for (var i = 0; i < length; ++i) {
data[i] = _encryptTable[data[i]];
}
}
private void Init0() {
for (var i = 0; i < _decryptTable.Length; ++i) {
_decryptTable[i] = (byte)i;
}
}
private void Init1() {
for (int i = 1, v = 0; i < _decryptTable.Length - 1; ++i) {
v = (v * 13 + 11) & 0xff;
if (v == 0 || v == 0xff) {
v = (v * 13 + 11) & 0xff;
}
_decryptTable[i] = (byte)v;
}
_decryptTable[0] = 0;
_decryptTable[_decryptTable.Length - 1] = 0xff;
}
private void Init56(uint key1, uint key2) {
byte[] t1 = new byte[8];
if (key1 == 0) {
--key2;
}
--key1;
for (int i = 0; i < 7; ++i) {
t1[i] = (byte)key1;
key1 = (key1 >> 8) | (key2 << 24);
key2 >>= 8;
}
byte[] t2 = new byte[0x10] {
t1[1], (byte)(t1[1] ^ t1[6]),
(byte)(t1[2] ^ t1[3]), t1[2],
(byte)(t1[2] ^ t1[1]), (byte)(t1[3] ^ t1[4]),
t1[3], (byte)(t1[3] ^ t1[2]),
(byte)(t1[4] ^ t1[5]), t1[4],
(byte)(t1[4] ^ t1[3]), (byte)(t1[5] ^ t1[6]),
t1[5], (byte)(t1[5] ^ t1[4]),
(byte)(t1[6] ^ t1[1]), t1[6],
};
byte[] t3 = new byte[0x100];
byte[] t31 = new byte[0x10];
byte[] t32 = new byte[0x10];
int c = 0;
Init56CreateTable(t31, t1[0]);
for (int i = 0; i < t31.Length; ++i) {
Init56CreateTable(t32, t2[i]);
byte v = (byte)(t31[i] << 4);
for (int j = 0; j < t32.Length; ++j) {
t3[c] = (byte)(v | t32[j]);
++c;
}
}
c = 1;
for (int i = 0, v = 0; i < _decryptTable.Length; ++i) {
v = (v + 0x11) & 0xff;
byte a = t3[v];
if (a != 0 && a != 0xff) {
_decryptTable[c] = a;
++c;
}
}
_decryptTable[0] = 0;
_decryptTable[_decryptTable.Length - 1] = 0xff;
}
private void Init56CreateTable(byte[] r, byte key) {
int mul = ((key & 1) << 3) | 5;
int add = (key & 0xe) | 1;
key >>= 4;
for (int i = 0; i < 0x10; ++i) {
key = (byte)((key * mul + add) & 0xf);
r[i] = key;
}
}
private void InitEncryptTable() {
for (var i = 0; i < 0x100; ++i) {
for (var j = 0; j < 0x100; ++j) {
if (_decryptTable[j] == i) {
_encryptTable[i] = (byte)(j & 0xff);
break;
}
}
}
}
private readonly byte[] _decryptTable = new byte[0x100];
private readonly byte[] _encryptTable = new byte[0x100];
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f00438030bf7aa848a5b66a53f6065c9
timeCreated: 1531897076
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,9 @@
namespace DereTore.Exchange.Audio.HCA {
public struct CipherConfig {
public CipherType CipherType;
public uint Key1;
public uint Key2;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c9c5f1664b7eaf24e83de3f94b82814a
timeCreated: 1531897075
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,197 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using DereTore.Common;
using DereTore.Exchange.Audio.HCA.Native;
namespace DereTore.Exchange.Audio.HCA {
public sealed class CipherConverter : HcaReader {
public CipherConverter(Stream sourceStream, Stream outputStream, CipherConfig ccFrom, CipherConfig ccTo)
: base(sourceStream) {
_outputStream = outputStream;
_ccFrom = ccFrom;
_ccTo = ccTo;
}
public void Convert() {
ParseHeaders();
InitializeCiphers();
UpdateHeader();
ConvertData();
}
/// <summary>
/// Whether to encrypt the header signatures ('HCA ', 'fmt ', 'ciph', etc.). Usually decoders recognize both types of header signatures.
/// </summary>
public bool EncryptHeaderSignatures { get; set; }
private void UpdateHeader() {
var dataOffset = HcaInfo.DataOffset;
var buffer = new byte[dataOffset];
var sourceStream = SourceStream;
var outputStream = _outputStream;
sourceStream.Seek(0, SeekOrigin.Begin);
sourceStream.Read(buffer, 0, buffer.Length);
sourceStream.Seek(0, SeekOrigin.Begin);
uint v;
// HCA
v = sourceStream.PeekUInt32LE();
if (MagicValues.IsMagicMatch(v, MagicValues.HCA)) {
ProcessHeaderSignature(sourceStream, buffer);
sourceStream.Skip(Marshal.SizeOf(typeof(HcaHeader)));
}
// FMT
v = sourceStream.PeekUInt32LE();
if (MagicValues.IsMagicMatch(v, MagicValues.FMT)) {
ProcessHeaderSignature(sourceStream, buffer);
sourceStream.Skip(Marshal.SizeOf(typeof(FormatHeader)));
}
// COMP / DEC
v = sourceStream.PeekUInt32LE();
if (MagicValues.IsMagicMatch(v, MagicValues.COMP)) {
ProcessHeaderSignature(sourceStream, buffer);
sourceStream.Skip(Marshal.SizeOf(typeof(CompressHeader)));
} else if (MagicValues.IsMagicMatch(v, MagicValues.DEC)) {
ProcessHeaderSignature(sourceStream, buffer);
sourceStream.Skip(Marshal.SizeOf(typeof(DecodeHeader)));
}
// VBR
v = sourceStream.PeekUInt32LE();
if (MagicValues.IsMagicMatch(v, MagicValues.VBR)) {
ProcessHeaderSignature(sourceStream, buffer);
sourceStream.Skip(Marshal.SizeOf(typeof(VbrHeader)));
}
// ATH
v = sourceStream.PeekUInt32LE();
if (MagicValues.IsMagicMatch(v, MagicValues.ATH)) {
ProcessHeaderSignature(sourceStream, buffer);
sourceStream.Skip(Marshal.SizeOf(typeof(AthHeader)));
}
// LOOP
v = sourceStream.PeekUInt32LE();
if (MagicValues.IsMagicMatch(v, MagicValues.LOOP)) {
ProcessHeaderSignature(sourceStream, buffer);
sourceStream.Skip(Marshal.SizeOf(typeof(LoopHeader)));
}
// CIPH
v = sourceStream.PeekUInt32LE();
if (MagicValues.IsMagicMatch(v, MagicValues.CIPH)) {
ProcessHeaderSignature(sourceStream, buffer);
var cipherOffset = (int)(sourceStream.Position + 4);
var u = (ushort)_ccTo.CipherType;
if (BitConverter.IsLittleEndian) {
u = DereToreHelper.SwapEndian(u);
}
var cipherTypeBytes = BitConverter.GetBytes(u);
buffer[cipherOffset] = cipherTypeBytes[0];
buffer[cipherOffset + 1] = cipherTypeBytes[1];
}
// RVA
v = sourceStream.PeekUInt32LE();
if (MagicValues.IsMagicMatch(v, MagicValues.RVA)) {
ProcessHeaderSignature(sourceStream, buffer);
sourceStream.Skip(Marshal.SizeOf(typeof(RvaHeader)));
}
// COMM
v = sourceStream.PeekUInt32LE();
if (MagicValues.IsMagicMatch(v, MagicValues.COMM)) {
ProcessHeaderSignature(sourceStream, buffer);
sourceStream.Skip(Marshal.SizeOf(typeof(CommentHeader)));
byte tmpByte;
do {
tmpByte = (byte)sourceStream.ReadByte();
} while (tmpByte != 0);
}
// PAD (undocumented)
v = sourceStream.PeekUInt32LE();
if (MagicValues.IsMagicMatch(v, MagicValues.PAD)) {
ProcessHeaderSignature(sourceStream, buffer);
sourceStream.Skip(4);
}
FixDataBlock(buffer);
outputStream.Write(buffer, 0, buffer.Length);
}
private void ConvertData() {
var hcaInfo = HcaInfo;
var sourceStream = SourceStream;
var outputStream = _outputStream;
var dataOffset = hcaInfo.DataOffset;
var totalBlockCount = hcaInfo.BlockCount;
var buffer = new byte[hcaInfo.BlockSize];
sourceStream.Seek(dataOffset, SeekOrigin.Begin);
for (var i = 0; i < totalBlockCount; ++i) {
var read = sourceStream.Read(buffer, 0, buffer.Length);
if (read < buffer.Length) {
throw new IOException("Something went wrong while trying to read data.");
}
var r = ConvertBlock(buffer, outputStream);
if (!r) {
throw new HcaException("Block conversion failed.", ActionResult.DecodeFailed);
}
}
}
private void InitializeCiphers() {
_cipherFrom = new Cipher();
_cipherFrom.Initialize(HcaInfo.CipherType, _ccFrom.Key1, _ccFrom.Key2);
_cipherTo = new Cipher();
_cipherTo.Initialize(_ccTo.CipherType, _ccTo.Key1, _ccTo.Key2);
}
private bool ConvertBlock(byte[] blockData, Stream outputStream) {
var checksum = HcaHelper.Checksum(blockData, 0);
if (checksum != 0) {
return false;
}
_cipherFrom.Decrypt(blockData);
var dataClass = new DataBits(blockData, (uint)blockData.Length);
var magic = dataClass.GetBit(16);
if (magic != 0xffff) {
return false;
}
_cipherTo.Encrypt(blockData);
FixDataBlock(blockData);
outputStream.Write(blockData, 0, blockData.Length);
return true;
}
private static void FixDataBlock(byte[] blockData) {
var length = blockData.Length;
var sum = HcaHelper.Checksum(blockData, 0, length - 2);
if (BitConverter.IsLittleEndian) {
sum = DereToreHelper.SwapEndian(sum);
}
var sumBytes = BitConverter.GetBytes(sum);
blockData[length - 2] = sumBytes[0];
blockData[length - 1] = sumBytes[1];
}
private static void OrBytes(byte[] blockData, int offset, int length) {
var end = offset + length;
for (var i = offset; i < blockData.Length && i < end; ++i) {
blockData[i] = (byte)(blockData[i] & 0xf0);
}
}
private void ProcessHeaderSignature(Stream stream, byte[] headerData) {
if (!EncryptHeaderSignatures) {
return;
}
var position = (int)stream.Position;
OrBytes(headerData, position, 4);
}
private readonly Stream _outputStream;
private readonly CipherConfig _ccFrom;
private readonly CipherConfig _ccTo;
private Cipher _cipherFrom;
private Cipher _cipherTo;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 03bfc50835ac766498c67e6936c89e20
timeCreated: 1531897074
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,9 @@
namespace DereTore.Exchange.Audio.HCA {
public enum CipherType : ushort {
NoChipher = 0,
CipherWithoutKeys = 1,
CipherWithAKey = 0x38
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 427f8dc86beea324f85fd18e1b060256
timeCreated: 1531897075
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,53 @@
namespace DereTore.Exchange.Audio.HCA {
internal sealed class DataBits {
public DataBits(byte[] data, uint size) {
_data = data;
_size = size * 8 - 16;
_bit = 0;
}
public int CheckBit(int bitSize)
{
var v = 0;
if (_bit + bitSize <= _size)
{
var i = _bit >> 3;
byte data;
if (i + 2 >= _data.Length)
{
data = 0; //なぜかインデックス外になることがあるため
}
else
{
data = _data[i + 2];
}
v = _data[i];
v = (v << 8) | _data[i + 1];
v = (v << 8) | data;
v &= Mask[_bit & 7];
v >>= 24 - (_bit & 7) - bitSize;
}
return v;
}
public int GetBit(int bitSize) {
var v = CheckBit(bitSize);
_bit += bitSize;
return v;
}
public void AddBit(int bitSize) {
_bit += bitSize;
}
private static readonly int[] Mask = { 0xffffff, 0x7fffff, 0x3fffff, 0x1fffff, 0x0fffff, 0x07ffff, 0x03ffff, 0x01ffff };
private readonly byte[] _data;
private readonly uint _size;
private int _bit;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b5c8765b4cb0d374b8f55cfa3bf0ec9d
timeCreated: 1531897075
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,36 @@
namespace DereTore.Exchange.Audio.HCA {
public struct DecodeParams {
public uint Key1 { get; set; }
public uint Key2 { get; set; }
public SamplingMode Mode { get; set; }
public float Volume { get; set; }
public bool CipherTypeOverrideEnabled { get; set; }
public CipherType OverriddenCipherType { get; set; }
public static DecodeParams CreateDefault() {
return new DecodeParams {
Key1 = 0,
Key2 = 0,
Mode = SamplingMode.S16,
Volume = 1.0f,
CipherTypeOverrideEnabled = false,
OverriddenCipherType = CipherType.NoChipher
};
}
public static DecodeParams CreateDefault(uint key1, uint key2) {
return new DecodeParams {
Key1 = key1,
Key2 = key2,
Mode = SamplingMode.S16,
Volume = 1.0f,
CipherTypeOverrideEnabled = false,
OverriddenCipherType = CipherType.NoChipher
};
}
public static readonly DecodeParams Default = CreateDefault();
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7eeaae60f9b15ae48a0877e45b21fb57
timeCreated: 1531897075
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,29 @@
namespace DereTore.Exchange.Audio.HCA {
internal static class ErrorMessages {
public static string GetBufferTooSmall(int minimum, int actual) {
return string.Format("Buffer too small. Required minimum: {0}, actual: {1}",minimum,actual);
}
public static string GetInvalidParameter(string paramName) {
return string.Format("Parameter '{0}' is invalid.",paramName);
}
public static string GetChecksumNotMatch(int expected, int actual) {
return string.Format("Checksum does not match. Expected: {0}({0:x8}), actual: {1}({1:x8}).",expected,actual);
}
public static string GetMagicNotMatch(int expected, int actual) {
return string.Format("Magic does not match. Expected: {0}({0:x8}), actual: {1}({1:x8}).",expected,actual);
}
public static string GetAthInitializationFailed() {
return "ATH table initialization failed.";
}
public static string GetCiphInitializationFailed() {
return "CIPH table initialization failed.";
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 893e8191939606d4d90d8e51dccef4a6
timeCreated: 1531897075
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,348 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using DereTore.Common;
using System.Linq.Expressions;
namespace DereTore.Exchange.Audio.HCA {
public sealed class HcaAudioStream : HcaAudioStreamBase {
public static string NameOf<T>(Expression<Func<T>> e)
{
return ((MemberExpression)e.Body).Member.Name;
}
public HcaAudioStream(Stream sourceStream)
: this(sourceStream, DecodeParams.Default) {
}
public HcaAudioStream(Stream sourceStream, AudioParams audioParams)
: this(sourceStream, DecodeParams.Default, audioParams) {
}
public HcaAudioStream(Stream sourceStream, DecodeParams decodeParams)
: this(sourceStream, decodeParams, AudioParams.Default) {
}
public HcaAudioStream(Stream sourceStream, DecodeParams decodeParams, AudioParams audioParams)
: base(sourceStream, decodeParams) {
var decoder = new HcaDecoder(sourceStream, decodeParams);
_decoder = decoder;
_audioParams = audioParams;
var buffer = new byte[GetTotalAfterDecodingWaveDataSize()];
_memoryCache = new MemoryStream(buffer, true);
_decodedBlocks = new Dictionary<long, long>();
_decodeBuffer = new byte[decoder.GetMinWaveDataBufferSize()];
_hasLoop = decoder.HcaInfo.LoopFlag;
PrepareDecoding();
}
public override long Seek(long offset, SeekOrigin origin) {
if (!EnsureNotDisposed()) {
return 0;
}
switch (origin) {
case SeekOrigin.Begin:
Position = offset;
break;
case SeekOrigin.Current:
Position = Position + offset;
break;
case SeekOrigin.End:
Position = Length - offset;
break;
default:
break;
}
return Position;
}
public override int Read(byte[] buffer, int offset, int count) {
if (!EnsureNotDisposed()) {
return 0;
}
if (!HasMoreData) {
return 0;
}
if (offset < 0 || offset >= buffer.Length) {
throw new ArgumentOutOfRangeException(NameOf(() => offset));
}
if (count < 0) {
throw new ArgumentOutOfRangeException(NameOf(() => count));
}
if (count == 0) {
return 0;
}
var hcaInfo = HcaInfo;
var memoryCache = _memoryCache;
var position = Position;
var read = 0;
if (position < hcaInfo.DataOffset) {
var maxCopy = Math.Min(Math.Min((int)(hcaInfo.DataOffset - position), count), buffer.Length - offset);
if (maxCopy == 0) {
return 0;
}
memoryCache.Seek(position, SeekOrigin.Begin);
memoryCache.Read(buffer, offset, maxCopy);
count -= maxCopy;
offset += maxCopy;
position += maxCopy;
if (count <= 0 || offset >= buffer.Length) {
Position = position;
return maxCopy;
}
read += maxCopy;
}
var audioParams = _audioParams;
var length = Length;
count = HasLoop && audioParams.InfiniteLoop ? Math.Min(count, buffer.Length - offset) : Math.Min((int)(length - position), count);
if (_decodedBlocks.Count < hcaInfo.BlockCount) {
if (HasLoop && audioParams.SimulatedLoopCount > 0) {
EnsureSoundDataDecodedWithLoops(position, count);
} else {
EnsureSoundDataDecoded(position, count);
}
}
var headerSize = _headerSize;
var waveBlockSize = _decoder.GetMinWaveDataBufferSize();
while (count > 0) {
var positionNonLooped = MapPosToNonLoopedWaveStreamPos(position);
memoryCache.Seek(positionNonLooped, SeekOrigin.Begin);
var shouldRead = Math.Min(count, waveBlockSize - ((int)(positionNonLooped - headerSize) % waveBlockSize));
if (shouldRead == 0) {
break;
}
var realRead = memoryCache.Read(buffer, offset, shouldRead);
Debug.Assert(realRead == shouldRead);
count -= realRead;
offset += realRead;
read += realRead;
position += realRead;
}
Position = position;
return read;
}
public override bool CanSeek { get { return true; } }
public override long Length {
get {
if (!EnsureNotDisposed()) {
return 0;
}
if (_length != null) {
return _length.Value;
}
var audioParams = _audioParams;
if (HasLoop && audioParams.InfiniteLoop) {
_length = long.MaxValue;
return _length.Value;
}
var hcaInfo = HcaInfo;
long totalLength = 0;
if (_audioParams.OutputWaveHeader) {
totalLength += _headerSize;
}
var waveDataBlockSize = _decoder.GetMinWaveDataBufferSize();
totalLength += waveDataBlockSize * hcaInfo.BlockCount;
if (HasLoop && audioParams.SimulatedLoopCount > 0) {
var loopedBlockCount = hcaInfo.LoopEnd - hcaInfo.LoopStart + 1;
totalLength += waveDataBlockSize * loopedBlockCount * audioParams.SimulatedLoopCount;
}
_length = totalLength;
return _length.Value;
}
}
public override long Position {
get {
return EnsureNotDisposed() ? _position : 0;
}
set {
EnsureNotDisposed();
if (value < 0 || value > Length) {
throw new ArgumentOutOfRangeException(NameOf(() => value));
}
_position = value;
}
}
public override float LengthInSeconds
{
get
{
return HcaHelper.CalculateLengthInSeconds(HcaInfo, _audioParams.SimulatedLoopCount, _audioParams.InfiniteLoop);
}
}
public override uint LengthInSamples
{
get
{
return HcaHelper.CalculateLengthInSamples(HcaInfo, _audioParams.SimulatedLoopCount, _audioParams.InfiniteLoop);
}
}
protected override void Dispose(bool disposing) {
if (!IsDisposed) {
_memoryCache.Dispose();
}
base.Dispose(disposing);
}
protected override bool HasMoreData
{
get
{
return Position < Length;
}
}
private void EnsureSoundDataDecoded(long waveDataOffset, int byteCount) {
var decoder = _decoder;
var headerSize = _headerSize;
var blockSize = decoder.GetMinWaveDataBufferSize();
var startBlockIndex = (uint)((waveDataOffset - headerSize) / blockSize);
var hcaInfo = HcaInfo;
var endBlockIndex = (uint)((waveDataOffset + byteCount - headerSize) / blockSize);
endBlockIndex = Math.Min(endBlockIndex, hcaInfo.BlockCount - 1);
for (var i = startBlockIndex; i <= endBlockIndex; ++i) {
EnsureDecodeOneBlock(i);
}
}
private void EnsureSoundDataDecodedWithLoops(long waveDataOffset, int byteCount) {
waveDataOffset = MapPosToNonLoopedWaveStreamPos(waveDataOffset);
var decoder = _decoder;
var headerSize = _headerSize;
var waveBlockSize = decoder.GetMinWaveDataBufferSize();
var startBlockIndex = (uint)((waveDataOffset - headerSize) / waveBlockSize);
var waveDataEnd = waveDataOffset + byteCount;
var hcaInfo = HcaInfo;
var audioParams = _audioParams;
var decodedSize = (waveDataOffset - headerSize) / waveBlockSize * waveBlockSize;
// For those before or in the loop range...
if (audioParams.InfiniteLoop || startBlockIndex <= hcaInfo.LoopEnd + (hcaInfo.LoopEnd - hcaInfo.LoopStart + 1) * audioParams.SimulatedLoopCount) {
var blockIndex = startBlockIndex;
var executed = false;
while (true) {
if (executed && blockIndex == startBlockIndex) {
if (audioParams.InfiniteLoop) {
return;
} else {
break;
}
}
if (!audioParams.InfiniteLoop && decodedSize >= waveDataEnd) {
break;
}
EnsureDecodeOneBlock(blockIndex);
decodedSize += waveBlockSize;
++blockIndex;
if (blockIndex > hcaInfo.LoopEnd) {
blockIndex = hcaInfo.LoopStart;
}
executed = true;
}
}
// And those following it.
if (audioParams.InfiniteLoop) {
return;
}
var endBlockIndex = hcaInfo.LoopEnd + (hcaInfo.LoopEnd - hcaInfo.LoopStart + 1) * audioParams.SimulatedLoopCount;
var startOfAfterLoopRegion = endBlockIndex * waveBlockSize;
if (waveDataEnd >= startOfAfterLoopRegion) {
for (var blockIndex = hcaInfo.LoopEnd + 1; blockIndex < hcaInfo.BlockCount && decodedSize < waveDataEnd; ++blockIndex) {
EnsureDecodeOneBlock(blockIndex);
decodedSize += waveBlockSize;
}
}
}
private void EnsureDecodeOneBlock(uint blockIndex) {
var decodedBlocks = _decodedBlocks;
if (decodedBlocks.ContainsKey(blockIndex)) {
return;
}
var decodeBuffer = _decodeBuffer;
var decoder = _decoder;
decoder.DecodeBlock(decodeBuffer, blockIndex);
var positionInOutputStream = _headerSize + decoder.GetMinWaveDataBufferSize() * blockIndex;
var memoryCache = _memoryCache;
memoryCache.Seek(positionInOutputStream, SeekOrigin.Begin);
memoryCache.WriteBytes(decodeBuffer);
decodedBlocks.Add(blockIndex, positionInOutputStream);
}
private long MapPosToNonLoopedWaveStreamPos(long requestedPosition) {
if (!HasLoop) {
return requestedPosition;
}
var hcaInfo = HcaInfo;
var waveBlockSize = _decoder.GetMinWaveDataBufferSize();
var headerSize = _headerSize;
var relativeDataPosition = requestedPosition - headerSize;
var endLoopDataPosition = (hcaInfo.LoopEnd + 1) * waveBlockSize;
if (relativeDataPosition < endLoopDataPosition) {
return requestedPosition;
}
var startLoopDataPosition = hcaInfo.LoopStart * waveBlockSize;
var loopLength = endLoopDataPosition - startLoopDataPosition;
var audioParams = _audioParams;
if (audioParams.InfiniteLoop) {
return headerSize + startLoopDataPosition + (relativeDataPosition - startLoopDataPosition) % loopLength;
}
var extendedLength = endLoopDataPosition + loopLength * audioParams.SimulatedLoopCount;
if (relativeDataPosition < extendedLength) {
return headerSize + startLoopDataPosition + (relativeDataPosition - startLoopDataPosition) % loopLength;
} else {
return headerSize + endLoopDataPosition + (relativeDataPosition - extendedLength);
}
}
private bool HasLoop
{
get
{
return _hasLoop;
}
}
private void PrepareDecoding() {
var decoder = _decoder;
var memoryCache = _memoryCache;
if (_audioParams.OutputWaveHeader) {
var waveHeaderBufferSize = decoder.GetMinWaveHeaderBufferSize();
var waveHeaderBuffer = new byte[waveHeaderBufferSize];
decoder.WriteWaveHeader(waveHeaderBuffer, _audioParams);
memoryCache.WriteBytes(waveHeaderBuffer);
_headerSize = waveHeaderBufferSize;
} else {
_headerSize = 0;
}
memoryCache.Position = 0;
}
private int GetTotalAfterDecodingWaveDataSize() {
var hcaInfo = HcaInfo;
var totalLength = 0;
if (_audioParams.OutputWaveHeader) {
totalLength += _decoder.GetMinWaveHeaderBufferSize();
}
totalLength += _decoder.GetMinWaveDataBufferSize() * (int)hcaInfo.BlockCount;
return totalLength;
}
private readonly AudioParams _audioParams;
private int _headerSize;
private readonly MemoryStream _memoryCache;
private readonly Dictionary<long, long> _decodedBlocks;
private long? _length;
private long _position;
private readonly byte[] _decodeBuffer;
private readonly bool _hasLoop;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c76257579ffd8564c939bbe76ca4203d
timeCreated: 1531897075
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,65 @@
using System;
using System.IO;
namespace DereTore.Exchange.Audio.HCA {
public abstract class HcaAudioStreamBase : Stream {
protected HcaAudioStreamBase(Stream sourceStream, DecodeParams decodeParams) {
_decodeParams = decodeParams;
}
public sealed override void Flush() {
throw new NotSupportedException();
}
public sealed override void SetLength(long value) {
throw new NotSupportedException();
}
public sealed override void Write(byte[] buffer, int offset, int count) {
throw new NotSupportedException();
}
public sealed override bool CanRead { get { return true; } }
public sealed override bool CanWrite { get { return false; } }
public bool AllowDisposedOperations { get; set; }
public bool IsDisposed { get { return _isDisposed; } }
public HcaDecoder Decoder { get { return _decoder; } }
public abstract float LengthInSeconds { get; }
public abstract uint LengthInSamples { get; }
public HcaInfo HcaInfo { get { return _decoder.HcaInfo; } }
public DecodeParams DecodeParams { get { return _decodeParams; } }
protected bool EnsureNotDisposed() {
if (IsDisposed) {
if (AllowDisposedOperations) {
return false;
} else {
throw new ObjectDisposedException(typeof(HcaAudioStream).Name);
}
} else {
return true;
}
}
protected override void Dispose(bool disposing) {
_isDisposed = true;
base.Dispose(disposing);
}
protected abstract bool HasMoreData { get; }
protected HcaDecoder _decoder;
private bool _isDisposed;
private readonly DecodeParams _decodeParams;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7f02074bbcbbe3f468aff93e5134e5ad
timeCreated: 1531897075
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,12 @@
using System;
namespace DereTore.Exchange.Audio.HCA {
[Flags]
internal enum HcaAudioStreamDecodeState {
Initialized = 0,
WaveHeaderTransmitting = 1,
WaveHeaderTransmitted = 2,
DataTransmitting = 4,
DataTransmitted = 8
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: cf0e1b54f4a99134ea689ef2e6a45bab
timeCreated: 1531897075
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,44 @@
using System;
using System.Linq.Expressions;
namespace DereTore.Exchange.Audio.HCA {
partial class HcaDecoder {
public static string NameOf<T>(Expression<Func<T>> e)
{
return ((MemberExpression)e.Body).Member.Name;
}
internal uint DecodeBlock(byte[] waveDataBuffer, uint blockIndex) {
if (waveDataBuffer == null) {
throw new ArgumentNullException(NameOf(() => waveDataBuffer));
}
var waveBlockSize = GetMinWaveDataBufferSize();
if (waveDataBuffer.Length < waveBlockSize) {
throw new HcaException(ErrorMessages.GetBufferTooSmall(waveBlockSize, waveDataBuffer.Length), ActionResult.BufferTooSmall);
}
TransformWaveDataBlocks(SourceStream, waveDataBuffer, blockIndex, 1, GetProperWaveWriter());
return 1;
}
internal uint DecodeBlocks(byte[] waveDataBuffer, uint startBlockIndex) {
if (waveDataBuffer == null) {
throw new ArgumentNullException(NameOf(() => waveDataBuffer));
}
var waveBlockSize = GetMinWaveDataBufferSize();
if (waveDataBuffer.Length < waveBlockSize) {
throw new HcaException(ErrorMessages.GetBufferTooSmall(waveBlockSize, waveDataBuffer.Length), ActionResult.BufferTooSmall);
}
var hcaInfo = HcaInfo;
var numBlocksToDecode = (uint)(waveDataBuffer.Length / waveBlockSize);
if (startBlockIndex + numBlocksToDecode >= hcaInfo.BlockCount) {
numBlocksToDecode = hcaInfo.BlockCount - startBlockIndex;
}
if (numBlocksToDecode == 0) {
return 0;
}
TransformWaveDataBlocks(SourceStream, waveDataBuffer, startBlockIndex, numBlocksToDecode, GetProperWaveWriter());
return numBlocksToDecode;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 72bfbcd478d98fb4fa5472b48facbfbd
timeCreated: 1531897075
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,217 @@
using System;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
//using System.Threading.Tasks;
namespace DereTore.Exchange.Audio.HCA {
partial class HcaDecoder {
private void Initialize() {
ParseHeaders();
InitializeDecodeComponents();
}
private void InitializeDecodeComponents() {
var hcaInfo = HcaInfo;
if (!_ath.Initialize(hcaInfo.AthType, hcaInfo.SamplingRate)) {
throw new HcaException(ErrorMessages.GetAthInitializationFailed(), ActionResult.AthInitFailed);
}
var decodeParams = _decodeParams;
var cipherType = decodeParams.CipherTypeOverrideEnabled ? decodeParams.OverriddenCipherType : hcaInfo.CipherType;
if (!_cipher.Initialize(cipherType, decodeParams.Key1, decodeParams.Key2)) {
throw new HcaException(ErrorMessages.GetCiphInitializationFailed(), ActionResult.CiphInitFailed);
}
var channels = _channels = new Channel[0x10];
for (var i = 0; i < channels.Length; ++i) {
channels[i] = Channel.CreateDefault();
}
var r = new byte[10];
uint b = hcaInfo.ChannelCount / hcaInfo.CompR03;
if (hcaInfo.CompR07 != 0 && b > 1) {
uint rIndex = 0;
for (uint i = 0; i < hcaInfo.CompR03; ++i, rIndex += b) {
switch (b) {
case 2:
case 3:
r[rIndex] = 1;
r[rIndex + 1] = 2;
break;
case 4:
r[rIndex] = 1;
r[rIndex + 1] = 2;
if (hcaInfo.CompR04 == 0) {
r[rIndex + 2] = 1;
r[rIndex + 3] = 2;
}
break;
case 5:
r[rIndex] = 1;
r[rIndex + 1] = 2;
if (hcaInfo.CompR04 <= 2) {
r[rIndex + 3] = 1;
r[rIndex + 4] = 2;
}
break;
case 6:
case 7:
r[rIndex] = 1;
r[rIndex + 1] = 2;
r[rIndex + 4] = 1;
r[rIndex + 5] = 2;
break;
case 8:
r[rIndex] = 1;
r[rIndex + 1] = 2;
r[rIndex + 4] = 1;
r[rIndex + 5] = 2;
r[rIndex + 6] = 1;
r[rIndex + 7] = 2;
break;
default:
throw new ArgumentOutOfRangeException("b");
}
}
}
for (uint i = 0; i < hcaInfo.ChannelCount; ++i) {
channels[i].Type = r[i];
channels[i].Value3 = (uint)(hcaInfo.CompR06 + hcaInfo.CompR07);
channels[i].Count = (uint)(hcaInfo.CompR06 + (r[i] != 2 ? hcaInfo.CompR07 : (ushort)0));
}
}
private int DecodeToWaveR32(byte[] blockData) {
var hcaInfo = HcaInfo;
if (blockData == null) {
throw new ArgumentNullException(NameOf(() => blockData));
}
if (blockData.Length < hcaInfo.BlockSize) {
throw new HcaException(ErrorMessages.GetInvalidParameter("blockData.Length"), ActionResult.InvalidParameter);
}
var checksum = HcaHelper.Checksum(blockData, 0);
if (checksum != 0) {
throw new HcaException(ErrorMessages.GetChecksumNotMatch(0, checksum), ActionResult.ChecksumNotMatch);
}
_cipher.Decrypt(blockData);
var d = new DataBits(blockData, hcaInfo.BlockSize);
var magic = d.GetBit(16);
if (magic != 0xffff) {
throw new HcaException(ErrorMessages.GetMagicNotMatch(0xffff, magic), ActionResult.MagicNotMatch);
}
var a = (d.GetBit(9) << 8) - d.GetBit(7);
var channels = _channels;
var ath = _ath;
try {
for (var i = 0; i < hcaInfo.ChannelCount; ++i) {
channels[i].Decode1(d, hcaInfo.CompR09, a, ath.Table);
}
for (var i = 0; i < 8; ++i) {
for (var j = 0; j < hcaInfo.ChannelCount; ++j) {
channels[j].Decode2(d);
}
for (var j = 0; j < hcaInfo.ChannelCount; ++j) {
channels[j].Decode3(hcaInfo.CompR09, hcaInfo.CompR08, (uint)(hcaInfo.CompR07 + hcaInfo.CompR06), hcaInfo.CompR05);
}
for (var j = 0; j < hcaInfo.ChannelCount - 1; ++j) {
Channel.Decode4(ref channels[j], ref channels[j + 1], i, (uint)(hcaInfo.CompR05 - hcaInfo.CompR06), hcaInfo.CompR06, hcaInfo.CompR07);
}
for (var j = 0; j < hcaInfo.ChannelCount; ++j) {
channels[j].Decode5(i);
}
}
return blockData.Length;
} catch (IndexOutOfRangeException ex) {
const string message = "Index access exception detected. It is probably because you are using an incorrect HCA key pair while decoding a type 56 HCA file.";
throw new HcaException(message, ActionResult.DecodeFailed, ex);
}
}
private void TransformWaveDataBlocks(Stream source, byte[] destination, uint startBlockIndex, uint blockCount, IWaveWriter waveWriter) {
if (source == null) {
throw new ArgumentNullException(NameOf(() => source));
}
if (destination == null) {
throw new ArgumentNullException(NameOf(() => destination));
}
if (waveWriter == null) {
throw new ArgumentNullException(NameOf(() => waveWriter));
}
var hcaInfo = HcaInfo;
var startOffset = hcaInfo.DataOffset + startBlockIndex * hcaInfo.BlockSize;
source.Seek(startOffset, SeekOrigin.Begin);
var channels = _channels;
var decodeParams = _decodeParams;
var hcaBlockBuffer = GetHcaBlockBuffer();
var channelCount = (int)hcaInfo.ChannelCount;
var rvaVolume = hcaInfo.RvaVolume;
var bytesPerSample = waveWriter.BytesPerSample;
foreach (var l in Enumerable.Range(0, (int)blockCount)) {
source.Read(hcaBlockBuffer, 0, hcaBlockBuffer.Length);
DecodeToWaveR32(hcaBlockBuffer);
for (int i = 0; i < 8; i++)
{
for (var j = 0; j < 0x80; ++j)
{
for (var k = 0; k < channelCount; ++k)
{
var f = channels[k].Wave[i * 0x80 + j] * decodeParams.Volume * rvaVolume;
HcaHelper.Clamp(ref f, -1f, 1f);
var offset = (((l * 8 + i) * 0x80 + j) * channelCount + k) * bytesPerSample;
waveWriter.DecodeToBuffer(f, destination, (uint)offset);
}
}
}
}
}
private byte[] GetHcaBlockBuffer() {
return _hcaBlockBuffer ?? (_hcaBlockBuffer = new byte[HcaInfo.BlockSize]);
}
private int GetSampleBitsFromParams() {
var mode = _decodeParams.Mode;
switch (mode) {
case SamplingMode.R32:
return 32;
case SamplingMode.S16:
return 16;
case SamplingMode.S24:
return 24;
case SamplingMode.S32:
return 32;
case SamplingMode.U8:
return 8;
default:
throw new ArgumentOutOfRangeException(NameOf(() => mode));
}
}
private IWaveWriter GetProperWaveWriter() {
var mode = _decodeParams.Mode;
switch (mode) {
case SamplingMode.S16:
return WaveHelper.S16;
case SamplingMode.R32:
return WaveHelper.R32;
case SamplingMode.S32:
return WaveHelper.S32;
case SamplingMode.U8:
return WaveHelper.U8;
case SamplingMode.S24:
throw new NotImplementedException();
default:
throw new ArgumentOutOfRangeException(NameOf(() => mode));
}
}
private byte[] _hcaBlockBuffer;
private readonly Ath _ath;
private readonly Cipher _cipher;
private Channel[] _channels;
private readonly DecodeParams _decodeParams;
private int? _minWaveHeaderBufferSize;
private int? _minWaveDataBufferSize;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ec3b49f5a468c0240af9ec5e8dd1ad8f
timeCreated: 1531897076
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,109 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using DereTore.Common;
using DereTore.Exchange.Audio.HCA.Native;
namespace DereTore.Exchange.Audio.HCA {
public partial class HcaDecoder : HcaReader {
public HcaDecoder(Stream sourceStream)
: this(sourceStream, DecodeParams.Default) {
}
public HcaDecoder(Stream sourceStream, DecodeParams decodeParams)
: base(sourceStream) {
_decodeParams = decodeParams;
HcaHelper.TranslateTables();
_ath = new Ath();
_cipher = new Cipher();
Initialize();
}
public int GetMinWaveHeaderBufferSize() {
if (_minWaveHeaderBufferSize != null) {
return _minWaveHeaderBufferSize.Value;
}
var wavNoteSize = 0;
var hcaInfo = HcaInfo;
if (hcaInfo.Comment != null) {
wavNoteSize = 4 + (int)hcaInfo.CommentLength + 1;
if ((wavNoteSize & 3) != 0) {
wavNoteSize += 4 - (wavNoteSize & 3);
}
}
var sizeNeeded = Marshal.SizeOf(typeof(WaveRiffSection));
if (hcaInfo.LoopFlag) {
sizeNeeded += Marshal.SizeOf(typeof(WaveSampleSection));
}
if (hcaInfo.Comment != null && hcaInfo.Comment.Length > 0) {
sizeNeeded += 8 * wavNoteSize;
}
sizeNeeded += Marshal.SizeOf(typeof(WaveDataSection));
_minWaveHeaderBufferSize = sizeNeeded;
return _minWaveHeaderBufferSize.Value;
}
public int GetMinWaveDataBufferSize() {
if (_minWaveDataBufferSize != null) {
return _minWaveDataBufferSize.Value;
}
_minWaveDataBufferSize = 0x80 * GetSampleBitsFromParams() * (int)HcaInfo.ChannelCount;
return _minWaveDataBufferSize.Value;
}
public int WriteWaveHeader(byte[] stream) {
return WriteWaveHeader(stream, AudioParams.Default);
}
public int WriteWaveHeader(byte[] stream, AudioParams audioParams) {
if (stream == null) {
throw new ArgumentNullException(NameOf(() => stream));
}
var hcaInfo = HcaInfo;
if (hcaInfo.LoopFlag && audioParams.InfiniteLoop) {
// See remarks of AudioParams.InfiniteLoop.
throw new HcaException(ErrorMessages.GetInvalidParameter(NameOf(() => audioParams.InfiniteLoop)), ActionResult.InvalidParameter);
}
var minimumHeaderBufferSize = GetMinWaveHeaderBufferSize();
if (stream.Length < minimumHeaderBufferSize) {
throw new HcaException(ErrorMessages.GetBufferTooSmall(minimumHeaderBufferSize, stream.Length), ActionResult.BufferTooSmall);
}
var sampleBits = GetSampleBitsFromParams();
var wavRiff = WaveRiffSection.CreateDefault();
var wavNote = WaveNoteSection.CreateDefault();
var wavData = WaveDataSection.CreateDefault();
wavRiff.FmtType = (ushort)(_decodeParams.Mode != SamplingMode.R32 ? 1 : 3);
wavRiff.FmtChannels = (ushort)hcaInfo.ChannelCount;
wavRiff.FmtBitCount = (ushort)(sampleBits > 0 ? sampleBits : sizeof(float));
wavRiff.FmtSamplingRate = hcaInfo.SamplingRate;
wavRiff.FmtSamplingSize = (ushort)(wavRiff.FmtBitCount / 8 * wavRiff.FmtChannels);
wavRiff.FmtSamplesPerSec = wavRiff.FmtSamplingRate * wavRiff.FmtSamplingSize;
if (hcaInfo.Comment != null) {
wavNote.NoteSize = 4 + hcaInfo.CommentLength + 1;
if ((wavNote.NoteSize & 3) != 0) {
wavNote.NoteSize += 4 - (wavNote.NoteSize & 3);
}
}
var totalBlockCount = hcaInfo.BlockCount;
if (hcaInfo.LoopFlag) {
totalBlockCount += (hcaInfo.LoopEnd - hcaInfo.LoopStart + 1) * audioParams.SimulatedLoopCount;
}
wavData.DataSize = totalBlockCount * 0x80 * 8 * wavRiff.FmtSamplingSize;
wavRiff.RiffSize = (uint)(0x1c + (hcaInfo.Comment != null ? wavNote.NoteSize : 0) + Marshal.SizeOf(wavData) + wavData.DataSize);
var bytesWritten = stream.Write(wavRiff, 0);
if (hcaInfo.Comment != null) {
var address = bytesWritten;
bytesWritten += stream.Write(wavNote, bytesWritten);
stream.Write(hcaInfo.Comment, bytesWritten);
bytesWritten = address + 8 + (int)wavNote.NoteSize;
bytesWritten += 8 + (int)wavNote.NoteSize;
}
bytesWritten += stream.Write(wavData, bytesWritten);
return bytesWritten;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c5e08f72e809cf74392c81b98ec6b6b2
timeCreated: 1531897075
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
namespace DereTore.Exchange.Audio.HCA {
public static class HcaEncoderInfo {
// Measured value
public static int EncoderDelayInSamples { get { return 128; } }
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a74dd3c487568f446bb67a284d881ca3
timeCreated: 1531897075
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,21 @@
using System;
namespace DereTore.Exchange.Audio.HCA {
public sealed class HcaException : Exception {
public HcaException(string message, ActionResult actionResult)
: base(message) {
_actionResult = actionResult;
}
public HcaException(string message, ActionResult actionResult, Exception innerException)
: base(message, innerException) {
_actionResult = actionResult;
}
public ActionResult ActionResult { get { return _actionResult; } }
private readonly ActionResult _actionResult;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f22f6ba511070d147a4bf6c4e14f9e56
timeCreated: 1531897076
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,150 @@
using System;
namespace DereTore.Exchange.Audio.HCA {
internal static class HcaHelper {
static HcaHelper() {
SyncObject = new object();
}
public static void TranslateTables() {
lock (SyncObject) {
if (_tablesTranslated) {
return;
}
ChannelTables.TranslateTables();
_tablesTranslated = true;
}
}
public static uint Ceil2(uint a, uint b) {
return (b > 0) ? (uint)(a / b + ((a % b) != 0 ? 1 : 0)) : 0;
}
public static ushort Checksum(byte[] data, ushort sum) {
return Checksum(data, sum, data.Length);
}
/// <summary></summary>
/// <example>
/// var headerChecksum = HcaHelper.Checksum(headerBytes, 0, headerBytes.Length - 2);
/// headerChecksum = HcaHelper.SwapEndian(headerChecksum);
/// headerBytes[headerBytes.Length - 2] = HIBYTE(headerChecksum);
/// headerBytes[headerBytes.Length - 1] = LOBYTE(headerChecksum);
/// </example>
public static ushort Checksum(byte[] data, ushort sum, int length) {
var dataLength = data.Length;
dataLength = Math.Min(dataLength, length);
for (var i = 0; i < dataLength; ++i) {
sum = (ushort)((sum << 8) ^ ChecksumTable[(sum >> 8) ^ data[i]]);
}
return sum;
}
public static void SetString(out byte[] p, string value) {
p = new byte[value.Length];
for (var i = 0; i < value.Length; ++i) {
p[i] = (byte)value[i];
}
}
public static float UInt32ToSingleBits(uint v) {
return BitConverter.ToSingle(BitConverter.GetBytes(v), 0);
}
public static uint SingleToUInt32Bits(float v) {
return BitConverter.ToUInt32(BitConverter.GetBytes(v), 0);
}
public static void Clamp(ref float value, float minimum, float maximum) {
if (value < minimum) {
value = minimum;
} else if (value > maximum) {
value = maximum;
}
}
public static float Clamp(float value, float minimum, float maximum) {
return value < minimum ? minimum : (value > maximum ? maximum : value);
}
public static void Exchange<T>(ref T v1, ref T v2) {
var v3 = v1;
v1 = v2;
v2 = v3;
}
public static bool Succeeded(ActionResult actionResult) {
return actionResult >= 0;
}
public static bool Failed(ActionResult actionResult) {
return actionResult < 0;
}
public static uint CalculateLengthInSamples(HcaInfo hcaInfo) {
return hcaInfo.BlockCount * hcaInfo.ChannelCount * 0x80 * 8;
}
public static uint CalculateLengthInSamples(HcaInfo hcaInfo, uint loopCount, bool infiniteLoop) {
if (infiniteLoop) {
return uint.MaxValue;
}
var totalBlockCount = hcaInfo.BlockCount;
totalBlockCount += (hcaInfo.LoopEnd - hcaInfo.LoopStart + 1) * loopCount;
return totalBlockCount * hcaInfo.ChannelCount * 0x80 * 8;
}
public static float CalculateLengthInSeconds(HcaInfo hcaInfo) {
return hcaInfo.BlockCount * 0x80 * 8 / (float)hcaInfo.SamplingRate;
}
public static float CalculateLengthInSeconds(HcaInfo hcaInfo, uint loopCount, bool infiniteLoop) {
if (infiniteLoop) {
return float.MaxValue;
}
var totalBlockCount = hcaInfo.BlockCount;
totalBlockCount += (hcaInfo.LoopEnd - hcaInfo.LoopStart + 1) * loopCount;
return totalBlockCount * 0x80 * 8 / (float)hcaInfo.SamplingRate;
}
private static readonly ushort[] ChecksumTable = {
0x0000, 0x8005, 0x800F, 0x000A, 0x801B, 0x001E, 0x0014, 0x8011,
0x8033, 0x0036, 0x003C, 0x8039, 0x0028, 0x802D, 0x8027, 0x0022,
0x8063, 0x0066, 0x006C, 0x8069, 0x0078, 0x807D, 0x8077, 0x0072,
0x0050, 0x8055, 0x805F, 0x005A, 0x804B, 0x004E, 0x0044, 0x8041,
0x80C3, 0x00C6, 0x00CC, 0x80C9, 0x00D8, 0x80DD, 0x80D7, 0x00D2,
0x00F0, 0x80F5, 0x80FF, 0x00FA, 0x80EB, 0x00EE, 0x00E4, 0x80E1,
0x00A0, 0x80A5, 0x80AF, 0x00AA, 0x80BB, 0x00BE, 0x00B4, 0x80B1,
0x8093, 0x0096, 0x009C, 0x8099, 0x0088, 0x808D, 0x8087, 0x0082,
0x8183, 0x0186, 0x018C, 0x8189, 0x0198, 0x819D, 0x8197, 0x0192,
0x01B0, 0x81B5, 0x81BF, 0x01BA, 0x81AB, 0x01AE, 0x01A4, 0x81A1,
0x01E0, 0x81E5, 0x81EF, 0x01EA, 0x81FB, 0x01FE, 0x01F4, 0x81F1,
0x81D3, 0x01D6, 0x01DC, 0x81D9, 0x01C8, 0x81CD, 0x81C7, 0x01C2,
0x0140, 0x8145, 0x814F, 0x014A, 0x815B, 0x015E, 0x0154, 0x8151,
0x8173, 0x0176, 0x017C, 0x8179, 0x0168, 0x816D, 0x8167, 0x0162,
0x8123, 0x0126, 0x012C, 0x8129, 0x0138, 0x813D, 0x8137, 0x0132,
0x0110, 0x8115, 0x811F, 0x011A, 0x810B, 0x010E, 0x0104, 0x8101,
0x8303, 0x0306, 0x030C, 0x8309, 0x0318, 0x831D, 0x8317, 0x0312,
0x0330, 0x8335, 0x833F, 0x033A, 0x832B, 0x032E, 0x0324, 0x8321,
0x0360, 0x8365, 0x836F, 0x036A, 0x837B, 0x037E, 0x0374, 0x8371,
0x8353, 0x0356, 0x035C, 0x8359, 0x0348, 0x834D, 0x8347, 0x0342,
0x03C0, 0x83C5, 0x83CF, 0x03CA, 0x83DB, 0x03DE, 0x03D4, 0x83D1,
0x83F3, 0x03F6, 0x03FC, 0x83F9, 0x03E8, 0x83ED, 0x83E7, 0x03E2,
0x83A3, 0x03A6, 0x03AC, 0x83A9, 0x03B8, 0x83BD, 0x83B7, 0x03B2,
0x0390, 0x8395, 0x839F, 0x039A, 0x838B, 0x038E, 0x0384, 0x8381,
0x0280, 0x8285, 0x828F, 0x028A, 0x829B, 0x029E, 0x0294, 0x8291,
0x82B3, 0x02B6, 0x02BC, 0x82B9, 0x02A8, 0x82AD, 0x82A7, 0x02A2,
0x82E3, 0x02E6, 0x02EC, 0x82E9, 0x02F8, 0x82FD, 0x82F7, 0x02F2,
0x02D0, 0x82D5, 0x82DF, 0x02DA, 0x82CB, 0x02CE, 0x02C4, 0x82C1,
0x8243, 0x0246, 0x024C, 0x8249, 0x0258, 0x825D, 0x8257, 0x0252,
0x0270, 0x8275, 0x827F, 0x027A, 0x826B, 0x026E, 0x0264, 0x8261,
0x0220, 0x8225, 0x822F, 0x022A, 0x823B, 0x023E, 0x0234, 0x8231,
0x8213, 0x0216, 0x021C, 0x8219, 0x0208, 0x820D, 0x8207, 0x0202
};
private static bool _tablesTranslated;
private static readonly object SyncObject;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: bc142b5623656334c943a5665f989a63
timeCreated: 1531897075
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,35 @@
namespace DereTore.Exchange.Audio.HCA {
public struct HcaInfo {
public ushort Version;
public uint DataOffset;
public uint ChannelCount;
public uint SamplingRate;
public uint BlockCount;
public ushort FmtR01;
public ushort FmtR02;
public uint BlockSize;
public ushort CompR01;
public ushort CompR02;
public ushort CompR03;
public ushort CompR04;
public ushort CompR05;
public ushort CompR06;
public ushort CompR07;
public ushort CompR08;
public uint CompR09;
public ushort VbrR01;
public ushort VbrR02;
public ushort AthType;
public uint LoopStart;
public uint LoopEnd;
public ushort LoopR01;
public ushort LoopR02;
public bool LoopFlag;
public CipherType CipherType;
public float RvaVolume;
public uint CommentLength;
public byte[] Comment;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 8171e8f52dd22e849a11f1808927bb37
timeCreated: 1531897075
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,220 @@
using System.Collections.Generic;
using System.IO;
using DereTore.Common;
using DereTore.Exchange.Audio.HCA.Native;
namespace DereTore.Exchange.Audio.HCA {
public abstract class HcaReader {
public Stream SourceStream
{
get
{
return _sourceStream;
}
}
public HcaInfo HcaInfo { get; private set; }
public static bool IsHcaStream(Stream stream) {
var position = stream.Position;
bool result;
try {
// The cipher keys do nothing to validating HCA files.
new HcaDecoder(stream, DecodeParams.Default);
result = true;
} catch (HcaException) {
result = false;
}
stream.Seek(position, SeekOrigin.Begin);
return result;
}
public static bool IsLoopedHcaStream(Stream stream) {
var position = stream.Position;
bool result;
try {
// The cipher keys do nothing to validating HCA files.
var decoder = new HcaDecoder(stream, DecodeParams.Default);
result = decoder.HcaInfo.LoopFlag;
} catch (HcaException) {
result = false;
}
stream.Seek(position, SeekOrigin.Begin);
return result;
}
internal void ParseHeaders() {
var stream = SourceStream;
uint v;
var hcaInfo = new HcaInfo();
// HCA
v = stream.PeekUInt32LE();
if (MagicValues.IsMagicMatch(v, MagicValues.HCA)) {
HcaHeader header;
stream.Read(out header);
hcaInfo.Version = DereToreHelper.SwapEndian(header.Version);
hcaInfo.DataOffset = DereToreHelper.SwapEndian(header.DataOffset);
} else {
throw new HcaException("Missing HCA signature.", ActionResult.MagicNotMatch);
}
// FMT
v = stream.PeekUInt32LE();
if (MagicValues.IsMagicMatch(v, MagicValues.FMT)) {
FormatHeader header;
stream.Read(out header);
hcaInfo.ChannelCount = header.Channels;
hcaInfo.SamplingRate = DereToreHelper.SwapEndian(header.SamplingRate << 8);
hcaInfo.BlockCount = DereToreHelper.SwapEndian(header.Blocks);
hcaInfo.FmtR01 = DereToreHelper.SwapEndian(header.R01);
hcaInfo.FmtR02 = DereToreHelper.SwapEndian(header.R02);
if (hcaInfo.ChannelCount < 1 || hcaInfo.ChannelCount > 16) {
throw new HcaException(string.Format("Channel count should be between 1 and 16, read {0}.", hcaInfo.ChannelCount), ActionResult.InvalidFieldValue);
}
if (hcaInfo.SamplingRate < 1 || hcaInfo.SamplingRate > 0x7fffff) {
throw new HcaException(string.Format("Sampling rate should be between 1 and {0}, read {1}.", 0x7fffffff, hcaInfo.SamplingRate), ActionResult.InvalidFieldValue);
}
} else {
throw new HcaException("Missing FMT signature.", ActionResult.MagicNotMatch);
}
// COMP / DEC
v = stream.PeekUInt32LE();
if (MagicValues.IsMagicMatch(v, MagicValues.COMP)) {
CompressHeader header;
stream.Read(out header);
hcaInfo.BlockSize = DereToreHelper.SwapEndian(header.BlockSize);
hcaInfo.CompR01 = header.R01;
hcaInfo.CompR02 = header.R02;
hcaInfo.CompR03 = header.R03;
hcaInfo.CompR04 = header.R04;
hcaInfo.CompR05 = header.R05;
hcaInfo.CompR06 = header.R06;
hcaInfo.CompR07 = header.R07;
hcaInfo.CompR08 = header.R08;
if ((hcaInfo.BlockSize < 8 || hcaInfo.BlockSize > 0xffff) && hcaInfo.BlockSize != 0) {
throw new HcaException(string.Format("Block size should be between 8 and {0}, read {hcaInfo.BlockSize}.", 0xffff), ActionResult.InvalidFieldValue);
}
if (!(hcaInfo.CompR01 <= hcaInfo.CompR02 && hcaInfo.CompR02 <= 0x1f)) {
throw new HcaException(string.Format("CompR01 should be less than or equal to CompR02, and CompR02 should be less than or equal to {0}, read {1} and {2}.", 0x1f, hcaInfo.CompR01, hcaInfo.CompR02), ActionResult.InvalidFieldValue);
}
} else if (MagicValues.IsMagicMatch(v, MagicValues.DEC)) {
DecodeHeader header;
stream.Read(out header);
hcaInfo.CompR01 = header.R01;
hcaInfo.CompR02 = header.R02;
hcaInfo.CompR03 = header.R04;
hcaInfo.CompR04 = header.R03;
hcaInfo.CompR05 = (ushort)(header.Count1 + 1);
hcaInfo.CompR06 = (ushort)((header.EnableCount2 ? header.Count2 : header.Count1) + 1);
hcaInfo.CompR07 = (ushort)(hcaInfo.CompR05 - hcaInfo.CompR06);
hcaInfo.CompR08 = 0;
if ((hcaInfo.BlockSize < 8 || hcaInfo.BlockSize > 0xffff) && hcaInfo.BlockSize != 0) {
throw new HcaException(string.Format("Block size should be between 8 and {0}, read {1}.", 0xffff, hcaInfo.BlockSize), ActionResult.InvalidFieldValue);
}
if (!(hcaInfo.CompR01 <= hcaInfo.CompR02 && hcaInfo.CompR02 <= 0x1f)) {
throw new HcaException(string.Format("CompR01 should be less than or equal to CompR02, and CompR02 should be less than or equal to {0}, read {1} and {2}.", 0x1f, hcaInfo.CompR01, hcaInfo.CompR02), ActionResult.InvalidFieldValue);
}
if (hcaInfo.CompR03 == 0) {
hcaInfo.CompR03 = 1;
}
} else {
throw new HcaException("Missing COMP/DEC signature.", ActionResult.MagicNotMatch);
}
// VBR
v = stream.PeekUInt32LE();
if (MagicValues.IsMagicMatch(v, MagicValues.VBR)) {
VbrHeader header;
stream.Read(out header);
hcaInfo.VbrR01 = DereToreHelper.SwapEndian(header.R01);
hcaInfo.VbrR02 = DereToreHelper.SwapEndian(header.R02);
if (!(hcaInfo.BlockSize == 0 && hcaInfo.VbrR01 < 0x01ff)) {
throw new HcaException(string.Format("VbrR01 should be less than {0} in VBR HCA.", 0x01ff), ActionResult.InvalidFieldValue);
}
} else {
hcaInfo.VbrR01 = hcaInfo.VbrR02 = 0;
}
// ATH
v = stream.PeekUInt32LE();
if (MagicValues.IsMagicMatch(v, MagicValues.ATH)) {
AthHeader header;
stream.Read(out header);
hcaInfo.AthType = header.Type;
} else {
hcaInfo.AthType = (ushort)(hcaInfo.Version < 0x0200 ? 1 : 0);
}
// LOOP
v = stream.PeekUInt32LE();
if (MagicValues.IsMagicMatch(v, MagicValues.LOOP)) {
LoopHeader header;
stream.Read(out header);
hcaInfo.LoopStart = DereToreHelper.SwapEndian(header.LoopStart);
hcaInfo.LoopEnd = DereToreHelper.SwapEndian(header.LoopEnd);
hcaInfo.LoopR01 = DereToreHelper.SwapEndian(header.R01);
hcaInfo.LoopR02 = DereToreHelper.SwapEndian(header.R02);
hcaInfo.LoopFlag = true;
} else {
hcaInfo.LoopStart = 0;
hcaInfo.LoopEnd = 0;
hcaInfo.LoopR01 = 0;
hcaInfo.LoopR02 = 0x400;
hcaInfo.LoopFlag = false;
}
// CIPH
v = stream.PeekUInt32LE();
if (MagicValues.IsMagicMatch(v, MagicValues.CIPH)) {
CipherHeader header;
stream.Read(out header);
hcaInfo.CipherType = (CipherType)DereToreHelper.SwapEndian(header.Type);
} else {
hcaInfo.CipherType = CipherType.NoChipher;
}
// RVA
v = stream.PeekUInt32LE();
if (MagicValues.IsMagicMatch(v, MagicValues.RVA)) {
RvaHeader header;
stream.Read(out header);
hcaInfo.RvaVolume = DereToreHelper.SwapEndian(header.Volume);
} else {
hcaInfo.RvaVolume = 1;
}
// COMM
v = stream.PeekUInt32LE();
if (MagicValues.IsMagicMatch(v, MagicValues.COMM)) {
CommentHeader header;
stream.Read(out header);
hcaInfo.CommentLength = header.Length;
var tmpCommentCharList = new List<byte>();
byte tmpByte;
do {
tmpByte = (byte)stream.ReadByte();
tmpCommentCharList.Add(tmpByte);
} while (tmpByte != 0);
hcaInfo.Comment = tmpCommentCharList.ToArray();
} else {
hcaInfo.CommentLength = 0;
hcaInfo.Comment = null;
}
// PAD (undocumented)
v = stream.PeekUInt32LE();
if (MagicValues.IsMagicMatch(v, MagicValues.PAD)) {
stream.Skip(4); // Length of 'pad '
}
if (hcaInfo.CompR03 == 0) {
hcaInfo.CompR03 = 1;
}
if (hcaInfo.CompR01 != 1 || hcaInfo.CompR02 != 0xf) {
throw new HcaException(string.Format("Expected CompR01=1, CompR02=15, read {0}, {1}.", hcaInfo.CompR01, hcaInfo.CompR02), ActionResult.InvalidFieldValue);
}
hcaInfo.CompR09 = HcaHelper.Ceil2((uint)(hcaInfo.CompR05 - (hcaInfo.CompR06 + hcaInfo.CompR07)), hcaInfo.CompR08);
HcaInfo = hcaInfo;
}
protected HcaReader(Stream sourceStream) {
_sourceStream = sourceStream;
}
private readonly Stream _sourceStream;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e09ca24683ca9014295f70d403cbe7e1
timeCreated: 1531897076
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,22 @@
using System.IO;
namespace DereTore.Exchange.Audio.HCA {
public interface IWaveWriter {
SamplingMode SamplingMode { get; }
uint BytesPerSample { get; }
/// <summary>
/// Decode an audio sample to buffer.
/// </summary>
/// <param name="f">Audio sample value.</param>
/// <param name="buffer">Decode buffer for output.</param>
/// <param name="offset">Offset of the desired starting byte in buffer.</param>
/// <returns>Bytes written.</returns>
uint DecodeToBuffer(float f, byte[] buffer, uint offset);
uint DecodeToStream(float f, Stream stream);
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 318b2a602109896449bc5cf05c5f35b2
timeCreated: 1531897074
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,31 @@
namespace DereTore.Exchange.Audio.HCA {
public static class MagicValues {
public static readonly uint HCA = 0x00414348;
public static readonly uint FMT = 0x00746d66;
public static readonly uint COMP = 0x706d6f63;
public static readonly uint DEC = 0x00636564;
public static readonly uint VBR = 0x00726276;
public static readonly uint ATH = 0x00687461;
public static readonly uint LOOP = 0x706f6f6c;
public static readonly uint CIPH = 0x68706963;
public static readonly uint RVA = 0x00617672;
public static readonly uint COMM = 0x6d6d6f63;
public static readonly uint PAD = 0x00646170;
public static bool IsMagicMatch(uint valueRead, uint valueToCheck) {
return (valueRead & 0x7f7f7f7f) == valueToCheck;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 26d0434290a199d41b42575dc34f5daa
timeCreated: 1531897074
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 9c6fdd3a8a7ed9a44b143bfe7affc218
folderAsset: yes
timeCreated: 1531897074
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,21 @@
using System.Runtime.InteropServices;
namespace DereTore.Exchange.Audio.HCA.Native {
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct AthHeader {
public uint ATH {
get { return _ath; }
set { _ath = value; }
}
public ushort Type {
get { return _type; }
set { _type = value; }
}
private uint _ath;
private ushort _type;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e1bf30dfad5bee047832455bf63b7211
timeCreated: 1531897076
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,21 @@
using System.Runtime.InteropServices;
namespace DereTore.Exchange.Audio.HCA.Native {
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct CipherHeader {
public uint CIPH {
get { return _ciph; }
set { _ciph = value; }
}
public ushort Type {
get { return _type; }
set { _type = value; }
}
private uint _ciph;
private ushort _type;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 228cab927670653418697c98965c350d
timeCreated: 1531897074
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,21 @@
using System.Runtime.InteropServices;
namespace DereTore.Exchange.Audio.HCA.Native {
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
public struct CommentHeader {
public uint COMM {
get { return _comm; }
set { _comm = value; }
}
public byte Length {
get { return _length; }
set { _length = value; }
}
private uint _comm;
private byte _length;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 205a93edd24ca4948aaccc59a9225c38
timeCreated: 1531897074
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,81 @@
using System.Runtime.InteropServices;
namespace DereTore.Exchange.Audio.HCA.Native {
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct CompressHeader {
public uint COMP {
get { return _comp; }
set { _comp = value; }
}
public ushort BlockSize {
get { return _blockSize; }
set { _blockSize = value; }
}
public byte R01 {
get { return _r01; }
set { _r01 = value; }
}
public byte R02 {
get { return _r02; }
set { _r02 = value; }
}
public byte R03 {
get { return _r03; }
set { _r03 = value; }
}
public byte R04 {
get { return _r04; }
set { _r04 = value; }
}
public byte R05 {
get { return _r05; }
set { _r05 = value; }
}
public byte R06 {
get { return _r06; }
set { _r06 = value; }
}
public byte R07 {
get { return _r07; }
set { _r07 = value; }
}
public byte R08 {
get { return _r08; }
set { _r08 = value; }
}
public byte Reserved1 {
get { return _rs1; }
set { _rs1 = value; }
}
public byte Reserved2 {
get { return _rs2; }
set { _rs2 = value; }
}
private uint _comp;
private ushort _blockSize;
private byte _r01;
private byte _r02;
private byte _r03;
private byte _r04;
private byte _r05;
private byte _r06;
private byte _r07;
private byte _r08;
private byte _rs1;
private byte _rs2;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 75f27239b6e77d4428f9c662dd9beb7d
timeCreated: 1531897075
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,62 @@
using System.Runtime.InteropServices;
namespace DereTore.Exchange.Audio.HCA.Native {
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct DecodeHeader {
public uint DEC {
get { return _dec; }
set { _dec = value; }
}
public ushort BlockSize {
get { return _blockSize; }
set { _blockSize = value; }
}
public byte R01 {
get { return _r01; }
set { _r01 = value; }
}
public byte R02 {
get { return _r02; }
set { _r02 = value; }
}
public byte Count1 {
get { return _count1; }
set { _count1 = value; }
}
public byte Count2 {
get { return _count2; }
set { _count2 = value; }
}
public byte R03 {
get { return (byte)(_tmpField1 & 0x0f); }
set { _tmpField1 = (byte)((_tmpField1 & 0xf0) | (value & 0x0f)); }
}
public byte R04 {
get { return (byte)((_tmpField1 & 0xf0) >> 4); }
set { _tmpField1 = (byte)((_tmpField1 & 0x0f) | ((value & 0x0f) << 4)); }
}
public bool EnableCount2 {
get { return _enableCount2 != 0; }
set { _enableCount2 = (byte)(value ? 1 : 0); }
}
private uint _dec;
private ushort _blockSize;
private byte _r01;
private byte _r02;
private byte _count1;
private byte _count2;
private byte _tmpField1;
private byte _enableCount2;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ac6ab3a083a9dab4c89d11c19ba8007a
timeCreated: 1531897075
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,44 @@
using System.Runtime.InteropServices;
namespace DereTore.Exchange.Audio.HCA.Native {
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct FormatHeader {
public uint FMT {
get { return _fmt; }
set { _fmt = value; }
}
public uint Channels {
get { return _tempField1 & 0x000000ff; }
set { _tempField1 = (_tempField1 & 0xffffff00) | (value & 0x000000ff); }
}
public uint SamplingRate {
get { return (_tempField1 & 0xffffff00) >> 8; }
set { _tempField1 = (_tempField1 & 0x000000ff) | ((value & 0x00ffffff) << 8); }
}
public uint Blocks {
get { return _blocks; }
set { _blocks = value; }
}
public ushort R01 {
get { return _r01; }
set { _r01 = value; }
}
public ushort R02 {
get { return _r02; }
set { _r02 = value; }
}
private uint _fmt;
private uint _tempField1;
private uint _blocks;
private ushort _r01;
private ushort _r02;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f1f5e07ab09e79c4cb4a047e3ca4dcaf
timeCreated: 1531897076
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,26 @@
using System.Runtime.InteropServices;
namespace DereTore.Exchange.Audio.HCA.Native {
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct HcaHeader {
public uint HCA {
get { return _hca; }
set { _hca = value; }
}
public ushort Version {
get { return _version; }
set { _version = value; }
}
public ushort DataOffset {
get { return _dataOffset; }
set { _dataOffset = value; }
}
private uint _hca;
private ushort _version;
private ushort _dataOffset;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 62f9c36a9b0321e499be72ff6f689539
timeCreated: 1531897075
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,39 @@
using System.Runtime.InteropServices;
namespace DereTore.Exchange.Audio.HCA.Native {
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct LoopHeader {
public uint LOOP {
get { return _loop; }
set { _loop = value; }
}
public uint LoopStart {
get { return _loopStart; }
set { _loopStart = value; }
}
public uint LoopEnd {
get { return _loopEnd; }
set { _loopEnd = value; }
}
public ushort R01 {
get { return _r01; }
set { _r01 = value; }
}
public ushort R02 {
get { return _r02; }
set { _r02 = value; }
}
private uint _loop;
private uint _loopStart;
private uint _loopEnd;
private ushort _r01;
private ushort _r02;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: cc745eb7512bd714cabdb77c4a409299
timeCreated: 1531897075
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,21 @@
using System.Runtime.InteropServices;
namespace DereTore.Exchange.Audio.HCA.Native {
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct RvaHeader {
public uint RVA {
get { return _rva; }
set { _rva = value; }
}
public float Volume {
get { return _volume; }
set { _volume = value; }
}
private uint _rva;
private float _volume;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 233557084787e4f428bf5c2f7afecca1
timeCreated: 1531897074
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,27 @@
using System.Runtime.InteropServices;
namespace DereTore.Exchange.Audio.HCA.Native {
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct VbrHeader {
public uint VBR {
get { return _vbr; }
set { _vbr = value; }
}
public ushort R01 {
get { return _r01; }
set { _r01 = value; }
}
public ushort R02 {
get { return _r02; }
set { _r02 = value; }
}
private uint _vbr;
private ushort _r01;
private ushort _r02;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0a9ede55bf3a2eb428324f4be4bae426
timeCreated: 1531897074
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,20 @@
using System.Runtime.InteropServices;
namespace DereTore.Exchange.Audio.HCA.Native {
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
public struct WaveDataSection {
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.U1, SizeConst = 4)]
public byte[] DATA;
public uint DataSize;
public static WaveDataSection CreateDefault() {
var v = default(WaveDataSection);
v.DataSize = 0;
HcaHelper.SetString(out v.DATA, "data");
return v;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 5f4777db495b7a242bc90ef3f0d41570
timeCreated: 1531897075
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,22 @@
using System.Runtime.InteropServices;
namespace DereTore.Exchange.Audio.HCA.Native {
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
public struct WaveNoteSection {
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.U1, SizeConst = 4)]
public byte[] NOTE;
public uint NoteSize;
public uint Name;
public static WaveNoteSection CreateDefault() {
var v = default(WaveNoteSection);
v.Name = 0;
v.NoteSize = 0;
HcaHelper.SetString(out v.NOTE, "note");
return v;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a70f2695872de014ab2f50396745b75c
timeCreated: 1531897075
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,43 @@
using System.Runtime.InteropServices;
namespace DereTore.Exchange.Audio.HCA.Native {
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
public struct WaveRiffSection {
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.U1, SizeConst = 4)]
public byte[] RIFF;
public uint RiffSize;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.U1, SizeConst = 4)]
public byte[] WAVE;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.U1, SizeConst = 4)]
public byte[] FMT;
public uint FmtSize;
public ushort FmtType;
public ushort FmtChannels;
public uint FmtSamplingRate;
public uint FmtSamplesPerSec;
public ushort FmtSamplingSize;
public ushort FmtBitCount;
public static WaveRiffSection CreateDefault() {
var v = default(WaveRiffSection);
v.RiffSize = 0;
v.FmtSize = 0x10;
v.FmtType = 0;
v.FmtChannels = 0;
v.FmtSamplingRate = 0;
v.FmtSamplesPerSec = 0;
v.FmtSamplingSize = 0;
v.FmtBitCount = 0;
HcaHelper.SetString(out v.RIFF, "RIFF");
HcaHelper.SetString(out v.WAVE, "WAVE");
HcaHelper.SetString(out v.FMT, "fmt ");
return v;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 070fb203876f0e84c86f57e3b1efa90c
timeCreated: 1531897074
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,50 @@
using System.Runtime.InteropServices;
namespace DereTore.Exchange.Audio.HCA.Native {
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
public struct WaveSampleSection {
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.U1, SizeConst = 4)]
public byte[] SMPL;
public uint SmplSize;
public uint Manufacturer;
public uint Product;
public uint SamplePeriod;
public uint MidiUnityNote;
public uint MidiPitchFraction;
public uint SmpteFormat;
public uint SmpteOffset;
public uint SampleLoops;
public uint SamplerData;
public uint LoopIdentifier;
public uint LoopType;
public uint LoopStart;
public uint LoopEnd;
public uint LoopFraction;
public uint LoopPlayCount;
public static WaveSampleSection CreateDefault() {
var v = default(WaveSampleSection);
v.SmplSize = 0x3c;
v.Manufacturer = 0;
v.Product = 0;
v.SamplePeriod = 0;
v.MidiUnityNote = 0x3c;
v.MidiPitchFraction = 0;
v.SmpteFormat = 0;
v.SmpteOffset = 0;
v.SampleLoops = 1;
v.SamplerData = 0x18;
v.LoopIdentifier = 0;
v.LoopType = 0;
v.LoopStart = 0;
v.LoopEnd = 0;
v.LoopFraction = 0;
v.LoopPlayCount = 0;
HcaHelper.SetString(out v.SMPL, "smpl");
return v;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 14f90a0d3ad3c1f4faf280de184a5a3c
timeCreated: 1531897074
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,195 @@
using System;
using System.IO;
using System.Linq.Expressions;
namespace DereTore.Exchange.Audio.HCA {
public sealed class OneWayHcaAudioStream : HcaAudioStreamBase {
public static string NameOf<T>(Expression<Func<T>> e)
{
return ((MemberExpression)e.Body).Member.Name;
}
public OneWayHcaAudioStream(Stream sourceStream)
: this(sourceStream, DecodeParams.Default) {
}
public OneWayHcaAudioStream(Stream sourceStream, bool outputWaveHeader)
: this(sourceStream, DecodeParams.Default, outputWaveHeader) {
}
public OneWayHcaAudioStream(Stream sourceStream, DecodeParams decodeParams)
: this(sourceStream, decodeParams, true) {
}
public OneWayHcaAudioStream(Stream sourceStream, DecodeParams decodeParams, bool outputWaveHeader)
: base(sourceStream, decodeParams) {
_decoder = new OneWayHcaDecoder(sourceStream, decodeParams);
OutputWaveHeader = outputWaveHeader;
_state = HcaAudioStreamDecodeState.Initialized;
}
public override long Seek(long offset, SeekOrigin origin) {
throw new NotSupportedException();
}
public override int Read(byte[] buffer, int offset, int count) {
if (!HasMoreData) {
return 0;
}
var writeLengthLimit = Math.Min(count, buffer.Length);
var outputWaveHeader = OutputWaveHeader;
var decoder = _decoder as OneWayHcaDecoder;
if (decoder == null) {
throw new NullReferenceException();
}
while (true) {
int maxToCopy;
var state = _state;
switch (state) {
case HcaAudioStreamDecodeState.Initialized: {
if (!outputWaveHeader) {
_state = HcaAudioStreamDecodeState.WaveHeaderTransmitted;
continue;
}
_waveHeaderSize = decoder.GetMinWaveHeaderBufferSize();
_waveHeaderBuffer = new byte[_waveHeaderSize];
_waveHeaderSizeLeft = _waveHeaderSize;
decoder.WriteWaveHeader(_waveHeaderBuffer);
maxToCopy = Math.Min(writeLengthLimit, _waveHeaderSizeLeft);
Array.Copy(_waveHeaderBuffer, _waveHeaderSize - _waveHeaderSizeLeft, buffer, offset, maxToCopy);
_waveHeaderSizeLeft -= maxToCopy;
_state = _waveHeaderSizeLeft <= 0 ? HcaAudioStreamDecodeState.WaveHeaderTransmitted : HcaAudioStreamDecodeState.WaveHeaderTransmitting;
return maxToCopy;
}
case HcaAudioStreamDecodeState.WaveHeaderTransmitting: {
if (!outputWaveHeader) {
_state = HcaAudioStreamDecodeState.WaveHeaderTransmitted;
continue;
}
maxToCopy = Math.Min(writeLengthLimit, _waveHeaderSizeLeft);
Array.Copy(_waveHeaderBuffer, _waveHeaderSize - _waveHeaderSizeLeft, buffer, offset, maxToCopy);
_waveHeaderSizeLeft -= maxToCopy;
if (_waveHeaderSizeLeft <= 0) {
_state = HcaAudioStreamDecodeState.WaveHeaderTransmitted;
}
return maxToCopy;
}
case HcaAudioStreamDecodeState.WaveHeaderTransmitted: {
_standardWaveDataSize = decoder.GetMinWaveDataBufferSize();
_waveDataSize = _standardWaveDataSize * BlockBatchSize;
_waveDataBuffer = new byte[_waveDataSize];
var decodedBlockCount = decoder.DecodeBlocks(_waveDataBuffer);
_waveDataSize = (int)(decodedBlockCount * decoder.GetMinWaveDataBufferSize());
_waveDataSizeLeft = _waveDataSize;
maxToCopy = Math.Min(writeLengthLimit, _waveDataSizeLeft);
Array.Copy(_waveDataBuffer, _waveDataSize - _waveDataSizeLeft, buffer, offset, maxToCopy);
_waveDataSizeLeft -= maxToCopy;
if (_waveDataSizeLeft <= 0) {
_state = decoder.HasMore ? HcaAudioStreamDecodeState.DataTransmitting : HcaAudioStreamDecodeState.WaveHeaderTransmitted;
} else {
_state = HcaAudioStreamDecodeState.DataTransmitting;
}
return maxToCopy;
}
case HcaAudioStreamDecodeState.DataTransmitting: {
if (_waveDataSizeLeft <= 0) {
_waveDataSize = _standardWaveDataSize * BlockBatchSize;
_waveDataBuffer = new byte[_waveDataSize];
var decodedBlockCount = decoder.DecodeBlocks(_waveDataBuffer);
if (decodedBlockCount > 0 || decoder.HasMore) {
_waveDataSize = (int)(decodedBlockCount * decoder.GetMinWaveDataBufferSize());
_waveDataSizeLeft = _waveDataSize;
_state = HcaAudioStreamDecodeState.DataTransmitting;
} else {
_state = HcaAudioStreamDecodeState.WaveHeaderTransmitted;
continue;
}
}
maxToCopy = Math.Min(writeLengthLimit, _waveDataSizeLeft);
Array.Copy(_waveDataBuffer, _waveDataSize - _waveDataSizeLeft, buffer, offset, maxToCopy);
_waveDataSizeLeft -= maxToCopy;
return maxToCopy;
}
case HcaAudioStreamDecodeState.DataTransmitted:
return 0;
default:
throw new ArgumentOutOfRangeException(NameOf(() => state));
}
}
}
public override bool CanSeek { get { return false; } }
public override long Length {
get {
if (!EnsureNotDisposed()) {
return 0;
}
if (_length != null) {
return _length.Value;
}
var hcaInfo = HcaInfo;
long totalLength = 0;
if (OutputWaveHeader) {
totalLength += _waveHeaderSize;
}
totalLength += _decoder.GetMinWaveDataBufferSize() * hcaInfo.BlockCount;
_length = totalLength;
return _length.Value;
}
}
public override long Position {
get { throw new NotSupportedException(); }
set { throw new NotSupportedException(); }
}
public override float LengthInSeconds { get { return HcaHelper.CalculateLengthInSeconds(HcaInfo); } }
public override uint LengthInSamples
{
get
{
return HcaHelper.CalculateLengthInSamples(HcaInfo);
}
}
public int BlockBatchSize
{
get
{
return 10;
}
}
protected override bool HasMoreData {
get {
const HcaAudioStreamDecodeState canDoHasMoreCheck = HcaAudioStreamDecodeState.WaveHeaderTransmitting | HcaAudioStreamDecodeState.WaveHeaderTransmitted | HcaAudioStreamDecodeState.DataTransmitting;
if ((_state & canDoHasMoreCheck) != 0) {
var decoder = _decoder as OneWayHcaDecoder;
var hasMore = true;
if (decoder == null)
{
hasMore = false;
}
return !(_waveDataSizeLeft <= 0 && _waveHeaderSizeLeft <= 0 && !hasMore);
} else {
return _state == HcaAudioStreamDecodeState.Initialized;
}
}
}
private bool OutputWaveHeader;
private HcaAudioStreamDecodeState _state;
private byte[] _waveHeaderBuffer;
private int _waveHeaderSize;
private int _waveHeaderSizeLeft;
private byte[] _waveDataBuffer;
private int _waveDataSize;
private int _standardWaveDataSize;
private int _waveDataSizeLeft;
private long? _length;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 8502dbf6b8f47c24485ddf9cad90e8f8
timeCreated: 1531897075
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,44 @@
using System.IO;
namespace DereTore.Exchange.Audio.HCA
{
public sealed class OneWayHcaDecoder : HcaDecoder
{
public OneWayHcaDecoder(Stream sourceStream)
: base(sourceStream)
{
}
public OneWayHcaDecoder(Stream sourceStream, DecodeParams decodeParams)
: base(sourceStream, decodeParams)
{
}
public uint DecodeBlocks(byte[] buffer)
{
if (!HasMore)
{
return 0;
}
var decodedBlockCount = DecodeBlocks(buffer, _blockIndex);
_blockIndex += decodedBlockCount;
return decodedBlockCount;
}
public bool HasMore
{
get
{
return (_blockIndex < HcaInfo.BlockCount);
}
}
public uint LengthInSamples { get { return HcaHelper.CalculateLengthInSamples(HcaInfo); } }
public float LengthInSeconds { get { return HcaHelper.CalculateLengthInSeconds(HcaInfo); } }
private uint _blockIndex = 0;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 3194898b6b558a14586337a085122e72
timeCreated: 1531897074
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,11 @@
namespace DereTore.Exchange.Audio.HCA {
public enum SamplingMode {
S16,
R32,
U8,
S24,
S32
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 04c01ad34c3714f4f9e680b00d14a506
timeCreated: 1531897074
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,146 @@
using System;
using System.IO;
using DereTore.Common;
using System.Linq.Expressions;
namespace DereTore.Exchange.Audio.HCA {
public static class WaveHelper {
public static readonly IWaveWriter U8 = new WaveWriterU8();
public static readonly IWaveWriter S16 = new WaveWriterS16();
public static readonly IWaveWriter S32 = new WaveWriterS32();
public static readonly IWaveWriter R32 = new WaveWriterR32();
private class WaveWriterU8 : IWaveWriter {
public static string NameOf<T>(Expression<Func<T>> e)
{
return ((MemberExpression)e.Body).Member.Name;
}
public uint BytesPerSample { get { return 1; } }
public SamplingMode SamplingMode { get { return SamplingMode.U8; } }
public uint DecodeToBuffer(float f, byte[] buffer, uint offset) {
if (offset >= buffer.Length) {
throw new ArgumentOutOfRangeException(NameOf(() => offset));
}
var s = (sbyte)((int)(f * 0xff) - 0x80);
unchecked {
buffer[offset] = (byte)s;
}
return 1;
}
public uint DecodeToStream(float f, Stream stream) {
return (uint)stream.Write((sbyte)((int)(f * 0xff) - 0x80));
}
}
private class WaveWriterS16 : IWaveWriter {
public static string NameOf<T>(Expression<Func<T>> e)
{
return ((MemberExpression)e.Body).Member.Name;
}
public uint BytesPerSample { get { return 2; } }
public SamplingMode SamplingMode { get { return SamplingMode.S16; } }
public uint DecodeToBuffer(float f, byte[] buffer, uint offset) {
if (offset >= buffer.Length) {
throw new ArgumentOutOfRangeException(NameOf(() => offset));
}
var value = (short)(f * 0x7fff);
if (!BitConverter.IsLittleEndian) {
value = DereToreHelper.SwapEndian(value);
}
var bytes = BitConverter.GetBytes(value);
var bytesWritten = 0u;
for (var i = 0; i < 2; ++i) {
if (offset + i > buffer.Length) {
break;
}
buffer[offset + i] = bytes[i];
++bytesWritten;
}
return bytesWritten;
}
public uint DecodeToStream(float f, Stream stream) {
return (uint)stream.Write((short)(f * 0x7fff));
}
}
private class WaveWriterS32 : IWaveWriter {
public static string NameOf<T>(Expression<Func<T>> e)
{
return ((MemberExpression)e.Body).Member.Name;
}
public uint BytesPerSample { get { return 4; } }
public SamplingMode SamplingMode { get { return SamplingMode.S32; } }
public uint DecodeToBuffer(float f, byte[] buffer, uint offset) {
if (offset >= buffer.Length) {
throw new ArgumentOutOfRangeException(NameOf(() => offset));
}
var value = (short)(f * 0x7fffffff);
if (!BitConverter.IsLittleEndian) {
value = DereToreHelper.SwapEndian(value);
}
var bytes = BitConverter.GetBytes(value);
var bytesWritten = 0u;
for (var i = 0; i < 4; ++i) {
if (offset + i >= buffer.Length) {
break;
}
buffer[offset + i] = bytes[i];
++bytesWritten;
}
return bytesWritten;
}
public uint DecodeToStream(float f, Stream stream) {
return (uint)stream.Write((short)(f * 0x7fffffff));
}
}
private class WaveWriterR32 : IWaveWriter {
public static string NameOf<T>(Expression<Func<T>> e)
{
return ((MemberExpression)e.Body).Member.Name;
}
public uint BytesPerSample { get { return 4; } }
public SamplingMode SamplingMode { get { return SamplingMode.R32; } }
public uint DecodeToBuffer(float f, byte[] buffer, uint offset) {
if (offset >= buffer.Length) {
throw new ArgumentOutOfRangeException(NameOf(() => offset));
}
if (!BitConverter.IsLittleEndian) {
f = DereToreHelper.SwapEndian(f);
}
var bytes = BitConverter.GetBytes(f);
var bytesWritten = 0u;
for (var i = 0; i < 4; ++i) {
if (offset + i >= buffer.Length) {
break;
}
buffer[offset + i] = bytes[i];
++bytesWritten;
}
return bytesWritten;
}
public uint DecodeToStream(float f, Stream stream) {
return (uint)stream.Write(f);
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 3c9ecdac3f46aa44ab2d4dc6c0bf7a47
timeCreated: 1531897074
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: