Added Treyarch NSLB bank format [Call of Duty 3]

This commit is contained in:
NicknineTheEagle 2021-12-07 07:34:03 +03:00
parent ad28329418
commit b52b9425b7
5 changed files with 185 additions and 3 deletions

View File

@ -1382,6 +1382,7 @@ static const meta_info meta_info_list[] = {
{meta_LOPU_FB, "French-Bread LOPU header"},
{meta_LPCM_FB, "French-Bread LPCM header"},
{meta_WBK, "Treyarch WBK header"},
{meta_WBK_NSLB, "Treyarch NSLB header"},
{meta_DSP_APEX, "Koei Tecmo APEX header"},
};

View File

@ -969,5 +969,6 @@ VGMSTREAM* init_vgmstream_lopu_fb(STREAMFILE* sf);
VGMSTREAM* init_vgmstream_lpcm_fb(STREAMFILE* sf);
VGMSTREAM* init_vgmstream_wbk(STREAMFILE* sf);
VGMSTREAM* init_vgmstream_wbk_nslb(STREAMFILE* sf);
#endif /*_META_H*/

View File

@ -13,7 +13,6 @@ VGMSTREAM* init_vgmstream_wbk(STREAMFILE* sf) {
!is_id32be(0x04, sf, "BK11"))
goto fail;
/* checks */
if (!check_extensions(sf, "wbk"))
goto fail;
@ -94,7 +93,7 @@ VGMSTREAM* init_vgmstream_wbk(STREAMFILE* sf) {
switch (codec) {
case 0x03: { /* DSP */
uint32_t coef_offset;
uint16_t coef_table[16] = {
static const int16_t coef_table[16] = {
0x0216,0xfc9f,0x026c,0x04b4,0x065e,0xfdec,0x0a11,0xfd1e,
0x0588,0xfc38,0x05ad,0x01da,0x083b,0xfdbc,0x08c3,0xff18
};
@ -116,6 +115,7 @@ VGMSTREAM* init_vgmstream_wbk(STREAMFILE* sf) {
}
break;
}
case 0x04: /* PSX */
vgmstream->coding_type = coding_PSX;
vgmstream->layout_type = layout_interleave;
@ -152,4 +152,182 @@ VGMSTREAM* init_vgmstream_wbk(STREAMFILE* sf) {
fail:
close_vgmstream(vgmstream);
return NULL;
}
}
/* .WBK - evolution of the above Treyarch bank format [Call of Duty 3] */
VGMSTREAM* init_vgmstream_wbk_nslb(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
uint32_t table_offset, name_table_offset, strings_offset, info_offset, data_offset, streams_offset,
name_offset, entry_offset, info_entry_offset,
codec, flags, channels, sound_offset, sound_size, num_samples, sample_rate;
int target_subsong = sf->stream_index, total_subsongs, loop_flag;
/* checks */
if (!is_id32be(0x00, sf, "NSLB"))
goto fail;
if (!check_extensions(sf, "wbk"))
goto fail;
/* always little endian, even on PS3/X360 */
if (read_u32le(0x04, sf) != 0x01)
goto fail;
total_subsongs = read_u32le(0x10, sf);
if (target_subsong == 0) target_subsong = 1;
if (target_subsong < 0 || target_subsong > total_subsongs || total_subsongs < 1)
goto fail;
name_table_offset = read_u32le(0x18, sf);
table_offset = read_u32le(0x1c, sf);
//info_size = read_u32le(0x20, sf);
info_offset = read_u32le(0x24, sf);
//strings_size = read_u32le(0x28, sf);
strings_offset = read_u32le(0x2c, sf);
//data_size = read_u32le(0x30, sf);
data_offset = read_u32le(0x34, sf);
//streams_size = read_u32le(0x38, sf);
streams_offset = read_u32le(0x3c, sf);
name_offset = read_u32le(name_table_offset + 0x04 * (target_subsong - 1), sf);
entry_offset = table_offset + 0x10 * (target_subsong - 1);
info_entry_offset = read_u32le(entry_offset + 0x00, sf) + info_offset;
sound_offset = read_u32le(entry_offset + 0x04, sf);
sound_size = read_u32le(entry_offset + 0x08, sf);
num_samples = read_u32le(entry_offset + 0x0c, sf);
sample_rate = read_u16le(info_entry_offset + 0x00, sf);
codec = read_u8(info_entry_offset + 0x04, sf);
flags = read_u8(info_entry_offset + 0x05, sf);
channels = read_u8(info_entry_offset + 0x06, sf) == 0x03 ? 2 : 1;
if (flags & 0x01)
sound_offset += streams_offset;
else
sound_offset += data_offset;
loop_flag = (flags & 0x02);
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channels, loop_flag);
if (!vgmstream) goto fail;
/* fill in the vital statistics */
vgmstream->meta_type = meta_WBK_NSLB;
vgmstream->sample_rate = sample_rate;
vgmstream->stream_size = sound_size;
vgmstream->num_samples = num_samples;
vgmstream->loop_start_sample = 0;
vgmstream->loop_end_sample = num_samples; /* full loops only */
vgmstream->num_streams = total_subsongs;
switch (codec) {
case 0x20: /* XBOX */
vgmstream->coding_type = coding_XBOX_IMA;
vgmstream->layout_type = layout_none;
break;
case 0x21: /* PSX */
vgmstream->coding_type = coding_PSX;
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = (flags & 0x01) ? 0x800 : sound_size / channels;
break;
case 0x22: { /* DSP */
int i, j;
vgmstream->coding_type = coding_NGC_DSP;
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = (flags & 0x01) ? 0x8000 : sound_size / channels;
/* It looks like the table is re-interpreted as 8 32-bit integers and stored with little endian byte order
* like the rest of the data. Fun times. */
for (i = 0; i < vgmstream->channels; i++) {
off_t coef_offset = info_entry_offset + 0x4c + 0x30*i;
for (j = 0; j < 8; j++) {
vgmstream->ch[i].adpcm_coef[j*2] = read_s16le(coef_offset + j*0x04 + 0x02, sf);
vgmstream->ch[i].adpcm_coef[j*2+1] = read_s16le(coef_offset + j*0x04 + 0x00, sf);
}
}
break;
}
case 0x25: /* FSB IMA */ {
VGMSTREAM* fsb_vgmstream;
STREAMFILE* temp_sf;
/* skip "fsb3adpc" */
sound_offset += 0x08;
sound_size -= 0x08;
temp_sf = setup_subfile_streamfile(sf, sound_offset, sound_size, "fsb");
if (!temp_sf) goto fail;
temp_sf->stream_index = 0;
fsb_vgmstream = init_vgmstream_fsb(temp_sf);
close_streamfile(temp_sf);
if (!fsb_vgmstream) goto fail;
fsb_vgmstream->meta_type = vgmstream->meta_type;
fsb_vgmstream->num_streams = vgmstream->num_streams;
vgmstream_force_loop(fsb_vgmstream, loop_flag, 0, fsb_vgmstream->num_samples);
read_string(fsb_vgmstream->stream_name, STREAM_NAME_SIZE, strings_offset + name_offset, sf);
close_vgmstream(vgmstream);
return fsb_vgmstream;
}
#ifdef VGM_USE_FFMPEG
case 0x30: { /* RIFF XMA */
uint8_t buf[0x100];
off_t riff_fmt_offset, riff_data_offset;
size_t bytes, riff_fmt_size, riff_data_size;
/* find "fmt" chunk */
if (!find_chunk_riff_le(sf, 0x666d7420, sound_offset + 0x0c, sound_size - 0x0c, &riff_fmt_offset, &riff_fmt_size))
goto fail;
/* find "data" chunk */
if (!find_chunk_riff_le(sf, 0x64617461, sound_offset + 0x0c, sound_size - 0x0c, &riff_data_offset, &riff_data_size))
goto fail;
bytes = ffmpeg_make_riff_xma_from_fmt_chunk(buf, 0x100, riff_fmt_offset, riff_fmt_size, riff_data_size, sf, 0);
vgmstream->codec_data = init_ffmpeg_header_offset(sf, buf, bytes, riff_data_offset, riff_data_size);
if (!vgmstream->codec_data) goto fail;
vgmstream->coding_type = coding_FFmpeg;
vgmstream->layout_type = layout_none;
xma_fix_raw_samples(vgmstream, sf, riff_data_offset, riff_data_size, riff_fmt_offset, 0, 0);
break;
}
#endif
#ifdef VGM_USE_MPEG
case 0x32: { /* MP3 */
coding_t mpeg_coding;
vgmstream->codec_data = init_mpeg(sf, sound_offset, &mpeg_coding, channels);
if (!vgmstream->codec_data) goto fail;
vgmstream->coding_type = mpeg_coding;
vgmstream->layout_type = layout_none;
break;
}
#endif
default:
goto fail;
}
if (codec != 0x21) /* name table is filled with garbage on PS2 for some reason */
read_string(vgmstream->stream_name, STREAM_NAME_SIZE, strings_offset + name_offset, sf);
if (!vgmstream_open_stream(vgmstream, sf, sound_offset))
goto fail;
return vgmstream;
fail:
close_vgmstream(vgmstream);
return NULL;
}

View File

@ -525,6 +525,7 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = {
init_vgmstream_lopu_fb,
init_vgmstream_lpcm_fb,
init_vgmstream_wbk,
init_vgmstream_wbk_nslb,
init_vgmstream_dsp_apex,
/* lowest priority metas (should go after all metas, and TXTH should go before raw formats) */

View File

@ -752,6 +752,7 @@ typedef enum {
meta_LOPU_FB,
meta_LPCM_FB,
meta_WBK,
meta_WBK_NSLB,
meta_DSP_APEX,
} meta_t;