Support auto names for the VAG files
This commit is contained in:
parent
a03e6f38d6
commit
dbaee2379a
|
@ -1,10 +1,16 @@
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|
||||||
|
use clap::Args;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use tool_helper::{Error, Input};
|
use tool_helper::{Error, Input};
|
||||||
use types::{LPC, MonoADPCMIterator, VAGADPCM, VAGHeader};
|
use types::{LPC, MonoADPCMIterator, VAGADPCM, VAGHeader};
|
||||||
|
|
||||||
pub fn convert(input: Input, output: &mut dyn Write) -> Result<(), Error> {
|
#[derive(Args)]
|
||||||
|
pub struct Arguments {
|
||||||
|
name: Option<String>
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn convert(args: Arguments, output_file_path: &Option<std::path::PathBuf>, input: Input, output: &mut dyn Write) -> Result<(), Error> {
|
||||||
let mut wav_file = hound::WavReader::new(input)?;
|
let mut wav_file = hound::WavReader::new(input)?;
|
||||||
let wav_header = wav_file.spec();
|
let wav_header = wav_file.spec();
|
||||||
|
|
||||||
|
@ -13,7 +19,7 @@ pub fn convert(input: Input, output: &mut dyn Write) -> Result<(), Error> {
|
||||||
let vagadpcm_samples = VAGHeader::expected_vagadpcm_samples(wav_file.len()) + 1;
|
let vagadpcm_samples = VAGHeader::expected_vagadpcm_samples(wav_file.len()) + 1;
|
||||||
let mut lpc = LPC::empty();
|
let mut lpc = LPC::empty();
|
||||||
|
|
||||||
tool_helper::raw::write_raw(output, &VAGHeader::create(vagadpcm_samples, wav_header.sample_rate, "Planschi")?)?;
|
tool_helper::raw::write_raw(output, &VAGHeader::create(vagadpcm_samples, wav_header.sample_rate, &get_name_for_file_header(args.name, output_file_path))?)?;
|
||||||
for adpcm_sample in MonoADPCMIterator::create(wav_file.samples::<i16>()) {
|
for adpcm_sample in MonoADPCMIterator::create(wav_file.samples::<i16>()) {
|
||||||
let (vagadpcm, new_lpc) = VAGADPCM::create(adpcm_sample?, lpc);
|
let (vagadpcm, new_lpc) = VAGADPCM::create(adpcm_sample?, lpc);
|
||||||
tool_helper::raw::write_raw(output, &vagadpcm)?;
|
tool_helper::raw::write_raw(output, &vagadpcm)?;
|
||||||
|
@ -37,4 +43,23 @@ fn validate(wav_header: &hound::WavSpec) -> Result<(), Error> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_name_for_file_header(name: Option<String>, output_file_path: &Option<std::path::PathBuf>) -> String {
|
||||||
|
if let Some(name) = name {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(output_file_path) = output_file_path {
|
||||||
|
if let Some(file_name) = output_file_path.file_name() {
|
||||||
|
let mut string = file_name.to_string_lossy().to_string();
|
||||||
|
|
||||||
|
if let Some(idx) = string.rfind('.') {
|
||||||
|
string.replace_range(idx.., "");
|
||||||
|
}
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "<out>".to_owned();
|
||||||
}
|
}
|
|
@ -24,7 +24,7 @@ enum SubCommands {
|
||||||
// === Internal Commands ===
|
// === Internal Commands ===
|
||||||
Nothing,
|
Nothing,
|
||||||
SimpleTIM(reduced_tim::Arguments),
|
SimpleTIM(reduced_tim::Arguments),
|
||||||
MyVAG,
|
MyVAG(my_vag::Arguments),
|
||||||
|
|
||||||
// === External Commands ===
|
// === External Commands ===
|
||||||
VAG(vag::Arguments),
|
VAG(vag::Arguments),
|
||||||
|
@ -36,7 +36,7 @@ impl SubCommands {
|
||||||
match self {
|
match self {
|
||||||
SubCommands::Nothing => false,
|
SubCommands::Nothing => false,
|
||||||
SubCommands::SimpleTIM(_) => false,
|
SubCommands::SimpleTIM(_) => false,
|
||||||
SubCommands::MyVAG => false,
|
SubCommands::MyVAG(_) => false,
|
||||||
|
|
||||||
SubCommands::VAG(_) => true,
|
SubCommands::VAG(_) => true,
|
||||||
SubCommands::XA(_) => true
|
SubCommands::XA(_) => true
|
||||||
|
@ -62,7 +62,7 @@ fn run_internal_conversion(cmd: CommandLine) -> Result<(), Error> {
|
||||||
match cmd.sub_command {
|
match cmd.sub_command {
|
||||||
SubCommands::Nothing => nothing::copy(&mut input, dst_buffer),
|
SubCommands::Nothing => nothing::copy(&mut input, dst_buffer),
|
||||||
SubCommands::SimpleTIM(args) => reduced_tim::convert(args, input, dst_buffer),
|
SubCommands::SimpleTIM(args) => reduced_tim::convert(args, input, dst_buffer),
|
||||||
SubCommands::MyVAG => audio::my_vag::convert(input, dst_buffer),
|
SubCommands::MyVAG(args) => audio::my_vag::convert(args, &cmd.output_file, input, dst_buffer),
|
||||||
_ => Err(Error::from_str("External functions can not be called for internal conversion"))
|
_ => Err(Error::from_str("External functions can not be called for internal conversion"))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue