Implement --no-strip-subchannel

This commit is contained in:
Matteo Cypriani 2018-05-05 13:38:46 +02:00
parent 924dd3c8c7
commit 9f29662cbf
2 changed files with 18 additions and 9 deletions

View File

@ -53,7 +53,6 @@ fn main() {
process::exit(main_main()); process::exit(main_main());
} }
fn main_main() -> i32 { fn main_main() -> i32 {
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
let prog_name = &args.first().expect("Can't retrieve program's name"); 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"); "extract cue sheet from the NRG metadata");
opts.optflag("r", "extract-raw", opts.optflag("r", "extract-raw",
"extract the raw audio tracks"); "extract the raw audio tracks");
opts.optflag("S", "no-strip-subchannel",
"don't strip the 96-bit subchannel if present");
opts.optflag("h", "help", opts.optflag("h", "help",
"print this help message"); "print this help message");
opts.optflag("V", "version", opts.optflag("V", "version",
@ -90,6 +91,8 @@ fn main_main() -> i32 {
return 0; return 0;
} }
let strip_subchannel = !options.opt_present("no-strip-subchannel");
// Get input NRG image name // Get input NRG image name
if options.free.len() != 1 { if options.free.len() != 1 {
// We need exactly one input file! // We need exactly one input file!
@ -143,8 +146,9 @@ fn main_main() -> i32 {
// Extract raw audio data // Extract raw audio data
if action_raw { if action_raw {
println!("\nExtracting raw audio data..."); println!("\nExtracting raw audio data...");
if let Err(err) = raw_audio::extract_nrg_raw_audio(&mut fd, &img_path, if let Err(err) =
&metadata) { raw_audio::extract_nrg_raw_audio(&mut fd, &img_path,
&metadata, strip_subchannel) {
println!("Error extracting raw audio data: {}", err); println!("Error extracting raw audio data: {}", err);
} }
println!("OK!"); println!("OK!");

View File

@ -42,7 +42,8 @@ const RAW96_SEC_SIZE: u16 = 2448;
/// The output file's name is derived from `img_path`. /// The output file's name is derived from `img_path`.
pub fn extract_nrg_raw_audio(in_fd: &mut File, pub fn extract_nrg_raw_audio(in_fd: &mut File,
img_path: &str, img_path: &str,
metadata: &NrgMetadata) metadata: &NrgMetadata,
strip_subchannel: bool)
-> Result<(), NrgError> { -> Result<(), NrgError> {
// Seek to the first audio byte // Seek to the first audio byte
let first_audio_byte = metadata.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 // Copy the audio data
let count = metadata.last_audio_byte() - first_audio_byte; let count = metadata.last_audio_byte() - first_audio_byte;
let bytes_read = match metadata.sector_size() { if metadata.sector_size() == 0 {
RAW96_SEC_SIZE => try!(copy_raw96_audio(in_fd, &mut out_fd, count)), return Err(NrgError::AudioReadError);
0 => return Err(NrgError::AudioReadError), }
_ => try!(copy_raw_audio(in_fd, &mut out_fd, count)), 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); assert_eq!(count, bytes_read);
Ok(()) Ok(())