From 9f29662cbf8b15f92e6b56043e656158171178c2 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Sat, 5 May 2018 13:38:46 +0200 Subject: [PATCH] Implement --no-strip-subchannel --- src/main.rs | 10 +++++++--- src/raw_audio.rs | 17 +++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 245e615..2f84e48 100644 --- a/src/main.rs +++ b/src/main.rs @@ -53,7 +53,6 @@ fn main() { process::exit(main_main()); } - fn main_main() -> i32 { let args: Vec = env::args().collect(); let prog_name = &args.first().expect("Can't retrieve program's name"); @@ -67,6 +66,8 @@ fn main_main() -> i32 { "extract cue sheet from the NRG metadata"); opts.optflag("r", "extract-raw", "extract the raw audio tracks"); + opts.optflag("S", "no-strip-subchannel", + "don't strip the 96-bit subchannel if present"); opts.optflag("h", "help", "print this help message"); opts.optflag("V", "version", @@ -90,6 +91,8 @@ fn main_main() -> i32 { return 0; } + let strip_subchannel = !options.opt_present("no-strip-subchannel"); + // Get input NRG image name if options.free.len() != 1 { // We need exactly one input file! @@ -143,8 +146,9 @@ fn main_main() -> i32 { // Extract raw audio data if action_raw { println!("\nExtracting raw audio data..."); - if let Err(err) = raw_audio::extract_nrg_raw_audio(&mut fd, &img_path, - &metadata) { + if let Err(err) = + raw_audio::extract_nrg_raw_audio(&mut fd, &img_path, + &metadata, strip_subchannel) { println!("Error extracting raw audio data: {}", err); } println!("OK!"); diff --git a/src/raw_audio.rs b/src/raw_audio.rs index b669f2c..d93af80 100644 --- a/src/raw_audio.rs +++ b/src/raw_audio.rs @@ -42,7 +42,8 @@ const RAW96_SEC_SIZE: u16 = 2448; /// The output file's name is derived from `img_path`. pub fn extract_nrg_raw_audio(in_fd: &mut File, img_path: &str, - metadata: &NrgMetadata) + metadata: &NrgMetadata, + strip_subchannel: bool) -> Result<(), NrgError> { // Seek to the first audio byte let first_audio_byte = metadata.first_audio_byte(); @@ -54,11 +55,15 @@ pub fn extract_nrg_raw_audio(in_fd: &mut File, // Copy the audio data let count = metadata.last_audio_byte() - first_audio_byte; - let bytes_read = match metadata.sector_size() { - RAW96_SEC_SIZE => try!(copy_raw96_audio(in_fd, &mut out_fd, count)), - 0 => return Err(NrgError::AudioReadError), - _ => try!(copy_raw_audio(in_fd, &mut out_fd, count)), - }; + if metadata.sector_size() == 0 { + return Err(NrgError::AudioReadError); + } + let bytes_read = + if strip_subchannel && metadata.sector_size() == RAW96_SEC_SIZE { + try!(copy_raw96_audio(in_fd, &mut out_fd, count)) + } else { + try!(copy_raw_audio(in_fd, &mut out_fd, count)) + }; assert_eq!(count, bytes_read); Ok(())