Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions src/SharpCompress/Compressors/Rar/UnpackV1/Unpack20.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ namespace SharpCompress.Compressors.Rar.UnpackV1;

internal partial class Unpack
{
private readonly MultDecode[] MD = new MultDecode[4];
private readonly MultDecode[] MD = new[]
{
new MultDecode(),
new MultDecode(),
new MultDecode(),
new MultDecode(),
};

private readonly byte[] UnpOldTable20 = new byte[PackDef.MC20 * 4];

Expand Down Expand Up @@ -475,6 +481,31 @@ private bool ReadTables20()
{
Table[I++] = 0;
}
// Nanook. Working port from Rar C code. Added when working on Audio Decode Fix. Seems equal to above, so commented it
//byte v;
//if (Number == 16)
//{
// N = (Utility.URShift(GetBits(), 14)) + 3;
// AddBits(2);
// v = Table[I - 1];
//}
//else
//{
// N = (Number - 17) * 4;
// int bits = 3 + N;
// N += N + 3 + (Utility.URShift(GetBits(), 16 - bits));
// AddBits(bits);
// v = 0;
//}
//N += I;
//if (N > TableSize)
//{
// N = TableSize; // original unRAR
//}
//do
//{
// Table[I++] = v;
//} while (I < N);
}
}
if (inAddr > readTop)
Expand Down Expand Up @@ -559,8 +590,7 @@ private byte DecodeAudio(int Delta)
PCh = (Utility.URShift(PCh, 3)) & 0xFF;

var Ch = PCh - Delta;

var D = ((byte)Delta) << 3;
var D = ((sbyte)Delta) << 3;

v.Dif[0] += Math.Abs(D); // V->Dif[0]+=abs(D);
v.Dif[1] += Math.Abs(D - v.D1); // V->Dif[1]+=abs(D-V->D1);
Expand All @@ -574,7 +604,7 @@ private byte DecodeAudio(int Delta)
v.Dif[9] += Math.Abs(D - UnpChannelDelta); // V->Dif[9]+=abs(D-UnpChannelDelta);
v.Dif[10] += Math.Abs(D + UnpChannelDelta); // V->Dif[10]+=abs(D+UnpChannelDelta);

v.LastDelta = (byte)(Ch - v.LastChar);
v.LastDelta = (sbyte)(Ch - v.LastChar);
UnpChannelDelta = v.LastDelta;
v.LastChar = Ch; // V->LastChar=Ch;

Expand Down