diff --git a/src/main.rs b/src/main.rs index 5c1ac63..b4183d5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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::>(); + 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, )); }; diff --git a/src/xact3/xwb.rs b/src/xact3/xwb.rs index fadc1c2..23e47b0 100644 --- a/src/xact3/xwb.rs +++ b/src/xact3/xwb.rs @@ -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<'_> {