Support file names

This commit is contained in:
jaby 2024-11-03 09:29:53 +00:00
parent 0b2b45d86f
commit a03e6f38d6
2 changed files with 15 additions and 6 deletions

View File

@ -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 vagadpcm_samples = VAGHeader::expected_vagadpcm_samples(wav_file.len()) + 1;
let mut lpc = LPC::empty(); 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::<i16>()) { for adpcm_sample in MonoADPCMIterator::create(wav_file.samples::<i16>()) {
let (vagadpcm, new_lpc) = VAGADPCM::create(adpcm_sample?, lpc); let (vagadpcm, new_lpc) = VAGADPCM::create(adpcm_sample?, lpc);
tool_helper::raw::write_raw(output, &vagadpcm)?; tool_helper::raw::write_raw(output, &vagadpcm)?;

View File

@ -24,12 +24,21 @@ impl VAGHeader {
((adpcm_samples as usize + (VAGADPCM::ADPCM_SAMPLES_PER_VAGADPCM - 1))/VAGADPCM::ADPCM_SAMPLES_PER_VAGADPCM) as u32 ((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 { pub fn create(vagadpcm_samples: u32, sampling_frequency: u32, name: &str) -> Result<VAGHeader, Error> {
// TODO: Support naming feature
let data_size = vagadpcm_samples*VAGADPCM::SIZE as u32; 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, _id: VAGHeader::ID,
_version: VAGHeader::VERSION.to_be(), _version: VAGHeader::VERSION.to_be(),
_reserved: VAGHeader::RESERVED, _reserved: VAGHeader::RESERVED,
@ -37,7 +46,7 @@ impl VAGHeader {
_sampling_frequency: sampling_frequency.to_be(), _sampling_frequency: sampling_frequency.to_be(),
_reserved2: VAGHeader::RESERVED2, _reserved2: VAGHeader::RESERVED2,
_name: name _name: name
} })
} }
} }