From 7966f5794b274d770169cf623954f6c75605aa75 Mon Sep 17 00:00:00 2001 From: Jaby Date: Sun, 26 May 2024 17:03:42 +0200 Subject: [PATCH] Fix CDXA sector count bug --- src/Library/src/CD/cd.cpp | 2 -- src/Tools/psxcdgen_ex/src/encoder/builder.rs | 15 +++-------- src/Tools/psxcdgen_ex/src/types/helper.rs | 28 ++++++++++++++++++++ src/Tools/psxcdgen_ex/src/types/mod.rs | 19 +++++-------- 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/src/Library/src/CD/cd.cpp b/src/Library/src/CD/cd.cpp index 0d62723c..aa88bc73 100644 --- a/src/Library/src/CD/cd.cpp +++ b/src/Library/src/CD/cd.cpp @@ -33,7 +33,6 @@ namespace JabyEngine { Command::send_wait(CD_IO::Command::SetLoc, loc.get_min_cd(), loc.get_sec_cd(), loc.get_sector_cd()); Command::send(desc); current_state = State::Reading; - printf("Done??\n"); } static void read_sector_dma(CD_IO::DataSector& sector) { @@ -160,7 +159,6 @@ namespace JabyEngine { } void read_s(uint32_t lba) { - printf("Now ReadS %i\n", lba); read_cd(lba, CD_IO::Command::ReadS); } diff --git a/src/Tools/psxcdgen_ex/src/encoder/builder.rs b/src/Tools/psxcdgen_ex/src/encoder/builder.rs index 962fb5be..a0e32bc7 100644 --- a/src/Tools/psxcdgen_ex/src/encoder/builder.rs +++ b/src/Tools/psxcdgen_ex/src/encoder/builder.rs @@ -1,4 +1,4 @@ -use crate::types::RawData; +use crate::types::{helper::InterleavedXASizes, RawData}; use cdtypes::types::{helper::*, sector::*}; pub struct SubModeBuilder { @@ -100,16 +100,9 @@ pub fn create_xa_data_for_vec(sub_mode: Option, data: &RawData) -> Vec< } pub fn create_xa_audio_for(data: &Vec) -> Vec { - let channel_count = data.len(); - let sectors_to_parse = { - let mut biggest_size = 0; - - for channel in data { - if channel.len() > biggest_size { - biggest_size = channel.len(); - } - } - sector_count_mode2_form2(biggest_size) + let (channel_count, sectors_to_parse) = { + let size_info = InterleavedXASizes::new(data); + (size_info.channels, size_info.biggest_file_sectors) }; let mut channels = { let mut new_channel = Vec::new(); diff --git a/src/Tools/psxcdgen_ex/src/types/helper.rs b/src/Tools/psxcdgen_ex/src/types/helper.rs index 5d75c800..b7440a22 100644 --- a/src/Tools/psxcdgen_ex/src/types/helper.rs +++ b/src/Tools/psxcdgen_ex/src/types/helper.rs @@ -1,3 +1,5 @@ +use cdtypes::types::helper::sector_count_mode2_form2; + use super::*; const CURRENT_DIR_NAME:&'static str = "\x00"; @@ -97,3 +99,29 @@ pub fn collect_directory_record_member(dir: &Directory) -> Vec) -> InterleavedXASizes { + let biggest_file_size = { + let mut biggest_size = 0; + + for channel in content { + if channel.len() > biggest_size { + biggest_size = channel.len(); + } + } + biggest_size + }; + let channels = content.len(); + let biggest_file_sectors = sector_count_mode2_form2(biggest_file_size); + InterleavedXASizes{ + channels, biggest_file_sectors, full_size_bytes: channels*biggest_file_sectors*Mode2Form2::DATA_SIZE + } + } +} \ No newline at end of file diff --git a/src/Tools/psxcdgen_ex/src/types/mod.rs b/src/Tools/psxcdgen_ex/src/types/mod.rs index 53c55392..5712df29 100644 --- a/src/Tools/psxcdgen_ex/src/types/mod.rs +++ b/src/Tools/psxcdgen_ex/src/types/mod.rs @@ -3,11 +3,13 @@ pub mod layout; pub mod file_map; pub mod overlay; -use cdtypes::types::{cdstring::DString, dir_record::DirectoryRecord, helper::xa_audio_interleave_count, path_table::PathTableL, sector::AudioSample}; +use cdtypes::types::{cdstring::DString, dir_record::DirectoryRecord, helper::xa_audio_interleave_count, path_table::PathTableL, sector::{AudioSample, Mode2Form2}}; use std::{cell::RefCell, path::PathBuf, rc::Rc}; pub use file_map::FileSystemMap; pub use tool_helper::Error; + +use crate::types::helper::InterleavedXASizes; pub type SharedPtr = Rc>; pub type RawData = Vec; @@ -258,19 +260,10 @@ impl File { } content } + let content = increase_content(content); + let content_size = InterleavedXASizes::new(&content); - let content = increase_content(content); - let channel_count = content.len(); - let highest_size = { - let mut size = 0; - for channel in &content { - if channel.len() > size { - size = channel.len(); - } - } - size - }; - Self::new_from_content(file_name, FileType::XAAudio(content), highest_size*channel_count) + Self::new_from_content(file_name, FileType::XAAudio(content), content_size.full_size_bytes) } pub fn is_streaming_file(&self) -> bool {