Fix some EA BNK [Medal of Honor Heroes 2 PSP]

This commit is contained in:
bnnm 2017-08-05 17:55:49 +02:00
parent aaa2613802
commit efdcd16ac1

View File

@ -46,6 +46,7 @@
#define EA_CODEC2_MT5 0x16
#define EA_CODEC2_EALAYER3 0x17
#define EA_CODEC2_ATRAC3PLUS 0x1B /* Medal of Honor Heroes 2 (PSP) */
//todo #define EA_CODEC2_ATRAC9 0x-- /* supposedly exists */
#define EA_MAX_CHANNELS 6
@ -86,7 +87,7 @@ VGMSTREAM * init_vgmstream_ea_schl(STREAMFILE *streamFile) {
/* check extension; exts don't seem enforced by EA's tools, but usually:
* STR/ASF/MUS ~early, EAM ~mid, SNG/AUD ~late, rest uncommon/one game (ex. STRM: MySims Kingdom Wii) */
if (!check_extensions(streamFile,"str,asf,mus,eam,sng,aud,sx,strm,xa,xsf,exa,stm"))
if (!check_extensions(streamFile,"str,asf,mus,eam,sng,aud,sx,strm,xa,xsf,exa,stm,ast"))
goto fail;
/* check header */
@ -115,7 +116,7 @@ fail:
/* EA BNK with variable header - from EA games SFXs; also created by sx.exe */
VGMSTREAM * init_vgmstream_ea_bnk(STREAMFILE *streamFile) {
off_t start_offset, header_offset, offset;
off_t start_offset, header_offset, offset, table_offset;
size_t header_size;
ea_header ea;
int32_t (*read_32bit)(off_t,STREAMFILE*) = NULL;
@ -128,7 +129,7 @@ VGMSTREAM * init_vgmstream_ea_bnk(STREAMFILE *streamFile) {
/* .bnk: sfx, .sdt: speech, .mus: streams/jingles (rare) */
if (!check_extensions(streamFile,"bnk,sdt,mus"))
goto fail;
VGM_LOG("1\n");
/* check header (doesn't use EA blocks, otherwise very similar to SCHl) */
if (read_32bitBE(0x00,streamFile) == 0x424E4B6C || /* "BNKl" (common) */
read_32bitBE(0x00,streamFile) == 0x424E4B62) /* "BNKb" (FIFA 98 SS) */
@ -137,7 +138,7 @@ VGM_LOG("1\n");
offset = 0x100; /* Harry Potter and the Goblet of Fire (PS2) .mus have weird extra 0x100 bytes */
else
goto fail;
VGM_LOG("2\n");
/* use header size as endianness flag */
if ((uint32_t)read_32bitLE(0x08,streamFile) > 0x00F00000) {
read_32bit = read_32bitBE;
@ -152,28 +153,34 @@ VGM_LOG("2\n");
/* check multi-streams */
if (target_stream == 0) target_stream = 1;
if (target_stream < 0 || target_stream > total_streams || total_streams < 1) goto fail;
VGM_LOG("3\n");
switch(bnk_version) {
case 0x02: /* early (Need For Speed PC, Fifa 98 SS) */
table_offset = 0x0c;
header_size = read_32bit(offset + 0x08,streamFile); /* full size */
header_offset = offset + 0x0c + 0x04*(target_stream-1) + read_32bit(offset + 0x0c + 0x04*(target_stream-1),streamFile);
header_offset = offset + table_offset + 0x04*(target_stream-1) + read_32bit(offset + table_offset + 0x04*(target_stream-1),streamFile);
break;
case 0x04: /* mid (last used in PSX banks) */
case 0x05: /* late (generated by sx.exe ~v2+) */
/* 0x08: header/file size, 0x0C: file size/null, 0x10: always null */
table_offset = 0x14;
if (read_32bit(offset + table_offset,streamFile) == 0x00)
table_offset += 0x4; /* MOH Heroes 2 PSP has an extra empty field, not sure why */
header_size = get_streamfile_size(streamFile); /* unknown (header is variable and may have be garbage until data) */
header_offset = offset + 0x14 + 0x04*(target_stream-1) + read_32bit(offset + 0x14 + 0x04*(target_stream-1),streamFile);
header_offset = offset + table_offset + 0x04*(target_stream-1) + read_32bit(offset + table_offset + 0x04*(target_stream-1),streamFile);
break;
default:
VGM_LOG("EA BNK: unknown version %x\n", bnk_version);
goto fail;
}
VGM_LOG("4\n");
if (!parse_variable_header(streamFile,&ea, header_offset, header_size - header_offset))
goto fail;
VGM_LOG("5\n");
/* fix absolute offsets so it works in next funcs */
if (offset) {
for (i = 0; i < ea.channels; i++) {
@ -338,7 +345,7 @@ static VGMSTREAM * init_vgmstream_ea_variable_header(STREAMFILE *streamFile, ea_
case EA_CODEC2_MT5: /* MicroTalk (5:1 compression) */
case EA_CODEC2_ATRAC3PLUS: /* regular ATRAC3plus chunked in SCxx blocks, including RIFF header */
default:
VGM_LOG("EA: unknown codec2 0x%02x for platform 0x%02x\n", ea->codec2, ea->platform);
VGM_LOG("EA SCHl: unknown codec2 0x%02x for platform 0x%02x\n", ea->codec2, ea->platform);
goto fail;
}
@ -609,7 +616,7 @@ static int parse_variable_header(STREAMFILE* streamFile, ea_header* ea, off_t be
break;
default:
VGM_LOG("EA: unknown patch 0x%02x at 0x%04lx\n", patch_type, (offset-1));
VGM_LOG("EA SCHl: unknown patch 0x%02x at 0x%04lx\n", patch_type, (offset-1));
break;
}
}
@ -653,7 +660,7 @@ static int parse_variable_header(STREAMFILE* streamFile, ea_header* ea, off_t be
case EA_PLATFORM_3DS: ea->version = EA_VERSION_V3; break;
case EA_PLATFORM_GENERIC: ea->version = EA_VERSION_V2; break;
default:
VGM_LOG("EA: unknown default version for platform 0x%02x\n", ea->platform);
VGM_LOG("EA SCHl: unknown default version for platform 0x%02x\n", ea->platform);
goto fail;
}
}
@ -667,7 +674,7 @@ static int parse_variable_header(STREAMFILE* streamFile, ea_header* ea, off_t be
case EA_PLATFORM_MAC: ea->codec1 = EA_CODEC1_PCM; break; // assumed
case EA_PLATFORM_SAT: ea->codec1 = EA_CODEC1_PCM; break;
default:
VGM_LOG("EA: unknown default codec1 for platform 0x%02x\n", ea->platform);
VGM_LOG("EA SCHl: unknown default codec1 for platform 0x%02x\n", ea->platform);
goto fail;
}
}
@ -682,7 +689,7 @@ static int parse_variable_header(STREAMFILE* streamFile, ea_header* ea, off_t be
case EA_CODEC1_EAXA: ea->codec2 = EA_CODEC2_EAXA; break;
case EA_CODEC1_MT10: ea->codec2 = EA_CODEC2_MT10; break;
default:
VGM_LOG("EA: unknown codec1 0x%02x\n", ea->codec1);
VGM_LOG("EA SCHl: unknown codec1 0x%02x\n", ea->codec1);
goto fail;
}
}
@ -701,7 +708,7 @@ static int parse_variable_header(STREAMFILE* streamFile, ea_header* ea, off_t be
case EA_PLATFORM_PSP: ea->codec2 = EA_CODEC2_EAXA; break;
case EA_PLATFORM_3DS: ea->codec2 = EA_CODEC2_GCADPCM; break;
default:
VGM_LOG("EA: unknown default codec2 for platform 0x%02x\n", ea->platform);
VGM_LOG("EA SCHl: unknown default codec2 for platform 0x%02x\n", ea->platform);
goto fail;
}
}
@ -722,7 +729,7 @@ static int parse_variable_header(STREAMFILE* streamFile, ea_header* ea, off_t be
case EA_PLATFORM_PSP: ea->sample_rate = 22050; break;
//case EA_PLATFORM_3DS: ea->sample_rate = 44100; break;//todo (not 22050/16000)
default:
VGM_LOG("EA: unknown default sample rate for platform 0x%02x\n", ea->platform);
VGM_LOG("EA SCHl: unknown default sample rate for platform 0x%02x\n", ea->platform);
goto fail;
}
}