Support auto names for the VAG files
This commit is contained in:
parent
834e6628a2
commit
48f2137c52
|
@ -1,10 +1,16 @@
|
|||
pub mod types;
|
||||
|
||||
use clap::Args;
|
||||
use std::io::Write;
|
||||
use tool_helper::{Error, Input};
|
||||
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 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 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>()) {
|
||||
let (vagadpcm, new_lpc) = VAGADPCM::create(adpcm_sample?, lpc);
|
||||
tool_helper::raw::write_raw(output, &vagadpcm)?;
|
||||
|
@ -38,3 +44,22 @@ fn validate(wav_header: &hound::WavSpec) -> Result<(), Error> {
|
|||
|
||||
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 ===
|
||||
Nothing,
|
||||
SimpleTIM(reduced_tim::Arguments),
|
||||
MyVAG,
|
||||
MyVAG(my_vag::Arguments),
|
||||
|
||||
// === External Commands ===
|
||||
VAG(vag::Arguments),
|
||||
|
@ -36,7 +36,7 @@ impl SubCommands {
|
|||
match self {
|
||||
SubCommands::Nothing => false,
|
||||
SubCommands::SimpleTIM(_) => false,
|
||||
SubCommands::MyVAG => false,
|
||||
SubCommands::MyVAG(_) => false,
|
||||
|
||||
SubCommands::VAG(_) => true,
|
||||
SubCommands::XA(_) => true
|
||||
|
@ -62,7 +62,7 @@ fn run_internal_conversion(cmd: CommandLine) -> Result<(), Error> {
|
|||
match cmd.sub_command {
|
||||
SubCommands::Nothing => nothing::copy(&mut 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"))
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue