Restructre writing of VAG file
This commit is contained in:
parent
09a2192e97
commit
0b2b45d86f
|
@ -9,25 +9,17 @@ pub fn convert(input: Input, output: &mut dyn Write) -> Result<(), Error> {
|
||||||
let wav_header = wav_file.spec();
|
let wav_header = wav_file.spec();
|
||||||
|
|
||||||
validate(&wav_header)?;
|
validate(&wav_header)?;
|
||||||
let mut samples = Vec::new();
|
|
||||||
let mut sample_count = 0;
|
|
||||||
|
|
||||||
|
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"))?;
|
||||||
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);
|
||||||
samples.push(vagadpcm);
|
tool_helper::raw::write_raw(output, &vagadpcm)?;
|
||||||
lpc = new_lpc;
|
lpc = new_lpc;
|
||||||
|
|
||||||
sample_count += 1;
|
|
||||||
}
|
|
||||||
samples.push(VAGADPCM::end());
|
|
||||||
sample_count += 1;
|
|
||||||
|
|
||||||
// TODO: Restructure
|
|
||||||
tool_helper::raw::write_raw(output, &VAGHeader::create(sample_count, wav_header.sample_rate, "Planschi"))?;
|
|
||||||
for sample in samples {
|
|
||||||
tool_helper::raw::write_raw(output, &sample)?;
|
|
||||||
}
|
}
|
||||||
|
tool_helper::raw::write_raw(output, &VAGADPCM::end())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,10 +20,13 @@ impl VAGHeader {
|
||||||
const RESERVED: u32 = 0;
|
const RESERVED: u32 = 0;
|
||||||
const RESERVED2: [u8; 12] = [0; 12];
|
const RESERVED2: [u8; 12] = [0; 12];
|
||||||
|
|
||||||
// TODO: Ensure big endianes
|
pub fn expected_vagadpcm_samples(adpcm_samples: u32) -> u32 {
|
||||||
pub fn create(vagadpcm_samples: usize, sampling_frequency: u32, _name: &str) -> 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
|
// 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 = ['A' as u8; 16];
|
||||||
|
|
||||||
VAGHeader{
|
VAGHeader{
|
||||||
|
|
Loading…
Reference in New Issue