Skip to content

Commit

Permalink
Merge pull request #3 from PikminGuts92/dev
Browse files Browse the repository at this point in the history
Dev merge
  • Loading branch information
PikminGuts92 authored Aug 15, 2023
2 parents 068c479 + 8e076c3 commit f53417e
Show file tree
Hide file tree
Showing 85 changed files with 4,573 additions and 407 deletions.
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ authors = ["PikminGuts92"]
edition = "2021"

[workspace.dependencies]
clap = { version = "4.2.1", features = ["derive"] }
clap = { version = "4.3.12", features = ["derive"] }
grim = { path = "core/grim" }
itertools = "0.10.5"
itertools = "0.11.0"
lazy_static = "1.4.0"
log = "0.4.17"
serde = { version = "1.0.160", features = ["derive"] }
serde_json = "1.0.95"
log = "0.4.19"
serde = { version = "1.0.171", features = ["derive"] }
serde_json = "1.0.103"
simplelog = "0.12.1"
thiserror = "1.0.40"
thiserror = "1.0.43"

[profile.dev.package."*"]
opt-level = 3
Expand Down
40 changes: 34 additions & 6 deletions apps/cli/audio_tool/src/apps/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ use std::path::{Path, PathBuf};

enum FileType {
Vgs,
Str,
SynthSample(u32, IOEndian)
}

#[derive(Parser, Debug)]
pub struct DecoderApp {
#[arg(help = "Path to input audio (.vgs, SynthSample (Xbox 360))", required = true)]
#[arg(help = "Path to input audio (.vgs, .str, SynthSample (Xbox 360))", required = true)]
pub input_path: String,
#[arg(help = "Path to output audio (.wav, .xma (Only for Xbox 360 samples))", required = true)]
pub output_path: String,
Expand All @@ -29,6 +30,7 @@ impl SubApp for DecoderApp {
let output_path = Path::new(&self.output_path);

let input_type = match input_path.extension().and_then(|e| e.to_str()) {
Some(ext) if "str".eq_ignore_ascii_case(ext) => FileType::Str,
Some(ext) if "vgs".eq_ignore_ascii_case(ext) => FileType::Vgs,
Some(ext) => {
// Guess file type from binary structure
Expand All @@ -51,15 +53,17 @@ impl SubApp for DecoderApp {
};

let input_type_name = match input_type {
FileType::Vgs => "VGS",
FileType::Str => "STR",
FileType::SynthSample(_, _) => "SynthSample",
FileType::Vgs => "VGS",
};

println!("Detected input file type of \"{input_type_name}\"");

let _output_ext = match (&input_type, output_path.extension().and_then(|e| e.to_str())) {
(FileType::Vgs, Some(ext)) if "wav".eq_ignore_ascii_case(ext) => ext,
(FileType::Str, Some(ext)) if "wav".eq_ignore_ascii_case(ext) => ext,
(FileType::SynthSample(_, _), Some(ext)) if "xma".eq_ignore_ascii_case(ext) => ext,
(FileType::Vgs, Some(ext)) if "wav".eq_ignore_ascii_case(ext) => ext,
(_, Some(ext)) => {
println!("Output audio with extension \".{ext}\" is not supported");
return Ok(());
Expand All @@ -71,13 +75,13 @@ impl SubApp for DecoderApp {
};

match input_type {
FileType::Vgs => {
FileType::Str => {
// Decode (returns interleaved audio samples)
println!("Decoding...");
let (sample_data, channels, sample_rate) = decode_vgs_file(input_path)?;
let sample_data = decode_str_file(input_path)?;

// Encode to wav
let encoder = WavEncoder::new(&sample_data, channels, sample_rate);
let encoder = WavEncoder::new(&sample_data, 2, 48_000);
encoder.encode_to_file(output_path).map_err(|e| Box::new(e) as Box<dyn Error>)?;
},
FileType::SynthSample(version, endian) => {
Expand All @@ -92,6 +96,15 @@ impl SubApp for DecoderApp {
let mut file = grim::io::create_new_file(output_path)?;
file.write_all(&xma)?;
},
FileType::Vgs => {
// Decode (returns interleaved audio samples)
println!("Decoding...");
let (sample_data, channels, sample_rate) = decode_vgs_file(input_path)?;

// Encode to wav
let encoder = WavEncoder::new(&sample_data, channels, sample_rate);
encoder.encode_to_file(output_path).map_err(|e| Box::new(e) as Box<dyn Error>)?;
},
};

println!("Wrote output to \"{}\"", output_path.to_str().unwrap_or_default());
Expand Down Expand Up @@ -120,6 +133,21 @@ fn decode_vgs_file(file_path: &Path) -> Result<(Vec<i16>, u16, u32), Box<dyn Err
Ok((interleaved_data, channel_count as u16, sample_rate))
}

fn decode_str_file(file_path: &Path) -> Result<Vec<i16>, std::io::Error> {
let mut input_file = std::fs::File::open(file_path)?;

let mut input_data = Vec::new();
input_file.read_to_end(&mut input_data)?;

deinterleave_str(&mut input_data);
let samples = convert_to_samples(input_data);

//let mut decoder = ADPCMDecoder::new();
//let samples = decoder.decode(&input_data);

Ok(samples)
}

fn generate_xma_from_synth_sample(file_path: &Path, info: &SystemInfo) -> Result<Vec<u8>, Box<dyn Error>> {
let mut stream = FileStream::from_path_as_read_open(file_path)?;

Expand Down
9 changes: 9 additions & 0 deletions apps/cli/mesh_tool/src/apps/milo2gltf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,16 @@ impl SubApp for Milo2GltfApp {
..Default::default()
});
exporter.add_milo_from_path(milo_path)?;

// Add extra milos
for extra_path in self.extra_milo_paths.iter() {
let extra_path = PathBuf::from(extra_path);
let extra_path_file_name = extra_path
.file_name()
.and_then(|f| f.to_str())
.unwrap();

println!("Adding {}", extra_path_file_name);
exporter.add_milo_from_path(extra_path)?;
}

Expand Down
8 changes: 4 additions & 4 deletions apps/cli/p9_scene_tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ authors.workspace = true
edition.workspace = true

[dependencies]
build-time = "0.1.2"
build-time = "0.1.3"
clap = { workspace = true }
const_format = "0.2.30"
const_format = "0.2.31"
grim = { workspace = true, features = [ "midi" ] }
log = { workspace = true }
serde = { workspace = true }
Expand All @@ -16,5 +16,5 @@ simplelog = { workspace = true }
thiserror = { workspace = true }

[dev-dependencies]
criterion = "0.4.0"
rstest = "0.17.0"
criterion = "0.5.1"
rstest = "0.18.1"
2 changes: 1 addition & 1 deletion apps/cli/p9_scene_tool/src/apps/milo2midi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl SubApp for Milo2MidiApp {
}

// Open milo
let mut stream: Box<dyn Stream> = Box::new(FileStream::from_path_as_read_open(&milo_path)?);
let mut stream = FileStream::from_path_as_read_open(&milo_path)?;
let milo = MiloArchive::from_stream(&mut stream)?;

// Unpack dir and entries
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/p9_scene_tool/src/apps/project2milo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ fn create_object_dir_entry(name: &str, obj_type: &str, subdir_paths: &[&str], in

// Viewports
const VIEWPORT_COUNT: i32 = 7;
let mat = Matrix::indentity();
let mat = Matrix::identity();
writer.write_int32(VIEWPORT_COUNT)?;

for _ in 0..VIEWPORT_COUNT {
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/scene_tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ edition.workspace = true

[dependencies]
clap = { workspace = true }
grim = { workspace = true, features = [ "model" ] }
grim = { workspace = true, features = [ "midi" ] }
thiserror = { workspace = true }
2 changes: 1 addition & 1 deletion apps/cli/scene_tool/src/apps/milo2dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl SubApp for Milo2DirApp {
println!("Opening {}", file_name);
}

let mut stream: Box<dyn Stream> = Box::new(FileStream::from_path_as_read_open(milo_path)?);
let mut stream = FileStream::from_path_as_read_open(milo_path)?;
let milo = MiloArchive::from_stream(&mut stream)?;

// TODO: First get system info from args then guess if not supplied
Expand Down
Loading

0 comments on commit f53417e

Please sign in to comment.