Browse Source

Implement --no-strip-subchannel

master
Matteo Cypriani 3 years ago
parent
commit
9f29662cbf
2 changed files with 18 additions and 9 deletions
  1. +7
    -3
      src/main.rs
  2. +11
    -6
      src/raw_audio.rs

+ 7
- 3
src/main.rs View File

@ -53,7 +53,6 @@ fn main() {
process::exit(main_main());
}
fn main_main() -> i32 {
let args: Vec<String> = 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!");


+ 11
- 6
src/raw_audio.rs View File

@ -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(())


Loading…
Cancel
Save