Integrate all the progress into master #6
|
@ -8,6 +8,7 @@ panic = "abort"
|
|||
|
||||
[dependencies]
|
||||
clap = {version = "4.4.11", features = ["derive"]}
|
||||
hound = "3.5.1"
|
||||
image = "0.24.7"
|
||||
paste = "1.0.14"
|
||||
png = "0.17.10"
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
use clap::{Args, ValueEnum};
|
||||
use hound::Sample;
|
||||
use image::{DynamicImage, io::Reader as ImageReader};
|
||||
use std::io::{Cursor, Write};
|
||||
use tool_helper::{print_warning, Error, Input};
|
||||
|
||||
#[derive(Args)]
|
||||
pub struct Arguments {
|
||||
}
|
||||
|
||||
pub fn convert(input: Input, output: &mut dyn Write) -> Result<(), Error> {
|
||||
let mut audio_io = hound::WavReader::new(input)?;
|
||||
let header = audio_io.spec();
|
||||
|
||||
if header.sample_format != hound::SampleFormat::Int ||header.bits_per_sample != 16 {
|
||||
return Err(Error::from_str("Only 16bit integer samples are supported"));
|
||||
}
|
||||
|
||||
if header.channels > 1 {
|
||||
print_warning("Found more than one audio channel. First channel will be encoded.".to_owned());
|
||||
}
|
||||
|
||||
let active_channel = 1;
|
||||
let mut sample_count = 0;
|
||||
for sample in audio_io.samples::<i16>() {
|
||||
match sample {
|
||||
Ok(sample) => {
|
||||
sample_count += 1;
|
||||
|
||||
if sample_count%active_channel == 0 {
|
||||
output.write(&sample.to_le_bytes())?;
|
||||
}
|
||||
}
|
||||
|
||||
Err(error) => {
|
||||
return Err(Error::from_text(format!("Failed iterating over samples: {}", error)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
|
@ -1 +1,2 @@
|
|||
pub mod adpcm;
|
||||
pub mod xa;
|
|
@ -21,8 +21,12 @@ struct CommandLine {
|
|||
|
||||
#[derive(Subcommand)]
|
||||
enum SubCommands {
|
||||
// === Internal Commands ===
|
||||
Nothing,
|
||||
SimpleTIM(reduced_tim::Arguments),
|
||||
ADPCM,
|
||||
|
||||
// === External Commands ===
|
||||
XA(xa::Arguments)
|
||||
}
|
||||
|
||||
|
@ -44,6 +48,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::ADPCM => adpcm::convert(input, dst_buffer),
|
||||
_ => Err(Error::not_implemented("External functions can not be called for internal conversion"))
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue