Integrate all the progress into master #6
|
@ -13,4 +13,5 @@ image = "0.24.7"
|
|||
hound = "3.5.1"
|
||||
paste = "1.0.14"
|
||||
png = "0.17.10"
|
||||
symphonia = "0.5.4"
|
||||
tool_helper = {path = "../tool_helper"}
|
|
@ -1,6 +1,18 @@
|
|||
mod raw_audio;
|
||||
|
||||
use std::io::Write;
|
||||
use symphonia::core::audio::SampleBuffer;
|
||||
use tool_helper::{Error, Input};
|
||||
|
||||
pub fn convert(_input: Input, _output: &mut dyn Write) -> Result<(), Error> {
|
||||
use symphonia::core::codecs::{DecoderOptions, CODEC_TYPE_NULL};
|
||||
use symphonia::core::errors::Error as SymError;
|
||||
use symphonia::core::formats::FormatOptions;
|
||||
use symphonia::core::io::MediaSourceStream;
|
||||
use symphonia::core::meta::MetadataOptions;
|
||||
use symphonia::core::probe::Hint;
|
||||
|
||||
pub fn convert(input: Input, _output: &mut dyn Write) -> Result<(), Error> {
|
||||
raw_audio::load_raw_audio(input)?;
|
||||
|
||||
Err(Error::not_implemented("XA conversion"))
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
use std::io::Write;
|
||||
use clap::error::ErrorKind;
|
||||
use symphonia::core::audio::SampleBuffer;
|
||||
use tool_helper::{Error, Input};
|
||||
|
||||
use symphonia::core::codecs::{DecoderOptions, CODEC_TYPE_NULL};
|
||||
use symphonia::core::errors::Error as SymError;
|
||||
use symphonia::core::formats::FormatOptions;
|
||||
use symphonia::core::io::MediaSourceStream;
|
||||
use symphonia::core::meta::MetadataOptions;
|
||||
use symphonia::core::probe::Hint;
|
||||
|
||||
pub struct RawAudio {
|
||||
|
||||
}
|
||||
|
||||
pub fn load_raw_audio(input: Input) -> Result<RawAudio, Error> {
|
||||
let media_stream = MediaSourceStream::new(Box::new(load_to_ram(input)?), Default::default());
|
||||
let probed = symphonia::default::get_probe().format(&Hint::new(), media_stream, &FormatOptions::default(), &MetadataOptions::default()).expect("unsupported format");
|
||||
let mut format = probed.format;
|
||||
let track = format.tracks().iter().find(|t| t.codec_params.codec != CODEC_TYPE_NULL).expect("no supported audio tracks");
|
||||
|
||||
// Use the default options for the decoder.
|
||||
let dec_opts: DecoderOptions = Default::default();
|
||||
|
||||
// Create a decoder for the track.
|
||||
let mut decoder = symphonia::default::get_codecs().make(&track.codec_params, &dec_opts).expect("unsupported codec");
|
||||
|
||||
// Store the track identifier, it will be used to filter packets.
|
||||
let track_id = track.id;
|
||||
|
||||
// The decode loop.
|
||||
loop {
|
||||
// Get the next packet from the media format.
|
||||
let packet = match format.next_packet() {
|
||||
Ok(packet) => packet,
|
||||
Err(SymError::ResetRequired) => {
|
||||
return Err(Error::not_implemented("Miau"));
|
||||
}
|
||||
Err(SymError::IoError(err)) => {
|
||||
// A unrecoverable error occurred, halt decoding.
|
||||
if err.kind() == std::io::ErrorKind::UnexpectedEof {
|
||||
return Err(Error::not_implemented("Miau2"));
|
||||
}
|
||||
|
||||
else {
|
||||
panic!("{}", err);
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
// A unrecoverable error occurred, halt decoding.
|
||||
panic!("{}", err);
|
||||
}
|
||||
};
|
||||
|
||||
// Consume any new metadata that has been read since the last packet.
|
||||
while !format.metadata().is_latest() {
|
||||
// Pop the old head of the metadata queue.
|
||||
format.metadata().pop();
|
||||
|
||||
// Consume the new metadata at the head of the metadata queue.
|
||||
}
|
||||
|
||||
// If the packet does not belong to the selected track, skip over it.
|
||||
if packet.track_id() != track_id {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Decode the packet into audio samples.
|
||||
let packet = decoder.decode(&packet).expect("Urgh");
|
||||
println!(">>>");
|
||||
}
|
||||
}
|
||||
|
||||
fn load_to_ram(mut input: Input) -> Result<std::io::Cursor<Vec<u8>>, Error> {
|
||||
let mut buffer = Vec::default();
|
||||
|
||||
input.read_to_end(&mut buffer)?;
|
||||
Ok(std::io::Cursor::new(buffer))
|
||||
}
|
Loading…
Reference in New Issue