public static void Extract(Disc disc, string path, string fileBase) { var dsr = new DiscSectorReader(disc); bool confirmed = false; var tracks = disc.Session1.Tracks; foreach (var track in tracks) { if (!track.IsAudio) { continue; } int trackLength = track.NextTrack.LBA - track.LBA; var waveData = new byte[trackLength * 2352]; int startLba = track.LBA; for (int sector = 0; sector < trackLength; sector++) { dsr.ReadLBA_2352(startLba + sector, waveData, sector * 2352); } string mp3Path = $"{Path.Combine(path, fileBase)} - Track {track.Number:D2}.mp3"; if (File.Exists(mp3Path)) { if (!confirmed) { var dr = MessageBox.Show("This file already exists. Do you want extraction to proceed overwriting files, or cancel the entire operation immediately?", "File already exists", MessageBoxButtons.OKCancel); if (dr == DialogResult.Cancel) { return; } confirmed = true; } File.Delete(mp3Path); } string tempfile = Path.GetTempFileName(); try { File.WriteAllBytes(tempfile, waveData); var ffmpeg = new FFmpegService(); ffmpeg.Run("-f", "s16le", "-ar", "44100", "-ac", "2", "-i", tempfile, "-f", "mp3", "-ab", "192k", mp3Path); } finally { File.Delete(tempfile); } } }
void EnsureSector() { if (CachedSector != CurrentSector) { if (CurrentSector >= Disc.Session1.LeadoutLBA) { Array.Clear(SectorCache, 0, 2352); // request reading past end of available disc } else { DiscSectorReader.ReadLBA_2352(CurrentSector, SectorCache, 0); } CachedSector = CurrentSector; } }
/// <summary> /// read a sector, should be 2352 bytes /// </summary> /// <param name="FAD"></param> /// <param name="dest"></param> /// <returns></returns> int CD_ReadSectorFAD(int FAD, IntPtr dest) { byte[] data = new byte[2352]; try { //CD.ReadABA_2352(FAD, data, 0); DiscSectorReader.ReadLBA_2352(FAD - 150, data, 0); //zero 21-jun-2015 - did I adapt this right? } catch (Exception e) { Console.WriteLine("CD_ReadSectorFAD: Managed Exception:\n" + e.ToString()); return(0); // failure } Marshal.Copy(data, 0, dest, 2352); DriveLightOn = true; return(1); // success }
private void CDRead(int lba, IntPtr dest, bool audio) { if (audio) { byte[] data = new byte[2352]; if (lba < _cd.Session1.LeadoutLBA && lba >= _cd.Session1.Tracks[2].LBA) { _cdReader.ReadLBA_2352(lba, data, 0); } Marshal.Copy(data, 0, dest, 2352); } else { byte[] data = new byte[2048]; _cdReader.ReadLBA_2048(lba, data, 0); Marshal.Copy(data, 0, dest, 2048); DriveLightOn = true; } }
public static void Extract(Disc disc, string path, string fileBase, Func <bool?> getOverwritePolicy) { var dsr = new DiscSectorReader(disc); var shouldHalt = false; bool?overwriteExisting = null; // true = overwrite, false = skip existing, null = unset var tracks = disc.Session1.Tracks; Parallel.ForEach(tracks, track => { if (shouldHalt) { return; } if (!track.IsAudio) { return; } if (track.NextTrack == null) { return; } int trackLength = track.NextTrack.LBA - track.LBA; var waveData = new byte[trackLength * 2352]; int startLba = track.LBA; lock (disc) for (int sector = 0; sector < trackLength; sector++) { dsr.ReadLBA_2352(startLba + sector, waveData, sector * 2352); } string mp3Path = $"{Path.Combine(path, fileBase)} - Track {track.Number:D2}.mp3"; if (File.Exists(mp3Path)) { overwriteExisting ??= getOverwritePolicy(); switch (overwriteExisting) { case true: // "Yes" -- overwrite File.Delete(mp3Path); break; case false: // "No" -- skip return; case null: // "Cancel" -- halt shouldHalt = true; return; } } string tempfile = Path.GetTempFileName(); try { File.WriteAllBytes(tempfile, waveData); FFmpegService.Run("-f", "s16le", "-ar", "44100", "-ac", "2", "-i", tempfile, "-f", "mp3", "-ab", "192k", mp3Path); } finally { File.Delete(tempfile); } }); }