Merge pull request #634 from NicknineTheEagle/ubi

Ubi
This commit is contained in:
NicknineTheEagle 2020-05-28 02:40:11 +03:00 committed by GitHub
commit 05963ef245
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 18 deletions

View File

@ -25,7 +25,7 @@ for:
only:
- image: Ubuntu
init:
- sudo apt-get install -y libmpg123-dev libvorbis-dev libavformat-dev libavcodec-dev libavutil-dev
- sudo apt-get install -y libmpg123-dev libvorbis-dev libavformat-dev libavcodec-dev libavutil-dev libswresample-dev
- sudo apt-get install -y libao-dev audacious-dev
- sudo apt-get install -y cmake
install:

View File

@ -11,7 +11,7 @@
* - expand type: IMA style or variations; low or high nibble first
*/
static const int ADPCMTable[89] = {
static const int ADPCMTable[90] = {
7, 8, 9, 10, 11, 12, 13, 14,
16, 17, 19, 21, 23, 25, 28, 31,
34, 37, 41, 45, 50, 55, 60, 66,
@ -23,7 +23,9 @@ static const int ADPCMTable[89] = {
3327, 3660, 4026, 4428, 4871, 5358, 5894, 6484,
7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794,
32767
32767,
0 /* garbage value for Ubisoft IMA (see blocked_ubi_sce.c) */
};
static const int IMA_IndexTable[16] = {
@ -1054,10 +1056,14 @@ void decode_ubi_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspa
if (has_header) {
first_sample -= 10; //todo fix hack (needed to adjust nibble offset below)
if (step_index < 0) step_index = 0;
if (step_index > 88) step_index = 88;
} else {
if (step_index < 0) step_index = 0;
if (step_index > 89) step_index = 89;
}
if (step_index < 0) step_index=0;
if (step_index > 88) step_index=88;
for (i = first_sample; i < first_sample + samples_to_do; i++, sample_count += channelspacing) {
off_t byte_offset = channelspacing == 1 ?

View File

@ -44,13 +44,13 @@ void block_update_ubi_sce(off_t block_offset, VGMSTREAM* vgmstream) {
vgmstream->ch[i].adpcm_step_index = read_32bitLE(block_offset + header_size * i + 0x04, sf);
vgmstream->ch[i].adpcm_history1_32 = read_32bitLE(block_offset + header_size * i + 0x08, sf);
/* TODO figure out
* First step seems to always be a special value for the decoder, unsure of meaning.
* 0 = too quiet and max = 88 = waveform starts a bit off and clicky. First hist is usually +-1,
* other frames look, fine not sure what are they aiming for.
*/
/* First step is always 0x500, not sure if it's a bug or a feature but the game just takes it as is and
* ends up reading 0 from out-of-bounds memory area which causes a pop at the start. Yikes.
* It gets clampled later so the rest of the sound plays ok.
* We put 89 here as our special index which contains 0 to simulate this.
*/
if (vgmstream->ch[i].adpcm_step_index == 0x500) {
vgmstream->ch[i].adpcm_step_index = 88;
vgmstream->ch[i].adpcm_step_index = 89;
}
}
}

View File

@ -1395,16 +1395,17 @@ static int parse_type_audio_ps2_old(ubi_sb_header* sb, off_t offset, STREAMFILE*
sb->stream_size = read_32bit(offset + sb->cfg.audio_stream_size, sf);
sb->stream_offset = read_32bit(offset + sb->cfg.audio_stream_offset, sf);
pitch = read_32bit(offset + sb->cfg.audio_pitch, sf);
test_sample_rate = read_32bit(offset + sb->cfg.audio_sample_rate, sf);
sb->sample_rate = ubi_ps2_pitch_to_freq(pitch);
VGM_ASSERT(sb->sample_rate != test_sample_rate, "UBI SB: Converted PS2 pitch doesn't match the sample rate (%d = %d vs %d)\n", pitch, sb->sample_rate, test_sample_rate);
if (sb->stream_size == 0) {
VGM_LOG("UBI SB: bad stream size\n");
goto fail;
}
pitch = read_32bit(offset + sb->cfg.audio_pitch, sf);
test_sample_rate = read_32bit(offset + sb->cfg.audio_sample_rate, sf);
sb->sample_rate = ubi_ps2_pitch_to_freq(pitch);
VGM_ASSERT(sb->sample_rate != test_sample_rate, "UBI SB: Converted PS2 sample rate mismatch (%d = %d vs %d)\n", pitch, sb->sample_rate, test_sample_rate);
sb->is_external = read_32bit(offset + sb->cfg.audio_external_flag, sf) & sb->cfg.audio_external_and;
sb->loop_flag = read_32bit(offset + sb->cfg.audio_loop_flag, sf) & sb->cfg.audio_loop_and;
sb->is_localized = read_32bit(offset + sb->cfg.audio_loc_flag, sf) & sb->cfg.audio_loc_and;
@ -1434,7 +1435,6 @@ static int parse_type_layer_ps2_old(ubi_sb_header* sb, off_t offset, STREAMFILE*
sb->layer_count = read_32bit(offset + sb->cfg.layer_layer_count, sf);
sb->stream_size = read_32bit(offset + sb->cfg.audio_stream_size, sf);
sb->stream_offset = read_32bit(offset + sb->cfg.audio_stream_offset, sf);
sb->sample_rate = ubi_ps2_pitch_to_freq(read_32bit(offset + sb->cfg.layer_pitch, sf));
if (sb->stream_size == 0) {
VGM_LOG("UBI SB: bad stream size\n");
@ -1446,6 +1446,7 @@ static int parse_type_layer_ps2_old(ubi_sb_header* sb, off_t offset, STREAMFILE*
goto fail;
}
sb->sample_rate = ubi_ps2_pitch_to_freq(read_32bit(offset + sb->cfg.layer_pitch, sf));
sb->is_localized = read_32bit(offset + sb->cfg.layer_loc_flag, sf) & sb->cfg.layer_loc_and;
sb->num_samples = 0; /* calculate from size */
@ -1537,7 +1538,7 @@ static int parse_type_audio(ubi_sb_header* sb, off_t offset, STREAMFILE* sf) {
}
else {
sb->cfg.audio_stream_name = read_32bit(offset + sb->cfg.audio_extra_name, sf);
if (sb->cfg.layer_stream_name != 0xFFFFFFFF)
if (sb->cfg.audio_stream_name != 0xFFFFFFFF)
read_string(sb->resource_name, sb->cfg.resource_name_size, sb->sectionX_offset + sb->cfg.audio_stream_name, sf);
}
@ -2012,6 +2013,11 @@ static int parse_offsets(ubi_sb_header* sb, STREAMFILE* sf) {
break;
}
}
if (k == table2_num) {
VGM_LOG("UBI SM: Failed to find group %d in map %s\n", sb->group_id, sb->map_name);
goto fail;
}
break;
}
}