1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2024-11-15 18:32:48 +00:00
doukutsu-rs/src/sound/wave_bank.rs

44 lines
1 KiB
Rust
Raw Normal View History

2020-09-02 22:58:11 +00:00
use crate::sound::wav;
use std::io;
use std::fmt;
pub struct SoundBank {
2021-08-16 06:48:17 +00:00
pub wave100: Box<[u8; 25600]>,
2020-09-02 22:58:11 +00:00
pub samples: Vec<wav::WavSample>
}
impl fmt::Display for SoundBank {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
writeln!(f, "WAVE100: {:2X?}...", &self.wave100[..8])?;
for sample in self.samples.iter() {
writeln!(f, "{}", sample)?;
}
Ok(())
}
}
impl SoundBank {
pub fn load_from<R: io::Read>(mut f: R) -> io::Result<SoundBank> {
2021-08-16 06:48:17 +00:00
let mut wave100 = Box::new([0u8; 25600]);
2020-09-02 22:58:11 +00:00
2021-08-16 06:48:17 +00:00
f.read_exact(wave100.as_mut())?;
2020-09-02 22:58:11 +00:00
let mut samples = Vec::with_capacity(16);
loop {
match wav::WavSample::read_from(&mut f) {
Ok(sample) => samples.push(sample),
Err(_) => return Ok(SoundBank { wave100, samples })
}
}
}
pub fn get_wave(&self, index: usize) -> &[u8] {
&self.wave100[index*256..(index+1)*256]
}
}