From 22b00b1bd5c787101532987c921e924aa264bc5a Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 25 Aug 2021 21:40:59 -0700 Subject: [PATCH] DataPlayback option applies to saving tracks --- .../ViewModels/PlayerViewModel.cs | 4 +-- RedBookPlayer.Models/Discs/CompactDisc.cs | 33 +++++++++++++++---- RedBookPlayer.Models/Discs/OpticalDiscBase.cs | 4 +-- RedBookPlayer.Models/Hardware/Player.cs | 4 +-- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/RedBookPlayer.GUI/ViewModels/PlayerViewModel.cs b/RedBookPlayer.GUI/ViewModels/PlayerViewModel.cs index 5c25eac..1750063 100644 --- a/RedBookPlayer.GUI/ViewModels/PlayerViewModel.cs +++ b/RedBookPlayer.GUI/ViewModels/PlayerViewModel.cs @@ -628,13 +628,13 @@ namespace RedBookPlayer.GUI.ViewModels /// Extract a single track from the image to WAV /// /// - /// Output path to write data toOutput path to write data to public void ExtractSingleTrackToWav(uint trackNumber, string outputDirectory) => _player?.ExtractSingleTrackToWav(trackNumber, outputDirectory); /// /// Extract all tracks from the image to WAV /// - /// Output path to write data toOutput path to write data to public void ExtractAllTracksToWav(string outputDirectory) => _player?.ExtractAllTracksToWav(outputDirectory); /// diff --git a/RedBookPlayer.Models/Discs/CompactDisc.cs b/RedBookPlayer.Models/Discs/CompactDisc.cs index ef22a06..9759b6f 100644 --- a/RedBookPlayer.Models/Discs/CompactDisc.cs +++ b/RedBookPlayer.Models/Discs/CompactDisc.cs @@ -449,17 +449,22 @@ namespace RedBookPlayer.Models.Discs Track track = _image.Tracks.FirstOrDefault(t => t.TrackSequence == trackNumber); // If the track isn't valid, we can't do anything - if(track == null || track.TrackType != TrackType.Audio) + if(track == null || !(DataPlayback != DataPlayback.Skip || track.TrackType == TrackType.Audio)) return; - // Read in the track data to a buffer + // Get the number of sectors to read uint length = (uint)(track.TrackEndSector - track.TrackStartSector); - byte[] buffer = _image.ReadSectors(track.TrackStartSector, length); + + // Read in the track data to a buffer + byte[] buffer = ReadSectors(track.TrackStartSector, length); // Build the WAV output string filename = Path.Combine(outputDirectory, $"Track {trackNumber.ToString().PadLeft(2, '0')}.wav"); using(WaveWriter waveWriter = new WaveWriter(filename, new CSCore.WaveFormat())) { + // TODO: This should also apply de-emphasis as on playback + // Should this be configurable? Match the de-emphasis status? + // Write out to the file waveWriter.Write(buffer, 0, buffer.Length); } @@ -502,14 +507,30 @@ namespace RedBookPlayer.Models.Discs } /// - public override byte[] ReadSectors(uint sectorsToRead) + public override byte[] ReadSectors(uint sectorsToRead) => ReadSectors(CurrentSector, sectorsToRead); + + /// + /// Read sector data from the base image starting from the specified sector + /// + /// Sector to start at for reading + /// Current number of sectors to read + /// Byte array representing the read sectors, if possible + private byte[] ReadSectors(ulong startSector, uint sectorsToRead) { if(TrackType == TrackType.Audio || DataPlayback == DataPlayback.Play) - return base.ReadSectors(sectorsToRead); + { + return _image.ReadSectors(startSector, sectorsToRead); + } else if(DataPlayback == DataPlayback.Blank) - return new byte[sectorsToRead * BytesPerSector]; + { + byte[] sectors = _image.ReadSectors(startSector, sectorsToRead); + Array.Clear(sectors, 0, sectors.Length); + return sectors; + } else + { return new byte[0]; + } } /// diff --git a/RedBookPlayer.Models/Discs/OpticalDiscBase.cs b/RedBookPlayer.Models/Discs/OpticalDiscBase.cs index 9b041d3..0a31b9b 100644 --- a/RedBookPlayer.Models/Discs/OpticalDiscBase.cs +++ b/RedBookPlayer.Models/Discs/OpticalDiscBase.cs @@ -131,13 +131,13 @@ namespace RedBookPlayer.Models.Discs /// Extract a track to WAV /// /// Track number to extract - /// Output path to write data toOutput path to write data to public abstract void ExtractTrackToWav(uint trackNumber, string outputDirectory); /// /// Extract all tracks to WAV /// - /// Output path to write data toOutput path to write data to public abstract void ExtractAllTracksToWav(string outputDirectory); /// diff --git a/RedBookPlayer.Models/Hardware/Player.cs b/RedBookPlayer.Models/Hardware/Player.cs index c22c23e..8651e95 100644 --- a/RedBookPlayer.Models/Hardware/Player.cs +++ b/RedBookPlayer.Models/Hardware/Player.cs @@ -535,12 +535,12 @@ namespace RedBookPlayer.Models.Hardware /// Extract a single track from the image to WAV /// /// - /// Output path to write data toOutput path to write data to public void ExtractSingleTrackToWav(uint trackNumber, string outputDirectory) => _opticalDisc?.ExtractTrackToWav(trackNumber, outputDirectory); /// /// Extract all tracks from the image to WAV - /// Output path to write data toOutput path to write data to public void ExtractAllTracksToWav(string outputDirectory) => _opticalDisc?.ExtractAllTracksToWav(outputDirectory); ///