General cleanup and refactor.

This commit is contained in:
2022-03-07 07:36:44 +00:00
parent bc6e432565
commit 762e3eb6d2
1321 changed files with 44657 additions and 45479 deletions

View File

@@ -26,6 +26,8 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
namespace Aaru.Core.Media;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -39,8 +41,6 @@ using Aaru.Decoders.CD;
using Aaru.Devices;
using Aaru.Helpers;
namespace Aaru.Core.Media;
/// <summary>Operations over CD based media</summary>
public static class CompactDisc
{
@@ -83,8 +83,7 @@ public static class CompactDisc
desiredSubchannel != MmcSubchannel.None)
outputPlugin.WriteSectorsTag(sub, sectorAddress, length, SectorTagType.CdSectorSubchannel);
subLog?.WriteEntry(sub, supportedSubchannel == MmcSubchannel.Raw, (long)sectorAddress, length, false,
false);
subLog?.WriteEntry(sub, supportedSubchannel == MmcSubchannel.Raw, (long)sectorAddress, length, false, false);
byte[] deSub = Subchannel.Deinterleave(sub);
@@ -98,15 +97,15 @@ public static class CompactDisc
int prePos = int.MinValue;
// Check subchannel
for(int subPos = 0; subPos < deSub.Length; subPos += 96)
for(var subPos = 0; subPos < deSub.Length; subPos += 96)
{
// Expected LBA
long lba = (long)sectorAddress + (subPos / 96);
long lba = (long)sectorAddress + subPos / 96;
// We fixed the subchannel
bool @fixed = false;
var @fixed = false;
byte[] q = new byte[12];
var q = new byte[12];
Array.Copy(deSub, subPos + 12, q, 0, 12);
// Check Q CRC
@@ -114,8 +113,8 @@ public static class CompactDisc
bool crcOk = crc[0] == q[10] && crc[1] == q[11];
// Start considering P to be OK
bool pOk = true;
int pWeight = 0;
var pOk = true;
var pWeight = 0;
// Check P and weight
for(int p = subPos; p < subPos + 12; p++)
@@ -124,7 +123,7 @@ public static class CompactDisc
deSub[p] != 255)
pOk = false;
for(int w = 0; w < 8; w++)
for(var w = 0; w < 8; w++)
if(((deSub[p] >> w) & 1) > 0)
pWeight++;
}
@@ -149,13 +148,13 @@ public static class CompactDisc
deSub.Skip(subPos + 84).Take(12).All(w => w == 0xFF);
bool rwOk = rOk && sOk && tOk && uOk && vOk && wOk;
bool rwPacket = false;
bool cdtextPacket = false;
var rwPacket = false;
var cdtextPacket = false;
// Check RW contents
if(!rwOk)
{
byte[] sectorSub = new byte[96];
var sectorSub = new byte[96];
Array.Copy(sub, subPos, sectorSub, 0, 96);
DetectRwPackets(sectorSub, out _, out rwPacket, out cdtextPacket);
@@ -211,9 +210,9 @@ public static class CompactDisc
isrcs.TryGetValue(currentTrack, out string knownGoodIsrc);
crcOk = FixQSubchannel(deSub, q, subPos, mcn, knownGoodIsrc, fixSubchannelCrc, out bool fixedAdr,
out bool controlFix, out bool fixedZero, out bool fixedTno,
out bool fixedIndex, out bool fixedRelPos, out bool fixedAbsPos,
out bool fixedCrc, out bool fixedMcn, out bool fixedIsrc);
out bool controlFix, out bool fixedZero, out bool fixedTno, out bool fixedIndex,
out bool fixedRelPos, out bool fixedAbsPos, out bool fixedCrc, out bool fixedMcn,
out bool fixedIsrc);
if(crcOk)
{
@@ -257,13 +256,13 @@ public static class CompactDisc
!rwOk)
continue;
aframe = (byte)((q[9] / 16 * 10) + (q[9] & 0x0F));
aframe = (byte)(q[9] / 16 * 10 + (q[9] & 0x0F));
if((q[0] & 0x3) == 1)
{
amin = (byte)((q[7] / 16 * 10) + (q[7] & 0x0F));
asec = (byte)((q[8] / 16 * 10) + (q[8] & 0x0F));
aPos = (amin * 60 * 75) + (asec * 75) + aframe - 150;
amin = (byte)(q[7] / 16 * 10 + (q[7] & 0x0F));
asec = (byte)(q[8] / 16 * 10 + (q[8] & 0x0F));
aPos = amin * 60 * 75 + asec * 75 + aframe - 150;
}
else
{
@@ -272,7 +271,7 @@ public static class CompactDisc
expectedSectorAddress -= (ulong)(smin * 60 * 75);
ssec = (byte)(expectedSectorAddress / 75);
aPos = (smin * 60 * 75) + (ssec * 75) + aframe - 150;
aPos = smin * 60 * 75 + ssec * 75 + aframe - 150;
// Next second
if(aPos < prePos)
@@ -285,7 +284,7 @@ public static class CompactDisc
prePos = aPos;
byte[] posSub = new byte[96];
var posSub = new byte[96];
Array.Copy(deSub, subPos, posSub, 0, 96);
posSub = Subchannel.Interleave(posSub);
outputPlugin.WriteSectorTag(posSub, (ulong)aPos, SectorTagType.CdSectorSubchannel);
@@ -315,12 +314,12 @@ public static class CompactDisc
UpdateStatusHandler updateStatus,
Dictionary<byte, int> smallestPregapLbaPerTrack, bool dumping)
{
bool status = false;
var status = false;
// Check subchannel
for(int subPos = 0; subPos < deSub.Length; subPos += 96)
for(var subPos = 0; subPos < deSub.Length; subPos += 96)
{
byte[] q = new byte[12];
var q = new byte[12];
Array.Copy(deSub, subPos + 12, q, 0, 12);
CRC16CCITTContext.Data(q, 10, out byte[] crc);
@@ -391,9 +390,9 @@ public static class CompactDisc
case 1 when !crcOk: continue;
case 1:
{
byte trackNo = (byte)((q[1] / 16 * 10) + (q[1] & 0x0F));
var trackNo = (byte)(q[1] / 16 * 10 + (q[1] & 0x0F));
for(int i = 0; i < tracks.Length; i++)
for(var i = 0; i < tracks.Length; i++)
{
if(tracks[i].Sequence != trackNo)
continue;
@@ -402,10 +401,10 @@ public static class CompactDisc
if(q[2] == 0 &&
trackNo > 1)
{
byte pmin = (byte)((q[3] / 16 * 10) + (q[3] & 0x0F));
byte psec = (byte)((q[4] / 16 * 10) + (q[4] & 0x0F));
byte pframe = (byte)((q[5] / 16 * 10) + (q[5] & 0x0F));
int qPos = (pmin * 60 * 75) + (psec * 75) + pframe;
var pmin = (byte)(q[3] / 16 * 10 + (q[3] & 0x0F));
var psec = (byte)(q[4] / 16 * 10 + (q[4] & 0x0F));
var pframe = (byte)(q[5] / 16 * 10 + (q[5] & 0x0F));
int qPos = pmin * 60 * 75 + psec * 75 + pframe;
// When we are dumping we calculate the pregap in reverse from index 1 back.
// When we are not, we go from index 0.
@@ -413,8 +412,7 @@ public static class CompactDisc
smallestPregapLbaPerTrack[trackNo] = dumping ? 1 : 0;
uint firstTrackNumberInSameSession = tracks.
Where(t => t.Session ==
tracks[i].Session).
Where(t => t.Session == tracks[i].Session).
Min(t => t.Sequence);
if(tracks[i].Sequence == firstTrackNumberInSameSession)
@@ -431,11 +429,9 @@ public static class CompactDisc
tracks[i - 1].EndSector >= tracks[i].StartSector)
tracks[i - 1].EndSector = tracks[i].StartSector - 1;
dumpLog?.
WriteLine($"Pregap for track {trackNo} set to {tracks[i].Pregap} sectors.");
dumpLog?.WriteLine($"Pregap for track {trackNo} set to {tracks[i].Pregap} sectors.");
updateStatus?.
Invoke($"Pregap for track {trackNo} set to {tracks[i].Pregap} sectors.");
updateStatus?.Invoke($"Pregap for track {trackNo} set to {tracks[i].Pregap} sectors.");
status = true;
}
@@ -452,11 +448,9 @@ public static class CompactDisc
tracks[i - 1].EndSector >= tracks[i].StartSector)
tracks[i - 1].EndSector = tracks[i].StartSector - 1;
dumpLog?.
WriteLine($"Pregap for track {trackNo} set to {tracks[i].Pregap} sectors.");
dumpLog?.WriteLine($"Pregap for track {trackNo} set to {tracks[i].Pregap} sectors.");
updateStatus?.
Invoke($"Pregap for track {trackNo} set to {tracks[i].Pregap} sectors.");
updateStatus?.Invoke($"Pregap for track {trackNo} set to {tracks[i].Pregap} sectors.");
status = true;
@@ -466,10 +460,10 @@ public static class CompactDisc
if(q[2] == 0)
continue;
byte amin = (byte)((q[7] / 16 * 10) + (q[7] & 0x0F));
byte asec = (byte)((q[8] / 16 * 10) + (q[8] & 0x0F));
byte aframe = (byte)((q[9] / 16 * 10) + (q[9] & 0x0F));
int aPos = (amin * 60 * 75) + (asec * 75) + aframe - 150;
var amin = (byte)(q[7] / 16 * 10 + (q[7] & 0x0F));
var asec = (byte)(q[8] / 16 * 10 + (q[8] & 0x0F));
var aframe = (byte)(q[9] / 16 * 10 + (q[9] & 0x0F));
int aPos = amin * 60 * 75 + asec * 75 + aframe - 150;
if(tracks[i].Indexes.ContainsKey(q[2]) &&
aPos >= tracks[i].Indexes[q[2]])
@@ -502,18 +496,18 @@ public static class CompactDisc
rwPacket = false;
cdtextPacket = false;
byte[] cdTextPack1 = new byte[18];
byte[] cdTextPack2 = new byte[18];
byte[] cdTextPack3 = new byte[18];
byte[] cdTextPack4 = new byte[18];
byte[] cdSubRwPack1 = new byte[24];
byte[] cdSubRwPack2 = new byte[24];
byte[] cdSubRwPack3 = new byte[24];
byte[] cdSubRwPack4 = new byte[24];
var cdTextPack1 = new byte[18];
var cdTextPack2 = new byte[18];
var cdTextPack3 = new byte[18];
var cdTextPack4 = new byte[18];
var cdSubRwPack1 = new byte[24];
var cdSubRwPack2 = new byte[24];
var cdSubRwPack3 = new byte[24];
var cdSubRwPack4 = new byte[24];
int i = 0;
var i = 0;
for(int j = 0; j < 18; j++)
for(var j = 0; j < 18; j++)
{
cdTextPack1[j] = (byte)(cdTextPack1[j] | ((subchannel[i++] & 0x3F) << 2));
@@ -532,7 +526,7 @@ public static class CompactDisc
cdTextPack1[j] = (byte)(cdTextPack1[j] | (subchannel[i++] & 0x3F));
}
for(int j = 0; j < 18; j++)
for(var j = 0; j < 18; j++)
{
cdTextPack2[j] = (byte)(cdTextPack2[j] | ((subchannel[i++] & 0x3F) << 2));
@@ -551,7 +545,7 @@ public static class CompactDisc
cdTextPack2[j] = (byte)(cdTextPack2[j] | (subchannel[i++] & 0x3F));
}
for(int j = 0; j < 18; j++)
for(var j = 0; j < 18; j++)
{
cdTextPack3[j] = (byte)(cdTextPack3[j] | ((subchannel[i++] & 0x3F) << 2));
@@ -570,7 +564,7 @@ public static class CompactDisc
cdTextPack3[j] = (byte)(cdTextPack3[j] | (subchannel[i++] & 0x3F));
}
for(int j = 0; j < 18; j++)
for(var j = 0; j < 18; j++)
{
cdTextPack4[j] = (byte)(cdTextPack4[j] | ((subchannel[i++] & 0x3F) << 2));
@@ -591,16 +585,16 @@ public static class CompactDisc
i = 0;
for(int j = 0; j < 24; j++)
for(var j = 0; j < 24; j++)
cdSubRwPack1[j] = (byte)(subchannel[i++] & 0x3F);
for(int j = 0; j < 24; j++)
for(var j = 0; j < 24; j++)
cdSubRwPack2[j] = (byte)(subchannel[i++] & 0x3F);
for(int j = 0; j < 24; j++)
for(var j = 0; j < 24; j++)
cdSubRwPack3[j] = (byte)(subchannel[i++] & 0x3F);
for(int j = 0; j < 24; j++)
for(var j = 0; j < 24; j++)
cdSubRwPack4[j] = (byte)(subchannel[i++] & 0x3F);
switch(cdSubRwPack1[0])
@@ -701,14 +695,14 @@ public static class CompactDisc
/// <returns><c>true</c> if subchannel contains a TEXT packet, <c>false</c> otherwise</returns>
static bool CheckCdTextPackets(byte[] subchannel)
{
byte[] cdTextPack1 = new byte[18];
byte[] cdTextPack2 = new byte[18];
byte[] cdTextPack3 = new byte[18];
byte[] cdTextPack4 = new byte[18];
var cdTextPack1 = new byte[18];
var cdTextPack2 = new byte[18];
var cdTextPack3 = new byte[18];
var cdTextPack4 = new byte[18];
int i = 0;
var i = 0;
for(int j = 0; j < 18; j++)
for(var j = 0; j < 18; j++)
{
cdTextPack1[j] = (byte)(cdTextPack1[j] | ((subchannel[i++] & 0x3F) << 2));
@@ -727,7 +721,7 @@ public static class CompactDisc
cdTextPack1[j] = (byte)(cdTextPack1[j] | (subchannel[i++] & 0x3F));
}
for(int j = 0; j < 18; j++)
for(var j = 0; j < 18; j++)
{
cdTextPack2[j] = (byte)(cdTextPack2[j] | ((subchannel[i++] & 0x3F) << 2));
@@ -746,7 +740,7 @@ public static class CompactDisc
cdTextPack2[j] = (byte)(cdTextPack2[j] | (subchannel[i++] & 0x3F));
}
for(int j = 0; j < 18; j++)
for(var j = 0; j < 18; j++)
{
cdTextPack3[j] = (byte)(cdTextPack3[j] | ((subchannel[i++] & 0x3F) << 2));
@@ -765,7 +759,7 @@ public static class CompactDisc
cdTextPack3[j] = (byte)(cdTextPack3[j] | (subchannel[i++] & 0x3F));
}
for(int j = 0; j < 18; j++)
for(var j = 0; j < 18; j++)
{
cdTextPack4[j] = (byte)(cdTextPack4[j] | ((subchannel[i++] & 0x3F) << 2));
@@ -784,12 +778,12 @@ public static class CompactDisc
cdTextPack4[j] = (byte)(cdTextPack4[j] | (subchannel[i++] & 0x3F));
}
bool status = true;
var status = true;
if((cdTextPack1[0] & 0x80) == 0x80)
{
ushort cdTextPack1Crc = BigEndianBitConverter.ToUInt16(cdTextPack1, 16);
byte[] cdTextPack1ForCrc = new byte[16];
var cdTextPack1Crc = BigEndianBitConverter.ToUInt16(cdTextPack1, 16);
var cdTextPack1ForCrc = new byte[16];
Array.Copy(cdTextPack1, 0, cdTextPack1ForCrc, 0, 16);
ushort calculatedCdtp1Crc = CRC16CCITTContext.Calculate(cdTextPack1ForCrc);
@@ -800,8 +794,8 @@ public static class CompactDisc
if((cdTextPack2[0] & 0x80) == 0x80)
{
ushort cdTextPack2Crc = BigEndianBitConverter.ToUInt16(cdTextPack2, 16);
byte[] cdTextPack2ForCrc = new byte[16];
var cdTextPack2Crc = BigEndianBitConverter.ToUInt16(cdTextPack2, 16);
var cdTextPack2ForCrc = new byte[16];
Array.Copy(cdTextPack2, 0, cdTextPack2ForCrc, 0, 16);
ushort calculatedCdtp2Crc = CRC16CCITTContext.Calculate(cdTextPack2ForCrc);
@@ -812,8 +806,8 @@ public static class CompactDisc
if((cdTextPack3[0] & 0x80) == 0x80)
{
ushort cdTextPack3Crc = BigEndianBitConverter.ToUInt16(cdTextPack3, 16);
byte[] cdTextPack3ForCrc = new byte[16];
var cdTextPack3Crc = BigEndianBitConverter.ToUInt16(cdTextPack3, 16);
var cdTextPack3ForCrc = new byte[16];
Array.Copy(cdTextPack3, 0, cdTextPack3ForCrc, 0, 16);
ushort calculatedCdtp3Crc = CRC16CCITTContext.Calculate(cdTextPack3ForCrc);
@@ -825,8 +819,8 @@ public static class CompactDisc
if((cdTextPack4[0] & 0x80) != 0x80)
return status;
ushort cdTextPack4Crc = BigEndianBitConverter.ToUInt16(cdTextPack4, 16);
byte[] cdTextPack4ForCrc = new byte[16];
var cdTextPack4Crc = BigEndianBitConverter.ToUInt16(cdTextPack4, 16);
var cdTextPack4ForCrc = new byte[16];
Array.Copy(cdTextPack4, 0, cdTextPack4ForCrc, 0, 16);
ushort calculatedCdtp4Crc = CRC16CCITTContext.Calculate(cdTextPack4ForCrc);
@@ -873,8 +867,8 @@ public static class CompactDisc
fixedMcn = false;
fixedIsrc = false;
byte[] preQ = new byte[12];
byte[] nextQ = new byte[12];
var preQ = new byte[12];
var nextQ = new byte[12];
Array.Copy(deSub, subPos + 12 - 96, preQ, 0, 12);
Array.Copy(deSub, subPos + 12 + 96, nextQ, 0, 12);
bool status;
@@ -1007,7 +1001,6 @@ public static class CompactDisc
}
if(preCrcOk && nextCrcOk)
{
if(preQ[1] == nextQ[1] &&
preQ[1] != q[1])
{
@@ -1020,10 +1013,8 @@ public static class CompactDisc
if(status)
return true;
}
}
if(preCrcOk && nextCrcOk)
{
if(preQ[2] == nextQ[2] &&
preQ[2] != q[2])
{
@@ -1036,17 +1027,16 @@ public static class CompactDisc
if(status)
return true;
}
}
amin = (byte)((q[7] / 16 * 10) + (q[7] & 0x0F));
asec = (byte)((q[8] / 16 * 10) + (q[8] & 0x0F));
aframe = (byte)((q[9] / 16 * 10) + (q[9] & 0x0F));
aPos = (amin * 60 * 75) + (asec * 75) + aframe - 150;
amin = (byte)(q[7] / 16 * 10 + (q[7] & 0x0F));
asec = (byte)(q[8] / 16 * 10 + (q[8] & 0x0F));
aframe = (byte)(q[9] / 16 * 10 + (q[9] & 0x0F));
aPos = amin * 60 * 75 + asec * 75 + aframe - 150;
pmin = (byte)((q[3] / 16 * 10) + (q[3] & 0x0F));
psec = (byte)((q[4] / 16 * 10) + (q[4] & 0x0F));
pframe = (byte)((q[5] / 16 * 10) + (q[5] & 0x0F));
pPos = (pmin * 60 * 75) + (psec * 75) + pframe;
pmin = (byte)(q[3] / 16 * 10 + (q[3] & 0x0F));
psec = (byte)(q[4] / 16 * 10 + (q[4] & 0x0F));
pframe = (byte)(q[5] / 16 * 10 + (q[5] & 0x0F));
pPos = pmin * 60 * 75 + psec * 75 + pframe;
// TODO: pregap
// Not pregap
@@ -1055,10 +1045,10 @@ public static class CompactDisc
// Previous was not pregap either
if(preQ[2] > 0 && preCrcOk)
{
rmin = (byte)((preQ[3] / 16 * 10) + (preQ[3] & 0x0F));
rsec = (byte)((preQ[4] / 16 * 10) + (preQ[4] & 0x0F));
rframe = (byte)((preQ[5] / 16 * 10) + (preQ[5] & 0x0F));
rPos = (rmin * 60 * 75) + (rsec * 75) + rframe;
rmin = (byte)(preQ[3] / 16 * 10 + (preQ[3] & 0x0F));
rsec = (byte)(preQ[4] / 16 * 10 + (preQ[4] & 0x0F));
rframe = (byte)(preQ[5] / 16 * 10 + (preQ[5] & 0x0F));
rPos = rmin * 60 * 75 + rsec * 75 + rframe;
dPos = pPos - rPos;
@@ -1112,10 +1102,10 @@ public static class CompactDisc
nextCrcOk &&
!fixedRelPos)
{
rmin = (byte)((nextQ[3] / 16 * 10) + (nextQ[3] & 0x0F));
rsec = (byte)((nextQ[4] / 16 * 10) + (nextQ[4] & 0x0F));
rframe = (byte)((nextQ[5] / 16 * 10) + (nextQ[5] & 0x0F));
rPos = (rmin * 60 * 75) + (rsec * 75) + rframe;
rmin = (byte)(nextQ[3] / 16 * 10 + (nextQ[3] & 0x0F));
rsec = (byte)(nextQ[4] / 16 * 10 + (nextQ[4] & 0x0F));
rframe = (byte)(nextQ[5] / 16 * 10 + (nextQ[5] & 0x0F));
rPos = rmin * 60 * 75 + rsec * 75 + rframe;
dPos = rPos - pPos;
@@ -1172,10 +1162,10 @@ public static class CompactDisc
// Previous Q's CRC is correct
if(preCrcOk)
{
rmin = (byte)((preQ[7] / 16 * 10) + (preQ[7] & 0x0F));
rsec = (byte)((preQ[8] / 16 * 10) + (preQ[8] & 0x0F));
rframe = (byte)((preQ[9] / 16 * 10) + (preQ[9] & 0x0F));
rPos = (rmin * 60 * 75) + (rsec * 75) + rframe - 150;
rmin = (byte)(preQ[7] / 16 * 10 + (preQ[7] & 0x0F));
rsec = (byte)(preQ[8] / 16 * 10 + (preQ[8] & 0x0F));
rframe = (byte)(preQ[9] / 16 * 10 + (preQ[9] & 0x0F));
rPos = rmin * 60 * 75 + rsec * 75 + rframe - 150;
dPos = aPos - rPos;
@@ -1229,10 +1219,10 @@ public static class CompactDisc
nextCrcOk &&
!fixedAbsPos)
{
rmin = (byte)((nextQ[7] / 16 * 10) + (nextQ[7] & 0x0F));
rsec = (byte)((nextQ[8] / 16 * 10) + (nextQ[8] & 0x0F));
rframe = (byte)((nextQ[9] / 16 * 10) + (nextQ[9] & 0x0F));
rPos = (rmin * 60 * 75) + (rsec * 75) + rframe - 150;
rmin = (byte)(nextQ[7] / 16 * 10 + (nextQ[7] & 0x0F));
rsec = (byte)(nextQ[8] / 16 * 10 + (nextQ[8] & 0x0F));
rframe = (byte)(nextQ[9] / 16 * 10 + (nextQ[9] & 0x0F));
rPos = rmin * 60 * 75 + rsec * 75 + rframe - 150;
dPos = rPos - pPos;
@@ -1295,19 +1285,19 @@ public static class CompactDisc
// Previous Q's CRC is correct
if(preCrcOk)
{
rmin = (byte)((preQ[7] / 16 * 10) + (preQ[7] & 0x0F));
rsec = (byte)((preQ[8] / 16 * 10) + (preQ[8] & 0x0F));
rframe = (byte)((preQ[9] / 16 * 10) + (preQ[9] & 0x0F));
rPos = (rmin * 60 * 75) + (rsec * 75) + rframe - 150;
rmin = (byte)(preQ[7] / 16 * 10 + (preQ[7] & 0x0F));
rsec = (byte)(preQ[8] / 16 * 10 + (preQ[8] & 0x0F));
rframe = (byte)(preQ[9] / 16 * 10 + (preQ[9] & 0x0F));
rPos = rmin * 60 * 75 + rsec * 75 + rframe - 150;
dPos = aPos - rPos;
bool absOk = dPos == 1;
rmin = (byte)((preQ[3] / 16 * 10) + (preQ[3] & 0x0F));
rsec = (byte)((preQ[4] / 16 * 10) + (preQ[4] & 0x0F));
rframe = (byte)((preQ[5] / 16 * 10) + (preQ[5] & 0x0F));
rPos = (rmin * 60 * 75) + (rsec * 75) + rframe;
rmin = (byte)(preQ[3] / 16 * 10 + (preQ[3] & 0x0F));
rsec = (byte)(preQ[4] / 16 * 10 + (preQ[4] & 0x0F));
rframe = (byte)(preQ[5] / 16 * 10 + (preQ[5] & 0x0F));
rPos = rmin * 60 * 75 + rsec * 75 + rframe;
dPos = pPos - rPos;
@@ -1333,19 +1323,19 @@ public static class CompactDisc
// Next Q's CRC is correct
if(nextCrcOk)
{
rmin = (byte)((nextQ[7] / 16 * 10) + (nextQ[7] & 0x0F));
rsec = (byte)((nextQ[8] / 16 * 10) + (nextQ[8] & 0x0F));
rframe = (byte)((nextQ[9] / 16 * 10) + (nextQ[9] & 0x0F));
rPos = (rmin * 60 * 75) + (rsec * 75) + rframe - 150;
rmin = (byte)(nextQ[7] / 16 * 10 + (nextQ[7] & 0x0F));
rsec = (byte)(nextQ[8] / 16 * 10 + (nextQ[8] & 0x0F));
rframe = (byte)(nextQ[9] / 16 * 10 + (nextQ[9] & 0x0F));
rPos = rmin * 60 * 75 + rsec * 75 + rframe - 150;
dPos = rPos - aPos;
bool absOk = dPos == 1;
rmin = (byte)((nextQ[3] / 16 * 10) + (nextQ[3] & 0x0F));
rsec = (byte)((nextQ[4] / 16 * 10) + (nextQ[4] & 0x0F));
rframe = (byte)((nextQ[5] / 16 * 10) + (nextQ[5] & 0x0F));
rPos = (rmin * 60 * 75) + (rsec * 75) + rframe;
rmin = (byte)(nextQ[3] / 16 * 10 + (nextQ[3] & 0x0F));
rsec = (byte)(nextQ[4] / 16 * 10 + (nextQ[4] & 0x0F));
rframe = (byte)(nextQ[5] / 16 * 10 + (nextQ[5] & 0x0F));
rPos = rmin * 60 * 75 + rsec * 75 + rframe;
dPos = rPos - pPos;
@@ -1378,8 +1368,8 @@ public static class CompactDisc
// Previous Q's CRC is correct
if(preCrcOk)
{
rframe = (byte)((preQ[9] / 16 * 10) + (preQ[9] & 0x0F));
aframe = (byte)((q[9] / 16 * 10) + (q[9] & 0x0F));
rframe = (byte)(preQ[9] / 16 * 10 + (preQ[9] & 0x0F));
aframe = (byte)(q[9] / 16 * 10 + (q[9] & 0x0F));
if(aframe - rframe != 1)
{
@@ -1406,8 +1396,8 @@ public static class CompactDisc
// Next Q's CRC is correct
else if(nextCrcOk)
{
rframe = (byte)((nextQ[9] / 16 * 10) + (nextQ[9] & 0x0F));
aframe = (byte)((q[9] / 16 * 10) + (q[9] & 0x0F));
rframe = (byte)(nextQ[9] / 16 * 10 + (nextQ[9] & 0x0F));
aframe = (byte)(q[9] / 16 * 10 + (q[9] & 0x0F));
if(aframe - rframe != 1)
{
@@ -1433,13 +1423,13 @@ public static class CompactDisc
// We know the MCN
if(mcn != null)
{
q[1] = (byte)((((mcn[0] - 0x30) & 0x0F) * 16) + ((mcn[1] - 0x30) & 0x0F));
q[2] = (byte)((((mcn[2] - 0x30) & 0x0F) * 16) + ((mcn[3] - 0x30) & 0x0F));
q[3] = (byte)((((mcn[4] - 0x30) & 0x0F) * 16) + ((mcn[5] - 0x30) & 0x0F));
q[4] = (byte)((((mcn[6] - 0x30) & 0x0F) * 16) + ((mcn[7] - 0x30) & 0x0F));
q[5] = (byte)((((mcn[8] - 0x30) & 0x0F) * 16) + ((mcn[9] - 0x30) & 0x0F));
q[6] = (byte)((((mcn[10] - 0x30) & 0x0F) * 16) + ((mcn[11] - 0x30) & 0x0F));
q[7] = (byte)(((mcn[12] - 0x30) & 0x0F) * 8);
q[1] = (byte)(((mcn[0] - 0x30) & 0x0F) * 16 + ((mcn[1] - 0x30) & 0x0F));
q[2] = (byte)(((mcn[2] - 0x30) & 0x0F) * 16 + ((mcn[3] - 0x30) & 0x0F));
q[3] = (byte)(((mcn[4] - 0x30) & 0x0F) * 16 + ((mcn[5] - 0x30) & 0x0F));
q[4] = (byte)(((mcn[6] - 0x30) & 0x0F) * 16 + ((mcn[7] - 0x30) & 0x0F));
q[5] = (byte)(((mcn[8] - 0x30) & 0x0F) * 16 + ((mcn[9] - 0x30) & 0x0F));
q[6] = (byte)(((mcn[10] - 0x30) & 0x0F) * 16 + ((mcn[11] - 0x30) & 0x0F));
q[7] = (byte)(((mcn[12] - 0x30) & 0x0F) * 8);
q[8] = 0;
fixedMcn = true;
@@ -1471,8 +1461,8 @@ public static class CompactDisc
// Previous Q's CRC is correct
if(preCrcOk)
{
rframe = (byte)((preQ[9] / 16 * 10) + (preQ[9] & 0x0F));
aframe = (byte)((q[9] / 16 * 10) + (q[9] & 0x0F));
rframe = (byte)(preQ[9] / 16 * 10 + (preQ[9] & 0x0F));
aframe = (byte)(q[9] / 16 * 10 + (q[9] & 0x0F));
if(aframe - rframe != 1)
{
@@ -1499,8 +1489,8 @@ public static class CompactDisc
// Next Q's CRC is correct
else if(nextCrcOk)
{
rframe = (byte)((nextQ[9] / 16 * 10) + (nextQ[9] & 0x0F));
aframe = (byte)((q[9] / 16 * 10) + (q[9] & 0x0F));
rframe = (byte)(nextQ[9] / 16 * 10 + (nextQ[9] & 0x0F));
aframe = (byte)(q[9] / 16 * 10 + (q[9] & 0x0F));
if(aframe - rframe != 1)
{
@@ -1536,10 +1526,10 @@ public static class CompactDisc
q[2] = (byte)(((i2 & 0xF) << 4) + (i3 >> 2));
q[3] = (byte)(((i3 & 0x3) << 6) + i4);
q[4] = (byte)(i5 << 2);
q[5] = (byte)((((isrc[5] - 0x30) & 0x0F) * 16) + ((isrc[6] - 0x30) & 0x0F));
q[6] = (byte)((((isrc[7] - 0x30) & 0x0F) * 16) + ((isrc[8] - 0x30) & 0x0F));
q[7] = (byte)((((isrc[9] - 0x30) & 0x0F) * 16) + ((isrc[10] - 0x30) & 0x0F));
q[8] = (byte)(((isrc[11] - 0x30) & 0x0F) * 16);
q[5] = (byte)(((isrc[5] - 0x30) & 0x0F) * 16 + ((isrc[6] - 0x30) & 0x0F));
q[6] = (byte)(((isrc[7] - 0x30) & 0x0F) * 16 + ((isrc[8] - 0x30) & 0x0F));
q[7] = (byte)(((isrc[9] - 0x30) & 0x0F) * 16 + ((isrc[10] - 0x30) & 0x0F));
q[8] = (byte)(((isrc[11] - 0x30) & 0x0F) * 16);
fixedIsrc = true;
@@ -1627,8 +1617,7 @@ public static class CompactDisc
updateProgress?.Invoke($"Generating subchannel for sector {sector}...", sector, (long)blocks);
dumpLog?.WriteLine($"Generating subchannel for sector {sector}.");
byte[] sub = Subchannel.Generate(sector, track?.Sequence ?? 0, (int)pregap, (int)trackStart, flags,
index);
byte[] sub = Subchannel.Generate(sector, track?.Sequence ?? 0, (int)pregap, (int)trackStart, flags, index);
outputPlugin.WriteSectorsTag(sub, (ulong)sector, 1, SectorTagType.CdSectorSubchannel);