Fix XA conversion issue
This commit is contained in:
parent
792d2c4549
commit
d0c7a14afa
|
@ -21,18 +21,18 @@ pub enum Orality {
|
|||
pub struct CDAudioSamples {
|
||||
samples: Vec::<i16>,
|
||||
orality: Orality,
|
||||
frequency: u32,
|
||||
_frequency: u32,
|
||||
}
|
||||
|
||||
impl CDAudioSamples {
|
||||
pub fn new(samples: Vec<i16>, channels: usize, frequency: u32) -> Result<CDAudioSamples, Error> {
|
||||
pub fn new(samples: Vec<i16>, channels: usize, _frequency: u32) -> Result<CDAudioSamples, Error> {
|
||||
let orality = match channels {
|
||||
0 => return Err(Error::from_str("Input file has no audio channels")),
|
||||
1 => Orality::Mono,
|
||||
2 => Orality::Stereo,
|
||||
_ => return Err(Error::from_str("Only Mono and Stereo input are supported")),
|
||||
};
|
||||
Ok(CDAudioSamples{samples, orality, frequency})
|
||||
Ok(CDAudioSamples{samples, orality, _frequency})
|
||||
}
|
||||
|
||||
pub fn samples(&self) -> &Vec::<i16> {
|
||||
|
@ -105,7 +105,7 @@ fn _test_write_wav(audio_samples: CDAudioSamples) -> Result<(), Error> {
|
|||
Orality::Mono => 1,
|
||||
Orality::Stereo => 2,
|
||||
},
|
||||
sample_rate: audio_samples.frequency,
|
||||
sample_rate: audio_samples._frequency,
|
||||
bits_per_sample: 16,
|
||||
sample_format: hound::SampleFormat::Int,
|
||||
};
|
||||
|
|
|
@ -29,12 +29,21 @@ impl<'a> Encoder<'a> {
|
|||
}
|
||||
|
||||
let mut sector = [0u8; 0x930];
|
||||
for i in 0..10 {
|
||||
sector[0x01+i] = 0xFF;
|
||||
}
|
||||
sector[0x0F] = 0x02;
|
||||
|
||||
sector[0x12] = 0x24 | 0x40;
|
||||
sector[0x13] = 1 | 0 | 0; // < TODO: Actually consider settings
|
||||
for i in 0..4 {
|
||||
sector[0x14+i] = sector[0x10+i];
|
||||
}
|
||||
|
||||
let mut dst = &mut sector[0x18..];
|
||||
for _ in 0..Self::BLOCKS_PER_SECTOR {
|
||||
if self.source.len() < self.samples_per_block as usize {
|
||||
self.source = &self.source[self.source.len()..];
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -63,7 +72,7 @@ impl<'a> Encoder<'a> {
|
|||
let byte = Self::encode(channels[idx%modulo], &samples[offset.sample..], sample_limit + offset.sample_limit, offset.pitch, &mut data[offset.data..], offset.data_shift, offset.data_pitch, Self::XA_ADPCM_FILTER_COUNT, SHIFT_RANGE_4BPS)?;
|
||||
data[idx + (offset_idx*8)] = byte;
|
||||
data[idx + 4 + (offset_idx*8)] = byte;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
SampleDepth::High => {
|
||||
|
@ -145,7 +154,7 @@ impl<'a> Encoder<'a> {
|
|||
return Err(Error::from_text(format!("Sample error exceeds 30bit: {}", sample_error)));
|
||||
}
|
||||
|
||||
data[(i*data_pitch) as usize] = ((data[(i*pitch) as usize] & nondata_mask) as i32 | (sample_enc << data_shift)) as u8;
|
||||
data[(i*data_pitch) as usize] = ((data[(i*data_pitch) as usize] & nondata_mask) as i32 | (sample_enc << data_shift)) as u8;
|
||||
|
||||
out_channel_state.mse += (sample_error as u64*sample_error as u64) as i64;
|
||||
out_channel_state.prev2 = out_channel_state.prev1;
|
||||
|
|
Loading…
Reference in New Issue