Skip to content

Commit

Permalink
Merge pull request #40 from statementreply/hca2wav-crach-fix
Browse files Browse the repository at this point in the history
[hca2wav] Fix crash in Decode3
  • Loading branch information
hozuki committed Jul 17, 2017
2 parents 0280928 + d62ca39 commit ed03489
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions Exchange/DereTore.Exchange.Audio.HCA/Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,11 @@ public void Decode2(DataBits data) {

public void Decode3(uint a, uint b, uint c, uint d) {
if (Type != 2 && b != 0) {
float[] listFloat = ChannelTables.Decode3ListSingle[1];
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]] * Block[l];
Block[k++] = listFloat[GetValue3(i) - Value[l] + offset] * Block[l];
}
}
Block[0x80 - 1] = 0;
Expand Down
20 changes: 12 additions & 8 deletions Exchange/DereTore.Exchange.Audio.HCA/ChannelTables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public static void TranslateTables() {
for (var i = 0; i < _decode1ScaleSingle.Length; ++i) {
_decode1ScaleSingle[i] = HcaHelper.UInt32ToSingleBits(_decode1ScaleUInt[i]);
}
_decode3ListSingle = new float[_decode3ListUInt.Length][];
for (var i = 0; i < _decode3ListSingle.Length; ++i) {
_decode3ListSingle[i] = new float[_decode3ListUInt[i].Length];
for (var j = 0; j < _decode3ListSingle[i].Length; ++j) {
_decode3ListSingle[i][j] = HcaHelper.UInt32ToSingleBits(_decode3ListUInt[i][j]);
}
_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) {
Expand Down Expand Up @@ -47,7 +47,9 @@ public static void TranslateTables() {

public static float[] Decode2List3 => _decode2List3;

public static float[][] Decode3ListSingle => _decode3ListSingle;
public static float[] Decode3ListSingle => _decode3ListSingle;

public static int Decode3ListOffset => _decode3ListOffset;

public static float[] Decode4ListSingle => _decode4ListSingle;

Expand Down Expand Up @@ -147,7 +149,9 @@ public static void TranslateTables() {
}
};

private static float[][] _decode3ListSingle;
private static float[] _decode3ListSingle;

private static readonly int _decode3ListOffset = _decode3ListUInt[0].Length;

private static readonly uint[] _decode4ListUInt = {
// v2.0
Expand Down

0 comments on commit ed03489

Please sign in to comment.