diff --git a/src/Tools/psxfileconv/src/audio/my_vag/mod.rs b/src/Tools/psxfileconv/src/audio/my_vag/mod.rs index 1a34f5e9..dcbb722d 100644 --- a/src/Tools/psxfileconv/src/audio/my_vag/mod.rs +++ b/src/Tools/psxfileconv/src/audio/my_vag/mod.rs @@ -13,7 +13,7 @@ pub fn convert(input: Input, output: &mut dyn Write) -> Result<(), Error> { let vagadpcm_samples = VAGHeader::expected_vagadpcm_samples(wav_file.len()) + 1; let mut lpc = LPC::empty(); - tool_helper::raw::write_raw(output, &VAGHeader::create(vagadpcm_samples, wav_header.sample_rate, "Planschi"))?; + tool_helper::raw::write_raw(output, &VAGHeader::create(vagadpcm_samples, wav_header.sample_rate, "Planschi")?)?; for adpcm_sample in MonoADPCMIterator::create(wav_file.samples::()) { let (vagadpcm, new_lpc) = VAGADPCM::create(adpcm_sample?, lpc); tool_helper::raw::write_raw(output, &vagadpcm)?; diff --git a/src/Tools/psxfileconv/src/audio/my_vag/types.rs b/src/Tools/psxfileconv/src/audio/my_vag/types.rs index 26199799..ae086962 100644 --- a/src/Tools/psxfileconv/src/audio/my_vag/types.rs +++ b/src/Tools/psxfileconv/src/audio/my_vag/types.rs @@ -24,12 +24,21 @@ impl VAGHeader { ((adpcm_samples as usize + (VAGADPCM::ADPCM_SAMPLES_PER_VAGADPCM - 1))/VAGADPCM::ADPCM_SAMPLES_PER_VAGADPCM) as u32 } - pub fn create(vagadpcm_samples: u32, sampling_frequency: u32, _name: &str) -> VAGHeader { - // TODO: Support naming feature + pub fn create(vagadpcm_samples: u32, sampling_frequency: u32, name: &str) -> Result { let data_size = vagadpcm_samples*VAGADPCM::SIZE as u32; - let name = ['A' as u8; 16]; + let name = { + if !name.is_ascii() { + return Err(Error::from_text(format!("File name {} is not ascii", name))); + } - VAGHeader{ + let name_length = if name.len() > 16 {16} else {name.len()}; + let mut new_name = [0u8; 16]; + + new_name[..name_length].copy_from_slice(&name.as_bytes()[..name_length]); + new_name + }; + + Ok(VAGHeader{ _id: VAGHeader::ID, _version: VAGHeader::VERSION.to_be(), _reserved: VAGHeader::RESERVED, @@ -37,7 +46,7 @@ impl VAGHeader { _sampling_frequency: sampling_frequency.to_be(), _reserved2: VAGHeader::RESERVED2, _name: name - } + }) } }