Fix XMA encoder delay in Ubi SB bigfiles

This commit is contained in:
bnnm 2020-04-16 00:27:53 +02:00
parent e46993b4fc
commit 71997fabf8

View File

@ -19,7 +19,7 @@
* read num_bits (up to 25) from a bit offset. * read num_bits (up to 25) from a bit offset.
* 25 since we read a 32 bit int, and need to adjust up to 7 bits from the byte-rounded fseek (32-7=25) * 25 since we read a 32 bit int, and need to adjust up to 7 bits from the byte-rounded fseek (32-7=25)
*/ */
static uint32_t read_bitsBE_b(off_t bit_offset, int num_bits, STREAMFILE *streamFile) { static uint32_t read_bitsBE_b(int64_t bit_offset, int num_bits, STREAMFILE *streamFile) {
uint32_t num, mask; uint32_t num, mask;
if (num_bits > 25) return -1; //??? if (num_bits > 25) return -1; //???
@ -400,7 +400,7 @@ fail:
/* XMA PARSING */ /* XMA PARSING */
/* ******************************************** */ /* ******************************************** */
static void ms_audio_parse_header(STREAMFILE *streamFile, int xma_version, off_t offset_b, int bits_frame_size, size_t *first_frame_b, size_t *packet_skip_count, size_t *header_size_b) { static void ms_audio_parse_header(STREAMFILE *streamFile, int xma_version, int64_t offset_b, int bits_frame_size, size_t *first_frame_b, size_t *packet_skip_count, size_t *header_size_b) {
if (xma_version == 1) { /* XMA1 */ if (xma_version == 1) { /* XMA1 */
//packet_sequence = read_bitsBE_b(offset_b+0, 4, streamFile); /* numbered from 0 to N */ //packet_sequence = read_bitsBE_b(offset_b+0, 4, streamFile); /* numbered from 0 to N */
//unknown = read_bitsBE_b(offset_b+4, 2, streamFile); /* packet_metadata? (always 2) */ //unknown = read_bitsBE_b(offset_b+4, 2, streamFile); /* packet_metadata? (always 2) */
@ -431,11 +431,11 @@ static void ms_audio_parse_header(STREAMFILE *streamFile, int xma_version, off_t
/* full packet skip, no new frames start in this packet (prev frames can end here) /* full packet skip, no new frames start in this packet (prev frames can end here)
* standardized to some value */ * standardized to some value */
if (*packet_skip_count == 0x7FF) { /* XMA1, 11b */ if (*packet_skip_count == 0x7FF) { /* XMA1, 11b */
VGM_LOG("MS_SAMPLES: XMA1 full packet_skip at 0x%x\n", (uint32_t)offset_b/8); VGM_LOG("MS_SAMPLES: XMA1 full packet_skip at %"PRIx64"\n", offset_b/8);
*packet_skip_count = 0x800; *packet_skip_count = 0x800;
} }
else if (*packet_skip_count == 0xFF) { /* XMA2, 8b*/ else if (*packet_skip_count == 0xFF) { /* XMA2, 8b*/
VGM_LOG("MS_SAMPLES: XMA2 full packet_skip at 0x%x\n", (uint32_t)offset_b/8); VGM_LOG("MS_SAMPLES: XMA2 full packet_skip at %"PRIx64"\n", offset_b/8);
*packet_skip_count = 0x800; *packet_skip_count = 0x800;
} }
@ -458,7 +458,7 @@ static void ms_audio_get_samples(ms_sample_data * msd, STREAMFILE *streamFile, i
int frames = 0, samples = 0, loop_start_frame = 0, loop_end_frame = 0; int frames = 0, samples = 0, loop_start_frame = 0, loop_end_frame = 0;
size_t first_frame_b, packet_skip_count, header_size_b, frame_size_b; size_t first_frame_b, packet_skip_count, header_size_b, frame_size_b;
off_t offset_b, packet_offset_b, frame_offset_b; int64_t offset_b, packet_offset_b, frame_offset_b;
size_t packet_size = bytes_per_packet; size_t packet_size = bytes_per_packet;
size_t packet_size_b = packet_size * 8; size_t packet_size_b = packet_size * 8;
@ -535,11 +535,11 @@ static void ms_audio_get_skips(STREAMFILE *streamFile, int xma_version, off_t da
int start_skip = 0, end_skip = 0; int start_skip = 0, end_skip = 0;
size_t first_frame_b, packet_skip_count, header_size_b, frame_size_b; size_t first_frame_b, packet_skip_count, header_size_b, frame_size_b;
off_t offset_b, packet_offset_b, frame_offset_b; int64_t offset_b, packet_offset_b, frame_offset_b;
size_t packet_size = bytes_per_packet; size_t packet_size = bytes_per_packet;
size_t packet_size_b = packet_size * 8; size_t packet_size_b = packet_size * 8;
off_t offset = data_offset; int64_t offset = data_offset;
/* read packet */ /* read packet */
{ {