Make XA build warning free
This commit is contained in:
parent
d33ee87c7a
commit
f0db659ab1
|
@ -28,7 +28,6 @@ pub enum SampleDepth {
|
|||
|
||||
pub fn convert(args: Arguments, input: Input, output: &mut dyn Write) -> Result<(), Error> {
|
||||
let prepared_xa_audio = raw_audio::load_as_i16_audio(input, frequency_to_value(args.frequency))?;
|
||||
|
||||
xa_audio::encode(prepared_xa_audio, output, &args)
|
||||
}
|
||||
|
||||
|
|
|
@ -21,18 +21,17 @@ pub enum Orality {
|
|||
pub struct CDAudioSamples {
|
||||
samples: Vec::<i16>,
|
||||
orality: Orality,
|
||||
_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) -> 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})
|
||||
}
|
||||
|
||||
pub fn samples(&self) -> &Vec::<i16> {
|
||||
|
@ -99,25 +98,6 @@ pub fn load_as_i16_audio(input: Input, target_frequency: u32) -> Result<CDAudioS
|
|||
down_sample_interleave(raw_audio)
|
||||
}
|
||||
|
||||
fn _test_write_wav(audio_samples: CDAudioSamples) -> Result<(), Error> {
|
||||
let spec = hound::WavSpec {
|
||||
channels: match audio_samples.orality {
|
||||
Orality::Mono => 1,
|
||||
Orality::Stereo => 2,
|
||||
},
|
||||
sample_rate: audio_samples._frequency,
|
||||
bits_per_sample: 16,
|
||||
sample_format: hound::SampleFormat::Int,
|
||||
};
|
||||
|
||||
let mut file = hound::WavWriter::create("planschi.wav", spec).unwrap();
|
||||
for sample in audio_samples.samples {
|
||||
file.write_sample(sample)?;
|
||||
}
|
||||
file.finalize()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn load_raw_audio(input: Input) -> Result<InternalAudioSamples, Error> {
|
||||
let media_stream = MediaSourceStream::new(Box::new(load_to_ram(input)?), Default::default());
|
||||
let format = symphonia::default::get_probe().format(&Hint::new(), media_stream, &FormatOptions::default(), &MetadataOptions::default()).map_err(error::probe)?.format;
|
||||
|
@ -258,12 +238,11 @@ fn resample(input: InternalAudioSamples, target_frequency: u32) -> Result<Intern
|
|||
|
||||
fn down_sample_interleave(input: InternalAudioSamples) -> Result<CDAudioSamples, Error> {
|
||||
let channels = input.channels();
|
||||
let frequency = input.frequency;
|
||||
let audio_buffer = input.into_audio_buffer();
|
||||
let mut sample_buffer = SampleBuffer::<i16>::new(audio_buffer.capacity() as u64, audio_buffer.spec().clone());
|
||||
|
||||
sample_buffer.copy_interleaved_typed::<f32>(&audio_buffer);
|
||||
CDAudioSamples::new(sample_buffer.samples().to_vec(), channels, frequency)
|
||||
CDAudioSamples::new(sample_buffer.samples().to_vec(), channels)
|
||||
}
|
||||
|
||||
fn load_to_ram(mut input: Input) -> Result<std::io::Cursor<Vec<u8>>, Error> {
|
||||
|
|
|
@ -9,7 +9,7 @@ pub const HIGH_FREQUENCY:u32 = 37_800;
|
|||
pub const LOW_FREQUENCY:u32 = 18_900;
|
||||
|
||||
pub fn encode(input: CDAudioSamples, output: &mut dyn Write, arguments: &Arguments) -> Result<(), Error> {
|
||||
let mut encoder = xapcm::Encoder::new(&input.samples(), arguments.clone(), input.orality());
|
||||
let mut encoder = xapcm::Encoder::new(&input, arguments.sample_depth);
|
||||
|
||||
while let Some(xa_sector) = encoder.encode_next_xa_sector()? {
|
||||
output.write(&xa_sector)?;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use crate::audio::my_xa::{Arguments, raw_audio::Orality, SampleDepth};
|
||||
use crate::audio::my_xa::{raw_audio::{CDAudioSamples, Orality}, SampleDepth};
|
||||
use tool_helper::Error;
|
||||
|
||||
pub struct Encoder<'a> {
|
||||
left: ChannelState,
|
||||
right: ChannelState,
|
||||
source: &'a[i16],
|
||||
arguments: Arguments,
|
||||
sample_depth: SampleDepth,
|
||||
orality: Orality,
|
||||
samples_per_block: i32,
|
||||
sample_limit: i32
|
||||
|
@ -17,10 +17,11 @@ impl<'a> Encoder<'a> {
|
|||
const FILTER_K1: [i16; 5] = [0, 60, 115, 98, 122];
|
||||
const FILTER_K2: [i16; 5] = [0, 0, -52, -55, -60];
|
||||
|
||||
// TODO: Arguments are not needed anymore, PreparedAudioSamples has all the information we need
|
||||
pub fn new(source: &[i16], arguments: Arguments, orality: Orality) -> Encoder {
|
||||
let (samples_per_block, sample_limit) = Self::samples_per_block_and_limit(&source, &arguments, &orality);
|
||||
Encoder{left: ChannelState::default(), right: ChannelState::default(), source, arguments, orality, samples_per_block, sample_limit}
|
||||
pub fn new(cd_sample: &CDAudioSamples, sample_depth: SampleDepth) -> Encoder {
|
||||
let orality = cd_sample.orality();
|
||||
let (samples_per_block, sample_limit) = Self::samples_per_block_and_limit(&cd_sample.samples(), sample_depth, orality);
|
||||
|
||||
Encoder{left: ChannelState::default(), right: ChannelState::default(), source: &cd_sample.samples(), sample_depth, orality, samples_per_block, sample_limit}
|
||||
}
|
||||
|
||||
pub fn encode_next_xa_sector(&mut self) -> Result<Option<[u8; 0x930]>, Error> {
|
||||
|
@ -62,7 +63,7 @@ impl<'a> Encoder<'a> {
|
|||
const SHIFT_RANGE_8BPS: i32 = 8;
|
||||
|
||||
let channels = [&mut self.left, &mut self.right];
|
||||
match self.arguments.sample_depth {
|
||||
match self.sample_depth {
|
||||
SampleDepth::Normal => {
|
||||
let (modulo, offset) = if self.orality == Orality::Stereo {(2, &STEREO_4BIT)} else {(1, &MONO_4BIT)};
|
||||
let (first_offset, second_offset) = offset;
|
||||
|
@ -217,8 +218,8 @@ impl<'a> Encoder<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn samples_per_block_and_limit(input: &[i16], arguments: &Arguments, orality: &Orality) -> (i32, i32) {
|
||||
let samples_per_block = match arguments.sample_depth {
|
||||
fn samples_per_block_and_limit(input: &[i16], sample_depth: SampleDepth, orality: Orality) -> (i32, i32) {
|
||||
let samples_per_block = match sample_depth {
|
||||
SampleDepth::Normal => 224,
|
||||
SampleDepth::High => 112,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue