Update wav rust library
This commit is contained in:
parent
3ce5dcff12
commit
db4cf3eefa
|
@ -10,8 +10,8 @@ panic = "abort"
|
||||||
cdtypes = {path = "../cdtypes"}
|
cdtypes = {path = "../cdtypes"}
|
||||||
clap = {version = "4.4.11", features = ["derive"]}
|
clap = {version = "4.4.11", features = ["derive"]}
|
||||||
colored = "2.1.0"
|
colored = "2.1.0"
|
||||||
|
hound = "3.5.1"
|
||||||
no-comment = "0.0.3"
|
no-comment = "0.0.3"
|
||||||
paste = "1.0.14"
|
paste = "1.0.14"
|
||||||
roxmltree = "0.19.0"
|
roxmltree = "0.19.0"
|
||||||
tool_helper = {path = "../tool_helper"}
|
tool_helper = {path = "../tool_helper"}
|
||||||
wav = "1.0.0"
|
|
||||||
|
|
|
@ -206,39 +206,46 @@ fn parse_configuration(config: config_reader::Configuration) -> Result<(CDDesc,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_cd_da(cd_da_tracks: &mut Vec<Vec<AudioSample>>, cd_da_files: Vec<PathBuf>) -> Result<(), Error> {
|
fn parse_cd_da(cd_da_tracks: &mut Vec<Vec<AudioSample>>, cd_da_files: Vec<PathBuf>) -> Result<(), Error> {
|
||||||
fn convert_into_16(data: wav::bit_depth::BitDepth, file_path: &PathBuf) -> Result<Vec<AudioSample>, Error> {
|
fn convert_into_16<R:std::io::Read, S:hound::Sample>(samples: hound::WavSamples<R,S>, file_path: &PathBuf) -> Result<Vec<AudioSample>, Error> {
|
||||||
match data.try_into_sixteen() {
|
let mut sample_buffer = 0;
|
||||||
Ok(data) => {
|
let mut sample_id = 0;
|
||||||
let mut samples = Vec::new();
|
let mut cd_samples = Vec::new();
|
||||||
|
|
||||||
for (left, right) in data.iter().step_by(2).zip(data.iter().skip(1).step_by(2)) {
|
for sample in samples {
|
||||||
samples.push(AudioSample::new(*left, *right))
|
match sample {
|
||||||
|
Ok(sample) => {
|
||||||
|
if sample_id == 0 {
|
||||||
|
sample_buffer = sample.as_i16();
|
||||||
|
sample_id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
cd_samples.push(AudioSample::new(sample_buffer, sample.as_i16()));
|
||||||
|
sample_id = 0;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(err) => {
|
||||||
|
return Err(Error::from_text(format!("{}: {}", file_path.to_string_lossy(), err)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Ok(samples)
|
|
||||||
},
|
|
||||||
Err(_) => Err(Error::from_text(format!("{}: Couldn't convert samples to 16bit", file_path.display()))),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(cd_samples)
|
||||||
}
|
}
|
||||||
|
|
||||||
for cd_da_file in cd_da_files {
|
for cd_da_file in cd_da_files {
|
||||||
let mut audio_io = {
|
let mut audio_io = hound::WavReader::open(&cd_da_file)?;
|
||||||
match std::fs::File::open(&cd_da_file) {
|
let header = audio_io.spec();
|
||||||
Ok(io) => Ok(io),
|
|
||||||
Err(error) => Err(Error::from_text(format!("Opening CD Audio file \"{}\" failed with: {}", cd_da_file.display(), error)))
|
|
||||||
}
|
|
||||||
}?;
|
|
||||||
let (header, raw) = wav::read(&mut audio_io)?;
|
|
||||||
|
|
||||||
if header.audio_format != wav::header::WAV_FORMAT_PCM {
|
if header.sample_format != hound::SampleFormat::Int {
|
||||||
return Err(Error::from_text(format!("{}: Only WAV PCM is supported for Audio tracks", cd_da_file.display())));
|
return Err(Error::from_text(format!("{}: Only integer WAV format (PCM) is supported for Audio tracks", cd_da_file.display())));
|
||||||
}
|
}
|
||||||
|
|
||||||
if header.sampling_rate != 44_100 {
|
if header.sample_rate != 44_100 {
|
||||||
return Err(Error::from_text(format!("{}: Only a sampling rate of 44.1kHz is supported for Audio tracks", cd_da_file.display())));
|
return Err(Error::from_text(format!("{}: Only a sampling rate of 44.1kHz is supported for Audio tracks", cd_da_file.display())));
|
||||||
}
|
}
|
||||||
|
|
||||||
cd_da_tracks.push(convert_into_16(raw, &cd_da_file)?);
|
cd_da_tracks.push(convert_into_16(audio_io.samples::<i16>(), &cd_da_file)?);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ byteorder = "1.5.0"
|
||||||
cdtypes = {path = "../cdtypes"}
|
cdtypes = {path = "../cdtypes"}
|
||||||
colored = "2.0.4"
|
colored = "2.0.4"
|
||||||
envmnt = "0.10.4"
|
envmnt = "0.10.4"
|
||||||
|
hound = "3.5.1"
|
||||||
lz4 = "1.24.0"
|
lz4 = "1.24.0"
|
||||||
paste = "1.0.14"
|
paste = "1.0.14"
|
||||||
wslpath = {path = "../wslpath"}
|
wslpath = {path = "../wslpath"}
|
|
@ -123,6 +123,12 @@ impl std::convert::From<std::sync::mpsc::RecvError> for Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::convert::From<hound::Error> for Error {
|
||||||
|
fn from(error: hound::Error) -> Self {
|
||||||
|
Error::from_error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn exit_with_error(error: Error) {
|
pub fn exit_with_error(error: Error) {
|
||||||
error.print_to_std_err();
|
error.print_to_std_err();
|
||||||
std::process::exit(error.exit_code);
|
std::process::exit(error.exit_code);
|
||||||
|
|
Loading…
Reference in New Issue