Fix form1 XA bugs [Glint Glitters (PS1), Dance! Dance! Dance! (PS1)]

This commit is contained in:
bnnm 2018-08-02 17:21:09 +02:00
parent 5dc8d55c7f
commit 6a86414990
2 changed files with 35 additions and 14 deletions

View File

@ -28,25 +28,33 @@ void block_update_xa(off_t block_offset, VGMSTREAM * vgmstream) {
(uint8_t)read_8bit(block_offset + 0x930 + 0x11,streamFile),
"XA block: subchannel change at %lx\n", block_offset);
/* submode flag bits (typical audio value = 0x64)
* - 7: end of file
* - 6: real time mode
* - 5: sector form (0=form1, 1=form2)
* - 4: trigger (for application)
* - 3: data sector
* - 2: audio sector
* - 1: video sector
* - 0: end of audio
/* submode flag bits (typical audio value = 0x64 01100100)
* - 7 (0x80 10000000): end of file
* - 6 (0x40 01000000): real time mode
* - 5 (0x20 00100000): sector form (0=form1, 1=form2)
* - 4 (0x10 00010000): trigger (for application)
* - 3 (0x08 00001000): data sector
* - 2 (0x04 00000100): audio sector
* - 1 (0x02 00000010): video sector
* - 0 (0x01 00000001): end of audio
*/
xa_submode = (uint8_t)read_8bit(block_offset + 0x12,streamFile);
/* audio sector must set/not set certain flags, as per spec */
if ((xa_submode & 0x20) && !(xa_submode & 0x08) && (xa_submode & 0x04) && !(xa_submode & 0x02) ) {
block_samples = (28*8 / vgmstream->channels) * 18; /* size 0x900, 18 frames of size 0x80 with 8 subframes of 28 samples */
if (!(xa_submode & 0x08) && (xa_submode & 0x04) && !(xa_submode & 0x02)) {
if (xa_submode & 0x20) {
/* form2 audio: size 0x900, 18 frames of size 0x80 with 8 subframes of 28 samples */
block_samples = (28*8 / vgmstream->channels) * 18;
}
else { /* rare, found with empty audio [Glint Glitters (PS1), Dance! Dance! Dance! (PS1)] */
/* form1 audio: size 0x800, 16 frames of size 0x80 with 8 subframes of 28 samples (rest is garbage/other data) */
block_samples = (28*8 / vgmstream->channels) * 16;
}
}
else {
;VGM_ASSERT_ONCE(block_offset < get_streamfile_size(streamFile),
"XA block: non audio block found at %lx\n", block_offset);
block_samples = 0; /* not an audio sector */
;VGM_LOG("XA block: non audio block found at %lx\n", block_offset);
}
vgmstream->current_block_offset = block_offset;

View File

@ -140,8 +140,6 @@ VGMSTREAM * init_vgmstream_cdxa(STREAMFILE *streamFile) {
if (!vgmstream) goto fail;
vgmstream->sample_rate = sample_rate;
//todo do block_updates to find num_samples? (to skip non-audio blocks)
vgmstream->num_samples = xa_bytes_to_samples(file_size - start_offset, channel_count, is_blocked);
vgmstream->meta_type = meta_PSX_XA;
vgmstream->coding_type = coding_XA;
@ -151,6 +149,21 @@ VGMSTREAM * init_vgmstream_cdxa(STREAMFILE *streamFile) {
if ( !vgmstream_open_stream(vgmstream, streamFile, start_offset) )
goto fail;
if (is_blocked) {
/* calc num_samples as blocks may be empty or smaller than usual depending on flags */
vgmstream->next_block_offset = start_offset;
do {
block_update_xa(vgmstream->next_block_offset,vgmstream);
vgmstream->num_samples += vgmstream->current_block_samples;
}
while (vgmstream->next_block_offset < get_streamfile_size(streamFile));
}
else {
vgmstream->num_samples = xa_bytes_to_samples(file_size - start_offset, channel_count, is_blocked);
}
if (vgmstream->layout_type == layout_blocked_xa)
block_update_xa(start_offset,vgmstream);
return vgmstream;