2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:23 +00:00
|
|
|
// Aaru Data Preservation Suite
|
2015-10-19 02:40:30 +01:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : FullTOC.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2015-10-19 02:40:30 +01:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Component : Device structures decoders.
|
2015-10-19 02:40:30 +01:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Decodes CD full Table of Contents.
|
2015-10-19 02:40:30 +01:00
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// This library is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
// published by the Free Software Foundation; either version 2.1 of the
|
2015-10-19 02:40:30 +01:00
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// This library is distributed in the hope that it will be useful, but
|
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
// Lesser General Public License for more details.
|
2015-10-19 02:40:30 +01:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2015-10-19 02:40:30 +01:00
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-12-31 23:08:22 +00:00
|
|
|
// Copyright © 2011-2021 Natalia Portillo
|
2015-10-19 02:40:30 +01:00
|
|
|
// ****************************************************************************/
|
2016-07-28 18:13:49 +01:00
|
|
|
|
2021-06-29 12:36:09 +01:00
|
|
|
using System.Collections.Generic;
|
2017-12-22 02:04:18 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2021-06-29 12:36:09 +01:00
|
|
|
using System.Linq;
|
2015-10-19 02:40:30 +01:00
|
|
|
using System.Text;
|
2021-06-29 12:36:09 +01:00
|
|
|
using Aaru.CommonTypes.Enums;
|
|
|
|
|
using Aaru.CommonTypes.Structs;
|
2020-02-27 00:33:24 +00:00
|
|
|
using Aaru.Console;
|
2020-07-20 15:43:51 +01:00
|
|
|
using Aaru.Helpers;
|
2015-10-19 02:40:30 +01:00
|
|
|
|
2020-02-27 00:33:24 +00:00
|
|
|
namespace Aaru.Decoders.CD
|
2015-10-19 02:40:30 +01:00
|
|
|
{
|
2020-03-11 22:31:09 +00:00
|
|
|
// Information from the following standards:
|
|
|
|
|
// ANSI X3.304-1997
|
|
|
|
|
// T10/1048-D revision 9.0
|
|
|
|
|
// T10/1048-D revision 10a
|
|
|
|
|
// T10/1228-D revision 7.0c
|
|
|
|
|
// T10/1228-D revision 11a
|
|
|
|
|
// T10/1363-D revision 10g
|
|
|
|
|
// T10/1545-D revision 1d
|
|
|
|
|
// T10/1545-D revision 5
|
|
|
|
|
// T10/1545-D revision 5a
|
|
|
|
|
// T10/1675-D revision 2c
|
|
|
|
|
// T10/1675-D revision 4
|
|
|
|
|
// T10/1836-D revision 2g
|
|
|
|
|
// ISO/IEC 61104: Compact disc video system - 12 cm CD-V
|
|
|
|
|
// ISO/IEC 60908: Audio recording - Compact disc digital audio system
|
2019-11-25 00:54:38 +00:00
|
|
|
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
|
|
|
|
|
SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
2015-10-19 02:40:30 +01:00
|
|
|
public static class FullTOC
|
|
|
|
|
{
|
2015-12-04 01:57:56 +00:00
|
|
|
const string StereoNoPre = "Stereo audio track with no pre-emphasis";
|
|
|
|
|
const string StereoPreEm = "Stereo audio track with 50/15 μs pre-emphasis";
|
|
|
|
|
const string QuadNoPreEm = "Quadraphonic audio track with no pre-emphasis";
|
|
|
|
|
const string QuadPreEmph = "Quadraphonic audio track with 50/15 μs pre-emphasis";
|
|
|
|
|
const string DataUnintrp = "Data track, recorded uninterrupted";
|
|
|
|
|
const string DataIncrtly = "Data track, recorded incrementally";
|
|
|
|
|
|
2015-10-19 02:46:04 +01:00
|
|
|
public static CDFullTOC? Decode(byte[] CDFullTOCResponse)
|
2015-10-19 02:40:30 +01:00
|
|
|
{
|
2020-03-06 20:39:31 +00:00
|
|
|
if(CDFullTOCResponse == null ||
|
|
|
|
|
CDFullTOCResponse.Length <= 4)
|
2019-11-25 00:54:38 +00:00
|
|
|
return null;
|
2015-10-19 02:40:30 +01:00
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
var decoded = new CDFullTOC
|
2019-05-11 20:49:32 +01:00
|
|
|
{
|
|
|
|
|
DataLength = BigEndianBitConverter.ToUInt16(CDFullTOCResponse, 0),
|
2020-07-20 04:34:15 +01:00
|
|
|
FirstCompleteSession = CDFullTOCResponse[2],
|
|
|
|
|
LastCompleteSession = CDFullTOCResponse[3]
|
2019-05-11 20:49:32 +01:00
|
|
|
};
|
2015-10-19 02:40:30 +01:00
|
|
|
|
2019-05-11 20:49:32 +01:00
|
|
|
decoded.TrackDescriptors = new TrackDataDescriptor[(decoded.DataLength - 2) / 11];
|
2015-10-19 02:40:30 +01:00
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
if(decoded.DataLength + 2 != CDFullTOCResponse.Length)
|
2015-10-19 02:40:30 +01:00
|
|
|
{
|
2020-02-27 23:48:39 +00:00
|
|
|
AaruConsole.DebugWriteLine("CD full TOC decoder",
|
2020-02-29 18:03:33 +00:00
|
|
|
"Expected CDFullTOC size ({0} bytes) is not received size ({1} bytes), not decoding",
|
|
|
|
|
decoded.DataLength + 2, CDFullTOCResponse.Length);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2015-10-19 02:40:30 +01:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:26:28 +00:00
|
|
|
for(int i = 0; i < (decoded.DataLength - 2) / 11; i++)
|
2015-10-19 02:40:30 +01:00
|
|
|
{
|
2020-02-29 18:03:33 +00:00
|
|
|
decoded.TrackDescriptors[i].SessionNumber = CDFullTOCResponse[0 + (i * 11) + 4];
|
|
|
|
|
decoded.TrackDescriptors[i].ADR = (byte)((CDFullTOCResponse[1 + (i * 11) + 4] & 0xF0) >> 4);
|
|
|
|
|
decoded.TrackDescriptors[i].CONTROL = (byte)(CDFullTOCResponse[1 + (i * 11) + 4] & 0x0F);
|
|
|
|
|
decoded.TrackDescriptors[i].TNO = CDFullTOCResponse[2 + (i * 11) + 4];
|
|
|
|
|
decoded.TrackDescriptors[i].POINT = CDFullTOCResponse[3 + (i * 11) + 4];
|
|
|
|
|
decoded.TrackDescriptors[i].Min = CDFullTOCResponse[4 + (i * 11) + 4];
|
|
|
|
|
decoded.TrackDescriptors[i].Sec = CDFullTOCResponse[5 + (i * 11) + 4];
|
|
|
|
|
decoded.TrackDescriptors[i].Frame = CDFullTOCResponse[6 + (i * 11) + 4];
|
|
|
|
|
decoded.TrackDescriptors[i].Zero = CDFullTOCResponse[7 + (i * 11) + 4];
|
|
|
|
|
decoded.TrackDescriptors[i].HOUR = (byte)((CDFullTOCResponse[7 + (i * 11) + 4] & 0xF0) >> 4);
|
|
|
|
|
decoded.TrackDescriptors[i].PHOUR = (byte)(CDFullTOCResponse[7 + (i * 11) + 4] & 0x0F);
|
2020-11-11 04:19:13 +00:00
|
|
|
decoded.TrackDescriptors[i].PMIN = CDFullTOCResponse[8 + (i * 11) + 4];
|
|
|
|
|
decoded.TrackDescriptors[i].PSEC = CDFullTOCResponse[9 + (i * 11) + 4];
|
2020-02-29 18:03:33 +00:00
|
|
|
decoded.TrackDescriptors[i].PFRAME = CDFullTOCResponse[10 + (i * 11) + 4];
|
2015-10-19 02:40:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return decoded;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-19 02:46:04 +01:00
|
|
|
public static string Prettify(CDFullTOC? CDFullTOCResponse)
|
2015-10-19 02:40:30 +01:00
|
|
|
{
|
2019-11-25 00:54:38 +00:00
|
|
|
if(CDFullTOCResponse == null)
|
|
|
|
|
return null;
|
2015-10-19 02:40:30 +01:00
|
|
|
|
|
|
|
|
CDFullTOC response = CDFullTOCResponse.Value;
|
|
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
var sb = new StringBuilder();
|
2015-10-19 02:40:30 +01:00
|
|
|
|
2015-12-03 09:31:06 +00:00
|
|
|
int lastSession = 0;
|
|
|
|
|
|
2015-10-19 02:40:30 +01:00
|
|
|
sb.AppendFormat("First complete session number: {0}", response.FirstCompleteSession).AppendLine();
|
2018-06-22 08:08:38 +01:00
|
|
|
sb.AppendFormat("Last complete session number: {0}", response.LastCompleteSession).AppendLine();
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
foreach(TrackDataDescriptor descriptor in response.TrackDescriptors)
|
2020-02-29 18:03:33 +00:00
|
|
|
if((descriptor.CONTROL & 0x08) == 0x08 ||
|
|
|
|
|
(descriptor.ADR != 1 && descriptor.ADR != 5 && descriptor.ADR != 4 && descriptor.ADR != 6) ||
|
2017-12-19 20:33:03 +00:00
|
|
|
descriptor.TNO != 0)
|
2015-10-19 02:40:30 +01:00
|
|
|
{
|
|
|
|
|
sb.AppendLine("Unknown TOC entry format, printing values as-is");
|
|
|
|
|
sb.AppendFormat("SessionNumber = {0}", descriptor.SessionNumber).AppendLine();
|
2018-06-22 08:08:38 +01:00
|
|
|
sb.AppendFormat("ADR = {0}", descriptor.ADR).AppendLine();
|
|
|
|
|
sb.AppendFormat("CONTROL = {0}", descriptor.CONTROL).AppendLine();
|
|
|
|
|
sb.AppendFormat("TNO = {0}", descriptor.TNO).AppendLine();
|
|
|
|
|
sb.AppendFormat("POINT = {0}", descriptor.POINT).AppendLine();
|
|
|
|
|
sb.AppendFormat("Min = {0}", descriptor.Min).AppendLine();
|
|
|
|
|
sb.AppendFormat("Sec = {0}", descriptor.Sec).AppendLine();
|
|
|
|
|
sb.AppendFormat("Frame = {0}", descriptor.Frame).AppendLine();
|
|
|
|
|
sb.AppendFormat("HOUR = {0}", descriptor.HOUR).AppendLine();
|
|
|
|
|
sb.AppendFormat("PHOUR = {0}", descriptor.PHOUR).AppendLine();
|
|
|
|
|
sb.AppendFormat("PMIN = {0}", descriptor.PMIN).AppendLine();
|
|
|
|
|
sb.AppendFormat("PSEC = {0}", descriptor.PSEC).AppendLine();
|
|
|
|
|
sb.AppendFormat("PFRAME = {0}", descriptor.PFRAME).AppendLine();
|
2015-10-19 02:40:30 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-12-03 09:31:06 +00:00
|
|
|
if(descriptor.SessionNumber > lastSession)
|
|
|
|
|
{
|
|
|
|
|
sb.AppendFormat("Session {0}", descriptor.SessionNumber).AppendLine();
|
|
|
|
|
lastSession = descriptor.SessionNumber;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
switch(descriptor.ADR)
|
2015-10-19 02:40:30 +01:00
|
|
|
{
|
|
|
|
|
case 1:
|
2015-12-03 09:31:06 +00:00
|
|
|
case 4:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
switch(descriptor.POINT)
|
2015-10-19 02:40:30 +01:00
|
|
|
{
|
2018-01-07 13:25:04 +00:00
|
|
|
case 0xA0 when descriptor.ADR == 4:
|
2015-10-19 02:40:30 +01:00
|
|
|
{
|
2018-01-07 13:25:04 +00:00
|
|
|
sb.AppendFormat("First video track number: {0}", descriptor.PMIN).AppendLine();
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
switch(descriptor.PSEC)
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2018-01-07 13:25:04 +00:00
|
|
|
case 0x10:
|
|
|
|
|
sb.AppendLine("CD-V single in NTSC format with digital stereo sound");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
break;
|
|
|
|
|
case 0x11:
|
|
|
|
|
sb.AppendLine("CD-V single in NTSC format with digital bilingual sound");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
break;
|
|
|
|
|
case 0x12:
|
|
|
|
|
sb.AppendLine("CD-V disc in NTSC format with digital stereo sound");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
break;
|
|
|
|
|
case 0x13:
|
|
|
|
|
sb.AppendLine("CD-V disc in NTSC format with digital bilingual sound");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
break;
|
|
|
|
|
case 0x20:
|
|
|
|
|
sb.AppendLine("CD-V single in PAL format with digital stereo sound");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
break;
|
|
|
|
|
case 0x21:
|
|
|
|
|
sb.AppendLine("CD-V single in PAL format with digital bilingual sound");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
break;
|
|
|
|
|
case 0x22:
|
|
|
|
|
sb.AppendLine("CD-V disc in PAL format with digital stereo sound");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
break;
|
|
|
|
|
case 0x23:
|
|
|
|
|
sb.AppendLine("CD-V disc in PAL format with digital bilingual sound");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
break;
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|
|
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2019-05-11 20:49:32 +01:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
case 0xA0 when descriptor.ADR == 1:
|
|
|
|
|
{
|
|
|
|
|
sb.AppendFormat("First track number: {0} (", descriptor.PMIN);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
switch((TocControl)(descriptor.CONTROL & 0x0D))
|
|
|
|
|
{
|
|
|
|
|
case TocControl.TwoChanNoPreEmph:
|
|
|
|
|
sb.Append(StereoNoPre);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
break;
|
|
|
|
|
case TocControl.TwoChanPreEmph:
|
|
|
|
|
sb.Append(StereoPreEm);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
break;
|
|
|
|
|
case TocControl.FourChanNoPreEmph:
|
|
|
|
|
sb.Append(QuadNoPreEm);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
break;
|
|
|
|
|
case TocControl.FourChanPreEmph:
|
|
|
|
|
sb.Append(QuadPreEmph);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
break;
|
|
|
|
|
case TocControl.DataTrack:
|
|
|
|
|
sb.Append(DataUnintrp);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
break;
|
|
|
|
|
case TocControl.DataTrackIncremental:
|
|
|
|
|
sb.Append(DataIncrtly);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
break;
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|
|
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
sb.AppendLine(")");
|
|
|
|
|
sb.AppendFormat("Disc type: {0}", descriptor.PSEC).AppendLine();
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
//sb.AppendFormat("Absolute time: {3:D2}:{0:D2}:{1:D2}:{2:D2}", descriptor.Min, descriptor.Sec, descriptor.Frame, descriptor.HOUR).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2019-05-11 20:49:32 +01:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
case 0xA1 when descriptor.ADR == 4:
|
|
|
|
|
sb.AppendFormat("Last video track number: {0}", descriptor.PMIN).AppendLine();
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
break;
|
|
|
|
|
case 0xA1 when descriptor.ADR == 1:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2018-01-07 13:25:04 +00:00
|
|
|
sb.AppendFormat("Last track number: {0} (", descriptor.PMIN);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
switch((TocControl)(descriptor.CONTROL & 0x0D))
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2018-01-07 13:25:04 +00:00
|
|
|
case TocControl.TwoChanNoPreEmph:
|
|
|
|
|
sb.Append(StereoNoPre);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
break;
|
|
|
|
|
case TocControl.TwoChanPreEmph:
|
|
|
|
|
sb.Append(StereoPreEm);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
break;
|
|
|
|
|
case TocControl.FourChanNoPreEmph:
|
|
|
|
|
sb.Append(QuadNoPreEm);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
break;
|
|
|
|
|
case TocControl.FourChanPreEmph:
|
|
|
|
|
sb.Append(QuadPreEmph);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
break;
|
|
|
|
|
case TocControl.DataTrack:
|
|
|
|
|
sb.Append(DataUnintrp);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
break;
|
|
|
|
|
case TocControl.DataTrackIncremental:
|
|
|
|
|
sb.Append(DataIncrtly);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2018-01-07 13:25:04 +00:00
|
|
|
break;
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|
2018-01-07 13:25:04 +00:00
|
|
|
|
|
|
|
|
sb.AppendLine(")");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
//sb.AppendFormat("Absolute time: {3:D2}:{0:D2}:{1:D2}:{2:D2}", descriptor.Min, descriptor.Sec, descriptor.Frame, descriptor.HOUR).AppendLine();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-05-11 20:49:32 +01:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
case 0xA2:
|
|
|
|
|
{
|
|
|
|
|
if(descriptor.PHOUR > 0)
|
|
|
|
|
sb.AppendFormat("Lead-out start position: {3:D2}:{0:D2}:{1:D2}:{2:D2}",
|
|
|
|
|
descriptor.PMIN, descriptor.PSEC, descriptor.PFRAME,
|
|
|
|
|
descriptor.PHOUR).AppendLine();
|
|
|
|
|
else
|
|
|
|
|
sb.AppendFormat("Lead-out start position: {0:D2}:{1:D2}:{2:D2}",
|
2019-11-25 00:54:38 +00:00
|
|
|
descriptor.PMIN, descriptor.PSEC, descriptor.PFRAME).
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
//sb.AppendFormat("Absolute time: {3:D2}:{0:D2}:{1:D2}:{2:D2}", descriptor.Min, descriptor.Sec, descriptor.Frame, descriptor.HOUR).AppendLine();
|
|
|
|
|
|
2017-12-22 02:04:18 +00:00
|
|
|
switch((TocControl)(descriptor.CONTROL & 0x0D))
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2017-12-22 02:04:18 +00:00
|
|
|
case TocControl.TwoChanNoPreEmph:
|
|
|
|
|
case TocControl.TwoChanPreEmph:
|
|
|
|
|
case TocControl.FourChanNoPreEmph:
|
|
|
|
|
case TocControl.FourChanPreEmph:
|
2017-12-19 20:33:03 +00:00
|
|
|
sb.AppendLine("Lead-out is audio type");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
2017-12-22 02:04:18 +00:00
|
|
|
case TocControl.DataTrack:
|
|
|
|
|
case TocControl.DataTrackIncremental:
|
2017-12-19 20:33:03 +00:00
|
|
|
sb.AppendLine("Lead-out is data type");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-05-11 20:49:32 +01:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
case 0xF0:
|
|
|
|
|
{
|
2019-11-25 00:54:38 +00:00
|
|
|
sb.AppendFormat("Book type: 0x{0:X2}", descriptor.PMIN);
|
|
|
|
|
sb.AppendFormat("Material type: 0x{0:X2}", descriptor.PSEC);
|
2017-12-19 20:33:03 +00:00
|
|
|
sb.AppendFormat("Moment of inertia: 0x{0:X2}", descriptor.PFRAME);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(descriptor.PHOUR > 0)
|
|
|
|
|
sb.AppendFormat("Absolute time: {3:D2}:{0:D2}:{1:D2}:{2:D2}", descriptor.Min,
|
|
|
|
|
descriptor.Sec, descriptor.Frame, descriptor.HOUR).AppendLine();
|
|
|
|
|
else
|
|
|
|
|
sb.AppendFormat("Absolute time: {0:D2}:{1:D2}:{2:D2}", descriptor.Min,
|
|
|
|
|
descriptor.Sec, descriptor.Frame).AppendLine();
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2019-05-11 20:49:32 +01:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
default:
|
|
|
|
|
{
|
2019-11-25 00:54:38 +00:00
|
|
|
if(descriptor.POINT >= 0x01 &&
|
|
|
|
|
descriptor.POINT <= 0x63)
|
2017-12-19 20:33:03 +00:00
|
|
|
if(descriptor.ADR == 4)
|
|
|
|
|
sb.AppendFormat("Video track {3} starts at: {0:D2}:{1:D2}:{2:D2}",
|
|
|
|
|
descriptor.PMIN, descriptor.PSEC, descriptor.PFRAME,
|
|
|
|
|
descriptor.POINT).AppendLine();
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
string type = "Audio";
|
|
|
|
|
|
2017-12-22 02:04:18 +00:00
|
|
|
if((TocControl)(descriptor.CONTROL & 0x0D) == TocControl.DataTrack ||
|
|
|
|
|
(TocControl)(descriptor.CONTROL & 0x0D) ==
|
2019-11-25 00:54:38 +00:00
|
|
|
TocControl.DataTrackIncremental)
|
|
|
|
|
type = "Data";
|
2017-12-19 20:33:03 +00:00
|
|
|
|
2015-12-03 09:31:06 +00:00
|
|
|
if(descriptor.PHOUR > 0)
|
2017-12-19 20:33:03 +00:00
|
|
|
sb.AppendFormat("{5} track {3} starts at: {4:D2}:{0:D2}:{1:D2}:{2:D2} (",
|
|
|
|
|
descriptor.PMIN, descriptor.PSEC, descriptor.PFRAME,
|
|
|
|
|
descriptor.POINT, descriptor.PHOUR, type);
|
2015-12-03 09:31:06 +00:00
|
|
|
else
|
2017-12-19 20:33:03 +00:00
|
|
|
sb.AppendFormat("{4} track {3} starts at: {0:D2}:{1:D2}:{2:D2} (",
|
|
|
|
|
descriptor.PMIN, descriptor.PSEC, descriptor.PFRAME,
|
|
|
|
|
descriptor.POINT, type);
|
2015-12-04 01:57:56 +00:00
|
|
|
|
2017-12-22 02:04:18 +00:00
|
|
|
switch((TocControl)(descriptor.CONTROL & 0x0D))
|
2015-12-04 01:57:56 +00:00
|
|
|
{
|
2017-12-22 02:04:18 +00:00
|
|
|
case TocControl.TwoChanNoPreEmph:
|
2017-12-19 20:33:03 +00:00
|
|
|
sb.Append(StereoNoPre);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
2017-12-22 02:04:18 +00:00
|
|
|
case TocControl.TwoChanPreEmph:
|
2017-12-19 20:33:03 +00:00
|
|
|
sb.Append(StereoPreEm);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
2017-12-22 02:04:18 +00:00
|
|
|
case TocControl.FourChanNoPreEmph:
|
2017-12-19 20:33:03 +00:00
|
|
|
sb.Append(QuadNoPreEm);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
2017-12-22 02:04:18 +00:00
|
|
|
case TocControl.FourChanPreEmph:
|
2017-12-19 20:33:03 +00:00
|
|
|
sb.Append(QuadPreEmph);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2015-12-04 01:57:56 +00:00
|
|
|
break;
|
2017-12-22 02:04:18 +00:00
|
|
|
case TocControl.DataTrack:
|
2017-12-19 20:33:03 +00:00
|
|
|
sb.Append(DataUnintrp);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
2017-12-22 02:04:18 +00:00
|
|
|
case TocControl.DataTrackIncremental:
|
2017-12-19 20:33:03 +00:00
|
|
|
sb.Append(DataIncrtly);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2015-12-04 01:57:56 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
sb.AppendLine(")");
|
2015-10-19 02:40:30 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
else
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
sb.AppendFormat("ADR = {0}", descriptor.ADR).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
sb.AppendFormat("CONTROL = {0}", descriptor.CONTROL).AppendLine();
|
2018-06-22 08:08:38 +01:00
|
|
|
sb.AppendFormat("TNO = {0}", descriptor.TNO).AppendLine();
|
|
|
|
|
sb.AppendFormat("POINT = {0}", descriptor.POINT).AppendLine();
|
|
|
|
|
sb.AppendFormat("Min = {0}", descriptor.Min).AppendLine();
|
|
|
|
|
sb.AppendFormat("Sec = {0}", descriptor.Sec).AppendLine();
|
|
|
|
|
sb.AppendFormat("Frame = {0}", descriptor.Frame).AppendLine();
|
|
|
|
|
sb.AppendFormat("HOUR = {0}", descriptor.HOUR).AppendLine();
|
|
|
|
|
sb.AppendFormat("PHOUR = {0}", descriptor.PHOUR).AppendLine();
|
|
|
|
|
sb.AppendFormat("PMIN = {0}", descriptor.PMIN).AppendLine();
|
|
|
|
|
sb.AppendFormat("PSEC = {0}", descriptor.PSEC).AppendLine();
|
|
|
|
|
sb.AppendFormat("PFRAME = {0}", descriptor.PFRAME).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
2015-10-19 02:40:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-05-11 20:49:32 +01:00
|
|
|
|
2015-10-19 02:40:30 +01:00
|
|
|
case 5:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
switch(descriptor.POINT)
|
2015-10-19 02:40:30 +01:00
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
case 0xB0:
|
2015-10-19 02:40:30 +01:00
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
if(descriptor.PHOUR > 0)
|
|
|
|
|
{
|
2019-11-25 00:54:38 +00:00
|
|
|
sb.
|
|
|
|
|
AppendFormat("Start of next possible program in the recordable area of the disc: {3:D2}:{0:D2}:{1:D2}:{2:D2}",
|
2018-01-07 13:25:04 +00:00
|
|
|
descriptor.Min, descriptor.Sec, descriptor.Frame,
|
|
|
|
|
descriptor.HOUR).AppendLine();
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
|
|
|
sb.
|
|
|
|
|
AppendFormat("Maximum start of outermost Lead-out in the recordable area of the disc: {3:D2}:{0:D2}:{1:D2}:{2:D2}",
|
2018-01-07 13:25:04 +00:00
|
|
|
descriptor.PMIN, descriptor.PSEC, descriptor.PFRAME,
|
|
|
|
|
descriptor.PHOUR).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-11-25 00:54:38 +00:00
|
|
|
sb.
|
|
|
|
|
AppendFormat("Start of next possible program in the recordable area of the disc: {0:D2}:{1:D2}:{2:D2}",
|
2018-01-07 13:25:04 +00:00
|
|
|
descriptor.Min, descriptor.Sec, descriptor.Frame).AppendLine();
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
|
|
|
sb.
|
|
|
|
|
AppendFormat("Maximum start of outermost Lead-out in the recordable area of the disc: {0:D2}:{1:D2}:{2:D2}",
|
|
|
|
|
descriptor.PMIN, descriptor.PSEC, descriptor.PFRAME).
|
|
|
|
|
AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|
2018-01-07 13:25:04 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2019-05-11 20:49:32 +01:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
case 0xB1:
|
|
|
|
|
{
|
2019-11-25 00:54:38 +00:00
|
|
|
sb.AppendFormat("Number of skip interval pointers: {0}", descriptor.PMIN).
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
sb.AppendFormat("Number of skip track pointers: {0}", descriptor.PSEC).AppendLine();
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2019-05-11 20:49:32 +01:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
case 0xB2:
|
|
|
|
|
case 0xB3:
|
|
|
|
|
case 0xB4:
|
|
|
|
|
{
|
|
|
|
|
sb.AppendFormat("Skip track {0}", descriptor.Min).AppendLine();
|
|
|
|
|
sb.AppendFormat("Skip track {0}", descriptor.Sec).AppendLine();
|
|
|
|
|
sb.AppendFormat("Skip track {0}", descriptor.Frame).AppendLine();
|
|
|
|
|
sb.AppendFormat("Skip track {0}", descriptor.Zero).AppendLine();
|
|
|
|
|
sb.AppendFormat("Skip track {0}", descriptor.PMIN).AppendLine();
|
|
|
|
|
sb.AppendFormat("Skip track {0}", descriptor.PSEC).AppendLine();
|
|
|
|
|
sb.AppendFormat("Skip track {0}", descriptor.PFRAME).AppendLine();
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2019-05-11 20:49:32 +01:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
case 0xC0:
|
|
|
|
|
{
|
|
|
|
|
sb.AppendFormat("Optimum recording power: 0x{0:X2}", descriptor.Min).AppendLine();
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(descriptor.PHOUR > 0)
|
2019-11-25 00:54:38 +00:00
|
|
|
sb.
|
|
|
|
|
AppendFormat("Start time of the first Lead-in area in the disc: {3:D2}:{0:D2}:{1:D2}:{2:D2}",
|
2018-01-07 13:25:04 +00:00
|
|
|
descriptor.PMIN, descriptor.PSEC, descriptor.PFRAME,
|
|
|
|
|
descriptor.PHOUR).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
else
|
2019-11-25 00:54:38 +00:00
|
|
|
sb.
|
|
|
|
|
AppendFormat("Start time of the first Lead-in area in the disc: {0:D2}:{1:D2}:{2:D2}",
|
|
|
|
|
descriptor.PMIN, descriptor.PSEC, descriptor.PFRAME).
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2019-05-11 20:49:32 +01:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
case 0xC1:
|
|
|
|
|
{
|
|
|
|
|
sb.AppendFormat("Copy of information of A1 from ATIP found");
|
2018-06-22 08:08:38 +01:00
|
|
|
sb.AppendFormat("Min = {0}", descriptor.Min).AppendLine();
|
|
|
|
|
sb.AppendFormat("Sec = {0}", descriptor.Sec).AppendLine();
|
|
|
|
|
sb.AppendFormat("Frame = {0}", descriptor.Frame).AppendLine();
|
|
|
|
|
sb.AppendFormat("Zero = {0}", descriptor.Zero).AppendLine();
|
|
|
|
|
sb.AppendFormat("PMIN = {0}", descriptor.PMIN).AppendLine();
|
|
|
|
|
sb.AppendFormat("PSEC = {0}", descriptor.PSEC).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
sb.AppendFormat("PFRAME = {0}", descriptor.PFRAME).AppendLine();
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2019-05-11 20:49:32 +01:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
case 0xCF:
|
|
|
|
|
{
|
|
|
|
|
if(descriptor.PHOUR > 0)
|
|
|
|
|
{
|
2019-11-25 00:54:38 +00:00
|
|
|
sb.
|
|
|
|
|
AppendFormat("Start position of outer part lead-in area: {3:D2}:{0:D2}:{1:D2}:{2:D2}",
|
2018-01-07 13:25:04 +00:00
|
|
|
descriptor.PMIN, descriptor.PSEC, descriptor.PFRAME,
|
|
|
|
|
descriptor.PHOUR).AppendLine();
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
|
|
|
sb.
|
|
|
|
|
AppendFormat("Stop position of inner part lead-out area: {3:D2}:{0:D2}:{1:D2}:{2:D2}",
|
2018-01-07 13:25:04 +00:00
|
|
|
descriptor.Min, descriptor.Sec, descriptor.Frame,
|
|
|
|
|
descriptor.HOUR).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-11-25 00:54:38 +00:00
|
|
|
sb.
|
|
|
|
|
AppendFormat("Start position of outer part lead-in area: {0:D2}:{1:D2}:{2:D2}",
|
|
|
|
|
descriptor.PMIN, descriptor.PSEC, descriptor.PFRAME).
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
|
|
|
|
sb.
|
|
|
|
|
AppendFormat("Stop position of inner part lead-out area: {0:D2}:{1:D2}:{2:D2}",
|
2018-01-07 13:25:04 +00:00
|
|
|
descriptor.Min, descriptor.Sec, descriptor.Frame).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|
2018-01-07 13:25:04 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2019-05-11 20:49:32 +01:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
default:
|
|
|
|
|
{
|
2019-11-25 00:54:38 +00:00
|
|
|
if(descriptor.POINT >= 0x01 &&
|
|
|
|
|
descriptor.POINT <= 0x40)
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
2019-11-25 00:54:38 +00:00
|
|
|
sb.
|
|
|
|
|
AppendFormat("Start time for interval that should be skipped: {0:D2}:{1:D2}:{2:D2}",
|
|
|
|
|
descriptor.PMIN, descriptor.PSEC, descriptor.PFRAME).
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
|
|
|
|
sb.
|
|
|
|
|
AppendFormat("Ending time for interval that should be skipped: {0:D2}:{1:D2}:{2:D2}",
|
2018-01-07 13:25:04 +00:00
|
|
|
descriptor.Min, descriptor.Sec, descriptor.Frame).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
sb.AppendFormat("ADR = {0}", descriptor.ADR).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
sb.AppendFormat("CONTROL = {0}", descriptor.CONTROL).AppendLine();
|
2018-06-22 08:08:38 +01:00
|
|
|
sb.AppendFormat("TNO = {0}", descriptor.TNO).AppendLine();
|
|
|
|
|
sb.AppendFormat("POINT = {0}", descriptor.POINT).AppendLine();
|
|
|
|
|
sb.AppendFormat("Min = {0}", descriptor.Min).AppendLine();
|
|
|
|
|
sb.AppendFormat("Sec = {0}", descriptor.Sec).AppendLine();
|
|
|
|
|
sb.AppendFormat("Frame = {0}", descriptor.Frame).AppendLine();
|
|
|
|
|
sb.AppendFormat("HOUR = {0}", descriptor.HOUR).AppendLine();
|
|
|
|
|
sb.AppendFormat("PHOUR = {0}", descriptor.PHOUR).AppendLine();
|
|
|
|
|
sb.AppendFormat("PMIN = {0}", descriptor.PMIN).AppendLine();
|
|
|
|
|
sb.AppendFormat("PSEC = {0}", descriptor.PSEC).AppendLine();
|
|
|
|
|
sb.AppendFormat("PFRAME = {0}", descriptor.PFRAME).AppendLine();
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|
2018-01-07 13:25:04 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
2015-10-19 02:40:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-05-11 20:49:32 +01:00
|
|
|
|
2015-12-04 07:26:03 +00:00
|
|
|
case 6:
|
2017-12-19 20:33:03 +00:00
|
|
|
{
|
|
|
|
|
uint id = (uint)((descriptor.Min << 16) + (descriptor.Sec << 8) + descriptor.Frame);
|
|
|
|
|
sb.AppendFormat("Disc ID: {0:X6}", id & 0x00FFFFFF).AppendLine();
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2015-10-19 02:40:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-19 02:46:04 +01:00
|
|
|
public static string Prettify(byte[] CDFullTOCResponse)
|
2015-10-19 02:40:30 +01:00
|
|
|
{
|
2015-10-19 02:46:04 +01:00
|
|
|
CDFullTOC? decoded = Decode(CDFullTOCResponse);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2015-10-19 02:46:04 +01:00
|
|
|
return Prettify(decoded);
|
2015-10-19 02:40:30 +01:00
|
|
|
}
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
|
|
|
public struct CDFullTOC
|
|
|
|
|
{
|
|
|
|
|
/// <summary>Total size of returned session information minus this field</summary>
|
|
|
|
|
public ushort DataLength;
|
|
|
|
|
/// <summary>First complete session number in hex</summary>
|
|
|
|
|
public byte FirstCompleteSession;
|
|
|
|
|
/// <summary>Last complete session number in hex</summary>
|
|
|
|
|
public byte LastCompleteSession;
|
|
|
|
|
/// <summary>Track descriptors</summary>
|
|
|
|
|
public TrackDataDescriptor[] TrackDescriptors;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public struct TrackDataDescriptor
|
|
|
|
|
{
|
|
|
|
|
/// <summary>Byte 0 Session number in hex</summary>
|
|
|
|
|
public byte SessionNumber;
|
|
|
|
|
/// <summary>Byte 1, bits 7 to 4 Type of information in Q subchannel of block where this TOC entry was found</summary>
|
|
|
|
|
public byte ADR;
|
|
|
|
|
/// <summary>Byte 1, bits 3 to 0 Track attributes</summary>
|
|
|
|
|
public byte CONTROL;
|
|
|
|
|
/// <summary>Byte 2</summary>
|
|
|
|
|
public byte TNO;
|
|
|
|
|
/// <summary>Byte 3</summary>
|
|
|
|
|
public byte POINT;
|
|
|
|
|
/// <summary>Byte 4</summary>
|
|
|
|
|
public byte Min;
|
|
|
|
|
/// <summary>Byte 5</summary>
|
|
|
|
|
public byte Sec;
|
|
|
|
|
/// <summary>Byte 6</summary>
|
|
|
|
|
public byte Frame;
|
|
|
|
|
/// <summary>Byte 7, CD only</summary>
|
|
|
|
|
public byte Zero;
|
|
|
|
|
/// <summary>Byte 7, bits 7 to 4, DDCD only</summary>
|
|
|
|
|
public byte HOUR;
|
|
|
|
|
/// <summary>Byte 7, bits 3 to 0, DDCD only</summary>
|
|
|
|
|
public byte PHOUR;
|
|
|
|
|
/// <summary>Byte 8</summary>
|
|
|
|
|
public byte PMIN;
|
|
|
|
|
/// <summary>Byte 9</summary>
|
|
|
|
|
public byte PSEC;
|
|
|
|
|
/// <summary>Byte 10</summary>
|
|
|
|
|
public byte PFRAME;
|
|
|
|
|
}
|
2021-06-29 12:36:09 +01:00
|
|
|
|
|
|
|
|
public static CDFullTOC Create(List<Track> tracks, Dictionary<byte, byte> trackFlags,
|
|
|
|
|
bool createC0Entry = false)
|
|
|
|
|
{
|
|
|
|
|
var toc = new CDFullTOC();
|
|
|
|
|
Dictionary<byte, byte> sessionEndingTrack = new Dictionary<byte, byte>();
|
|
|
|
|
toc.FirstCompleteSession = byte.MaxValue;
|
|
|
|
|
toc.LastCompleteSession = byte.MinValue;
|
|
|
|
|
List<TrackDataDescriptor> trackDescriptors = new List<TrackDataDescriptor>();
|
|
|
|
|
byte currentTrack = 0;
|
|
|
|
|
|
|
|
|
|
foreach(Track track in tracks.OrderBy(t => t.TrackSession).ThenBy(t => t.TrackSequence))
|
|
|
|
|
{
|
|
|
|
|
if(track.TrackSession < toc.FirstCompleteSession)
|
|
|
|
|
toc.FirstCompleteSession = (byte)track.TrackSession;
|
|
|
|
|
|
|
|
|
|
if(track.TrackSession <= toc.LastCompleteSession)
|
|
|
|
|
{
|
|
|
|
|
currentTrack = (byte)track.TrackSequence;
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(toc.LastCompleteSession > 0)
|
|
|
|
|
sessionEndingTrack.Add(toc.LastCompleteSession, currentTrack);
|
|
|
|
|
|
|
|
|
|
toc.LastCompleteSession = (byte)track.TrackSession;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-03 04:37:31 +01:00
|
|
|
if(!sessionEndingTrack.ContainsKey(toc.LastCompleteSession))
|
|
|
|
|
sessionEndingTrack[toc.LastCompleteSession] = (byte)tracks.
|
|
|
|
|
Where(t => t.TrackSession ==
|
|
|
|
|
toc.LastCompleteSession).
|
|
|
|
|
Max(t => t.TrackSequence);
|
|
|
|
|
|
2021-06-29 12:36:09 +01:00
|
|
|
byte currentSession = 0;
|
|
|
|
|
|
|
|
|
|
foreach(Track track in tracks.OrderBy(t => t.TrackSession).ThenBy(t => t.TrackSequence))
|
|
|
|
|
{
|
|
|
|
|
trackFlags.TryGetValue((byte)track.TrackSequence, out byte trackControl);
|
|
|
|
|
|
|
|
|
|
if(trackControl == 0 &&
|
|
|
|
|
track.TrackType != TrackType.Audio)
|
|
|
|
|
trackControl = (byte)CdFlags.DataTrack;
|
|
|
|
|
|
|
|
|
|
// Lead-Out
|
|
|
|
|
if(track.TrackSession > currentSession &&
|
|
|
|
|
currentSession != 0)
|
|
|
|
|
{
|
|
|
|
|
(byte minute, byte second, byte frame) leadoutAmsf = LbaToMsf(track.TrackStartSector - 150);
|
|
|
|
|
|
|
|
|
|
(byte minute, byte second, byte frame) leadoutPmsf =
|
|
|
|
|
LbaToMsf(tracks.OrderBy(t => t.TrackSession).ThenBy(t => t.TrackSequence).Last().
|
|
|
|
|
TrackStartSector);
|
|
|
|
|
|
|
|
|
|
// Lead-out
|
|
|
|
|
trackDescriptors.Add(new TrackDataDescriptor
|
|
|
|
|
{
|
|
|
|
|
SessionNumber = currentSession,
|
|
|
|
|
POINT = 0xB0,
|
|
|
|
|
ADR = 5,
|
|
|
|
|
CONTROL = 0,
|
|
|
|
|
HOUR = 0,
|
|
|
|
|
Min = leadoutAmsf.minute,
|
|
|
|
|
Sec = leadoutAmsf.second,
|
|
|
|
|
Frame = leadoutAmsf.frame,
|
|
|
|
|
PHOUR = 2,
|
|
|
|
|
PMIN = leadoutPmsf.minute,
|
|
|
|
|
PSEC = leadoutPmsf.second,
|
|
|
|
|
PFRAME = leadoutPmsf.frame
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// This seems to be constant? It should not exist on CD-ROM but CloneCD creates them anyway
|
|
|
|
|
// Format seems like ATIP, but ATIP should not be as 0xC0 in TOC...
|
|
|
|
|
if(createC0Entry)
|
|
|
|
|
trackDescriptors.Add(new TrackDataDescriptor
|
|
|
|
|
{
|
|
|
|
|
SessionNumber = currentSession,
|
|
|
|
|
POINT = 0xC0,
|
|
|
|
|
ADR = 5,
|
|
|
|
|
CONTROL = 0,
|
|
|
|
|
Min = 128,
|
|
|
|
|
PMIN = 97,
|
|
|
|
|
PSEC = 25
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Lead-in
|
|
|
|
|
if(track.TrackSession > currentSession)
|
|
|
|
|
{
|
|
|
|
|
currentSession = (byte)track.TrackSession;
|
|
|
|
|
sessionEndingTrack.TryGetValue(currentSession, out byte endingTrackNumber);
|
|
|
|
|
|
|
|
|
|
(byte minute, byte second, byte frame) leadinPmsf =
|
2021-08-03 04:37:31 +01:00
|
|
|
LbaToMsf((tracks.FirstOrDefault(t => t.TrackSequence == endingTrackNumber)?.TrackEndSector ??
|
|
|
|
|
0) + 1);
|
2021-06-29 12:36:09 +01:00
|
|
|
|
|
|
|
|
// Starting track
|
|
|
|
|
trackDescriptors.Add(new TrackDataDescriptor
|
|
|
|
|
{
|
|
|
|
|
SessionNumber = currentSession,
|
|
|
|
|
POINT = 0xA0,
|
|
|
|
|
ADR = 1,
|
|
|
|
|
CONTROL = trackControl,
|
|
|
|
|
PMIN = (byte)track.TrackSequence
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Ending track
|
|
|
|
|
trackDescriptors.Add(new TrackDataDescriptor
|
|
|
|
|
{
|
|
|
|
|
SessionNumber = currentSession,
|
|
|
|
|
POINT = 0xA1,
|
|
|
|
|
ADR = 1,
|
|
|
|
|
CONTROL = trackControl,
|
|
|
|
|
PMIN = endingTrackNumber
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Lead-out start
|
|
|
|
|
trackDescriptors.Add(new TrackDataDescriptor
|
|
|
|
|
{
|
|
|
|
|
SessionNumber = currentSession,
|
|
|
|
|
POINT = 0xA2,
|
|
|
|
|
ADR = 1,
|
|
|
|
|
CONTROL = trackControl,
|
|
|
|
|
PHOUR = 0,
|
|
|
|
|
PMIN = leadinPmsf.minute,
|
|
|
|
|
PSEC = leadinPmsf.second,
|
|
|
|
|
PFRAME = leadinPmsf.frame
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-03 04:37:31 +01:00
|
|
|
(byte minute, byte second, byte frame) pmsf = LbaToMsf((ulong)track.Indexes[1]);
|
2021-06-29 12:36:09 +01:00
|
|
|
|
|
|
|
|
// Track
|
|
|
|
|
trackDescriptors.Add(new TrackDataDescriptor
|
|
|
|
|
{
|
|
|
|
|
SessionNumber = (byte)track.TrackSession,
|
|
|
|
|
POINT = (byte)track.TrackSequence,
|
|
|
|
|
ADR = 1,
|
|
|
|
|
CONTROL = trackControl,
|
|
|
|
|
PHOUR = 0,
|
|
|
|
|
PMIN = pmsf.minute,
|
|
|
|
|
PSEC = pmsf.second,
|
|
|
|
|
PFRAME = pmsf.frame
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toc.TrackDescriptors = trackDescriptors.ToArray();
|
|
|
|
|
|
|
|
|
|
return toc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static (byte minute, byte second, byte frame) LbaToMsf(ulong sector) =>
|
|
|
|
|
((byte)((sector + 150) / 75 / 60), (byte)((sector + 150) / 75 % 60), (byte)((sector + 150) % 75));
|
2015-10-19 02:40:30 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|