Skip to content

Commit

Permalink
loop_wave: fix u8 upsampling at library level
Browse files Browse the repository at this point in the history
  • Loading branch information
khanghugo committed Dec 6, 2024
1 parent 84b9ebf commit af63dcf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 4 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gchimp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ rand = "0.8.5"
lazy_static = "1.5.0"
cuet = "0.1.0"
chrono = "0.4.38"
wav_io = "0.1.14"
wav_io = { git = "https://github.com/khanghugo/wav_io.git" }

# enable js support for this random shit so that wasm32 can compile
getrandom = { version = "0.2.15", features = ["js"] }
9 changes: 8 additions & 1 deletion gchimp/src/modules/loop_wave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ fn make_pcm16u_mono_and_22050(bytes: Vec<u8>) -> eyre::Result<Vec<u8>> {
};

const BEST_SAMPLING_RATE: u32 = 22050;
const BEST_BIT_PER_SAMPLE: u16 = 16;

let samples2 = wav_io::resample::linear(f32_samples, 1, header.sample_rate, BEST_SAMPLING_RATE);

let res_wav_header = wav_io::new_header(BEST_SAMPLING_RATE, 16, false, true);
let res_wav_header = wav_io::new_header(BEST_SAMPLING_RATE, BEST_BIT_PER_SAMPLE, false, true);

let Ok(res_bytes) = wav_io::write_to_bytes(&res_wav_header, &samples2) else {
return err!("cannot write .wav");
Expand Down Expand Up @@ -106,4 +107,10 @@ mod test {
let path = PathBuf::from("/home/khang/gchimp/examples/loop_wave/birds_32bit.wav");
loop_wave(path).unwrap();
}

#[test]
fn run_8bit() {
let path = PathBuf::from("/home/khang/gchimp/examples/loop_wave/eightbits.wav");
loop_wave(path).unwrap();
}
}

0 comments on commit af63dcf

Please sign in to comment.