Support end frame
This commit is contained in:
parent
ec8c1bb316
commit
09a2192e97
|
@ -7,6 +7,7 @@ edition = "2021"
|
||||||
panic = "abort"
|
panic = "abort"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
bitflags = "2.6.0"
|
||||||
clap = {version = "4.4.11", features = ["derive"]}
|
clap = {version = "4.4.11", features = ["derive"]}
|
||||||
image = "0.24.7"
|
image = "0.24.7"
|
||||||
hound = "3.5.1"
|
hound = "3.5.1"
|
||||||
|
|
|
@ -20,6 +20,8 @@ pub fn convert(input: Input, output: &mut dyn Write) -> Result<(), Error> {
|
||||||
|
|
||||||
sample_count += 1;
|
sample_count += 1;
|
||||||
}
|
}
|
||||||
|
samples.push(VAGADPCM::end());
|
||||||
|
sample_count += 1;
|
||||||
|
|
||||||
// TODO: Restructure
|
// TODO: Restructure
|
||||||
tool_helper::raw::write_raw(output, &VAGHeader::create(sample_count, wav_header.sample_rate, "Planschi"))?;
|
tool_helper::raw::write_raw(output, &VAGHeader::create(sample_count, wav_header.sample_rate, "Planschi"))?;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use bitflags::bitflags;
|
||||||
use tool_helper::{raw::RawConversion, Error};
|
use tool_helper::{raw::RawConversion, Error};
|
||||||
|
|
||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
|
@ -20,13 +21,11 @@ impl VAGHeader {
|
||||||
const RESERVED2: [u8; 12] = [0; 12];
|
const RESERVED2: [u8; 12] = [0; 12];
|
||||||
|
|
||||||
// TODO: Ensure big endianes
|
// TODO: Ensure big endianes
|
||||||
pub fn create(vagpcm_samples: usize, sampling_frequency: u32, _name: &str) -> VAGHeader {
|
pub fn create(vagadpcm_samples: usize, sampling_frequency: u32, _name: &str) -> VAGHeader {
|
||||||
// TODO: Support naming feature
|
// TODO: Support naming feature
|
||||||
let data_size = (vagpcm_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];
|
||||||
|
|
||||||
println!("Got {} samples; Writing {} bytes", vagpcm_samples, data_size);
|
|
||||||
|
|
||||||
VAGHeader{
|
VAGHeader{
|
||||||
_id: VAGHeader::ID,
|
_id: VAGHeader::ID,
|
||||||
_version: VAGHeader::VERSION.to_be(),
|
_version: VAGHeader::VERSION.to_be(),
|
||||||
|
@ -48,6 +47,14 @@ impl RawConversion<{VAGHeader::SIZE}> for VAGHeader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bitflags! {
|
||||||
|
struct VAGFlagBits : u8 {
|
||||||
|
const LoopEnd = (1 << 0);
|
||||||
|
const Repeat = (1 << 1);
|
||||||
|
const LoopStart = (1 << 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct VAGADPCM {
|
pub struct VAGADPCM {
|
||||||
data: [u32; 4]
|
data: [u32; 4]
|
||||||
}
|
}
|
||||||
|
@ -60,10 +67,14 @@ impl VAGADPCM {
|
||||||
VAGADPCM{data: [0; 4]}
|
VAGADPCM{data: [0; 4]}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_for_filter_shift(filter: u32, shift: u32) -> VAGADPCM {
|
fn create_for_filter_shift(filter: u32, shift: u32) -> VAGADPCM {
|
||||||
VAGADPCM{data: [(12 - shift) | filter << 4, 0, 0, 0]}
|
VAGADPCM{data: [(12 - shift) | filter << 4, 0, 0, 0]}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn end() -> VAGADPCM {
|
||||||
|
VAGADPCM::empty().set_loop_self()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn create(samples: ADPCMSampleForVag, lpc_tap: LPC) -> (VAGADPCM, LPC) {
|
pub fn create(samples: ADPCMSampleForVag, lpc_tap: LPC) -> (VAGADPCM, LPC) {
|
||||||
fn cap_value(value: i32, min: i32, max: i32) -> i32 {
|
fn cap_value(value: i32, min: i32, max: i32) -> i32 {
|
||||||
if value < min {
|
if value < min {
|
||||||
|
@ -107,9 +118,30 @@ impl VAGADPCM {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(best_frame, best_tap)
|
(best_frame, best_tap)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_vag_flags(&mut self, flags: VAGFlagBits) {
|
||||||
|
let mut first_sample = self.data[0].to_ne_bytes();
|
||||||
|
|
||||||
|
first_sample[1] = flags.bits();
|
||||||
|
self.data[0] = u32::from_ne_bytes(first_sample);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_loop_start(mut self) -> Self {
|
||||||
|
self.set_vag_flags(VAGFlagBits::LoopStart);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_loop_end_repeat(mut self) -> Self {
|
||||||
|
self.set_vag_flags(VAGFlagBits::LoopEnd | VAGFlagBits::Repeat);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_loop_self(mut self) -> Self {
|
||||||
|
self.set_vag_flags(VAGFlagBits::LoopStart | VAGFlagBits::LoopEnd);
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RawConversion<{VAGADPCM::SIZE}> for VAGADPCM {
|
impl RawConversion<{VAGADPCM::SIZE}> for VAGADPCM {
|
||||||
|
|
Loading…
Reference in New Issue