Simplify getting the audio data
This commit is contained in:
parent
f8ed0e2f1a
commit
c32adf47e6
51
src/main.rs
51
src/main.rs
|
@ -219,37 +219,34 @@ fn ddr2osu(
|
||||||
.with_context(|| format!("failed to read XWB file {}", &xwb_file.clone().display()))?;
|
.with_context(|| format!("failed to read XWB file {}", &xwb_file.clone().display()))?;
|
||||||
let wave_bank = WaveBank::parse(&xwb_data).context("failed to parse XWB file")?;
|
let wave_bank = WaveBank::parse(&xwb_data).context("failed to parse XWB file")?;
|
||||||
|
|
||||||
let audio_data = if wave_bank.sounds.contains_key(&basename) {
|
let audio_data = wave_bank.sounds.get(&basename)
|
||||||
wave_bank
|
.map(|sound| sound.to_wav().with_context(|| {
|
||||||
.sounds
|
|
||||||
.get(&basename)
|
|
||||||
.unwrap()
|
|
||||||
.to_wav()
|
|
||||||
.with_context(|| {
|
|
||||||
format!(
|
|
||||||
"failed to convert wave bank sound entry “{}” to WAV",
|
|
||||||
basename
|
|
||||||
)
|
|
||||||
})?
|
|
||||||
} else if wave_bank.sounds.len() == 2 {
|
|
||||||
warn!(
|
|
||||||
"Sound {} not found in wave bank, but it has two entries; assuming these are preview and full song",
|
|
||||||
basename
|
|
||||||
);
|
|
||||||
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().with_context(|| {
|
|
||||||
format!(
|
format!(
|
||||||
"failed to convert wave bank sound entry “{}” to WAV",
|
"failed to convert wave bank sound entry “{}” to WAV",
|
||||||
basename
|
basename
|
||||||
)
|
)
|
||||||
})?
|
}))
|
||||||
} else {
|
.unwrap_or_else(|| {
|
||||||
return Err(anyhow!(
|
if wave_bank.sounds.len() == 2 {
|
||||||
"Could not find matching sound in wave bank (searched for {})",
|
warn!(
|
||||||
basename,
|
"Sound {} not found in wave bank, but it has two entries; assuming these are preview and full song",
|
||||||
));
|
basename
|
||||||
};
|
);
|
||||||
|
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().with_context(|| {
|
||||||
|
format!(
|
||||||
|
"failed to convert wave bank sound entry “{}” to WAV",
|
||||||
|
basename
|
||||||
|
)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Err(anyhow!(
|
||||||
|
"Could not find matching sound in wave bank (searched for {})",
|
||||||
|
basename,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
})?;
|
||||||
|
|
||||||
let osz = osu::osz::Archive {
|
let osz = osu::osz::Archive {
|
||||||
beatmaps,
|
beatmaps,
|
||||||
|
|
Reference in a new issue