2020-05-25 20:57:29 +02:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../coding/coding.h"
|
2022-05-01 20:34:58 +02:00
|
|
|
#include "../util/cri_utf.h"
|
2020-05-25 20:57:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* ACB (Atom Cue sheet Binary) - CRI container of memory audio, often together with a .awb wave bank */
|
|
|
|
VGMSTREAM* init_vgmstream_acb(STREAMFILE* sf) {
|
|
|
|
VGMSTREAM* vgmstream = NULL;
|
|
|
|
STREAMFILE* temp_sf = NULL;
|
2021-09-12 20:08:55 +02:00
|
|
|
uint32_t subfile_offset;
|
|
|
|
uint32_t subfile_size;
|
|
|
|
utf_context* utf = NULL;
|
2020-05-25 20:57:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* checks */
|
2021-09-12 20:08:55 +02:00
|
|
|
if (!is_id32be(0x00,sf, "@UTF"))
|
2020-05-25 20:57:29 +02:00
|
|
|
goto fail;
|
2022-07-07 23:13:35 +02:00
|
|
|
/* mainly for bigger files (utf lib checks smaller) */
|
|
|
|
if (read_u32be(0x04,sf) + 0x08 != get_streamfile_size(sf))
|
|
|
|
goto fail;
|
|
|
|
|
2021-09-12 20:08:55 +02:00
|
|
|
if (!check_extensions(sf, "acb"))
|
2020-05-25 20:57:29 +02:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* .acb is a cue sheet that uses @UTF (CRI's generic table format) to store row/columns
|
2020-11-15 00:11:48 +01:00
|
|
|
* with complex info (cues, sequences, spatial info, etc). It can store a memory .awb
|
2020-05-25 20:57:29 +02:00
|
|
|
* (our target here), or reference external/streamed .awb (loaded elsewhere)
|
|
|
|
* we only want .awb with actual waves but may use .acb to get names */
|
|
|
|
{
|
|
|
|
int rows;
|
|
|
|
const char* name;
|
|
|
|
uint32_t offset = 0, size = 0;
|
|
|
|
uint32_t table_offset = 0x00;
|
|
|
|
|
|
|
|
utf = utf_open(sf, table_offset, &rows, &name);
|
|
|
|
if (!utf) goto fail;
|
|
|
|
|
|
|
|
if (rows != 1 || strcmp(name, "Header") != 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (!utf_query_data(utf, 0, "AwbFile", &offset, &size))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
subfile_offset = table_offset + offset;
|
|
|
|
subfile_size = size;
|
|
|
|
|
|
|
|
/* column exists but can be empty */
|
2021-09-12 20:08:55 +02:00
|
|
|
if (subfile_size == 0) {
|
|
|
|
vgm_logi("ACB: bank has no subsongs (ignore)\n");
|
2020-05-25 20:57:29 +02:00
|
|
|
goto fail;
|
2021-09-12 20:08:55 +02:00
|
|
|
}
|
2020-05-25 20:57:29 +02:00
|
|
|
}
|
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
//;VGM_LOG("acb: subfile offset=%lx + %x\n", subfile_offset, subfile_size);
|
2020-05-25 20:57:29 +02:00
|
|
|
|
|
|
|
temp_sf = setup_subfile_streamfile(sf, subfile_offset,subfile_size, "awb");
|
|
|
|
if (!temp_sf) goto fail;
|
|
|
|
|
2021-09-12 20:08:55 +02:00
|
|
|
if (is_id32be(0x00, temp_sf, "CPK ")) {
|
2020-11-15 00:11:48 +01:00
|
|
|
vgmstream = init_vgmstream_cpk_memory(temp_sf, sf); /* older */
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
vgmstream = init_vgmstream_awb_memory(temp_sf, sf); /* newer */
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
}
|
2020-05-25 20:57:29 +02:00
|
|
|
|
2020-11-15 00:11:48 +01:00
|
|
|
/* name-loading for this for memory .awb will be called from init_vgmstream_awb/cpk_memory */
|
2020-05-25 20:57:29 +02:00
|
|
|
|
|
|
|
utf_close(utf);
|
|
|
|
close_streamfile(temp_sf);
|
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
utf_close(utf);
|
|
|
|
close_streamfile(temp_sf);
|
|
|
|
close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ************************************** */
|
|
|
|
|
2020-05-25 23:51:27 +02:00
|
|
|
/* extra config for .acb with lots of sounds, since there is a lot of IO back and forth,
|
|
|
|
* ex. +7000 acb+awb subsongs in Ultra Despair Girls (PC) */
|
|
|
|
//TODO: could pre-load all sections first, but needs cache for multiple subsongs (+semaphs, if multiple read the same thing)
|
2021-09-15 23:13:06 +02:00
|
|
|
#define ACB_TABLE_BUFFER_CUENAME 0x4000
|
|
|
|
#define ACB_TABLE_BUFFER_CUE 0x2000
|
2020-09-18 23:47:28 +02:00
|
|
|
#define ACB_TABLE_BUFFER_BLOCKSEQUENCE 0x8000
|
2020-05-25 23:51:27 +02:00
|
|
|
#define ACB_TABLE_BUFFER_BLOCK 0x8000
|
2021-09-15 23:13:06 +02:00
|
|
|
#define ACB_TABLE_BUFFER_SEQUENCE 0x4000
|
|
|
|
#define ACB_TABLE_BUFFER_TRACK 0x1000
|
|
|
|
#define ACB_TABLE_BUFFER_TRACKCOMMAND 0x2000
|
|
|
|
#define ACB_TABLE_BUFFER_SYNTH 0x4000
|
|
|
|
#define ACB_TABLE_BUFFER_WAVEFORM 0x4000
|
2023-11-11 12:39:30 +01:00
|
|
|
#define ACB_TABLE_BUFFER_WAVEFORMEXTENSIONDATA 0x1000
|
2020-05-25 23:51:27 +02:00
|
|
|
|
|
|
|
#define ACB_MAX_NAMELIST 255
|
|
|
|
#define ACB_MAX_NAME 1024 /* even more is possible in rare cases [Senran Kagura Burst Re:Newal (PC)] */
|
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
#define ACB_MAX_BUFFER 0x8000
|
2020-05-25 20:57:29 +02:00
|
|
|
|
2021-07-29 22:29:49 +02:00
|
|
|
static STREAMFILE* setup_acb_streamfile(STREAMFILE* sf, size_t buffer_size) {
|
2020-05-25 20:57:29 +02:00
|
|
|
STREAMFILE* new_sf = NULL;
|
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
new_sf = reopen_streamfile(sf, buffer_size);
|
2020-05-25 20:57:29 +02:00
|
|
|
return new_sf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
typedef struct {
|
|
|
|
uint16_t CueIndex;
|
|
|
|
const char* CueName;
|
|
|
|
} CueName_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint8_t ReferenceType;
|
|
|
|
uint16_t ReferenceIndex;
|
|
|
|
} Cue_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint16_t NumTracks;
|
|
|
|
uint32_t TrackIndex_offset;
|
|
|
|
uint32_t TrackIndex_size;
|
|
|
|
uint16_t NumBlocks;
|
|
|
|
uint32_t BlockIndex_offset;
|
|
|
|
uint32_t BlockIndex_size;
|
|
|
|
} BlockSequence_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint16_t NumTracks;
|
|
|
|
uint32_t TrackIndex_offset;
|
|
|
|
uint32_t TrackIndex_size;
|
|
|
|
} Block_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint16_t NumTracks;
|
|
|
|
uint32_t TrackIndex_offset;
|
|
|
|
uint32_t TrackIndex_size;
|
2021-09-19 23:51:59 +02:00
|
|
|
//uint16_t ActionTrackStartIndex;
|
|
|
|
//uint16_t NumActionTracks;
|
2021-09-15 23:13:06 +02:00
|
|
|
uint8_t Type;
|
|
|
|
} Sequence_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint16_t EventIndex;
|
|
|
|
} Track_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint32_t Command_offset;
|
|
|
|
uint32_t Command_size;
|
|
|
|
} TrackCommand_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint8_t Type;
|
|
|
|
uint32_t ReferenceItems_offset;
|
|
|
|
uint32_t ReferenceItems_size;
|
|
|
|
} Synth_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint16_t Id;
|
|
|
|
uint16_t PortNo;
|
|
|
|
uint8_t Streaming;
|
2023-11-11 12:39:30 +01:00
|
|
|
uint8_t LoopFlag;
|
|
|
|
uint16_t ExtensionData;
|
2021-09-15 23:13:06 +02:00
|
|
|
} Waveform_t;
|
|
|
|
|
2023-11-11 12:39:30 +01:00
|
|
|
typedef struct {
|
|
|
|
uint32_t LoopStart;
|
|
|
|
uint32_t LoopEnd;
|
|
|
|
} WaveformExtensionData_t;
|
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
|
2020-05-25 20:57:29 +02:00
|
|
|
typedef struct {
|
|
|
|
STREAMFILE* acbFile; /* original reference, don't close */
|
|
|
|
|
|
|
|
/* keep track of these tables so they can be closed when done */
|
2021-09-12 20:08:55 +02:00
|
|
|
utf_context* Header;
|
2021-09-19 23:51:59 +02:00
|
|
|
utf_context* CueNames;
|
|
|
|
|
2020-05-25 20:57:29 +02:00
|
|
|
STREAMFILE* CueNameSf;
|
|
|
|
STREAMFILE* CueSf;
|
2020-09-18 23:47:28 +02:00
|
|
|
STREAMFILE* BlockSequenceSf;
|
2020-05-25 20:57:29 +02:00
|
|
|
STREAMFILE* BlockSf;
|
|
|
|
STREAMFILE* SequenceSf;
|
|
|
|
STREAMFILE* TrackSf;
|
|
|
|
STREAMFILE* TrackCommandSf;
|
|
|
|
STREAMFILE* SynthSf;
|
|
|
|
STREAMFILE* WaveformSf;
|
2023-11-11 12:39:30 +01:00
|
|
|
STREAMFILE* WaveformExtensionDataSf;
|
2020-05-25 20:57:29 +02:00
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
Cue_t* Cue;
|
|
|
|
CueName_t* CueName;
|
|
|
|
BlockSequence_t* BlockSequence;
|
|
|
|
Block_t* Block;
|
|
|
|
Sequence_t* Sequence;
|
|
|
|
Track_t* Track;
|
|
|
|
TrackCommand_t* TrackCommand;
|
|
|
|
Synth_t* Synth;
|
|
|
|
Waveform_t* Waveform;
|
2023-11-11 12:39:30 +01:00
|
|
|
WaveformExtensionData_t* WaveformExtensionData;
|
2021-09-15 23:13:06 +02:00
|
|
|
|
|
|
|
int Cue_rows;
|
|
|
|
int CueName_rows;
|
|
|
|
int BlockSequence_rows;
|
|
|
|
int Block_rows;
|
|
|
|
int Sequence_rows;
|
|
|
|
int Track_rows;
|
|
|
|
int TrackCommand_rows;
|
|
|
|
int Synth_rows;
|
|
|
|
int Waveform_rows;
|
2023-11-11 12:39:30 +01:00
|
|
|
int WaveformExtensionData_rows;
|
2021-09-15 23:13:06 +02:00
|
|
|
|
2020-05-25 20:57:29 +02:00
|
|
|
/* config */
|
|
|
|
int is_memory;
|
|
|
|
int target_waveid;
|
2021-06-20 13:45:01 +02:00
|
|
|
int target_port;
|
2020-05-25 20:57:29 +02:00
|
|
|
|
|
|
|
/* to avoid infinite/circular references (AtomViewer crashes otherwise) */
|
|
|
|
int synth_depth;
|
|
|
|
int sequence_depth;
|
|
|
|
|
2023-11-11 12:39:30 +01:00
|
|
|
/* name/config stuff */
|
|
|
|
int16_t waveform_index;
|
2020-05-25 20:57:29 +02:00
|
|
|
int16_t cuename_index;
|
2021-09-12 20:08:55 +02:00
|
|
|
const char* cuename_name;
|
2020-05-25 20:57:29 +02:00
|
|
|
int awbname_count;
|
2020-05-25 23:51:27 +02:00
|
|
|
int16_t awbname_list[ACB_MAX_NAMELIST];
|
|
|
|
char name[ACB_MAX_NAME];
|
2020-05-25 20:57:29 +02:00
|
|
|
} acb_header;
|
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
|
|
|
|
|
2020-05-25 23:51:27 +02:00
|
|
|
static int open_utf_subtable(acb_header* acb, STREAMFILE* *TableSf, utf_context* *Table, const char* TableName, int* rows, int buffer) {
|
2020-05-25 20:57:29 +02:00
|
|
|
uint32_t offset = 0;
|
|
|
|
|
|
|
|
/* already loaded */
|
|
|
|
if (*Table != NULL)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (!utf_query_data(acb->Header, 0, TableName, &offset, NULL))
|
|
|
|
goto fail;
|
|
|
|
|
2020-05-25 23:51:27 +02:00
|
|
|
*TableSf = setup_acb_streamfile(acb->acbFile, buffer);
|
2020-05-25 20:57:29 +02:00
|
|
|
if (!*TableSf) goto fail;
|
|
|
|
|
|
|
|
*Table = utf_open(*TableSf, offset, rows, NULL);
|
|
|
|
if (!*Table) goto fail;
|
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
//;VGM_LOG("acb: loaded table %s\n", TableName);
|
2020-05-25 20:57:29 +02:00
|
|
|
return 1;
|
|
|
|
fail:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-25 23:51:27 +02:00
|
|
|
//todo safeops, avoid recalc lens
|
|
|
|
static void acb_cat(char* dst, int dst_max, const char* src) {
|
|
|
|
int dst_len = strlen(dst);
|
|
|
|
int src_len = strlen(dst);
|
|
|
|
if (dst_len + src_len > dst_max - 1)
|
|
|
|
return;
|
|
|
|
strcat(dst, src);
|
|
|
|
}
|
|
|
|
static void acb_cpy(char* dst, int dst_max, const char* src) {
|
|
|
|
int src_len = strlen(dst);
|
|
|
|
if (src_len > dst_max - 1)
|
|
|
|
return;
|
|
|
|
strcpy(dst, src);
|
|
|
|
}
|
2020-05-25 20:57:29 +02:00
|
|
|
|
2020-09-18 23:47:28 +02:00
|
|
|
static void add_acb_name(acb_header* acb, int8_t Streaming) {
|
2021-09-15 23:13:06 +02:00
|
|
|
if (!acb->cuename_name) {
|
2021-09-19 23:51:59 +02:00
|
|
|
//;VGM_LOG("acb: no name\n");
|
2021-09-15 23:13:06 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-05-25 20:57:29 +02:00
|
|
|
|
|
|
|
/* ignore name repeats */
|
|
|
|
if (acb->awbname_count) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < acb->awbname_count; i++) {
|
|
|
|
if (acb->awbname_list[i] == acb->cuename_index)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-25 23:51:27 +02:00
|
|
|
/* since waveforms can be reused by cues, multiple names are a thing */
|
2020-05-25 20:57:29 +02:00
|
|
|
if (acb->awbname_count) {
|
2020-05-25 23:51:27 +02:00
|
|
|
acb_cat(acb->name, sizeof(acb->name), "; ");
|
|
|
|
acb_cat(acb->name, sizeof(acb->name), acb->cuename_name);
|
2020-05-25 20:57:29 +02:00
|
|
|
}
|
|
|
|
else {
|
2020-05-25 23:51:27 +02:00
|
|
|
acb_cpy(acb->name, sizeof(acb->name), acb->cuename_name);
|
2020-05-25 20:57:29 +02:00
|
|
|
}
|
2020-09-18 23:47:28 +02:00
|
|
|
if (Streaming == 2 && acb->is_memory) {
|
2020-05-25 23:51:27 +02:00
|
|
|
acb_cat(acb->name, sizeof(acb->name), " [pre]");
|
2020-05-25 20:57:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
acb->awbname_list[acb->awbname_count] = acb->cuename_index;
|
|
|
|
acb->awbname_count++;
|
2020-05-25 23:51:27 +02:00
|
|
|
if (acb->awbname_count >= ACB_MAX_NAMELIST)
|
|
|
|
acb->awbname_count = ACB_MAX_NAMELIST - 1; /* ??? */
|
2020-05-25 20:57:29 +02:00
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
//;VGM_LOG("acb: found cue for waveid=%i: %s\n", acb->target_waveid, acb->cuename_name);
|
2020-05-25 20:57:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
/*****************************************************************************/
|
2020-09-18 23:47:28 +02:00
|
|
|
/* OBJECT HANDLERS */
|
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
static int preload_acb_waveform(acb_header* acb) {
|
2021-09-19 23:51:59 +02:00
|
|
|
utf_context* Table = NULL;
|
2021-09-15 23:13:06 +02:00
|
|
|
int* p_rows = &acb->Waveform_rows;
|
2023-11-11 12:39:30 +01:00
|
|
|
int i, c_Id, c_MemoryAwbId, c_StreamAwbId, c_StreamAwbPortNo, c_Streaming, c_LoopFlag, c_ExtensionData;
|
2020-05-25 20:57:29 +02:00
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
if (*p_rows)
|
|
|
|
return 1;
|
|
|
|
if (!open_utf_subtable(acb, &acb->WaveformSf, &Table, "WaveformTable", p_rows, ACB_TABLE_BUFFER_WAVEFORM))
|
2020-05-25 20:57:29 +02:00
|
|
|
goto fail;
|
2021-09-15 23:13:06 +02:00
|
|
|
if (!*p_rows)
|
|
|
|
return 1;
|
2021-09-19 23:51:59 +02:00
|
|
|
//;VGM_LOG("acb: preload Waveform=%i\n", *p_rows);
|
2021-09-15 23:13:06 +02:00
|
|
|
|
|
|
|
acb->Waveform = malloc(*p_rows * sizeof(Waveform_t));
|
|
|
|
if (!acb->Waveform) goto fail;
|
|
|
|
|
|
|
|
c_Id = utf_get_column(Table, "Id");
|
|
|
|
c_MemoryAwbId = utf_get_column(Table, "MemoryAwbId");
|
|
|
|
c_StreamAwbId = utf_get_column(Table, "StreamAwbId");
|
|
|
|
c_StreamAwbPortNo = utf_get_column(Table, "StreamAwbPortNo");
|
|
|
|
c_Streaming = utf_get_column(Table, "Streaming");
|
2023-11-11 12:39:30 +01:00
|
|
|
c_LoopFlag = utf_get_column(Table, "LoopFlag");
|
|
|
|
c_ExtensionData = utf_get_column(Table, "ExtensionData");
|
2021-09-15 23:13:06 +02:00
|
|
|
|
|
|
|
for (i = 0; i < *p_rows; i++) {
|
|
|
|
Waveform_t* r = &acb->Waveform[i];
|
|
|
|
|
|
|
|
if (!utf_query_col_u16(Table, i, c_Id, &r->Id)) { /* older versions use Id */
|
|
|
|
if (acb->is_memory) {
|
|
|
|
utf_query_col_u16(Table, i, c_MemoryAwbId, &r->Id);
|
|
|
|
r->PortNo = 0xFFFF;
|
|
|
|
} else {
|
|
|
|
utf_query_col_u16(Table, i, c_StreamAwbId, &r->Id);
|
|
|
|
utf_query_col_u16(Table, i, c_StreamAwbPortNo, &r->PortNo); /* assumed default 0 if doesn't exist */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
r->PortNo = 0xFFFF;
|
2020-05-25 20:57:29 +02:00
|
|
|
}
|
2021-09-15 23:13:06 +02:00
|
|
|
utf_query_col_u8(Table, i, c_Streaming, &r->Streaming);
|
2023-11-11 12:39:30 +01:00
|
|
|
utf_query_col_u8(Table, i, c_LoopFlag, &r->LoopFlag);
|
|
|
|
|
|
|
|
r->ExtensionData = -1;
|
|
|
|
utf_query_col_u16(Table, i, c_ExtensionData, &r->ExtensionData); /* optional for newer/Switch acb */
|
2020-05-25 20:57:29 +02:00
|
|
|
}
|
2021-09-15 23:13:06 +02:00
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
utf_close(Table);
|
2021-09-15 23:13:06 +02:00
|
|
|
return 1;
|
|
|
|
fail:
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: failed Waveform preload\n");
|
|
|
|
utf_close(Table);
|
2021-09-15 23:13:06 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int load_acb_waveform(acb_header* acb, uint16_t Index) {
|
|
|
|
Waveform_t* r;
|
2021-06-20 13:45:01 +02:00
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
if (!preload_acb_waveform(acb)) goto fail;
|
2023-11-11 12:39:30 +01:00
|
|
|
if (Index >= acb->Waveform_rows) goto fail;
|
2021-09-19 23:51:59 +02:00
|
|
|
r = &acb->Waveform[Index];
|
|
|
|
//;VGM_LOG("acb: Waveform[%i]: Id=%i, PortNo=%i, Streaming=%i\n", Index, r->Id, r->PortNo, r->Streaming);
|
2020-05-25 20:57:29 +02:00
|
|
|
|
|
|
|
/* not found but valid */
|
2021-09-15 23:13:06 +02:00
|
|
|
if (r->Id != acb->target_waveid)
|
2020-05-25 20:57:29 +02:00
|
|
|
return 1;
|
2021-06-20 13:45:01 +02:00
|
|
|
|
|
|
|
/* correct AWB port (check ignored if set to -1) */
|
2021-09-15 23:13:06 +02:00
|
|
|
if (acb->target_port >= 0 && r->PortNo != 0xFFFF && r->PortNo != acb->target_port)
|
2021-06-20 13:45:01 +02:00
|
|
|
return 1;
|
|
|
|
|
2020-05-25 20:57:29 +02:00
|
|
|
/* must match our target's (0=memory, 1=streaming, 2=memory (prefetch)+stream) */
|
2021-09-15 23:13:06 +02:00
|
|
|
if ((acb->is_memory && r->Streaming == 1) || (!acb->is_memory && r->Streaming == 0))
|
2020-05-25 20:57:29 +02:00
|
|
|
return 1;
|
|
|
|
|
2023-11-11 12:39:30 +01:00
|
|
|
/* save waveid <> Index translation */
|
|
|
|
acb->waveform_index = Index;
|
|
|
|
|
2020-05-25 20:57:29 +02:00
|
|
|
/* aaand finally get name (phew) */
|
2021-09-15 23:13:06 +02:00
|
|
|
add_acb_name(acb, r->Streaming);
|
2020-05-25 20:57:29 +02:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
fail:
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: failed Waveform %i\n", Index);
|
2020-05-25 20:57:29 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
2020-05-25 20:57:29 +02:00
|
|
|
/* define here for Synths pointing to Sequences */
|
2021-09-15 23:13:06 +02:00
|
|
|
static int load_acb_sequence(acb_header* acb, uint16_t Index);
|
|
|
|
|
|
|
|
static int preload_acb_synth(acb_header* acb) {
|
2021-09-19 23:51:59 +02:00
|
|
|
utf_context* Table = NULL;
|
2021-09-15 23:13:06 +02:00
|
|
|
int* p_rows = &acb->Synth_rows;
|
|
|
|
int i, c_Type, c_ReferenceItems;
|
|
|
|
|
|
|
|
if (*p_rows)
|
|
|
|
return 1;
|
|
|
|
if (!open_utf_subtable(acb, &acb->SynthSf, &Table, "SynthTable", p_rows, ACB_TABLE_BUFFER_SYNTH))
|
|
|
|
goto fail;
|
|
|
|
if (!*p_rows)
|
|
|
|
return 1;
|
2021-09-19 23:51:59 +02:00
|
|
|
//;VGM_LOG("acb: preload Synth=%i\n", *p_rows);
|
2021-09-15 23:13:06 +02:00
|
|
|
|
|
|
|
acb->Synth = malloc(*p_rows * sizeof(Synth_t));
|
|
|
|
if (!acb->Synth) goto fail;
|
|
|
|
|
|
|
|
c_Type = utf_get_column(Table, "Type");
|
|
|
|
c_ReferenceItems = utf_get_column(Table, "ReferenceItems");
|
|
|
|
|
|
|
|
for (i = 0; i < *p_rows; i++) {
|
|
|
|
Synth_t* r = &acb->Synth[i];
|
|
|
|
|
|
|
|
utf_query_col_u8(Table, i, c_Type, &r->Type);
|
|
|
|
utf_query_col_data(Table, i, c_ReferenceItems, &r->ReferenceItems_offset, &r->ReferenceItems_size);
|
2021-09-19 23:51:59 +02:00
|
|
|
/* CommandIndex: references SynthCommand[i], defines how index is used? */
|
2021-09-15 23:13:06 +02:00
|
|
|
}
|
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
utf_close(Table);
|
2021-09-15 23:13:06 +02:00
|
|
|
return 1;
|
|
|
|
fail:
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: failed Synth preload\n");
|
|
|
|
utf_close(Table);
|
2021-09-15 23:13:06 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-25 20:57:29 +02:00
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
static int load_acb_synth(acb_header* acb, uint16_t Index) {
|
|
|
|
Synth_t* r;
|
2021-09-19 23:51:59 +02:00
|
|
|
int i, count;
|
2021-09-15 23:13:06 +02:00
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
if (!preload_acb_synth(acb)) goto fail;
|
2023-11-11 12:39:30 +01:00
|
|
|
if (Index >= acb->Synth_rows) goto fail;
|
2021-09-19 23:51:59 +02:00
|
|
|
r = &acb->Synth[Index];
|
|
|
|
//;VGM_LOG("acb: Synth[%i]: Type=%x, ReferenceItems={%x,%x}\n", Index, r->Type, r->ReferenceItems_offset, r->ReferenceItems_size);
|
2020-05-25 20:57:29 +02:00
|
|
|
|
|
|
|
acb->synth_depth++;
|
|
|
|
|
2020-11-15 01:28:42 +01:00
|
|
|
/* sometimes 2 (ex. Yakuza 6) or even 3 (Street Fighter vs Tekken) */
|
|
|
|
if (acb->synth_depth > 3) {
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: Synth depth too high\n");
|
2020-11-15 01:28:42 +01:00
|
|
|
goto fail;
|
2020-05-25 20:57:29 +02:00
|
|
|
}
|
2020-11-15 00:11:48 +01:00
|
|
|
|
2020-09-18 23:47:28 +02:00
|
|
|
//todo .CommandIndex > CommandTable
|
2020-05-25 20:57:29 +02:00
|
|
|
|
|
|
|
/* Cue.ReferenceType 2 uses Synth.Type, while 3 always sets it to 0 and uses Sequence.Type instead
|
|
|
|
* Both look the same and probably affect which item in the ReferenceItems list is picked:
|
|
|
|
* - 0: polyphonic (1 item)
|
|
|
|
* - 1: sequential (1 to N?)
|
|
|
|
* - 2: shuffle (1 from N?)
|
|
|
|
* - 3: random (1 from N?)
|
|
|
|
* - 4: random no repeat
|
|
|
|
* - 5: switch game variable
|
|
|
|
* - 6: combo sequential
|
|
|
|
* - 7: switch selector
|
|
|
|
* - 8: track transition by selector
|
|
|
|
* - other: undefined?
|
|
|
|
* Since we want to find all possible Waveforms that could match our id, we ignore Type and just parse all ReferenceItems.
|
|
|
|
*/
|
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
count = r->ReferenceItems_size / 0x04;
|
2020-05-25 20:57:29 +02:00
|
|
|
for (i = 0; i < count; i++) {
|
2021-09-19 23:51:59 +02:00
|
|
|
uint16_t item_type = read_u16be(r->ReferenceItems_offset + i*0x04 + 0x00, acb->SynthSf);
|
|
|
|
uint16_t item_index = read_u16be(r->ReferenceItems_offset + i*0x04 + 0x02, acb->SynthSf);
|
|
|
|
//;VGM_LOG("acb: Synth.ReferenceItem: type=%x, index=%x\n", item_type, item_index);
|
2020-05-25 20:57:29 +02:00
|
|
|
|
2020-09-18 23:47:28 +02:00
|
|
|
switch(item_type) {
|
2020-05-25 20:57:29 +02:00
|
|
|
case 0x00: /* no reference */
|
|
|
|
count = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x01: /* Waveform (most common) */
|
2020-09-18 23:47:28 +02:00
|
|
|
if (!load_acb_waveform(acb, item_index))
|
2020-05-25 20:57:29 +02:00
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x02: /* Synth, possibly random (rare, found in Sonic Lost World with ReferenceType 2) */
|
2020-09-18 23:47:28 +02:00
|
|
|
if (!load_acb_synth(acb, item_index))
|
2020-05-25 20:57:29 +02:00
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x03: /* Sequence of Synths w/ % in Synth.TrackValues (rare, found in Sonic Lost World with ReferenceType 2) */
|
2020-09-18 23:47:28 +02:00
|
|
|
if (!load_acb_sequence(acb, item_index))
|
2020-05-25 20:57:29 +02:00
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
2020-09-18 23:47:28 +02:00
|
|
|
/* others: same as cue's ReferenceType? */
|
|
|
|
|
2020-05-25 20:57:29 +02:00
|
|
|
case 0x06: /* this seems to point to Synth but results don't make sense (rare, from Sonic Lost World) */
|
|
|
|
default: /* undefined/crashes AtomViewer */
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: unknown Synth.ReferenceItem type %x at %x + %x\n", item_type, r->ReferenceItems_offset, r->ReferenceItems_size);
|
2020-05-25 20:57:29 +02:00
|
|
|
count = 0; /* force end without failing */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
acb->synth_depth--;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
fail:
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: failed Synth %i\n", Index);
|
2020-05-25 20:57:29 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
/*****************************************************************************/
|
2020-05-25 20:57:29 +02:00
|
|
|
|
2020-09-18 23:47:28 +02:00
|
|
|
static int load_acb_command_tlvs(acb_header* acb, STREAMFILE* sf, uint32_t Command_offset, uint32_t Command_size) {
|
|
|
|
uint16_t tlv_code, tlv_type, tlv_index;
|
|
|
|
uint8_t tlv_size;
|
2021-09-15 23:13:06 +02:00
|
|
|
uint32_t pos = 0;
|
|
|
|
uint32_t max_pos = Command_size;
|
2020-09-18 23:47:28 +02:00
|
|
|
|
|
|
|
/* read a (name)Command multiple TLV data */
|
2021-09-15 23:13:06 +02:00
|
|
|
while (pos < max_pos) {
|
2021-09-19 23:51:59 +02:00
|
|
|
tlv_code = read_u16be(Command_offset + pos + 0x00, sf);
|
|
|
|
tlv_size = read_u8 (Command_offset + pos + 0x02, sf);
|
2021-09-15 23:13:06 +02:00
|
|
|
pos += 0x03;
|
2020-11-15 00:11:48 +01:00
|
|
|
|
2020-09-18 23:47:28 +02:00
|
|
|
/* There are around 160 codes (some unused), with things like set volume, pan, stop, mute, and so on.
|
|
|
|
* Multiple commands are linked and only "note on" seems to point so other objects, so maybe others
|
|
|
|
* apply to current object (since there is "note off" without reference. */
|
|
|
|
switch(tlv_code) {
|
|
|
|
case 2000: /* noteOn */
|
|
|
|
case 2003: /* noteOnWithNo plus 16b (null?) [rare, ex. PES 2014] */
|
2020-05-25 20:57:29 +02:00
|
|
|
if (tlv_size < 0x04) {
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: TLV with unknown size\n");
|
2020-05-25 20:57:29 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
tlv_type = read_u16be(Command_offset + pos + 0x00, sf); /* ReferenceItem */
|
|
|
|
tlv_index = read_u16be(Command_offset + pos + 0x02, sf);
|
|
|
|
//;VGM_LOG("acb: TLV at %x: type %x, index=%x\n", offset, tlv_type, tlv_index);
|
2020-05-25 20:57:29 +02:00
|
|
|
|
2020-09-18 23:47:28 +02:00
|
|
|
/* same as Synth's ReferenceItem type? */
|
2020-05-25 20:57:29 +02:00
|
|
|
switch(tlv_type) {
|
|
|
|
case 0x02: /* Synth (common) */
|
|
|
|
if (!load_acb_synth(acb, tlv_index))
|
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
2020-09-18 23:47:28 +02:00
|
|
|
case 0x03: /* Sequence (common, ex. Yakuza 6, Yakuza Kiwami 2) */
|
2020-05-25 20:57:29 +02:00
|
|
|
if (!load_acb_sequence(acb, tlv_index))
|
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: unknown TLV type %x at %x + %x\n", tlv_type, Command_offset + pos, tlv_size);
|
2021-09-15 23:13:06 +02:00
|
|
|
max_pos = 0; /* force end without failing */
|
2020-05-25 20:57:29 +02:00
|
|
|
break;
|
|
|
|
}
|
2020-09-18 23:47:28 +02:00
|
|
|
break;
|
2020-05-25 20:57:29 +02:00
|
|
|
|
2020-09-18 23:47:28 +02:00
|
|
|
case 2004: /* noteOnWithDuration */
|
|
|
|
/* same as the above plus extra field */
|
2021-09-19 23:51:59 +02:00
|
|
|
//;VGM_LOG("acb: TLV at %x: usable code %i?\n", offset-0x03, tlv_code);
|
2020-09-18 23:47:28 +02:00
|
|
|
break;
|
2020-05-25 20:57:29 +02:00
|
|
|
|
2020-09-18 23:47:28 +02:00
|
|
|
case 33: /* mute */
|
|
|
|
case 124: /* stopAtLoopEnd */
|
|
|
|
case 1000: /* noteOff */
|
|
|
|
case 1251: /* sequenceCallbackWithId */
|
|
|
|
case 1252: /* sequenceCallbackWithString */
|
|
|
|
case 1253: /* sequenceCallbackWithIdAndString */
|
|
|
|
case 2002: /* setSynthOrWaveform */
|
|
|
|
case 4051: /* transitionTrack */
|
|
|
|
case 7102: /* muteTrackAction */
|
|
|
|
case 7100: /* startAction */
|
|
|
|
case 7101: /* stopAction */
|
|
|
|
/* may be needed? */
|
2021-09-19 23:51:59 +02:00
|
|
|
//;VGM_LOG("acb: TLV at %x: check code %i?\n", offset-0x03, tlv_code);
|
2020-09-18 23:47:28 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0: /* no-op */
|
|
|
|
case 998: /* sequenceStartRandom (plays following note ons in random?)*/
|
|
|
|
case 999: /* sequenceStart (plays following note ons in sequence?) */
|
|
|
|
default: /* ignore others */
|
|
|
|
break;
|
2020-05-25 20:57:29 +02:00
|
|
|
}
|
2020-09-18 23:47:28 +02:00
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
pos += tlv_size;
|
2020-09-18 23:47:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
fail:
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: failed Command TLVs\n");
|
2020-09-18 23:47:28 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
/*****************************************************************************/
|
2020-09-18 23:47:28 +02:00
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
static int preload_acb_trackcommand(acb_header* acb) {
|
2021-09-19 23:51:59 +02:00
|
|
|
utf_context* Table = NULL;
|
2021-09-15 23:13:06 +02:00
|
|
|
int* p_rows = &acb->TrackCommand_rows;
|
|
|
|
int i, c_Command;
|
2020-09-18 23:47:28 +02:00
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
if (*p_rows)
|
|
|
|
return 1;
|
2021-09-19 23:51:59 +02:00
|
|
|
/* load either TrackEvent (>=v1.28) or Command (<=v1.27) */
|
2021-09-15 23:13:06 +02:00
|
|
|
if (!open_utf_subtable(acb, &acb->TrackCommandSf, &Table, "TrackEventTable", p_rows, ACB_TABLE_BUFFER_TRACKCOMMAND)) {
|
|
|
|
if (!open_utf_subtable(acb, &acb->TrackCommandSf, &Table, "CommandTable", p_rows, ACB_TABLE_BUFFER_TRACKCOMMAND))
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
if (!*p_rows)
|
|
|
|
return 1;
|
2021-09-19 23:51:59 +02:00
|
|
|
//;VGM_LOG("acb: preload TrackEvent/Command=%i\n", *p_rows);
|
2021-09-15 23:13:06 +02:00
|
|
|
|
|
|
|
acb->TrackCommand = malloc(*p_rows * sizeof(TrackCommand_t));
|
|
|
|
if (!acb->TrackCommand) goto fail;
|
|
|
|
|
|
|
|
c_Command = utf_get_column(Table, "Command");
|
|
|
|
|
|
|
|
for (i = 0; i < *p_rows; i++) {
|
|
|
|
TrackCommand_t* r = &acb->TrackCommand[i];
|
|
|
|
|
|
|
|
utf_query_col_data(Table, i, c_Command, &r->Command_offset, &r->Command_size);
|
|
|
|
}
|
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
utf_close(Table);
|
2021-09-15 23:13:06 +02:00
|
|
|
return 1;
|
|
|
|
fail:
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: failed TrackEvent/Command preload\n");
|
|
|
|
utf_close(Table);
|
2021-09-15 23:13:06 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int load_acb_trackcommand(acb_header* acb, uint16_t Index) {
|
|
|
|
TrackCommand_t* r;
|
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
if (!preload_acb_trackcommand(acb)) goto fail;
|
2023-11-11 12:39:30 +01:00
|
|
|
if (Index >= acb->TrackCommand_rows) goto fail;
|
2021-09-19 23:51:59 +02:00
|
|
|
r = &acb->TrackCommand[Index];
|
|
|
|
//;VGM_LOG("acb: TrackEvent/Command[%i]: Command={%x,%x}\n", Index, r->Command_offset, r->Command_size);
|
2021-09-15 23:13:06 +02:00
|
|
|
|
|
|
|
/* read Command's TLVs */
|
|
|
|
if (!load_acb_command_tlvs(acb, acb->TrackCommandSf, r->Command_offset, r->Command_size))
|
2020-09-18 23:47:28 +02:00
|
|
|
goto fail;
|
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
return 1;
|
|
|
|
fail:
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: failed TrackCommand %i\n", Index);
|
2021-09-15 23:13:06 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2020-09-18 23:47:28 +02:00
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
static int preload_acb_track(acb_header* acb) {
|
2021-09-19 23:51:59 +02:00
|
|
|
utf_context* Table = NULL;
|
2021-09-15 23:13:06 +02:00
|
|
|
int* p_rows = &acb->Track_rows;
|
|
|
|
int i, c_EventIndex;
|
|
|
|
|
|
|
|
if (*p_rows)
|
2020-09-18 23:47:28 +02:00
|
|
|
return 1;
|
2021-09-15 23:13:06 +02:00
|
|
|
if (!open_utf_subtable(acb, &acb->TrackSf, &Table, "TrackTable", p_rows, ACB_TABLE_BUFFER_CUE))
|
|
|
|
goto fail;
|
|
|
|
if (!*p_rows)
|
|
|
|
return 1;
|
2021-09-19 23:51:59 +02:00
|
|
|
//;VGM_LOG("acb: preload Track=%i\n", *p_rows);
|
2020-09-18 23:47:28 +02:00
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
acb->Track = malloc(*p_rows * sizeof(Track_t));
|
|
|
|
if (!acb->Track) goto fail;
|
|
|
|
|
|
|
|
c_EventIndex = utf_get_column(Table, "EventIndex");
|
|
|
|
|
|
|
|
for (i = 0; i < *p_rows; i++) {
|
|
|
|
Track_t* r = &acb->Track[i];
|
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
utf_query_col_u16(Table, i, c_EventIndex, &r->EventIndex);
|
|
|
|
/* TargetType: changes ACB target? */
|
|
|
|
/* CommandIndex: references TrackCommand[i], defines how index is used? */
|
2021-09-15 23:13:06 +02:00
|
|
|
}
|
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
utf_close(Table);
|
2021-09-15 23:13:06 +02:00
|
|
|
return 1;
|
|
|
|
fail:
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: failed Track preload\n");
|
|
|
|
utf_close(Table);
|
2021-09-15 23:13:06 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int load_acb_track(acb_header* acb, uint16_t Index) {
|
|
|
|
Track_t* r;
|
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
if (!preload_acb_track(acb)) goto fail;
|
2023-11-11 12:39:30 +01:00
|
|
|
if (Index >= acb->Track_rows) goto fail;
|
2021-09-19 23:51:59 +02:00
|
|
|
r = &acb->Track[Index];
|
|
|
|
//;VGM_LOG("acb: Track[%i]: EventIndex=%i\n", Index, r->EventIndex);
|
2021-09-15 23:13:06 +02:00
|
|
|
|
|
|
|
//todo CommandIndex?
|
|
|
|
|
|
|
|
/* happens with some odd track without anything useful */
|
|
|
|
if (r->EventIndex == 65535)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (!load_acb_trackcommand(acb, r->EventIndex))
|
2020-09-18 23:47:28 +02:00
|
|
|
goto fail;
|
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
return 1;
|
|
|
|
fail:
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: failed Track %i\n", Index);
|
2021-09-15 23:13:06 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
static int preload_acb_sequence(acb_header* acb) {
|
2021-09-19 23:51:59 +02:00
|
|
|
utf_context* Table = NULL;
|
2021-09-15 23:13:06 +02:00
|
|
|
int* p_rows = &acb->Sequence_rows;
|
2021-09-19 23:51:59 +02:00
|
|
|
int i, c_NumTracks, c_TrackIndex, c_Type;
|
2021-09-15 23:13:06 +02:00
|
|
|
|
|
|
|
if (*p_rows)
|
|
|
|
return 1;
|
|
|
|
if (!open_utf_subtable(acb, &acb->SequenceSf, &Table, "SequenceTable", p_rows, ACB_TABLE_BUFFER_SEQUENCE))
|
2020-09-18 23:47:28 +02:00
|
|
|
goto fail;
|
2021-09-15 23:13:06 +02:00
|
|
|
if (!*p_rows)
|
|
|
|
return 1;
|
2021-09-19 23:51:59 +02:00
|
|
|
//;VGM_LOG("acb: preload Sequence=%i\n", *p_rows);
|
2021-09-15 23:13:06 +02:00
|
|
|
|
|
|
|
acb->Sequence = malloc(*p_rows * sizeof(Sequence_t));
|
|
|
|
if (!acb->Sequence) goto fail;
|
|
|
|
|
|
|
|
c_NumTracks = utf_get_column(Table, "NumTracks");
|
|
|
|
c_TrackIndex = utf_get_column(Table, "TrackIndex");
|
2021-09-19 23:51:59 +02:00
|
|
|
//c_ActionTrackStartIndex = utf_get_column(Table, "ActionTrackStartIndex");
|
|
|
|
//c_NumActionTracks = utf_get_column(Table, "NumActionTracks");
|
2021-09-15 23:13:06 +02:00
|
|
|
c_Type = utf_get_column(Table, "Type");
|
|
|
|
|
|
|
|
for (i = 0; i < *p_rows; i++) {
|
|
|
|
Sequence_t* r = &acb->Sequence[i];
|
|
|
|
|
|
|
|
utf_query_col_u16(Table, i, c_NumTracks, &r->NumTracks);
|
|
|
|
utf_query_col_data(Table, i, c_TrackIndex, &r->TrackIndex_offset, &r->TrackIndex_size);
|
2021-09-19 23:51:59 +02:00
|
|
|
//utf_query_col_u16(Table, i, c_ActionTrackStartIndex, &r->ActionTrackStartIndex);
|
|
|
|
//utf_query_col_u16(Table, i, c_NumActionTracks, &r->NumActionTracks);
|
2021-09-15 23:13:06 +02:00
|
|
|
utf_query_col_u8(Table, i, c_Type, &r->Type);
|
2021-09-19 23:51:59 +02:00
|
|
|
/* CommandIndex: references SequenceCommand[i], defines how index is used? */
|
2021-09-15 23:13:06 +02:00
|
|
|
}
|
2020-05-25 20:57:29 +02:00
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
utf_close(Table);
|
2020-05-25 20:57:29 +02:00
|
|
|
return 1;
|
|
|
|
fail:
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: failed Sequence preload\n");
|
|
|
|
utf_close(Table);
|
2020-05-25 20:57:29 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
static int load_acb_sequence(acb_header* acb, uint16_t Index) {
|
|
|
|
Sequence_t* r;
|
2021-09-19 23:51:59 +02:00
|
|
|
int i;
|
2021-09-15 23:13:06 +02:00
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
if (!preload_acb_sequence(acb)) goto fail;
|
2023-11-11 12:39:30 +01:00
|
|
|
if (Index >= acb->Sequence_rows) goto fail;
|
2021-09-19 23:51:59 +02:00
|
|
|
r = &acb->Sequence[Index];
|
|
|
|
//;VGM_LOG("acb: Sequence[%i]: NumTracks=%i, TrackIndex={%x, %x}, Type=%x\n", Index, r->NumTracks, r->TrackIndex_offset, r->TrackIndex_size, r->Type);
|
2020-09-18 23:47:28 +02:00
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
//TODO most unknown types can be found in Ultra Despair Girls (PC)
|
2020-05-25 20:57:29 +02:00
|
|
|
|
|
|
|
acb->sequence_depth++;
|
|
|
|
|
|
|
|
if (acb->sequence_depth > 3) {
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: Sequence depth too high\n");
|
2020-05-25 20:57:29 +02:00
|
|
|
goto fail; /* max Sequence > Sequence > Sequence > Synth > Waveform (ex. Yakuza 6) */
|
|
|
|
}
|
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
#if 0
|
|
|
|
/* reference to ActionTrack[i..] */
|
2021-09-15 23:13:06 +02:00
|
|
|
if (r->NumActionTracks) {
|
|
|
|
VGM_LOG_ONCE("ACB: ignored ActionTrack[%i~%i]\n", r->ActionTrackStartIndex, r->NumActionTracks);
|
|
|
|
}
|
2021-09-19 23:51:59 +02:00
|
|
|
#endif
|
2021-09-15 23:13:06 +02:00
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
if (r->NumTracks * 0x02 > r->TrackIndex_size) { /* padding may exist */
|
|
|
|
VGM_LOG("acb: wrong Sequence.TrackIndex size\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
2021-09-15 23:13:06 +02:00
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
/* read Tracks inside Sequence */
|
|
|
|
switch(r->Type) {
|
|
|
|
/* types affect which item in the TrackIndex list is picked (see load_acb_synth) */
|
|
|
|
case 0: /* polyphonic (TrackIndex only) */
|
|
|
|
case 1: /* sequential (TrackIndex only) */
|
|
|
|
case 3: /* random (TrackIndex + TrackValues = int percent) */
|
|
|
|
case 4: /* random no repeat (TrackIndex + TrackValues = int percent) */
|
|
|
|
default:
|
|
|
|
for (i = 0; i < r->NumTracks; i++) {
|
|
|
|
int16_t TrackIndex_index = read_s16be(r->TrackIndex_offset + i*0x02, acb->SequenceSf);
|
2021-09-15 23:13:06 +02:00
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
if (!load_acb_track(acb, TrackIndex_index))
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
break;
|
2021-09-15 23:13:06 +02:00
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
//default:
|
|
|
|
// VGM_LOG_ONCE("ACB: unknown Sequence.Type=%x\n", r->Type);
|
|
|
|
// break;
|
2020-05-25 20:57:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
acb->sequence_depth--;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
fail:
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: failed Sequence %i\n", Index);
|
2020-05-25 20:57:29 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
static int preload_acb_block(acb_header* acb) {
|
2021-09-19 23:51:59 +02:00
|
|
|
utf_context* Table = NULL;
|
2021-09-15 23:13:06 +02:00
|
|
|
int* p_rows = &acb->Block_rows;
|
|
|
|
int i, c_NumTracks, c_TrackIndex;
|
|
|
|
|
|
|
|
if (*p_rows)
|
|
|
|
return 1;
|
|
|
|
if (!open_utf_subtable(acb, &acb->BlockSf, &Table, "BlockTable", p_rows, ACB_TABLE_BUFFER_BLOCK))
|
|
|
|
goto fail;
|
|
|
|
if (!*p_rows)
|
|
|
|
return 1;
|
2021-09-19 23:51:59 +02:00
|
|
|
//;VGM_LOG("acb: preload Block=%i\n", *p_rows);
|
2021-09-15 23:13:06 +02:00
|
|
|
|
|
|
|
acb->Block = malloc(*p_rows * sizeof(Block_t));
|
|
|
|
if (!acb->Block) goto fail;
|
|
|
|
|
|
|
|
c_NumTracks = utf_get_column(Table, "NumTracks");
|
|
|
|
c_TrackIndex = utf_get_column(Table, "TrackIndex");
|
|
|
|
|
|
|
|
for (i = 0; i < *p_rows; i++) {
|
|
|
|
Block_t* r = &acb->Block[i];
|
|
|
|
|
|
|
|
utf_query_col_u16(Table, i, c_NumTracks, &r->NumTracks);
|
|
|
|
utf_query_col_data(Table, i, c_TrackIndex, &r->TrackIndex_offset, &r->TrackIndex_size);
|
2021-09-19 23:51:59 +02:00
|
|
|
//todo .ActionTrackStartIndex/NumActionTracks > ?
|
2021-09-15 23:13:06 +02:00
|
|
|
}
|
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
utf_close(Table);
|
2021-09-15 23:13:06 +02:00
|
|
|
return 1;
|
|
|
|
fail:
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: failed Block preload\n");
|
|
|
|
utf_close(Table);
|
2021-09-15 23:13:06 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int load_acb_block(acb_header* acb, uint16_t Index) {
|
|
|
|
Block_t* r;
|
2021-09-19 23:51:59 +02:00
|
|
|
int i;
|
2020-05-25 20:57:29 +02:00
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
if (!preload_acb_block(acb)) goto fail;
|
2023-11-11 12:39:30 +01:00
|
|
|
if (Index >= acb->Block_rows) goto fail;
|
2021-09-19 23:51:59 +02:00
|
|
|
r = &acb->Block[Index];
|
|
|
|
//;VGM_LOG("acb: Block[%i]: NumTracks=%i, TrackIndex={%x, %x}\n", Index, r->NumTracks, r->TrackIndex_offset, r->TrackIndex_size);
|
2021-09-15 23:13:06 +02:00
|
|
|
|
|
|
|
if (r->NumTracks * 0x02 > r->TrackIndex_size) { /* padding may exist */
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: wrong Block.TrackIndex size\n");
|
2020-05-25 20:57:29 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
2020-11-15 00:11:48 +01:00
|
|
|
|
2020-05-25 20:57:29 +02:00
|
|
|
/* read Tracks inside Block */
|
2021-09-15 23:13:06 +02:00
|
|
|
for (i = 0; i < r->NumTracks; i++) {
|
2021-09-19 23:51:59 +02:00
|
|
|
int16_t TrackIndex_index = read_s16be(r->TrackIndex_offset + i*0x02, acb->BlockSf);
|
2020-05-25 20:57:29 +02:00
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
if (!load_acb_track(acb, TrackIndex_index))
|
2020-05-25 20:57:29 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
fail:
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: failed Block %i\n", Index);
|
2020-05-25 20:57:29 +02:00
|
|
|
return 0;
|
2020-09-18 23:47:28 +02:00
|
|
|
}
|
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
/*****************************************************************************/
|
2020-09-18 23:47:28 +02:00
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
static int preload_acb_blocksequence(acb_header* acb) {
|
2021-09-19 23:51:59 +02:00
|
|
|
utf_context* Table = NULL;
|
2021-09-15 23:13:06 +02:00
|
|
|
int* p_rows = &acb->BlockSequence_rows;
|
|
|
|
int i, c_NumTracks, c_TrackIndex, c_NumBlocks, c_BlockIndex;
|
|
|
|
|
|
|
|
if (*p_rows)
|
|
|
|
return 1;
|
|
|
|
if (!open_utf_subtable(acb, &acb->BlockSequenceSf, &Table, "BlockSequenceTable", p_rows, ACB_TABLE_BUFFER_BLOCKSEQUENCE))
|
|
|
|
goto fail;
|
|
|
|
if (!*p_rows)
|
|
|
|
return 1;
|
2021-09-19 23:51:59 +02:00
|
|
|
//;VGM_LOG("acb: preload BlockSequence=%i\n", *p_rows);
|
2021-09-15 23:13:06 +02:00
|
|
|
|
|
|
|
acb->BlockSequence = malloc(*p_rows * sizeof(BlockSequence_t));
|
|
|
|
if (!acb->BlockSequence) goto fail;
|
|
|
|
|
|
|
|
c_NumTracks = utf_get_column(Table, "NumTracks");
|
|
|
|
c_TrackIndex = utf_get_column(Table, "TrackIndex");
|
|
|
|
c_NumBlocks = utf_get_column(Table, "NumBlocks");
|
|
|
|
c_BlockIndex = utf_get_column(Table, "BlockIndex");
|
|
|
|
|
|
|
|
for (i = 0; i < *p_rows; i++) {
|
|
|
|
BlockSequence_t* r = &acb->BlockSequence[i];
|
|
|
|
|
|
|
|
utf_query_col_u16(Table, i, c_NumTracks, &r->NumTracks);
|
|
|
|
utf_query_col_data(Table, i, c_TrackIndex, &r->TrackIndex_offset, &r->TrackIndex_size);
|
|
|
|
utf_query_col_u16(Table, i, c_NumBlocks, &r->NumBlocks);
|
|
|
|
utf_query_col_data(Table, i, c_BlockIndex, &r->BlockIndex_offset, &r->BlockIndex_size);
|
|
|
|
}
|
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
utf_close(Table);
|
2021-09-15 23:13:06 +02:00
|
|
|
return 1;
|
|
|
|
fail:
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: failed BlockSequence preload\n");
|
|
|
|
utf_close(Table);
|
2021-09-15 23:13:06 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int load_acb_blocksequence(acb_header* acb, uint16_t Index) {
|
|
|
|
BlockSequence_t* r;
|
2021-09-19 23:51:59 +02:00
|
|
|
int i;
|
2020-09-18 23:47:28 +02:00
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
if (!preload_acb_blocksequence(acb)) goto fail;
|
2023-11-11 12:39:30 +01:00
|
|
|
if (Index >= acb->BlockSequence_rows) goto fail;
|
2021-09-19 23:51:59 +02:00
|
|
|
r = &acb->BlockSequence[Index];
|
|
|
|
//;VGM_LOG("acb: BlockSequence[%i]: NumTracks=%i, TrackIndex={%x, %x}, NumBlocks=%i, BlockIndex={%x, %x}\n", Index, r->NumTracks, r->TrackIndex_offset,r->TrackIndex_size, r->NumBlocks, r->BlockIndex_offset, r->BlockIndex_size);
|
2020-09-18 23:47:28 +02:00
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
if (r->NumTracks * 0x02 > r->TrackIndex_size) { /* padding may exist */
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: wrong BlockSequence.TrackIndex size\n");
|
2020-09-18 23:47:28 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read Tracks inside BlockSequence */
|
2021-09-15 23:13:06 +02:00
|
|
|
for (i = 0; i < r->NumTracks; i++) {
|
2021-09-19 23:51:59 +02:00
|
|
|
int16_t TrackIndex_index = read_s16be(r->TrackIndex_offset + i*0x02, acb->BlockSequenceSf);
|
2020-09-18 23:47:28 +02:00
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
if (!load_acb_track(acb, TrackIndex_index))
|
2020-09-18 23:47:28 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
if (r->NumBlocks * 0x02 > r->BlockIndex_size) {
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: wrong BlockSequence.BlockIndex size\n");
|
2020-09-18 23:47:28 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read Blocks inside BlockSequence */
|
2021-09-15 23:13:06 +02:00
|
|
|
for (i = 0; i < r->NumBlocks; i++) {
|
2021-09-19 23:51:59 +02:00
|
|
|
int16_t BlockIndex_index = read_s16be(r->BlockIndex_offset + i*0x02, acb->BlockSequenceSf);
|
2020-09-18 23:47:28 +02:00
|
|
|
|
|
|
|
if (!load_acb_block(acb, BlockIndex_index))
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
fail:
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: failed BlockSequence %i\n", Index);
|
2020-09-18 23:47:28 +02:00
|
|
|
return 0;
|
2020-05-25 20:57:29 +02:00
|
|
|
}
|
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
/*****************************************************************************/
|
2020-05-25 20:57:29 +02:00
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
static int preload_acb_cue(acb_header* acb) {
|
2021-09-19 23:51:59 +02:00
|
|
|
utf_context* Table = NULL;
|
2021-09-15 23:13:06 +02:00
|
|
|
int* p_rows = &acb->Cue_rows;
|
|
|
|
int i, c_ReferenceType, c_ReferenceIndex;
|
2020-05-25 20:57:29 +02:00
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
if (*p_rows)
|
|
|
|
return 1;
|
|
|
|
if (!open_utf_subtable(acb, &acb->CueSf, &Table, "CueTable", p_rows, ACB_TABLE_BUFFER_CUE))
|
2020-05-25 20:57:29 +02:00
|
|
|
goto fail;
|
2021-09-15 23:13:06 +02:00
|
|
|
if (!*p_rows)
|
|
|
|
return 1;
|
2021-09-19 23:51:59 +02:00
|
|
|
//;VGM_LOG("acb: preload Cue=%i\n", *p_rows);
|
2021-09-15 23:13:06 +02:00
|
|
|
|
|
|
|
acb->Cue = malloc(*p_rows * sizeof(Cue_t));
|
|
|
|
if (!acb->Cue) goto fail;
|
|
|
|
|
|
|
|
c_ReferenceType = utf_get_column(Table, "ReferenceType");
|
|
|
|
c_ReferenceIndex = utf_get_column(Table, "ReferenceIndex");
|
|
|
|
|
|
|
|
for (i = 0; i < *p_rows; i++) {
|
|
|
|
Cue_t* r = &acb->Cue[i];
|
|
|
|
|
|
|
|
utf_query_col_u8(Table, i, c_ReferenceType, &r->ReferenceType);
|
|
|
|
utf_query_col_u16(Table, i, c_ReferenceIndex, &r->ReferenceIndex);
|
|
|
|
}
|
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
utf_close(Table);
|
2021-09-15 23:13:06 +02:00
|
|
|
return 1;
|
|
|
|
fail:
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: failed Cue preload\n");
|
|
|
|
utf_close(Table);
|
2021-09-15 23:13:06 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int load_acb_cue(acb_header* acb, uint16_t Index) {
|
|
|
|
Cue_t* r;
|
|
|
|
|
|
|
|
/* read Cue[Index] */
|
2021-09-19 23:51:59 +02:00
|
|
|
if (!preload_acb_cue(acb)) goto fail;
|
2023-11-11 12:39:30 +01:00
|
|
|
if (Index >= acb->Cue_rows) goto fail;
|
2021-09-19 23:51:59 +02:00
|
|
|
r = &acb->Cue[Index];
|
|
|
|
//;VGM_LOG("acb: Cue[%i]: ReferenceType=%i, ReferenceIndex=%i\n", Index, r->ReferenceType, r->ReferenceIndex);
|
2020-05-25 20:57:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* usually older games use older references but not necessarily */
|
2021-09-15 23:13:06 +02:00
|
|
|
switch(r->ReferenceType) {
|
2020-05-25 20:57:29 +02:00
|
|
|
|
|
|
|
case 0x01: /* Cue > Waveform (ex. PES 2015) */
|
2021-09-15 23:13:06 +02:00
|
|
|
if (!load_acb_waveform(acb, r->ReferenceIndex))
|
2020-05-25 20:57:29 +02:00
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x02: /* Cue > Synth > Waveform (ex. Ukiyo no Roushi) */
|
2021-09-15 23:13:06 +02:00
|
|
|
if (!load_acb_synth(acb, r->ReferenceIndex))
|
2020-05-25 20:57:29 +02:00
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x03: /* Cue > Sequence > Track > Command > Synth > Waveform (ex. Valkyrie Profile anatomia, Yakuza Kiwami 2) */
|
2021-09-15 23:13:06 +02:00
|
|
|
if (!load_acb_sequence(acb, r->ReferenceIndex))
|
2020-05-25 20:57:29 +02:00
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
2020-09-18 23:47:28 +02:00
|
|
|
case 0x08: /* Cue > BlockSequence > Track / Block > Track > Command > Synth > Waveform (ex. Sonic Lost World, Kandagawa Jet Girls, rare) */
|
2021-09-15 23:13:06 +02:00
|
|
|
if (!load_acb_blocksequence(acb, r->ReferenceIndex))
|
2020-05-25 20:57:29 +02:00
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x00: /* none */
|
|
|
|
case 0x04: /* "track" */
|
|
|
|
case 0x05: /* "outsideLink" */
|
|
|
|
case 0x06: /* "insideLinkSynth" (ex. PES 2014) */
|
|
|
|
case 0x07: /* "insideLinkSequence" (ex. PES 2014) */
|
|
|
|
case 0x09: /* "insideLinkBlockSequence" */
|
|
|
|
case 0x0a: /* "eventCue_UnUse" */
|
|
|
|
case 0x0b: /* "soundGenerator" */
|
|
|
|
default:
|
2021-09-15 23:13:06 +02:00
|
|
|
VGM_LOG_ONCE("ACB: unknown Cue.ReferenceType=%x, Cue.ReferenceIndex=%x\n", r->ReferenceType, r->ReferenceIndex);
|
2020-05-25 20:57:29 +02:00
|
|
|
break; /* ignore and continue */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
fail:
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: failed Cue %i\n", Index);
|
2020-05-25 20:57:29 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
/*****************************************************************************/
|
2020-05-25 20:57:29 +02:00
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
static int preload_acb_cuename(acb_header* acb) {
|
2021-09-19 23:51:59 +02:00
|
|
|
utf_context* Table = acb->CueNames;
|
2021-09-15 23:13:06 +02:00
|
|
|
int* p_rows = &acb->CueName_rows;
|
|
|
|
int i, c_CueIndex, c_CueName;
|
2020-05-25 20:57:29 +02:00
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
if (*p_rows)
|
|
|
|
return 1;
|
|
|
|
if (!open_utf_subtable(acb, &acb->CueNameSf, &Table, "CueNameTable", p_rows, ACB_TABLE_BUFFER_CUENAME))
|
2020-05-25 20:57:29 +02:00
|
|
|
goto fail;
|
2021-09-15 23:13:06 +02:00
|
|
|
if (!*p_rows)
|
|
|
|
return 1;
|
2021-09-19 23:51:59 +02:00
|
|
|
//;VGM_LOG("acb: preload CueName=%i\n", *p_rows);
|
2021-09-15 23:13:06 +02:00
|
|
|
|
|
|
|
acb->CueName = malloc(*p_rows * sizeof(CueName_t));
|
|
|
|
if (!acb->CueName) goto fail;
|
|
|
|
|
|
|
|
c_CueIndex = utf_get_column(Table, "CueIndex");
|
|
|
|
c_CueName = utf_get_column(Table, "CueName");
|
|
|
|
|
|
|
|
for (i = 0; i < *p_rows; i++) {
|
|
|
|
CueName_t* r = &acb->CueName[i];
|
|
|
|
|
|
|
|
utf_query_col_u16(Table, i, c_CueIndex, &r->CueIndex);
|
|
|
|
utf_query_col_string(Table, i, c_CueName, &r->CueName);
|
|
|
|
}
|
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
//utf_close(Table); /* keep this table around since we need CueName pointers */
|
2021-09-15 23:13:06 +02:00
|
|
|
return 1;
|
|
|
|
fail:
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: failed CueName preload\n");
|
2021-09-15 23:13:06 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int load_acb_cuename(acb_header* acb, uint16_t Index) {
|
|
|
|
CueName_t* r;
|
2020-05-25 20:57:29 +02:00
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
if (!preload_acb_cuename(acb)) goto fail;
|
2023-11-11 12:39:30 +01:00
|
|
|
if (Index >= acb->CueName_rows) goto fail;
|
2021-09-19 23:51:59 +02:00
|
|
|
r = &acb->CueName[Index];
|
|
|
|
//;VGM_LOG("acb: CueName[%i]: CueIndex=%i, CueName=%s\n", Index, r->CueIndex, r->CueName);
|
2020-05-25 20:57:29 +02:00
|
|
|
|
|
|
|
/* save as will be needed if references waveform */
|
|
|
|
acb->cuename_index = Index;
|
2021-09-15 23:13:06 +02:00
|
|
|
acb->cuename_name = r->CueName;
|
2020-05-25 20:57:29 +02:00
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
if (!load_acb_cue(acb, r->CueIndex))
|
2020-05-25 20:57:29 +02:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
fail:
|
2021-09-19 23:51:59 +02:00
|
|
|
VGM_LOG("acb: failed CueName %i\n", Index);
|
2020-05-25 20:57:29 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-11-11 12:39:30 +01:00
|
|
|
static int preload_acb_waveformextensiondata(acb_header* acb) {
|
|
|
|
utf_context* Table = NULL;
|
|
|
|
int* p_rows = &acb->WaveformExtensionData_rows;
|
|
|
|
int i, c_LoopStart, c_LoopEnd;
|
|
|
|
|
|
|
|
if (*p_rows)
|
|
|
|
return 1;
|
|
|
|
if (!open_utf_subtable(acb, &acb->WaveformExtensionDataSf, &Table, "WaveformExtensionDataTable", p_rows, ACB_TABLE_BUFFER_WAVEFORMEXTENSIONDATA))
|
|
|
|
goto fail;
|
|
|
|
if (!*p_rows)
|
|
|
|
return 1;
|
|
|
|
//;VGM_LOG("acb: preload WaveformExtensionData=%i\n", *p_rows);
|
|
|
|
|
|
|
|
acb->WaveformExtensionData = malloc(*p_rows * sizeof(WaveformExtensionData_t));
|
|
|
|
if (!acb->WaveformExtensionData) goto fail;
|
|
|
|
|
|
|
|
c_LoopStart = utf_get_column(Table, "LoopStart");
|
|
|
|
c_LoopEnd = utf_get_column(Table, "LoopEnd");
|
|
|
|
|
|
|
|
for (i = 0; i < *p_rows; i++) {
|
|
|
|
WaveformExtensionData_t* r = &acb->WaveformExtensionData[i];
|
|
|
|
|
|
|
|
utf_query_col_u32(Table, i, c_LoopStart, &r->LoopStart);
|
|
|
|
utf_query_col_u32(Table, i, c_LoopEnd, &r->LoopEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
utf_close(Table);
|
|
|
|
return 1;
|
|
|
|
fail:
|
|
|
|
VGM_LOG("acb: failed WaveformExtensionData preload\n");
|
|
|
|
utf_close(Table);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* for Switch Opus that has loop info in a separate "WaveformExtensionData" table (pointed by a field in Waveform) */
|
|
|
|
static int load_acb_loops(acb_header* acb, VGMSTREAM* vgmstream) {
|
|
|
|
Waveform_t* rw;
|
|
|
|
WaveformExtensionData_t* r;
|
|
|
|
uint16_t WaveIndex = acb->waveform_index;
|
|
|
|
uint16_t ExtensionIndex = -1;
|
|
|
|
|
|
|
|
if (vgmstream->loop_flag)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* assumes that will be init'd before while searching for names */
|
|
|
|
if (WaveIndex < 0) goto fail;
|
|
|
|
//if (!preload_acb_waveform(acb)) goto fail;
|
|
|
|
if (WaveIndex >= acb->Waveform_rows) goto fail;
|
|
|
|
rw = &acb->Waveform[WaveIndex];
|
|
|
|
|
|
|
|
/* 1=no loop, 2=loop, ignore others/0(default)/255 just in case */
|
|
|
|
if (rw->LoopFlag != 2)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ExtensionIndex = rw->ExtensionData;
|
|
|
|
if (ExtensionIndex < 0) goto fail; /* not init'd? */
|
|
|
|
|
|
|
|
if (!preload_acb_waveformextensiondata(acb)) goto fail;
|
|
|
|
if (ExtensionIndex >= acb->WaveformExtensionData_rows) goto fail;
|
|
|
|
|
|
|
|
r = &acb->WaveformExtensionData[ExtensionIndex];
|
|
|
|
|
|
|
|
//;VGM_LOG("acb: WaveformExtensionData[%i]: LoopStart=%i, LoopEnd=%i\n", Index, r->LoopStart, r->LoopEnd);
|
|
|
|
|
|
|
|
vgmstream_force_loop(vgmstream, 1, r->LoopStart, r->LoopEnd);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
fail:
|
|
|
|
VGM_LOG("acb: failed WaveformExtensionData %i\n", ExtensionIndex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-15 23:13:06 +02:00
|
|
|
/*****************************************************************************/
|
2020-05-25 20:57:29 +02:00
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
/* Normally games load a .acb + .awb, and asks the .acb to play a cue by name or index.
|
|
|
|
* Since we only care for actual waves, to get its name we need to find which cue uses our wave.
|
|
|
|
* Multiple cues can use the same wave (meaning multiple names), and one cue may use multiple waves.
|
|
|
|
* There is no easy way to map cue name <> wave name so basically we parse the whole thing.
|
|
|
|
*
|
|
|
|
* .acb are created in CRI Atom Craft, where user defines N Cues with CueName each, then link somehow
|
|
|
|
* to a Waveform (.awb=streamed or memory .acb=internal, data 'material' encoded in some format),
|
|
|
|
* depending on reference types. Typical links are:
|
|
|
|
* - CueName > Cue > Waveform (type 1)
|
|
|
|
* - CueName > Cue > Synth > Waveform (type 2)
|
|
|
|
* - CueName > Cue > Sequence > Track > Command > Synth > Waveform (type 3, <=v1.27)
|
|
|
|
* - CueName > Cue > Sequence > Track > Command > Synth > Synth > Waveform (type 3, <=v1.27)
|
|
|
|
* - CueName > Cue > Sequence > Track > TrackEvent > Command > Synth > Waveform (type 3, >=v1.28)
|
|
|
|
* - CueName > Cue > Sequence > Track > TrackEvent > Command > Synth > Synth > Waveform (type 3, >=v1.28)
|
|
|
|
* - CueName > Cue > Sequence > Track > TrackEvent > Command > Sequence > (...) > Synth > Waveform (type 3, >=v1.28)
|
|
|
|
* - CueName > Cue > Block > Track > Command > Synth > Synth > Waveform (type 8)
|
|
|
|
* - others should be possible
|
|
|
|
* Atom Craft may only target certain .acb versions so some links are later removed
|
|
|
|
* Not all cues to point to Waveforms, some are just config events/commands.
|
|
|
|
* .acb link to .awb by name (loaded manually), though they have a checksum/hash/header to validate.
|
|
|
|
*
|
|
|
|
* .acb can contain info for multiple .awb, that are loaded sequentially and assigned "port numbers" (0 to N).
|
|
|
|
* Both Wave ID and port number must be passed externally to find appropriate song name.
|
|
|
|
*
|
|
|
|
* To improve performance we pre-read each table objects's useful fields. Extra complex files may include +8000 objects,
|
|
|
|
* per table, meaning it uses a decent chunk of memory, but having to re-read with streamfiles is much slower.
|
|
|
|
*/
|
|
|
|
|
2023-11-11 12:39:30 +01:00
|
|
|
void load_acb_wave_info(STREAMFILE* sf, VGMSTREAM* vgmstream, int waveid, int port, int is_memory, int load_loops) {
|
2020-05-25 20:57:29 +02:00
|
|
|
acb_header acb = {0};
|
2021-09-19 23:51:59 +02:00
|
|
|
int i;
|
2020-05-25 20:57:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
if (!sf || !vgmstream || waveid < 0)
|
|
|
|
return;
|
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
//;VGM_LOG("acb: find waveid=%i, port=%i\n", waveid, port);
|
2020-05-25 20:57:29 +02:00
|
|
|
|
|
|
|
acb.acbFile = sf;
|
|
|
|
|
|
|
|
acb.Header = utf_open(acb.acbFile, 0x00, NULL, NULL);
|
|
|
|
if (!acb.Header) goto fail;
|
|
|
|
|
|
|
|
acb.target_waveid = waveid;
|
2021-06-20 13:45:01 +02:00
|
|
|
acb.target_port = port;
|
2020-05-25 20:57:29 +02:00
|
|
|
acb.is_memory = is_memory;
|
2023-11-11 12:39:30 +01:00
|
|
|
acb.waveform_index = -1;
|
2021-09-15 23:13:06 +02:00
|
|
|
|
2020-05-25 20:57:29 +02:00
|
|
|
/* read all possible cue names and find which waveids are referenced by it */
|
2021-09-19 23:51:59 +02:00
|
|
|
preload_acb_cuename(&acb);
|
|
|
|
for (i = 0; i < acb.CueName_rows; i++) {
|
2020-05-25 20:57:29 +02:00
|
|
|
if (!load_acb_cuename(&acb, i))
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* meh copy */
|
|
|
|
if (acb.awbname_count > 0) {
|
|
|
|
strncpy(vgmstream->stream_name, acb.name, STREAM_NAME_SIZE);
|
|
|
|
vgmstream->stream_name[STREAM_NAME_SIZE - 1] = '\0';
|
|
|
|
}
|
|
|
|
|
2023-11-11 12:39:30 +01:00
|
|
|
/* uncommon */
|
|
|
|
if (load_loops) {
|
|
|
|
load_acb_loops(&acb, vgmstream);
|
|
|
|
}
|
|
|
|
|
2021-09-19 23:51:59 +02:00
|
|
|
/* done */
|
2020-05-25 20:57:29 +02:00
|
|
|
fail:
|
|
|
|
utf_close(acb.Header);
|
2021-09-19 23:51:59 +02:00
|
|
|
utf_close(acb.CueNames);
|
2020-05-25 20:57:29 +02:00
|
|
|
|
|
|
|
close_streamfile(acb.CueNameSf);
|
|
|
|
close_streamfile(acb.CueSf);
|
2020-09-18 23:47:28 +02:00
|
|
|
close_streamfile(acb.BlockSequenceSf);
|
|
|
|
close_streamfile(acb.BlockSf);
|
2020-05-25 20:57:29 +02:00
|
|
|
close_streamfile(acb.SequenceSf);
|
|
|
|
close_streamfile(acb.TrackSf);
|
|
|
|
close_streamfile(acb.TrackCommandSf);
|
|
|
|
close_streamfile(acb.SynthSf);
|
|
|
|
close_streamfile(acb.WaveformSf);
|
2023-11-11 12:39:30 +01:00
|
|
|
close_streamfile(acb.WaveformExtensionDataSf);
|
2021-09-15 23:13:06 +02:00
|
|
|
|
|
|
|
free(acb.CueName);
|
|
|
|
free(acb.Cue);
|
|
|
|
free(acb.BlockSequence);
|
|
|
|
free(acb.Block);
|
|
|
|
free(acb.Sequence);
|
|
|
|
free(acb.Track);
|
|
|
|
free(acb.TrackCommand);
|
|
|
|
free(acb.Synth);
|
|
|
|
free(acb.Waveform);
|
2023-11-11 12:39:30 +01:00
|
|
|
free(acb.WaveformExtensionData);
|
2020-05-25 20:57:29 +02:00
|
|
|
}
|