Support conversion to XA audio
This commit is contained in:
parent
49417295fc
commit
983c416ee3
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "jaby_engine_fconv"
|
name = "jaby_engine_fconv"
|
||||||
version = "0.1.5"
|
version = "0.1.6"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use clap::{Args, ValueEnum};
|
use clap::{Args, ValueEnum};
|
||||||
use std::path::PathBuf;
|
use std::{env, path::PathBuf, process::Command, str};
|
||||||
use tool_helper::Error;
|
use tool_helper::Error;
|
||||||
|
|
||||||
#[derive(Args)]
|
#[derive(Args)]
|
||||||
|
@ -16,12 +16,73 @@ pub enum Quality {
|
||||||
High
|
High
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Quality {
|
||||||
|
fn get_frequency(&self) -> u64 {
|
||||||
|
match self {
|
||||||
|
Self::Low => 18900,
|
||||||
|
Self::High => 37800,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_bith_depth(&self) -> u64 {
|
||||||
|
match self {
|
||||||
|
Self::Low => 4,
|
||||||
|
Self::High => 8,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, ValueEnum)]
|
#[derive(Copy, Clone, ValueEnum)]
|
||||||
pub enum Sample {
|
pub enum Sample {
|
||||||
Mono,
|
Mono,
|
||||||
Stereo
|
Stereo
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert(_args: Arguments, _input: PathBuf, _output: PathBuf) -> Result<(), Error> {
|
impl Sample {
|
||||||
Err(Error::not_implemented("XA Audio convert"))
|
fn get_channel(&self) -> u64 {
|
||||||
|
match self {
|
||||||
|
Self::Mono => 1,
|
||||||
|
Self::Stereo => 2,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn convert(args: Arguments, input: PathBuf, output: PathBuf) -> Result<(), Error> {
|
||||||
|
let quality = args.quality;
|
||||||
|
let sample = args.sample;
|
||||||
|
let tool_path = {
|
||||||
|
let mut my_path = env::current_exe()?;
|
||||||
|
|
||||||
|
my_path.pop();
|
||||||
|
my_path.push("extern");
|
||||||
|
my_path.push("psxavenc");
|
||||||
|
|
||||||
|
my_path
|
||||||
|
};
|
||||||
|
|
||||||
|
if !tool_path.exists() {
|
||||||
|
return Err(Error::from_str("Could not locate psxavenc. Make sure it is installed under \"<Jaby Engine>/bin/extern\""));
|
||||||
|
}
|
||||||
|
|
||||||
|
let result = Command::new(tool_path).args([
|
||||||
|
"-t", "xacd",
|
||||||
|
"-f", quality.get_frequency().to_string().as_ref(),
|
||||||
|
"-b", quality.get_bith_depth().to_string().as_ref(),
|
||||||
|
"-c", sample.get_channel().to_string().as_ref(),
|
||||||
|
"-F", "0",
|
||||||
|
"-C", "0",
|
||||||
|
input.to_string_lossy().as_ref(), output.to_string_lossy().as_ref()
|
||||||
|
]) .output()?;
|
||||||
|
|
||||||
|
let stderr = tool_helper::vec_helper::to_string(result.stderr)?;
|
||||||
|
let stdout = tool_helper::vec_helper::to_string(result.stdout)?;
|
||||||
|
|
||||||
|
if !result.status.success() {
|
||||||
|
return Err(Error::from_text(format!("psxavenc returned: {}. {}", result.status, stderr)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if !stdout.is_empty() {
|
||||||
|
println!("{}", stdout);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
|
@ -44,7 +44,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),
|
||||||
_ => Err(Error::not_implemented("External functions can not be called internal"))
|
_ => Err(Error::not_implemented("External functions can not be called for internal conversion"))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ fn run_external_conversion(cmd: CommandLine) -> Result<(), Error> {
|
||||||
|
|
||||||
match cmd.sub_command {
|
match cmd.sub_command {
|
||||||
SubCommands::XA(args) => xa::convert(args, input_file, output_file),
|
SubCommands::XA(args) => xa::convert(args, input_file, output_file),
|
||||||
_ => Err(Error::not_implemented("Internal functions can not be called external"))
|
_ => Err(Error::not_implemented("Internal functions can not be called for external conversion"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "tool_helper"
|
name = "tool_helper"
|
||||||
version = "0.9.5"
|
version = "0.9.6"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
|
|
|
@ -5,6 +5,7 @@ use std::{boxed::Box, io::{BufRead, BufReader, BufWriter, Read, Write}, path::Pa
|
||||||
pub mod bits;
|
pub mod bits;
|
||||||
pub mod compress;
|
pub mod compress;
|
||||||
pub mod raw;
|
pub mod raw;
|
||||||
|
pub mod vec_helper;
|
||||||
|
|
||||||
pub type BufferedInputFile = BufReader<std::fs::File>;
|
pub type BufferedInputFile = BufReader<std::fs::File>;
|
||||||
pub type Output = Box<dyn Write>;
|
pub type Output = Box<dyn Write>;
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
use super::Error;
|
||||||
|
use std::str;
|
||||||
|
|
||||||
|
pub fn to_string(output: Vec<u8>) -> Result<String, Error> {
|
||||||
|
match str::from_utf8(&output) {
|
||||||
|
Ok(str) => Ok(str.to_owned()),
|
||||||
|
Err(_) => Err(Error::from_str("Invalid UTF8 sequence"))
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue