Update creation of buffers
This commit is contained in:
parent
b74c2cb578
commit
e242181b74
|
@ -24,7 +24,3 @@ pub fn decode(error: SymError) -> Error {
|
|||
pub fn find_track() -> Error {
|
||||
Error::from_str("symphonia error: No audio track located")
|
||||
}
|
||||
|
||||
pub fn no_buffer_created() -> Error {
|
||||
Error::from_str("No packets found for XA conversion")
|
||||
}
|
|
@ -10,7 +10,7 @@ use symphonia::core::{
|
|||
};
|
||||
use tool_helper::{Error, Input};
|
||||
|
||||
pub type I16Samples = SampleBuffer::<i16>;
|
||||
pub type I16Samples = Vec::<i16>;
|
||||
pub struct Settings {
|
||||
frequency: u32,
|
||||
layout: Layout
|
||||
|
@ -35,7 +35,8 @@ pub fn load_as_i16_audio(input: Input, settings: Settings) -> Result<I16Samples,
|
|||
}
|
||||
|
||||
fn decode(mut format: Box<dyn FormatReader>, mut decoder: Box<dyn Decoder>, settings: Settings, track_id: u32) -> Result<I16Samples, Error> {
|
||||
let mut i16_audio = None;
|
||||
let mut i16_audio = Vec::new();
|
||||
let mut cur_sample = None;
|
||||
|
||||
loop {
|
||||
// Get the next packet from the media format.
|
||||
|
@ -44,7 +45,7 @@ fn decode(mut format: Box<dyn FormatReader>, mut decoder: Box<dyn Decoder>, sett
|
|||
Err(err) => {
|
||||
if let SymError::IoError(io_err) = &err {
|
||||
if io_err.kind() == std::io::ErrorKind::UnexpectedEof {
|
||||
return i16_audio.ok_or_else(error::no_buffer_created);
|
||||
return Ok(i16_audio);
|
||||
}
|
||||
}
|
||||
return Err(error::next_packet(err));
|
||||
|
@ -61,14 +62,18 @@ fn decode(mut format: Box<dyn FormatReader>, mut decoder: Box<dyn Decoder>, sett
|
|||
|
||||
// Decode the packet into audio samples.
|
||||
let packet = decoder.decode(&packet).map_err(error::decode)?;
|
||||
if i16_audio.is_none() {
|
||||
if cur_sample.is_none() {
|
||||
let duration = packet.capacity() as u64;
|
||||
|
||||
i16_audio = Some(I16Samples::new(duration, SignalSpec::new_with_layout(settings.frequency, settings.layout)));
|
||||
cur_sample = Some(SampleBuffer::<i16>::new(duration, SignalSpec::new_with_layout(settings.frequency, settings.layout)));
|
||||
}
|
||||
|
||||
if let Some(i16_audio) = &mut i16_audio {
|
||||
i16_audio.copy_interleaved_ref(packet);
|
||||
if let Some(cur_sample) = &mut cur_sample {
|
||||
cur_sample.copy_interleaved_ref(packet);
|
||||
|
||||
for sample in cur_sample.samples() {
|
||||
i16_audio.push(*sample);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,26 @@ pub fn audio_conversion_settings(arguments: &Arguments) -> Settings {
|
|||
Settings::new(frequency, layout)
|
||||
}
|
||||
|
||||
pub fn convert(_input: I16Samples, _output: &mut dyn Write, _arguments: &Arguments) -> Result<(), Error> {
|
||||
pub fn convert(input: I16Samples, _output: &mut dyn Write, arguments: &Arguments) -> Result<(), Error> {
|
||||
let (samples_per_block, sample_count) = init_values(&input, arguments);
|
||||
|
||||
for (iteration, sampled_id) in (0..sample_count).step_by(samples_per_block).enumerate() {
|
||||
print!("\rIteration: {}; Sample: {}", iteration, sampled_id);
|
||||
}
|
||||
println!();
|
||||
Err(Error::not_implemented("XA conversion"))
|
||||
}
|
||||
|
||||
fn init_values(input: &I16Samples, arguments: &Arguments) -> (usize, u32) {
|
||||
let samples_per_block = match arguments.sample_depth {
|
||||
super::SampleDepth::Normal => 224,
|
||||
super::SampleDepth::High => 112,
|
||||
};
|
||||
|
||||
let sample_count = match arguments.channels {
|
||||
super::Channels::Stereo => input.len() / 2,
|
||||
super::Channels::Mono => input.len(),
|
||||
};
|
||||
|
||||
(samples_per_block as usize, sample_count as u32)
|
||||
}
|
Loading…
Reference in New Issue