integrating the ripper

This commit is contained in:
chudov
2008-11-30 23:47:13 +00:00
parent c289ecce0b
commit 38ad9d9923
10 changed files with 149 additions and 57 deletions

View File

@@ -81,6 +81,7 @@ namespace CUETools.CDImage
_isAudio = isAudio; _isAudio = isAudio;
_indexes = new List<CDTrackIndex>(); _indexes = new List<CDTrackIndex>();
_indexes.Add(new CDTrackIndex(0, start, 0)); _indexes.Add(new CDTrackIndex(0, start, 0));
_indexes.Add(new CDTrackIndex(1, start, length));
} }
public CDTrack(CDTrack src) public CDTrack(CDTrack src)
@@ -209,8 +210,8 @@ namespace CUETools.CDImage
public void AddIndex(CDTrackIndex index) public void AddIndex(CDTrackIndex index)
{ {
if (index.Index == 0) if (index.Index < 2)
_indexes[0] = index; _indexes[(int)index.Index] = index;
else else
_indexes.Add(index); _indexes.Add(index);
} }

View File

@@ -97,6 +97,10 @@
<Project>{8CF07381-BEA2-4AFC-B3DD-9B2F21C65A3A}</Project> <Project>{8CF07381-BEA2-4AFC-B3DD-9B2F21C65A3A}</Project>
<Name>CUETools.Ripper.SCSI</Name> <Name>CUETools.Ripper.SCSI</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\FLACDotNet\FLACDotNet.vcproj">
<Project>{E70FA90A-7012-4A52-86B5-362B699D1540}</Project>
<Name>FLACDotNet</Name>
</ProjectReference>
<ProjectReference Include="..\MusicBrainz\MusicBrainz.csproj"> <ProjectReference Include="..\MusicBrainz\MusicBrainz.csproj">
<Project>{74C2036B-2C9B-4FC8-B7BD-AE81A8DCE533}</Project> <Project>{74C2036B-2C9B-4FC8-B7BD-AE81A8DCE533}</Project>
<Name>MusicBrainz</Name> <Name>MusicBrainz</Name>

View File

@@ -27,6 +27,7 @@ using CUETools.Ripper.SCSI;
using CUETools.Codecs; using CUETools.Codecs;
using CUETools.CDImage; using CUETools.CDImage;
using CUETools.AccurateRip; using CUETools.AccurateRip;
using FLACDotNet;
using MusicBrainz; using MusicBrainz;
namespace CUERipper namespace CUERipper
@@ -67,7 +68,7 @@ namespace CUERipper
audioSource.Open(driveLetter); audioSource.Open(driveLetter);
audioSource.DriveOffset = 48; audioSource.DriveOffset = 48;
bool toStdout = false; //bool toStdout = false;
AccurateRipVerify arVerify = new AccurateRipVerify(audioSource.TOC); AccurateRipVerify arVerify = new AccurateRipVerify(audioSource.TOC);
int[,] buff = new int[audioSource.BestBlockSize, audioSource.ChannelCount]; int[,] buff = new int[audioSource.BestBlockSize, audioSource.ChannelCount];
string CDDBId = AccurateRipVerify.CalculateCDDBId(audioSource.TOC); string CDDBId = AccurateRipVerify.CalculateCDDBId(audioSource.TOC);
@@ -89,7 +90,7 @@ namespace CUERipper
} }
if (destFile == null || destFile == "") if (destFile == null || destFile == "")
destFile = (release == null) ? "cdimage.wav" : release.GetArtist() + " - " + release.GetTitle() + ".wav"; destFile = (release == null) ? "cdimage.flac" : release.GetArtist() + " - " + release.GetTitle() + ".flac";
Console.WriteLine("Drive : {0}", audioSource.Path); Console.WriteLine("Drive : {0}", audioSource.Path);
Console.WriteLine("Filename : {0}", destFile); Console.WriteLine("Filename : {0}", destFile);
@@ -97,7 +98,8 @@ namespace CUERipper
Console.WriteLine("AccurateRip : {0}", arVerify.ARStatus == null ? "ok" : arVerify.ARStatus); Console.WriteLine("AccurateRip : {0}", arVerify.ARStatus == null ? "ok" : arVerify.ARStatus);
Console.WriteLine("MusicBrainz : {0}", release == null ? "not found" : release.GetArtist() + " - " + release.GetTitle()); Console.WriteLine("MusicBrainz : {0}", release == null ? "not found" : release.GetArtist() + " - " + release.GetTitle());
WAVWriter audioDest = new WAVWriter(destFile, audioSource.BitsPerSample, audioSource.ChannelCount, audioSource.SampleRate, toStdout ? Console.OpenStandardOutput() : null); IAudioDest audioDest = new FLACWriter(destFile, audioSource.BitsPerSample, audioSource.ChannelCount, audioSource.SampleRate);
//IAudioDest audioDest = new WAVWriter(destFile, audioSource.BitsPerSample, audioSource.ChannelCount, audioSource.SampleRate, toStdout ? Console.OpenStandardOutput() : null);
audioDest.FinalSampleCount = (long)audioSource.Length; audioDest.FinalSampleCount = (long)audioSource.Length;
@@ -131,7 +133,7 @@ namespace CUERipper
); );
audioDest.Close(); audioDest.Close();
StreamWriter logWriter = new StreamWriter(Path.ChangeExtension(destFile, ".log")); StringWriter logWriter = new StringWriter();
logWriter.WriteLine("{0}", programVersion); logWriter.WriteLine("{0}", programVersion);
logWriter.WriteLine(); logWriter.WriteLine();
logWriter.WriteLine("Extraction logfile from {0}", DateTime.Now); logWriter.WriteLine("Extraction logfile from {0}", DateTime.Now);
@@ -157,20 +159,23 @@ namespace CUERipper
arVerify.GenerateFullLog(logWriter, 0); arVerify.GenerateFullLog(logWriter, 0);
logWriter.WriteLine(); logWriter.WriteLine();
logWriter.WriteLine("End of status report"); logWriter.WriteLine("End of status report");
logWriter.Close(); logWriter.Close();
StreamWriter logFile = new StreamWriter(Path.ChangeExtension(destFile, ".log"));
logFile.Write(logWriter.ToString());
logFile.Close();
StreamWriter cueWriter = new StreamWriter(Path.ChangeExtension(destFile, ".cue")); StringWriter cueWriter = new StringWriter();
cueWriter.WriteLine("REM DISCID {0}", CDDBId); cueWriter.WriteLine("REM DISCID {0}", CDDBId);
cueWriter.WriteLine("REM ACCURATERIPID {0}", ArId); cueWriter.WriteLine("REM ACCURATERIPID {0}", ArId);
cueWriter.WriteLine("REM COMMENT \"{0}\"", programVersion); cueWriter.WriteLine("REM COMMENT \"{0}\"", programVersion);
if (release != null && release.GetEvents().Count > 0)
cueWriter.WriteLine("REM DATE {0}", release.GetEvents()[0].Date.Substring(0,4));
if (audioSource.TOC.Catalog != null) if (audioSource.TOC.Catalog != null)
cueWriter.WriteLine("CATALOG {0}", audioSource.TOC.Catalog); cueWriter.WriteLine("CATALOG {0}", audioSource.TOC.Catalog);
if (release != null) if (release != null)
{ {
if (release.GetEvents().Count > 0) cueWriter.WriteLine("PERFORMER \"{0}\"", release.GetArtist());
cueWriter.WriteLine("DATE {0}", release.GetEvents()[0].Date); cueWriter.WriteLine("TITLE \"{0}\"", release.GetTitle());
cueWriter.WriteLine("PERFORMER {0}", release.GetArtist());
cueWriter.WriteLine("TITLE {0}", release.GetTitle());
} }
cueWriter.WriteLine("FILE \"{0}\" WAVE", destFile); cueWriter.WriteLine("FILE \"{0}\" WAVE", destFile);
for (int track = 1; track <= audioSource.TOC.TrackCount; track++) for (int track = 1; track <= audioSource.TOC.TrackCount; track++)
@@ -179,8 +184,8 @@ namespace CUERipper
cueWriter.WriteLine(" TRACK {0:00} AUDIO", audioSource.TOC[track].Number); cueWriter.WriteLine(" TRACK {0:00} AUDIO", audioSource.TOC[track].Number);
if (release != null && release.GetTracks().Count >= audioSource.TOC[track].Number) if (release != null && release.GetTracks().Count >= audioSource.TOC[track].Number)
{ {
cueWriter.WriteLine(" TITLE {0}", release.GetTracks()[(int)audioSource.TOC[track].Number - 1].GetTitle()); cueWriter.WriteLine(" TITLE \"{0}\"", release.GetTracks()[(int)audioSource.TOC[track].Number - 1].GetTitle());
cueWriter.WriteLine(" PERFORMER {0}", release.GetTracks()[(int)audioSource.TOC[track].Number - 1].GetArtist()); cueWriter.WriteLine(" PERFORMER \"{0}\"", release.GetTracks()[(int)audioSource.TOC[track].Number - 1].GetArtist());
} }
if (audioSource.TOC[track].ISRC != null) if (audioSource.TOC[track].ISRC != null)
cueWriter.WriteLine(" ISRC {0}", audioSource.TOC[track].ISRC); cueWriter.WriteLine(" ISRC {0}", audioSource.TOC[track].ISRC);
@@ -188,8 +193,16 @@ namespace CUERipper
cueWriter.WriteLine(" INDEX {0:00} {1}", index, audioSource.TOC[track][index].MSF); cueWriter.WriteLine(" INDEX {0:00} {1}", index, audioSource.TOC[track][index].MSF);
} }
cueWriter.Close(); cueWriter.Close();
StreamWriter cueFile = new StreamWriter(Path.ChangeExtension(destFile, ".cue"));
cueFile.Write(cueWriter.ToString());
cueFile.Close();
audioSource.Close(); audioSource.Close();
FLACReader tagger = new FLACReader(destFile, null);
tagger.Tags.Add("CUESHEET", cueWriter.ToString());
tagger.Tags.Add("LOG", logWriter.ToString());
tagger.UpdateTags(false);
} }
#if !DEBUG #if !DEBUG
catch (Exception ex) catch (Exception ex)

View File

@@ -68,15 +68,15 @@ namespace CUETools.Ripper.SCSI
{ {
Device.CommandStatus st; Device.CommandStatus st;
m_info = DeviceInfo.CreateDevice(Drive + ":");
// Open the base device // Open the base device
m_device = new Device(m_logger); m_device = new Device(m_logger);
if (!m_device.Open(Drive)) if (!m_device.Open(Drive))
throw new Exception("SCSI error"); throw new Exception("Open failed: SCSI error");
// Get device info
m_info = DeviceInfo.CreateDevice(Drive + ":");
if (!m_info.ExtractInfo(m_device)) if (!m_info.ExtractInfo(m_device))
throw new Exception("SCSI error"); throw new Exception("ExtractInfo failed: SCSI error");
//// Open/Initialize the driver //// Open/Initialize the driver
//Drive m_drive = new Drive(dev); //Drive m_drive = new Drive(dev);
@@ -100,16 +100,16 @@ namespace CUETools.Ripper.SCSI
SpeedDescriptorList speed_list; SpeedDescriptorList speed_list;
st = m_device.GetSpeed(out speed_list); st = m_device.GetSpeed(out speed_list);
if (st != Device.CommandStatus.Success) if (st != Device.CommandStatus.Success)
throw new Exception("SCSI error"); throw new Exception("GetSpeed failed: SCSI error");
st = m_device.SetCdSpeed(Device.RotationalControl.CLVandNonPureCav, Device.OptimumSpeed, Device.OptimumSpeed); st = m_device.SetCdSpeed(Device.RotationalControl.CLVandNonPureCav, Device.OptimumSpeed, Device.OptimumSpeed);
if (st != Device.CommandStatus.Success) if (st != Device.CommandStatus.Success)
throw new Exception("SCSI error"); throw new Exception("SetCdSpeed failed: SCSI error");
IList<TocEntry> toc; IList<TocEntry> toc;
st = m_device.ReadToc((byte)0, false, out toc); st = m_device.ReadToc((byte)0, false, out toc);
if (st != Device.CommandStatus.Success) if (st != Device.CommandStatus.Success)
throw new Exception("SCSI error"); throw new Exception("ReadToc failed: SCSI error");
st = m_device.ReadCDText(out cdtext); st = m_device.ReadCDText(out cdtext);
// new CDTextEncoderDecoder // new CDTextEncoderDecoder
@@ -126,6 +126,8 @@ namespace CUETools.Ripper.SCSI
public void Close() public void Close()
{ {
m_device.Close();
m_device = null;
_toc = null; _toc = null;
} }
@@ -218,7 +220,7 @@ namespace CUETools.Ripper.SCSI
{ {
Device.CommandStatus st = m_device.ReadCDAndSubChannel(2, 1, true, (uint)sector, (uint)Sectors2Read, (IntPtr)((void*)data), Sectors2Read * (2352 + 16)); Device.CommandStatus st = m_device.ReadCDAndSubChannel(2, 1, true, (uint)sector, (uint)Sectors2Read, (IntPtr)((void*)data), Sectors2Read * (2352 + 16));
if (st != Device.CommandStatus.Success) if (st != Device.CommandStatus.Success)
throw new Exception("SCSI error"); throw new Exception("ReadCDAndSubChannel failed: SCSI error");
} }
ProcessSubchannel(sector, Sectors2Read); ProcessSubchannel(sector, Sectors2Read);
} }
@@ -226,7 +228,7 @@ namespace CUETools.Ripper.SCSI
public unsafe uint Read(int[,] buff, uint sampleCount) public unsafe uint Read(int[,] buff, uint sampleCount)
{ {
if (_toc == null) if (_toc == null)
throw new Exception("invalid TOC"); throw new Exception("Read: invalid TOC");
if (_sampleOffset - _driveOffset >= (uint)Length) if (_sampleOffset - _driveOffset >= (uint)Length)
return 0; return 0;
if (_sampleOffset > (uint)Length) if (_sampleOffset > (uint)Length)
@@ -287,7 +289,7 @@ namespace CUETools.Ripper.SCSI
} }
// if (_sampleOffset < PreGapLength && !_overreadIntoPreGap ... ? // if (_sampleOffset < PreGapLength && !_overreadIntoPreGap ... ?
int firstSector = (int)_sampleOffset / 588; int firstSector = (int)_sampleOffset / 588;
int lastSector = (int)(_sampleOffset + sampleCount + 577) / 588; int lastSector = (int)(_sampleOffset + sampleCount + 587) / 588;
for (int sector = firstSector; sector < lastSector; sector += NSECTORS) for (int sector = firstSector; sector < lastSector; sector += NSECTORS)
{ {
int Sectors2Read = ((sector + NSECTORS) < lastSector) ? NSECTORS : (lastSector - sector); int Sectors2Read = ((sector + NSECTORS) < lastSector) ? NSECTORS : (lastSector - sector);

View File

@@ -133,7 +133,7 @@ namespace JDP
throw new Exception("Input CUE Sheet not found."); throw new Exception("Input CUE Sheet not found.");
if (!pathIn.EndsWith(new string(Path.DirectorySeparatorChar, 1))) if (!pathIn.EndsWith(new string(Path.DirectorySeparatorChar, 1)))
pathIn = pathIn + Path.DirectorySeparatorChar; pathIn = pathIn + Path.DirectorySeparatorChar;
cueName = Path.GetFileNameWithoutExtension(Path.GetDirectoryName(pathIn)) + ".cue"; cueName = Path.GetFileNameWithoutExtension(Path.GetDirectoryName(pathIn) ?? pathIn) + ".cue";
} }
else else
cueName = Path.GetFileNameWithoutExtension(pathIn) + ".cue"; cueName = Path.GetFileNameWithoutExtension(pathIn) + ".cue";
@@ -145,7 +145,7 @@ namespace JDP
bool pathFound = false; bool pathFound = false;
for (int i = 0; i < 20; i++) for (int i = 0; i < 20; i++)
{ {
string outDir = Path.Combine(Path.GetDirectoryName(pathIn), "CUEToolsOutput" + (i > 0 ? String.Format("({0})", i) : "")); string outDir = Path.Combine(Path.GetDirectoryName(pathIn) ?? pathIn, "CUEToolsOutput" + (i > 0 ? String.Format("({0})", i) : ""));
if (!Directory.Exists(outDir)) if (!Directory.Exists(outDir))
{ {
Directory.CreateDirectory(outDir); Directory.CreateDirectory(outDir);
@@ -158,7 +158,7 @@ namespace JDP
throw new Exception("Could not create a folder."); throw new Exception("Could not create a folder.");
} }
else else
pathOut = Path.Combine(Path.GetDirectoryName(pathIn), cueName); pathOut = Path.Combine(Path.GetDirectoryName(pathIn) ?? pathIn, cueName);
cueSheet.GenerateFilenames(_audioFormat, pathOut); cueSheet.GenerateFilenames(_audioFormat, pathOut);
if (outputAudio) if (outputAudio)
{ {

View File

@@ -761,7 +761,7 @@ namespace JDP {
{ {
if (!pathIn.EndsWith(new string(Path.DirectorySeparatorChar, 1))) if (!pathIn.EndsWith(new string(Path.DirectorySeparatorChar, 1)))
pathIn = pathIn + Path.DirectorySeparatorChar; pathIn = pathIn + Path.DirectorySeparatorChar;
dir = Path.GetDirectoryName(pathIn); dir = Path.GetDirectoryName(pathIn) ?? pathIn;
file = Path.GetFileNameWithoutExtension(dir); file = Path.GetFileNameWithoutExtension(dir);
} }
else else

View File

@@ -109,6 +109,10 @@
<Project>{1DD41038-D885-46C5-8DDE-E0B82F066584}</Project> <Project>{1DD41038-D885-46C5-8DDE-E0B82F066584}</Project>
<Name>CUETools.CDImage</Name> <Name>CUETools.CDImage</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\CUETools.Ripper.SCSI\CUETools.Ripper.SCSI.csproj">
<Project>{8CF07381-BEA2-4AFC-B3DD-9B2F21C65A3A}</Project>
<Name>CUETools.Ripper.SCSI</Name>
</ProjectReference>
<ProjectReference Include="..\FLACDotNet\FLACDotNet.vcproj"> <ProjectReference Include="..\FLACDotNet\FLACDotNet.vcproj">
<Project>{E70FA90A-7012-4A52-86B5-362B699D1540}</Project> <Project>{E70FA90A-7012-4A52-86B5-362B699D1540}</Project>
<Name>FLACDotNet</Name> <Name>FLACDotNet</Name>
@@ -121,6 +125,10 @@
<Project>{8A0426FA-0BC2-4C49-A6E5-1F9A68156F19}</Project> <Project>{8A0426FA-0BC2-4C49-A6E5-1F9A68156F19}</Project>
<Name>CUETools.Codecs.LossyWAV</Name> <Name>CUETools.Codecs.LossyWAV</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\MusicBrainz\MusicBrainz.csproj">
<Project>{74C2036B-2C9B-4FC8-B7BD-AE81A8DCE533}</Project>
<Name>MusicBrainz</Name>
</ProjectReference>
<ProjectReference Include="..\UnRarDotNet\UnRarDotNet.csproj"> <ProjectReference Include="..\UnRarDotNet\UnRarDotNet.csproj">
<Project>{8427CAA5-80B8-4952-9A68-5F3DFCFBDF40}</Project> <Project>{8427CAA5-80B8-4952-9A68-5F3DFCFBDF40}</Project>
<Name>UnRarDotNet</Name> <Name>UnRarDotNet</Name>

View File

@@ -34,6 +34,8 @@ using CUETools.Codecs;
using CUETools.Codecs.LossyWAV; using CUETools.Codecs.LossyWAV;
using CUETools.CDImage; using CUETools.CDImage;
using CUETools.AccurateRip; using CUETools.AccurateRip;
using CUETools.Ripper.SCSI;
using MusicBrainz;
#if !MONO #if !MONO
using UnRarDotNet; using UnRarDotNet;
using FLACDotNet; using FLACDotNet;
@@ -421,8 +423,9 @@ namespace CUETools.Processor
private const int _arOffsetRange = 5 * 588 - 1; private const int _arOffsetRange = 5 * 588 - 1;
private HDCDDotNet.HDCDDotNet hdcdDecoder; private HDCDDotNet.HDCDDotNet hdcdDecoder;
private bool _outputLossyWAV = false; private bool _outputLossyWAV = false;
CUEConfig _config; private CUEConfig _config;
string _cddbDiscIdTag; private string _cddbDiscIdTag;
private bool _isCD;
private bool _isArchive; private bool _isArchive;
private List<string> _archiveContents; private List<string> _archiveContents;
private string _archiveCUEpath; private string _archiveCUEpath;
@@ -440,6 +443,7 @@ namespace CUETools.Processor
_progress = new CUEToolsProgressEventArgs(); _progress = new CUEToolsProgressEventArgs();
_attributes = new List<CUELine>(); _attributes = new List<CUELine>();
_tracks = new List<TrackInfo>(); _tracks = new List<TrackInfo>();
_trackFilenames = new List<string>();
_toc = new CDImageLayout(); _toc = new CDImageLayout();
_sources = new List<SourceInfo>(); _sources = new List<SourceInfo>();
_sourcePaths = new List<string>(); _sourcePaths = new List<string>();
@@ -458,39 +462,86 @@ namespace CUETools.Processor
hdcdDecoder = null; hdcdDecoder = null;
_hasEmbeddedCUESheet = false; _hasEmbeddedCUESheet = false;
_isArchive = false; _isArchive = false;
_isCD = false;
} }
public void Open(string pathIn, bool outputLossyWAV) public void Open(string pathIn, bool outputLossyWAV)
{ {
_outputLossyWAV = outputLossyWAV;
if (_config.detectHDCD) if (_config.detectHDCD)
{ {
try { hdcdDecoder = new HDCDDotNet.HDCDDotNet(2, 44100, ((_outputLossyWAV && _config.decodeHDCDtoLW16) || !_config.decodeHDCDto24bit) ? 20 : 24, _config.decodeHDCD); } try { hdcdDecoder = new HDCDDotNet.HDCDDotNet(2, 44100, ((_outputLossyWAV && _config.decodeHDCDtoLW16) || !_config.decodeHDCDto24bit) ? 20 : 24, _config.decodeHDCD); }
catch { } catch { }
} }
_outputLossyWAV = outputLossyWAV;
SourceInfo sourceInfo;
string cueDir = Path.GetDirectoryName(pathIn) ?? pathIn;
#if !MONO
if (cueDir == pathIn)
{
CDDriveReader ripper = new CDDriveReader();
ripper.Open(pathIn[0]);
// We needed to clone TOC in case we reuse the ripper, because it's going to modify it.
//_toc = (CDImageLayout)ripper.TOC.Clone();
_toc = (CDImageLayout)ripper.TOC;
sourceInfo.Path = pathIn;
sourceInfo.Offset = 0;
sourceInfo.Length = (uint)ripper.Length;
ripper.Close();
if (_toc.AudioTracks > 0)
{
_isCD = true;
_sources.Add(sourceInfo);
for (int iTrack = 0; iTrack < _toc.AudioTracks; iTrack++)
{
_trackFilenames.Add(string.Format("{0:00}.wav", iTrack + 1));
_tracks.Add(new TrackInfo());
}
_hasTrackFilenames = false;
_accurateRipId = _accurateRipIdActual = AccurateRipVerify.CalculateAccurateRipId(_toc);
_arVerify = new AccurateRipVerify(_toc);
string cueDir, lineStr, command, pathAudio = null, fileType; Release release;
ReleaseQueryParameters p = new ReleaseQueryParameters();
p.DiscId = _toc.MusicBrainzId;
Query<Release> results = Release.Query(p);
MusicBrainzService.XmlRequest += new EventHandler<XmlRequestEventArgs>(MusicBrainz_LookupProgress);
_progress.percentDisk = 0;
try
{
release = results.First();
General.SetCUELine(_attributes, "PERFORMER", release.GetArtist(), true);
General.SetCUELine(_attributes, "TITLE", release.GetTitle(), true);
General.SetCUELine(_attributes, "REM", "DATE", release.GetEvents()[0].Date.Substring(0, 4), false);
for (int iTrack = 0; iTrack < _toc.AudioTracks; iTrack++)
{
General.SetCUELine(_tracks[iTrack].Attributes, "TITLE", release.GetTracks()[iTrack].GetTitle(), true);
General.SetCUELine(_tracks[iTrack].Attributes, "PERFORMER ", release.GetTracks()[iTrack].GetArtist(), true);
}
}
catch
{
release = null;
}
return;
}
}
#endif
string lineStr, command, pathAudio = null, fileType;
CUELine line; CUELine line;
TrackInfo trackInfo; TrackInfo trackInfo = null;
int timeRelativeToFileStart, absoluteFileStartTime; int timeRelativeToFileStart, absoluteFileStartTime = 0;
int fileTimeLengthSamples, fileTimeLengthFrames, i; int fileTimeLengthSamples = 0, fileTimeLengthFrames = 0, i;
int trackNumber = 0; int trackNumber = 0;
bool seenFirstFileIndex = false, seenDataTrack = false; bool seenFirstFileIndex = false, seenDataTrack = false;
List<IndexInfo> indexes = new List<IndexInfo>(); List<IndexInfo> indexes = new List<IndexInfo>();
IndexInfo indexInfo; IndexInfo indexInfo;
SourceInfo sourceInfo;
NameValueCollection _trackTags = null; NameValueCollection _trackTags = null;
cueDir = Path.GetDirectoryName(pathIn);
trackInfo = null;
absoluteFileStartTime = 0;
fileTimeLengthSamples = 0;
fileTimeLengthFrames = 0;
TextReader sr; TextReader sr;
if (Directory.Exists(pathIn)) if (Directory.Exists(pathIn))
{ {
if (cueDir + Path.DirectorySeparatorChar != pathIn) if (cueDir + Path.DirectorySeparatorChar != pathIn && cueDir != pathIn)
throw new Exception("Input directory must end on path separator character."); throw new Exception("Input directory must end on path separator character.");
string cueSheet = null; string cueSheet = null;
string[] audioExts = new string[] { "*.wav", "*.flac", "*.wv", "*.ape", "*.m4a" }; string[] audioExts = new string[] { "*.wav", "*.flac", "*.wv", "*.ape", "*.m4a" };
@@ -768,7 +819,6 @@ namespace CUETools.Processor
_htoaFilename = _hasHTOAFilename ? Path.GetFileName(_sourcePaths[0]) : "01.00.wav"; _htoaFilename = _hasHTOAFilename ? Path.GetFileName(_sourcePaths[0]) : "01.00.wav";
_hasTrackFilenames = (_sourcePaths.Count == TrackCount) || _hasHTOAFilename; _hasTrackFilenames = (_sourcePaths.Count == TrackCount) || _hasHTOAFilename;
_trackFilenames = new List<string>();
for (i = 0; i < TrackCount; i++) { for (i = 0; i < TrackCount; i++) {
_trackFilenames.Add( _hasTrackFilenames ? Path.GetFileName( _trackFilenames.Add( _hasTrackFilenames ? Path.GetFileName(
_sourcePaths[i + (_hasHTOAFilename ? 1 : 0)]) : String.Format("{0:00}.wav", i + 1) ); _sourcePaths[i + (_hasHTOAFilename ? 1 : 0)]) : String.Format("{0:00}.wav", i + 1) );
@@ -892,6 +942,18 @@ namespace CUETools.Processor
} }
#if !MONO #if !MONO
private void MusicBrainz_LookupProgress(object sender, XmlRequestEventArgs e)
{
if (this.CUEToolsProgress == null)
return;
_progress.percentDisk = (1.0 + _progress.percentDisk) / 2;
_progress.percentTrack = 0;
_progress.input = e.Uri.ToString();
_progress.output = null;
_progress.status = "Looking up album via MusicBrainz";
this.CUEToolsProgress(this, _progress);
}
private void unrar_ExtractionProgress(object sender, ExtractionProgressEventArgs e) private void unrar_ExtractionProgress(object sender, ExtractionProgressEventArgs e)
{ {
if (this.CUEToolsProgress == null) if (this.CUEToolsProgress == null)
@@ -1210,14 +1272,7 @@ namespace CUETools.Processor
} }
private void CalculateMusicBrainzDiscID() { private void CalculateMusicBrainzDiscID() {
StringBuilder mbSB = new StringBuilder(); _mbDiscId = _toc.MusicBrainzId;
mbSB.AppendFormat("{0:X2}{1:X2}{2:X8}", 1, TrackCount, _toc.Length + 150);
for (int iTrack = 1; iTrack <= _toc.TrackCount; iTrack++)
mbSB.AppendFormat("{0:X8}", _toc[iTrack].Start + 150);
mbSB.Append(new string('0', (99 - TrackCount) * 8));
byte[] hashBytes = (new SHA1CryptoServiceProvider()).ComputeHash(Encoding.ASCII.GetBytes(mbSB.ToString()));
_mbDiscId = Convert.ToBase64String(hashBytes).Replace('+', '.').Replace('/', '_').Replace('=', '-');
System.Diagnostics.Debug.WriteLine(_mbDiscId); System.Diagnostics.Debug.WriteLine(_mbDiscId);
} }
@@ -1834,7 +1889,8 @@ namespace CUETools.Processor
uint currentOffset = 0, previousOffset = 0; uint currentOffset = 0, previousOffset = 0;
uint trackLength = _toc.Pregap * 588; uint trackLength = _toc.Pregap * 588;
uint diskLength = _toc.Length * 588, diskOffset = 0; uint diskLength = 588 * (_toc[_toc.TrackCount].IsAudio ? _toc[_toc.TrackCount].End + 1 : _toc[_toc.TrackCount - 1].End + 1);
uint diskOffset = 0;
if (_accurateRip && noOutput) if (_accurateRip && noOutput)
_arVerify.Init(); _arVerify.Init();
@@ -1908,11 +1964,12 @@ namespace CUETools.Processor
if (trackPercent != lastTrackPercent) if (trackPercent != lastTrackPercent)
ShowProgress(String.Format("{2} track {0:00} ({1:00}%)...", iIndex > 0 ? iTrack + 1 : iTrack, trackPercent, ShowProgress(String.Format("{2} track {0:00} ({1:00}%)...", iIndex > 0 ? iTrack + 1 : iTrack, trackPercent,
noOutput ? "Verifying" : "Writing"), trackPercent, diskPercent, noOutput ? "Verifying" : "Writing"), trackPercent, diskPercent,
audioSource.Path, discardOutput ? null : audioDest.Path); _isCD ? audioSource.Path + ": " + _tracks[iTrack].Title : audioSource.Path, discardOutput ? null : audioDest.Path);
lastTrackPercent = trackPercent; lastTrackPercent = trackPercent;
} }
audioSource.Read(sampleBuffer, copyCount); if (audioSource.Read(sampleBuffer, copyCount) != copyCount)
throw new Exception("samples read != samples expected");
if (!discardOutput) if (!discardOutput)
{ {
if (!_config.detectHDCD || !_config.decodeHDCD) if (!_config.detectHDCD || !_config.decodeHDCD)
@@ -2159,6 +2216,13 @@ namespace CUETools.Processor
} }
else { else {
#if !MONO #if !MONO
if (_isCD)
{
CDDriveReader ripper = new CDDriveReader();
ripper.Open(sourceInfo.Path[0]);
ripper.DriveOffset = 48;
audioSource = ripper;
} else
if (_isArchive) if (_isArchive)
{ {
RarStream IO = new RarStream(_archivePath, sourceInfo.Path); RarStream IO = new RarStream(_archivePath, sourceInfo.Path);

View File

@@ -81,11 +81,11 @@
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\AudioCodecsDotNet\AudioCodecsDotNet.csproj"> <ProjectReference Include="..\AudioCodecsDotNet\CUETools.Codecs.csproj">
<Project>{6458A13A-30EF-45A9-9D58-E5031B17BEE2}</Project> <Project>{6458A13A-30EF-45A9-9D58-E5031B17BEE2}</Project>
<Name>AudioCodecsDotNet</Name> <Name>AudioCodecsDotNet</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\LossyWAVDotNet\LossyWAVDotNet.csproj"> <ProjectReference Include="..\LossyWAVDotNet\CUETools.Codecs.LossyWAV.csproj">
<Project>{8A0426FA-0BC2-4C49-A6E5-1F9A68156F19}</Project> <Project>{8A0426FA-0BC2-4C49-A6E5-1F9A68156F19}</Project>
<Name>LossyWAVDotNet</Name> <Name>LossyWAVDotNet</Name>
</ProjectReference> </ProjectReference>