2019-12-15 22:24:54 +01:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../coding/coding.h"
|
2022-05-01 20:34:58 +02:00
|
|
|
#include "../util/cri_utf.h"
|
2019-12-15 22:24:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* CSB (Cue Sheet Binary?) - CRI container of memory audio, often together with a .cpk wave bank */
|
2021-01-03 16:01:20 +01:00
|
|
|
VGMSTREAM* init_vgmstream_csb(STREAMFILE* sf) {
|
|
|
|
VGMSTREAM* vgmstream = NULL;
|
|
|
|
STREAMFILE* temp_sf = NULL;
|
2023-03-12 14:53:29 +01:00
|
|
|
uint32_t subfile_offset, subfile_size;
|
2022-05-01 20:34:58 +02:00
|
|
|
utf_context* utf = NULL;
|
|
|
|
utf_context* utf_sdl = NULL;
|
2021-01-03 16:01:20 +01:00
|
|
|
int total_subsongs, target_subsong = sf->stream_index;
|
2020-01-24 22:52:04 +01:00
|
|
|
uint8_t fmt = 0;
|
2021-09-21 18:29:32 +02:00
|
|
|
const char* stream_name = NULL;
|
2019-12-15 22:24:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* checks */
|
2021-01-03 16:01:20 +01:00
|
|
|
if (!is_id32be(0x00,sf, "@UTF"))
|
2019-12-15 22:24:54 +01:00
|
|
|
goto fail;
|
2023-03-12 14:53:29 +01:00
|
|
|
if (!check_extensions(sf, "csb"))
|
|
|
|
goto fail;
|
2019-12-15 22:24:54 +01:00
|
|
|
|
|
|
|
/* .csb is an early, simpler version of .acb+awk (see acb.c) used until ~2013?
|
|
|
|
* Can stream from .cpk but this only loads memory data. */
|
|
|
|
{
|
|
|
|
int rows, sdl_rows, sdl_row, i;
|
|
|
|
const char *name;
|
|
|
|
const char *row_name;
|
|
|
|
const char *sdl_name;
|
|
|
|
uint32_t sdl_offset, sdl_size, offset, size;
|
|
|
|
uint32_t table_offset = 0x00;
|
2020-01-24 22:52:04 +01:00
|
|
|
uint8_t ttype;
|
2019-12-15 22:24:54 +01:00
|
|
|
int found = 0;
|
|
|
|
|
|
|
|
|
2021-01-03 16:01:20 +01:00
|
|
|
utf = utf_open(sf, table_offset, &rows, &name);
|
2019-12-15 22:24:54 +01:00
|
|
|
if (!utf) goto fail;
|
|
|
|
|
|
|
|
if (strcmp(name, "TBLCSB") != 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* each TBLCSB row has a name and subtable with actual things:
|
2021-01-03 16:01:20 +01:00
|
|
|
* - INFO (TBL_INFO): table type/version, rarely ommited [Nights: Journey of Dreams (Wii)-some csb]
|
2019-12-15 22:24:54 +01:00
|
|
|
* - CUE (TBLCUE): base cues
|
|
|
|
* - SYNTH (TBLSYN): cue configs
|
|
|
|
* - SOUND_ELEMENT (TBLSDL): audio info/data (usually AAX)
|
|
|
|
* - ISAAC (TBLISC): 3D config
|
|
|
|
* - VOICE_LIMIT_GROUP (TBLVLG): system info?
|
2021-01-03 16:01:20 +01:00
|
|
|
* Subtable can be empty but still appear (0 rows).
|
2019-12-15 22:24:54 +01:00
|
|
|
*/
|
2021-01-03 16:01:20 +01:00
|
|
|
sdl_row = -1;
|
|
|
|
for (i = 0; i < rows; i++) {
|
|
|
|
if (!utf_query_string(utf, i, "name", &row_name))
|
|
|
|
goto fail;
|
|
|
|
if (strcmp(row_name, "SOUND_ELEMENT") == 0) {
|
|
|
|
sdl_row = i; /* usually 2 or 3 */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sdl_row < 0)
|
2019-12-15 22:24:54 +01:00
|
|
|
goto fail;
|
2021-01-03 16:01:20 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* read SOUND_ELEMENT table */
|
2020-01-24 22:52:04 +01:00
|
|
|
if (!utf_query_u8(utf, sdl_row, "ttype", &ttype) || ttype != 4)
|
2019-12-15 22:24:54 +01:00
|
|
|
goto fail;
|
|
|
|
if (!utf_query_data(utf, sdl_row, "utf", &sdl_offset, &sdl_size))
|
|
|
|
goto fail;
|
|
|
|
|
2021-01-03 16:01:20 +01:00
|
|
|
utf_sdl = utf_open(sf, sdl_offset, &sdl_rows, &sdl_name);
|
2019-12-15 22:24:54 +01:00
|
|
|
if (!utf_sdl) goto fail;
|
|
|
|
|
|
|
|
if (strcmp(sdl_name, "TBLSDL") != 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
total_subsongs = 0;
|
|
|
|
if (target_subsong == 0) target_subsong = 1;
|
|
|
|
|
|
|
|
/* get target subsong */
|
|
|
|
for (i = 0; i < sdl_rows; i++) {
|
2020-01-24 22:52:04 +01:00
|
|
|
uint8_t stream_flag;
|
2019-12-15 22:24:54 +01:00
|
|
|
|
2020-01-24 22:52:04 +01:00
|
|
|
if (!utf_query_u8(utf_sdl, i, "stmflg", &stream_flag))
|
2019-12-15 22:24:54 +01:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* only internal data for now (when 1 this refers to a .cpk subfile probably using "name", has size 0) */
|
2020-01-24 22:52:04 +01:00
|
|
|
if (stream_flag)
|
2019-12-15 22:24:54 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
total_subsongs++;
|
|
|
|
if (total_subsongs == target_subsong && !found) {
|
|
|
|
|
|
|
|
if (!utf_query_string(utf_sdl, i, "name", &stream_name))
|
|
|
|
goto fail;
|
|
|
|
if (!utf_query_data(utf_sdl, i, "data", &offset, &size))
|
|
|
|
goto fail;
|
2020-01-24 22:52:04 +01:00
|
|
|
if (!utf_query_u8(utf_sdl, i, "fmt", &fmt))
|
2019-12-15 22:24:54 +01:00
|
|
|
goto fail;
|
|
|
|
/* also nch/sfreq/nsmpl info */
|
|
|
|
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) goto fail;
|
|
|
|
if (target_subsong < 0 || target_subsong > total_subsongs || total_subsongs < 1) goto fail;
|
2019-12-27 01:48:45 +01:00
|
|
|
|
2019-12-15 22:24:54 +01:00
|
|
|
subfile_offset = /*sdl_offset +*/ offset;
|
|
|
|
subfile_size = size;
|
|
|
|
|
|
|
|
/* column exists but can be empty */
|
|
|
|
if (subfile_size == 0)
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2023-03-12 14:53:29 +01:00
|
|
|
//;VGM_LOG("CSB: subfile offset=%x + %x\n", subfile_offset, subfile_size);
|
2021-01-03 16:01:20 +01:00
|
|
|
temp_sf = setup_subfile_streamfile(sf, subfile_offset, subfile_size, "aax");
|
2019-12-15 22:24:54 +01:00
|
|
|
if (!temp_sf) goto fail;
|
|
|
|
|
|
|
|
switch(fmt) {
|
|
|
|
case 0: /* AAX */
|
|
|
|
case 6: /* HCA */
|
|
|
|
vgmstream = init_vgmstream_aax(temp_sf);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
break;
|
|
|
|
|
2023-03-12 14:53:29 +01:00
|
|
|
case 2: /* AHX */
|
|
|
|
vgmstream = init_vgmstream_utf_ahx(temp_sf);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
break;
|
|
|
|
|
2019-12-15 22:24:54 +01:00
|
|
|
case 4: /* ADPCM_WII */
|
|
|
|
vgmstream = init_vgmstream_utf_dsp(temp_sf);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
VGM_LOG("CSB: unknown format %i\n", fmt);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
vgmstream->num_streams = total_subsongs;
|
|
|
|
strncpy(vgmstream->stream_name, stream_name, STREAM_NAME_SIZE-1);
|
|
|
|
|
|
|
|
utf_close(utf);
|
|
|
|
utf_close(utf_sdl);
|
|
|
|
close_streamfile(temp_sf);
|
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
utf_close(utf);
|
|
|
|
utf_close(utf_sdl);
|
|
|
|
close_streamfile(temp_sf);
|
|
|
|
close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|
2023-03-12 14:53:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* CRI's UTF wrapper around AHX [Yakuza: Dead Souls (PS3)-voices] */
|
|
|
|
VGMSTREAM* init_vgmstream_utf_ahx(STREAMFILE* sf) {
|
|
|
|
VGMSTREAM* vgmstream = NULL;
|
|
|
|
STREAMFILE* temp_sf = NULL;
|
|
|
|
uint32_t subfile_offset, subfile_size;
|
|
|
|
utf_context* utf = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
/* checks */
|
|
|
|
if (!is_id32be(0x00,sf, "@UTF"))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* .aax: assumed
|
|
|
|
* (extensionless): extracted names inside csb/cpk often don't have extensions */
|
|
|
|
if (!check_extensions(sf, "aax,"))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* contains a simple UTF table with one row and offset+size info */
|
|
|
|
{
|
|
|
|
int rows;
|
|
|
|
const char* name;
|
|
|
|
uint32_t table_offset = 0x00;
|
|
|
|
|
|
|
|
utf = utf_open(sf, table_offset, &rows, &name);
|
|
|
|
if (!utf) goto fail;
|
|
|
|
|
|
|
|
if (strcmp(name, "AHX") != 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (rows != 1)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (!utf_query_data(utf, 0, "data", &subfile_offset, &subfile_size))
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
//;VGM_LOG("UTF_AHX: subfile offset=%x + %x\n", subfile_offset, subfile_size);
|
|
|
|
temp_sf = setup_subfile_streamfile(sf, subfile_offset, subfile_size, "ahx");
|
|
|
|
if (!temp_sf) goto fail;
|
|
|
|
|
|
|
|
vgmstream = init_vgmstream_ahx(temp_sf);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
utf_close(utf);
|
|
|
|
close_streamfile(temp_sf);
|
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
utf_close(utf);
|
|
|
|
close_streamfile(temp_sf);
|
|
|
|
close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|