Support file names
This commit is contained in:
parent
0b2b45d86f
commit
a03e6f38d6
|
@ -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::<i16>()) {
|
||||
let (vagadpcm, new_lpc) = VAGADPCM::create(adpcm_sample?, lpc);
|
||||
tool_helper::raw::write_raw(output, &vagadpcm)?;
|
||||
|
|
|
@ -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<VAGHeader, Error> {
|
||||
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
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue