Better handling of anonymous sounds in wave banks

This commit is contained in:
Simon Bruder 2020-06-23 20:16:51 +02:00
parent 3dc24d58b5
commit 0c24fd0847
No known key found for this signature in database
GPG key ID: 6F03E0000CC5B62F
2 changed files with 10 additions and 6 deletions

View file

@ -9,7 +9,7 @@ use log::{debug, error, info, warn};
use brd::converter;
use brd::ddr::ssq::SSQ;
use brd::osu;
use brd::xact3::xwb::WaveBank;
use brd::xact3::xwb::{Sound as XWBSound, WaveBank};
#[derive(Clap)]
#[clap()]
@ -161,15 +161,17 @@ fn main() -> Result<()> {
let audio_data = if wave_bank.sounds.contains_key(sound_name) {
wave_bank.sounds.get(sound_name).unwrap().to_wav()?
} else if wave_bank.sounds.contains_key("1") {
} else if wave_bank.sounds.len() == 2 {
warn!(
"Sound {} not found in wave bank, using second entry",
"Sound {} not found in wave bank, but it has two entries; assuming these are preview and full song",
sound_name
);
wave_bank.sounds.get("1").unwrap().to_wav()?
let mut sounds = wave_bank.sounds.values().collect::<Vec<&XWBSound>>();
sounds.sort_unstable_by(|a, b| b.size.cmp(&a.size));
sounds[0].to_wav()?
} else {
return error(format!(
"Could not find sound with chart name {} or second numbered entry in wave bank",
"Could not find matching sound in wave bank (searched for {})",
sound_name,
));
};

View file

@ -199,7 +199,7 @@ impl WaveBank<'_> {
let entry_names = if segments[3].len() == info.entry_count as usize * 64 {
exec_nom_parser(count(take_str64, info.entry_count as usize), segments[3])?
} else {
warn!("File does not have name entries");
warn!("Wave bank does not have name entries");
(0..info.entry_count).map(|x| x.to_string()).collect()
};
@ -216,6 +216,7 @@ impl WaveBank<'_> {
Sound {
format: entry.format.clone(),
data: &segments[4][start..end],
size: end - start,
},
);
}
@ -230,6 +231,7 @@ impl WaveBank<'_> {
pub struct Sound<'a> {
format: Format,
data: &'a [u8],
pub size: usize,
}
impl Sound<'_> {