From d62ca39aee852e3eda73400f5757eeefdf83ec53 Mon Sep 17 00:00:00 2001 From: statementreply Date: Sun, 16 Jul 2017 15:19:13 +0800 Subject: [PATCH] [hca2wav] Fix crash in Decode3 --- .../DereTore.Exchange.Audio.HCA/Channel.cs | 5 +++-- .../ChannelTables.cs | 20 +++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Exchange/DereTore.Exchange.Audio.HCA/Channel.cs b/Exchange/DereTore.Exchange.Audio.HCA/Channel.cs index c1bbd26..813da16 100644 --- a/Exchange/DereTore.Exchange.Audio.HCA/Channel.cs +++ b/Exchange/DereTore.Exchange.Audio.HCA/Channel.cs @@ -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; diff --git a/Exchange/DereTore.Exchange.Audio.HCA/ChannelTables.cs b/Exchange/DereTore.Exchange.Audio.HCA/ChannelTables.cs index ffaa91b..a4b17ab 100644 --- a/Exchange/DereTore.Exchange.Audio.HCA/ChannelTables.cs +++ b/Exchange/DereTore.Exchange.Audio.HCA/ChannelTables.cs @@ -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) { @@ -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; @@ -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