diff options
Diffstat (limited to 'exporter')
-rw-r--r-- | exporter/Cargo.toml | 1 | ||||
-rw-r--r-- | exporter/src/bin/audioclips.rs | 64 |
2 files changed, 65 insertions, 0 deletions
diff --git a/exporter/Cargo.toml b/exporter/Cargo.toml index 02eca5c..12fe97f 100644 --- a/exporter/Cargo.toml +++ b/exporter/Cargo.toml @@ -14,3 +14,4 @@ glam = { version = "0.30.0", features = ["serde"] } gltf-json = "1.4.1" gltf = "1.4.1" bytemuck = "1.22.0" +hound = "3.5.1" diff --git a/exporter/src/bin/audioclips.rs b/exporter/src/bin/audioclips.rs new file mode 100644 index 0000000..cc16a22 --- /dev/null +++ b/exporter/src/bin/audioclips.rs @@ -0,0 +1,64 @@ +#![feature(array_chunks)] +use std::{ + env::args, + fs::{File, create_dir_all}, + io::{BufReader, BufWriter, Write}, +}; +use unity_tools::{ + assetbundle::AssetBundle, + classes::audio_clip::{AudioClip, AudioCompressionFormat}, +}; + +fn main() -> anyhow::Result<()> { + env_logger::init_from_env("LOG"); + let file = BufReader::new(File::open(args().nth(1).unwrap()).unwrap()); + let mut bundle = AssetBundle::open(file, "samples")?; + + let mut i = 0; + create_dir_all("/tmp/a").unwrap(); + + for ob in bundle.all_toplevel_of_class("AudioClip") { + let clip = ob.load(&mut bundle)?.parse::<AudioClip>()?; + + if clip.compression_format == AudioCompressionFormat::Vorbis { + let mut ogg = BufWriter::new(File::create(format!( + "/tmp/a/{}_{i}.ogg", + clip.name.replace("/", "-").replace(".", "-") + ))?); + ogg.write_all(&clip.read_ogg(&bundle.fs)?)?; + } + + // let wav = BufWriter::new(File::create(format!( + // "/tmp/a/{}_{i}.wav", + // clip.name.replace("/", "-").replace(".", "-") + // ))?); + // let mut writer = hound::WavWriter::new( + // wav, + // WavSpec { + // bits_per_sample: 32, + // channels: clip.channels as u16, + // sample_format: hound::SampleFormat::Float, + // sample_rate: clip.frequency as u32, + // }, + // )?; + + // if clip.channels == 2 { + // for (l, r) in samples[0] + // .clone() + // .into_iter() + // .zip(samples[1].clone().into_iter()) + // { + // writer.write_sample(l)?; + // writer.write_sample(r)?; + // } + // } else { + // todo!() + // } + + // writer.finalize()?; + + i += 1; + } + + Ok(()) +} |