diff --git a/CUETools.Processor/CUESheetLogWriter.cs b/CUETools.Processor/CUESheetLogWriter.cs index 6acd67e..80652d0 100644 --- a/CUETools.Processor/CUESheetLogWriter.cs +++ b/CUETools.Processor/CUESheetLogWriter.cs @@ -87,9 +87,15 @@ namespace CUETools.Processor private static double GetRangeQuality(CUESheet sheet, uint start, uint length) { - int failedSectorsCount = sheet.CDRipper.FailedSectors.PopulationCount((int)start - (int)sheet.TOC[sheet.TOC.FirstAudio][0].Start, (int)length); - int retrySectorsCount = sheet.CDRipper.RetrySectors.PopulationCount((int)start - (int)sheet.TOC[sheet.TOC.FirstAudio][0].Start, (int)length); - return 100 * (1.0 - Math.Log(failedSectorsCount / 5.0 + retrySectorsCount / 100.0 + 1) / Math.Log(length / 5.0 + length / 100.0 + 1)); + int retrySectorsCount = 0; + for (int i = 0; i < (int)length; i++) + retrySectorsCount += sheet.CDRipper.RetryCount[(int)start - (int)sheet.TOC[sheet.TOC.FirstAudio][0].Start + i]; +#if LOGQ + int max_scans = (16 << sheet.CDRipper.CorrectionQuality) - 1; + return 100 * (1.0 - Math.Log(retrySectorsCount / 100.0 + 1) / Math.Log(max_scans * (int)length / 100.0 + 1)); +#else + return 100.0 * (sheet.CDRipper.CorrectionQuality + 1) * length / retrySectorsCount; +#endif } public static string GetExactAudioCopyLog(CUESheet sheet) diff --git a/CUETools.Ripper.SCSI/SCSIDrive.cs b/CUETools.Ripper.SCSI/SCSIDrive.cs index 507ab96..102aa19 100644 --- a/CUETools.Ripper.SCSI/SCSIDrive.cs +++ b/CUETools.Ripper.SCSI/SCSIDrive.cs @@ -60,8 +60,8 @@ namespace CUETools.Ripper.SCSI public long[,,] UserData; public byte[,] C2Count; public long[] byte2long; - BitArray m_failedSectors, m_retrySctors; - int _crcErrorsCount = 0; + BitArray m_failedSectors; + byte[] m_retryCount; AudioBuffer currentData = new AudioBuffer(AudioPCMConfig.RedBook, MSECTORS * 588); short[] _valueScore = new short[256]; bool _debugMessages = false; @@ -85,19 +85,25 @@ namespace CUETools.Ripper.SCSI } } - public BitArray FailedSectors - { - get - { - return m_failedSectors; - } - } - - public BitArray RetrySectors + public byte[] RetryCount { get { - return m_retrySctors; + return m_retryCount; + } + } + + public BitArray FailedSectors + { + get + { + if (m_failedSectors == null) + { + m_failedSectors = new BitArray((int)_toc.AudioLength); + for (int i = 0; i < m_failedSectors.Length; i++) + m_failedSectors[i] = m_retryCount[i] == (16 << _correctionQuality) + 1; + } + return m_failedSectors; } } @@ -966,7 +972,7 @@ namespace CUETools.Ripper.SCSI throw ex; } - private unsafe void CorrectSectors(int pass, int sector, int Sectors2Read, BitArray markErrors) + private unsafe void CorrectSectors(int pass, int sector, int Sectors2Read) { for (int iSector = 0; iSector < Sectors2Read; iSector++) { @@ -1000,18 +1006,17 @@ namespace CUETools.Ripper.SCSI } currentData.Bytes[pos * 4 * 588 + iPar] = (byte)bestValue; } - int newerr = (fError ? 1 : 0); - //_currentErrorsCount += newerr; - _currentErrorsCount += newerr - errtmp[pos]; - errtmp[pos] = newerr; - if (markErrors != null) - markErrors[sector + iSector] |= fError; + + if (pass > _correctionQuality || fError) + { + int olderr = pass > _correctionQuality && m_retryCount[sector + iSector] == pass + 1 ? 1 : 0; + int newerr = fError ? 1 : 0; + _currentErrorsCount += newerr - olderr; + if (fError) m_retryCount[sector + iSector] = (byte)(pass + 2); + } } - } - int[] errtmp = new int[MSECTORS]; - public unsafe void PrefetchSector(int iSector) { if (iSector >= _currentStart && iSector < _currentEnd) @@ -1041,10 +1046,8 @@ namespace CUETools.Ripper.SCSI //correctFile.Close(); _currentErrorsCount = 0; - for (int i = 0; i < MSECTORS; i++) - errtmp[i] = 0; - //Device.CommandStatus st = m_device.SetCdSpeed(Device.RotationalControl.CLVandNonPureCav, (ushort)(176 * 4), 65535); + //Device.CommandStatus st = m_device.SetCdSpeed(Device.RotationalControl.CLVandNonPureCav, (ushort)(176 * 4), 65535); //if (st != Device.CommandStatus.Success) // System.Console.WriteLine("SetCdSpeed: {0}", (st == Device.CommandStatus.DeviceFailed ? Device.LookupSenseError(m_device.GetSenseAsc(), m_device.GetSenseAscq()) : st.ToString())); @@ -1071,7 +1074,7 @@ namespace CUETools.Ripper.SCSI //TimeSpan delay1 = DateTime.Now - LastFetch; //DateTime LastFetched = DateTime.Now; if (pass >= _correctionQuality) - CorrectSectors(pass, sector, Sectors2Read, pass == max_scans - 1 ? m_failedSectors : pass == _correctionQuality ? m_retrySctors : null); + CorrectSectors(pass, sector, Sectors2Read); //TimeSpan delay2 = DateTime.Now - LastFetched; //if (sector == _currentStart) //System.Console.WriteLine("\n{0},{1}", delay1.TotalMilliseconds, delay2.TotalMilliseconds); @@ -1189,11 +1192,12 @@ namespace CUETools.Ripper.SCSI { if (_toc == null || _toc.AudioLength <= 0) throw new ReadCDException(Resource1.NoAudio); - _crcErrorsCount = 0; _currentStart = -1; _currentEnd = -1; - m_failedSectors = new BitArray((int)_toc.AudioLength); // !!! - m_retrySctors = new BitArray((int)_toc.AudioLength); + m_retryCount = new byte[(int)_toc.AudioLength]; + for (int i = 0; i < m_retryCount.Length; i++) + m_retryCount[i] = (byte)(_correctionQuality + 1); + m_failedSectors = null; _sampleOffset = (int)value + _driveOffset; } } @@ -1230,7 +1234,9 @@ namespace CUETools.Ripper.SCSI if (value < 0 || value > 3) throw new Exception("invalid CorrectionQuality"); _correctionQuality = value; - } + for (int i = 0; i < m_retryCount.Length; i++) + m_retryCount[i] = (byte)(_correctionQuality + 1); + } } public string RipperVersion diff --git a/CUETools.Ripper/Ripper.cs b/CUETools.Ripper/Ripper.cs index 0fcccae..49615fa 100644 --- a/CUETools.Ripper/Ripper.cs +++ b/CUETools.Ripper/Ripper.cs @@ -22,7 +22,7 @@ namespace CUETools.Ripper string CurrentReadCommand { get; } int CorrectionQuality { get; set; } BitArray FailedSectors { get; } - BitArray RetrySectors { get; } + byte[] RetryCount { get; } event EventHandler ReadProgress; }