Embedd CDXA audio (untested)

This commit is contained in:
Jaby 2024-05-24 19:29:16 +02:00
parent 5bc0c28739
commit 7c39fbad37
1 changed files with 20 additions and 6 deletions

View File

@ -1,6 +1,5 @@
use crate::types::RawData; use crate::types::RawData;
use cdtypes::types::{helper::*, sector::*}; use cdtypes::types::{helper::*, sector::*};
use tool_helper::print_warning;
pub struct SubModeBuilder { pub struct SubModeBuilder {
sub_mode: SubMode sub_mode: SubMode
@ -111,7 +110,7 @@ pub fn create_xa_audio_for(data: &Vec<RawData>) -> Vec<Mode2Form2> {
} }
sector_count_mode2_form2(biggest_size) sector_count_mode2_form2(biggest_size)
}; };
let channels = { let mut channels = {
let mut new_channel = Vec::new(); let mut new_channel = Vec::new();
for channel in data { for channel in data {
new_channel.push(&channel[0..channel.len()]); new_channel.push(&channel[0..channel.len()]);
@ -123,20 +122,35 @@ pub fn create_xa_audio_for(data: &Vec<RawData>) -> Vec<Mode2Form2> {
for sector_id in 0..sectors_to_parse { for sector_id in 0..sectors_to_parse {
let mut channel_id = 0; let mut channel_id = 0;
let sub_mode = {
let mut sub_mode = SubMode::default_form2();
for channel in &channels { if sector_id + 1 == sectors_to_parse {
sub_mode.set_eof();
sub_mode.set_eor();
}
sub_mode
};
for channel in &mut channels {
let raw_data = { let raw_data = {
if channel.is_empty() { if channel.is_empty() {
[0u8; Mode2Form2::DATA_SIZE] [0u8; Mode2Form2::DATA_SIZE]
} }
else { else {
print_warning(format!("Encoding XA-Audio sector #{} for file {} not supported yet", sector_id, channel_id)); let mut raw_data = [0u8; Mode2Form2::DATA_SIZE];
[0u8; Mode2Form2::DATA_SIZE]
// v Skip header stuff
*channel = &channel[0x18..channel.len()];
*channel = copy_array(&mut raw_data, &channel);
*channel = &channel[0x4..channel.len()];
// ^ Skip EDC
raw_data
} }
}; };
sectors[cur_sector_id] = create_xa_audio_for_raw(SubMode::default_form2(), channel_id, &raw_data); sectors[cur_sector_id] = create_xa_audio_for_raw(sub_mode, channel_id, &raw_data);
channel_id += 1; channel_id += 1;
cur_sector_id += 1; cur_sector_id += 1;
} }