Skip to content

Commit 08ceac9

Browse files
authored
Merge pull request #896 from adamhathcock/rar_unpack20_audio_fix
Rar2 v20,v26 Multimedia (Audio) decoder fix
2 parents 6d3c980 + 6bc690b commit 08ceac9

1 file changed

Lines changed: 34 additions & 4 deletions

File tree

src/SharpCompress/Compressors/Rar/UnpackV1/Unpack20.cs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ namespace SharpCompress.Compressors.Rar.UnpackV1;
1414

1515
internal partial class Unpack
1616
{
17-
private readonly MultDecode[] MD = new MultDecode[4];
17+
private readonly MultDecode[] MD = new[]
18+
{
19+
new MultDecode(),
20+
new MultDecode(),
21+
new MultDecode(),
22+
new MultDecode(),
23+
};
1824

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

@@ -475,6 +481,31 @@ private bool ReadTables20()
475481
{
476482
Table[I++] = 0;
477483
}
484+
// Nanook. Working port from Rar C code. Added when working on Audio Decode Fix. Seems equal to above, so commented it
485+
//byte v;
486+
//if (Number == 16)
487+
//{
488+
// N = (Utility.URShift(GetBits(), 14)) + 3;
489+
// AddBits(2);
490+
// v = Table[I - 1];
491+
//}
492+
//else
493+
//{
494+
// N = (Number - 17) * 4;
495+
// int bits = 3 + N;
496+
// N += N + 3 + (Utility.URShift(GetBits(), 16 - bits));
497+
// AddBits(bits);
498+
// v = 0;
499+
//}
500+
//N += I;
501+
//if (N > TableSize)
502+
//{
503+
// N = TableSize; // original unRAR
504+
//}
505+
//do
506+
//{
507+
// Table[I++] = v;
508+
//} while (I < N);
478509
}
479510
}
480511
if (inAddr > readTop)
@@ -559,8 +590,7 @@ private byte DecodeAudio(int Delta)
559590
PCh = (Utility.URShift(PCh, 3)) & 0xFF;
560591

561592
var Ch = PCh - Delta;
562-
563-
var D = ((byte)Delta) << 3;
593+
var D = ((sbyte)Delta) << 3;
564594

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

577-
v.LastDelta = (byte)(Ch - v.LastChar);
607+
v.LastDelta = (sbyte)(Ch - v.LastChar);
578608
UnpChannelDelta = v.LastDelta;
579609
v.LastChar = Ch; // V->LastChar=Ch;
580610

0 commit comments

Comments
 (0)