2008-07-01 05:23:44 +02:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../layout/layout.h"
|
2019-12-27 01:29:56 +01:00
|
|
|
#include "../coding/coding.h"
|
2008-07-01 05:23:44 +02:00
|
|
|
|
|
|
|
|
2020-05-01 16:04:23 +02:00
|
|
|
/* for reading integers inexplicably packed into 80-bit ('double extended') floats, AKA:
|
|
|
|
* "80 bit IEEE Standard 754 floating point number (Standard AppleNumeric Environment [SANE] data type Extended)" */
|
2020-05-01 09:12:20 +02:00
|
|
|
static uint32_t read_f80be(off_t offset, STREAMFILE* sf) {
|
2019-12-27 01:29:56 +01:00
|
|
|
uint8_t buf[0x0a];
|
2008-07-01 05:23:44 +02:00
|
|
|
int32_t exponent;
|
|
|
|
int32_t mantissa;
|
|
|
|
int i;
|
|
|
|
|
2020-05-01 09:12:20 +02:00
|
|
|
if (read_streamfile(buf, offset, sizeof(buf), sf) != sizeof(buf))
|
2019-12-27 01:29:56 +01:00
|
|
|
return 0;
|
2008-07-01 05:23:44 +02:00
|
|
|
|
2020-05-01 09:12:20 +02:00
|
|
|
exponent = ((buf[0]<<8) | (buf[1])) & 0x7fff;
|
2008-07-01 05:23:44 +02:00
|
|
|
exponent -= 16383;
|
|
|
|
|
|
|
|
mantissa = 0;
|
2020-05-01 09:12:20 +02:00
|
|
|
for (i = 0; i < 8; i++) {
|
2008-07-01 05:23:44 +02:00
|
|
|
int32_t shift = exponent-7-i*8;
|
|
|
|
if (shift >= 0)
|
|
|
|
mantissa |= buf[i+2] << shift;
|
|
|
|
else if (shift > -8)
|
|
|
|
mantissa |= buf[i+2] >> -shift;
|
|
|
|
}
|
|
|
|
|
2020-05-01 09:12:20 +02:00
|
|
|
return mantissa * ((buf[0]&0x80) ? -1 : 1);
|
2008-07-01 05:23:44 +02:00
|
|
|
}
|
|
|
|
|
2020-05-01 09:12:20 +02:00
|
|
|
static uint32_t find_marker(STREAMFILE* sf, off_t mark_offset, int marker_id) {
|
2008-07-01 18:11:59 +02:00
|
|
|
uint16_t marker_count;
|
|
|
|
off_t marker_offset;
|
2020-05-01 09:12:20 +02:00
|
|
|
int i;
|
2008-07-01 18:11:59 +02:00
|
|
|
|
2020-05-01 09:12:20 +02:00
|
|
|
marker_count = read_u16be(mark_offset + 0x00,sf);
|
|
|
|
marker_offset = mark_offset + 0x02;
|
|
|
|
for (i = 0; i < marker_count; i++) {
|
2008-07-01 18:11:59 +02:00
|
|
|
int name_length;
|
|
|
|
|
2020-05-01 09:12:20 +02:00
|
|
|
if (read_u16be(marker_offset + 0x00, sf) == marker_id)
|
|
|
|
return read_u32be(marker_offset + 0x02,sf);
|
2008-07-01 18:11:59 +02:00
|
|
|
|
2020-05-01 09:12:20 +02:00
|
|
|
name_length = read_u8(marker_offset + 0x06,sf) + 1;
|
2008-07-01 18:11:59 +02:00
|
|
|
if (name_length % 2) name_length++;
|
2020-05-01 09:12:20 +02:00
|
|
|
marker_offset += 0x06 + name_length;
|
2008-07-01 18:11:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-05-01 16:04:23 +02:00
|
|
|
static int is_str(const char* str, int len, off_t offset, STREAMFILE* sf) {
|
|
|
|
uint8_t buf[0x100];
|
2018-06-02 16:13:37 +02:00
|
|
|
|
2020-05-01 16:04:23 +02:00
|
|
|
if (len == 0)
|
|
|
|
len = strlen(str);
|
|
|
|
|
|
|
|
if (len > sizeof(buf))
|
|
|
|
return 0;
|
|
|
|
if (read_streamfile(buf, offset, len, sf) != len)
|
|
|
|
return 0;
|
|
|
|
return memcmp(buf, str, len) == 0; /* memcmp to allow "AB\0\0" */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* AIFF/AIFF-C (Audio Interchange File Format - Compressed) - Apple format, from Mac/3DO/other games */
|
2020-05-01 09:12:20 +02:00
|
|
|
VGMSTREAM* init_vgmstream_aifc(STREAMFILE* sf) {
|
|
|
|
VGMSTREAM* vgmstream = NULL;
|
2020-05-01 16:04:23 +02:00
|
|
|
off_t start_offset = 0, coef_offset = 0;
|
2018-07-22 23:13:03 +02:00
|
|
|
size_t file_size;
|
|
|
|
coding_t coding_type = 0;
|
2020-05-01 16:04:23 +02:00
|
|
|
int channels = 0, sample_count = 0, sample_size = 0, sample_rate = 0;
|
2018-07-22 23:13:03 +02:00
|
|
|
int interleave = 0;
|
2008-07-01 18:11:59 +02:00
|
|
|
int loop_flag = 0;
|
2018-07-22 23:13:03 +02:00
|
|
|
int32_t loop_start = 0, loop_end = 0;
|
|
|
|
|
|
|
|
int is_aiff_ext = 0, is_aifc_ext = 0, is_aiff = 0, is_aifc = 0;
|
2020-05-01 09:12:20 +02:00
|
|
|
int fver_found = 0, comm_found = 0, data_found = 0;
|
|
|
|
off_t mark_offset = 0, inst_offset = 0;
|
2008-07-01 05:23:44 +02:00
|
|
|
|
2018-06-02 16:13:37 +02:00
|
|
|
|
|
|
|
/* checks */
|
2021-10-23 13:14:54 +02:00
|
|
|
if (!is_id32be(0x00,sf, "FORM"))
|
|
|
|
goto fail;
|
|
|
|
|
2018-06-02 16:13:37 +02:00
|
|
|
/* .aif: common (AIFF or AIFC), .aiff: common AIFF, .aifc: common AIFC
|
2021-10-23 13:14:54 +02:00
|
|
|
* .laif/laiff/laifc: for plugins
|
2018-07-22 23:13:03 +02:00
|
|
|
* .cbd2: M2 games
|
|
|
|
* .bgm: Super Street Fighter II Turbo (3DO)
|
|
|
|
* .acm: Crusader - No Remorse (SAT)
|
2018-07-23 10:27:12 +02:00
|
|
|
* .adp: Sonic Jam (SAT)
|
2019-07-21 13:08:53 +02:00
|
|
|
* .ai: Dragon Force (SAT)
|
2019-12-27 01:29:56 +01:00
|
|
|
* (extensionless: Doom (3DO)
|
2020-05-01 16:04:23 +02:00
|
|
|
* .fda: Homeworld 2 (PC)
|
2021-10-23 13:14:54 +02:00
|
|
|
* .n64: Turok (N64) src
|
|
|
|
* .pcm: Road Rash (SAT)
|
|
|
|
*/
|
2020-05-01 09:12:20 +02:00
|
|
|
if (check_extensions(sf, "aif,laif,")) {
|
2018-07-22 23:13:03 +02:00
|
|
|
is_aifc_ext = 1;
|
|
|
|
is_aiff_ext = 1;
|
2008-07-01 18:11:59 +02:00
|
|
|
}
|
2021-10-23 13:14:54 +02:00
|
|
|
else if (check_extensions(sf, "aifc,laifc,afc,cbd2,bgm,fda,n64")) {
|
2018-07-22 23:13:03 +02:00
|
|
|
is_aifc_ext = 1;
|
2018-06-02 16:13:37 +02:00
|
|
|
}
|
2021-10-23 13:14:54 +02:00
|
|
|
else if (check_extensions(sf, "aiff,laiff,acm,adp,ai,pcm")) {
|
2018-07-22 23:13:03 +02:00
|
|
|
is_aiff_ext = 1;
|
2008-07-01 18:11:59 +02:00
|
|
|
}
|
2018-06-02 16:13:37 +02:00
|
|
|
else {
|
|
|
|
goto fail;
|
|
|
|
}
|
2008-07-01 05:23:44 +02:00
|
|
|
|
2020-05-01 09:12:20 +02:00
|
|
|
file_size = get_streamfile_size(sf);
|
2021-10-23 13:14:54 +02:00
|
|
|
if (read_u32be(0x04,sf) + 0x08 != file_size)
|
2018-07-22 23:13:03 +02:00
|
|
|
goto fail;
|
|
|
|
|
2020-05-01 16:04:23 +02:00
|
|
|
/* AIFF originally allowed only PCM (non-compressed) audio, so newer AIFC was added,
|
|
|
|
* though some AIFF with other codecs exist */
|
2021-10-23 13:14:54 +02:00
|
|
|
if (is_id32be(0x08,sf, "AIFC")) {
|
2018-07-22 23:13:03 +02:00
|
|
|
if (!is_aifc_ext) goto fail;
|
|
|
|
is_aifc = 1;
|
|
|
|
}
|
2021-10-23 13:14:54 +02:00
|
|
|
else if (is_id32be(0x08,sf, "AIFF")) {
|
2018-07-22 23:13:03 +02:00
|
|
|
if (!is_aiff_ext) goto fail;
|
|
|
|
is_aiff = 1;
|
2018-06-02 16:13:37 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2008-07-01 05:23:44 +02:00
|
|
|
|
|
|
|
/* read through chunks to verify format and find metadata */
|
|
|
|
{
|
2020-05-01 09:12:20 +02:00
|
|
|
off_t offset = 0x0c; /* start with first chunk within FORM */
|
2008-07-01 05:23:44 +02:00
|
|
|
|
2020-05-01 09:12:20 +02:00
|
|
|
while (offset < file_size) {
|
|
|
|
uint32_t chunk_type = read_u32be(offset + 0x00,sf);
|
|
|
|
uint32_t chunk_size = read_u32be(offset + 0x04,sf);
|
2008-07-01 05:23:44 +02:00
|
|
|
|
|
|
|
/* chunks must be padded to an even number of bytes but chunk
|
|
|
|
* size does not include that padding */
|
2020-05-01 09:12:20 +02:00
|
|
|
if (chunk_size % 2)
|
|
|
|
chunk_size++;
|
2008-07-01 05:23:44 +02:00
|
|
|
|
2020-05-01 09:12:20 +02:00
|
|
|
offset += 0x08;
|
|
|
|
if (offset + chunk_size > file_size)
|
|
|
|
goto fail;
|
2008-07-01 05:23:44 +02:00
|
|
|
|
|
|
|
switch(chunk_type) {
|
2020-05-01 16:04:23 +02:00
|
|
|
case 0x46564552: /* "FVER" (version info, required) */
|
2019-12-27 01:29:56 +01:00
|
|
|
if (fver_found) goto fail;
|
2018-07-22 23:13:03 +02:00
|
|
|
if (is_aiff) goto fail; /* plain AIFF shouldn't have */
|
2019-12-27 01:29:56 +01:00
|
|
|
fver_found = 1;
|
2008-07-01 05:23:44 +02:00
|
|
|
|
2020-05-01 16:04:23 +02:00
|
|
|
if (chunk_size != 4)
|
|
|
|
goto fail;
|
2008-07-01 05:23:44 +02:00
|
|
|
/* Version 1 of AIFF-C spec timestamp */
|
2020-05-01 09:12:20 +02:00
|
|
|
if (read_u32be(offset + 0x00,sf) != 0xA2805140)
|
|
|
|
goto fail;
|
2008-07-01 05:23:44 +02:00
|
|
|
break;
|
2018-06-02 16:13:37 +02:00
|
|
|
|
|
|
|
case 0x434F4D4D: /* "COMM" (main header) */
|
2019-12-27 01:29:56 +01:00
|
|
|
if (comm_found) goto fail;
|
|
|
|
comm_found = 1;
|
2008-07-01 05:23:44 +02:00
|
|
|
|
2021-10-23 13:14:54 +02:00
|
|
|
channels = read_u16be(offset + 0x00,sf);
|
2020-05-01 16:04:23 +02:00
|
|
|
sample_count = read_u32be(offset + 0x02,sf); /* sample_frames in theory, depends on codec */
|
2020-05-01 09:12:20 +02:00
|
|
|
sample_size = read_u16be(offset + 0x06,sf);
|
|
|
|
sample_rate = read_f80be(offset + 0x08,sf);
|
2008-07-01 05:23:44 +02:00
|
|
|
|
2018-07-22 23:13:03 +02:00
|
|
|
if (is_aifc) {
|
2020-05-01 09:12:20 +02:00
|
|
|
uint32_t codec = read_u32be(offset + 0x12,sf);
|
2020-05-01 16:04:23 +02:00
|
|
|
/* followed by "pascal string": name size + human-readable name (full count padded to even size) */
|
|
|
|
|
2019-12-27 01:29:56 +01:00
|
|
|
switch (codec) {
|
2018-06-02 16:13:37 +02:00
|
|
|
case 0x53445832: /* "SDX2" [3DO games: Super Street Fighter II Turbo (3DO), etc] */
|
2020-05-01 16:04:23 +02:00
|
|
|
/* "2:1 Squareroot-Delta-Exact compression" */
|
2008-07-01 18:11:59 +02:00
|
|
|
coding_type = coding_SDX2;
|
2018-06-02 16:13:37 +02:00
|
|
|
interleave = 0x01;
|
2008-07-01 18:11:59 +02:00
|
|
|
break;
|
2019-12-27 01:29:56 +01:00
|
|
|
|
2018-06-02 16:13:37 +02:00
|
|
|
case 0x43424432: /* "CBD2" [M2 (arcade 3DO) games: IMSA Racing (M2), etc] */
|
2020-05-01 16:04:23 +02:00
|
|
|
/* "2:1 Cuberoot-Delta-Exact compression" */
|
2010-07-27 14:24:03 +02:00
|
|
|
coding_type = coding_CBD2;
|
2018-06-02 16:13:37 +02:00
|
|
|
interleave = 0x01;
|
2010-07-27 14:24:03 +02:00
|
|
|
break;
|
2019-12-27 01:29:56 +01:00
|
|
|
|
2018-06-02 16:13:37 +02:00
|
|
|
case 0x41445034: /* "ADP4" */
|
2017-11-19 03:34:25 +01:00
|
|
|
coding_type = coding_DVI_IMA_int;
|
2020-05-01 16:04:23 +02:00
|
|
|
if (channels != 1) break; /* don't know how stereo DVI is laid out */
|
2018-06-02 16:13:37 +02:00
|
|
|
break;
|
2019-12-27 01:29:56 +01:00
|
|
|
|
2018-07-22 23:13:03 +02:00
|
|
|
case 0x696D6134: /* "ima4" [Alida (PC), Lunar SSS (iOS)] */
|
2020-05-01 16:04:23 +02:00
|
|
|
/* "IMA 4:1FLLR" */
|
2018-06-02 16:13:37 +02:00
|
|
|
coding_type = coding_APPLE_IMA4;
|
|
|
|
interleave = 0x22;
|
|
|
|
sample_count = sample_count * ((interleave-0x2)*2);
|
2008-07-02 03:41:20 +02:00
|
|
|
break;
|
2019-12-27 01:29:56 +01:00
|
|
|
|
|
|
|
case 0x434F4D50: { /* "COMP" (generic compression) */
|
2020-05-01 16:04:23 +02:00
|
|
|
uint8_t name_size = read_u8(offset + 0x16, sf);
|
|
|
|
|
|
|
|
if (is_str("Relic Codec v1.6", name_size, offset + 0x17, sf)) {
|
2019-12-27 01:29:56 +01:00
|
|
|
coding_type = coding_RELIC;
|
|
|
|
sample_count = sample_count * 512;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-05-01 16:04:23 +02:00
|
|
|
case 0x56415043: { /* "VAPC" [N64 (SDK mainly but apparently may exist in ROMs)] */
|
|
|
|
/* "VADPCM ~4-1" */
|
|
|
|
coding_type = coding_VADPCM;
|
|
|
|
|
|
|
|
/* N64 tools don't create FVER, but it's required by the spec (could skip the check though) */
|
|
|
|
fver_found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-07-01 18:11:59 +02:00
|
|
|
default:
|
2018-06-02 16:13:37 +02:00
|
|
|
VGM_LOG("AIFC: unknown codec\n");
|
2008-07-01 18:11:59 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
2018-06-02 16:13:37 +02:00
|
|
|
}
|
2018-07-22 23:13:03 +02:00
|
|
|
else if (is_aiff) {
|
2008-07-01 18:11:59 +02:00
|
|
|
switch (sample_size) {
|
|
|
|
case 8:
|
|
|
|
coding_type = coding_PCM8;
|
|
|
|
interleave = 1;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
coding_type = coding_PCM16BE;
|
|
|
|
interleave = 2;
|
|
|
|
break;
|
2021-10-23 13:14:54 +02:00
|
|
|
case 4: /* Crusader: No Remorse (SAT), Road Rash (3DO/SAT) */
|
2018-07-22 23:13:03 +02:00
|
|
|
coding_type = coding_XA;
|
|
|
|
break;
|
2008-07-01 18:11:59 +02:00
|
|
|
default:
|
2018-06-02 16:13:37 +02:00
|
|
|
VGM_LOG("AIFF: unknown codec\n");
|
2008-07-01 18:11:59 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
2008-07-01 05:23:44 +02:00
|
|
|
}
|
|
|
|
break;
|
2018-06-02 16:13:37 +02:00
|
|
|
|
|
|
|
case 0x53534E44: /* "SSND" (main data) */
|
2018-07-22 23:13:03 +02:00
|
|
|
case 0x4150434D: /* "APCM" (main data for XA) */
|
2019-12-27 01:29:56 +01:00
|
|
|
if (data_found) goto fail;
|
|
|
|
data_found = 1;
|
2008-07-01 05:23:44 +02:00
|
|
|
|
2020-05-01 16:04:23 +02:00
|
|
|
/* 00: offset (for aligment, usually 0)
|
|
|
|
* 04: block size (ex. XA: 0x914) */
|
2020-05-01 09:12:20 +02:00
|
|
|
start_offset = offset + 0x08 + read_u32be(offset + 0x00,sf);
|
2008-07-01 05:23:44 +02:00
|
|
|
break;
|
2018-06-02 16:13:37 +02:00
|
|
|
|
|
|
|
case 0x4D41524B: /* "MARK" (loops) */
|
2020-05-01 09:12:20 +02:00
|
|
|
mark_offset = offset;
|
2008-07-01 18:11:59 +02:00
|
|
|
break;
|
2018-06-02 16:13:37 +02:00
|
|
|
|
|
|
|
case 0x494E5354: /* "INST" (loops) */
|
2020-05-01 09:12:20 +02:00
|
|
|
inst_offset = offset;
|
2008-07-01 18:11:59 +02:00
|
|
|
break;
|
2018-06-02 16:13:37 +02:00
|
|
|
|
2020-05-01 16:04:23 +02:00
|
|
|
case 0x4150504C: /* "APPL" (application specific) */
|
|
|
|
if (is_str("stoc", 0, offset + 0x00, sf)) {
|
|
|
|
uint8_t name_size = read_u8(offset + 0x4, sf);
|
|
|
|
off_t next_offset = offset + 0x04 + align_size_to_block(0x1 + name_size, 0x02);
|
|
|
|
|
|
|
|
/* chunks appears multiple times per substring */
|
|
|
|
if (is_str("VADPCMCODES", name_size, offset + 0x05, sf)) {
|
|
|
|
coef_offset = next_offset;
|
|
|
|
}
|
|
|
|
else if (is_str("VADPCMLOOPS", name_size, offset + 0x05, sf)) {
|
|
|
|
/* goes with inst (spec says app chunks have less priority than inst+mark loops) */
|
|
|
|
int version = read_u16be(next_offset + 0x00, sf);
|
|
|
|
int loops = read_u16be(next_offset + 0x02, sf);
|
|
|
|
if (version != 1 || loops != 1) goto fail;
|
|
|
|
|
|
|
|
loop_start = read_u32be(next_offset + 0x04, sf);
|
|
|
|
loop_end = read_u32be(next_offset + 0x08, sf);
|
|
|
|
loop_flag = read_s32be(next_offset + 0x08, sf) != 0; /*-1 = infinite */
|
|
|
|
/* 0x10: ADPCM state[16] (hists?) */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
VGM_LOG("AIFC: unknown APPL chunk\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-07-01 05:23:44 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-05-01 09:12:20 +02:00
|
|
|
offset += chunk_size;
|
2008-07-01 05:23:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-22 23:13:03 +02:00
|
|
|
if (is_aifc) {
|
2019-12-27 01:29:56 +01:00
|
|
|
if (!fver_found || !comm_found || !data_found)
|
2008-07-01 18:11:59 +02:00
|
|
|
goto fail;
|
2018-07-22 23:13:03 +02:00
|
|
|
} else if (is_aiff) {
|
2019-12-27 01:29:56 +01:00
|
|
|
if (!comm_found || !data_found)
|
2008-07-01 18:11:59 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2018-06-02 16:13:37 +02:00
|
|
|
|
2008-07-01 18:11:59 +02:00
|
|
|
/* read loop points */
|
2020-05-01 09:12:20 +02:00
|
|
|
if (inst_offset && mark_offset) {
|
2008-07-01 18:11:59 +02:00
|
|
|
int start_marker;
|
|
|
|
int end_marker;
|
2020-05-01 09:12:20 +02:00
|
|
|
|
|
|
|
/* use the 'sustain loop', if playMode=ForwardLooping */
|
|
|
|
if (read_u16be(inst_offset + 0x08,sf) == 1) {
|
|
|
|
start_marker = read_u16be(inst_offset + 0x0a,sf);
|
|
|
|
end_marker = read_u16be(inst_offset + 0x0c,sf);
|
2008-07-01 18:27:27 +02:00
|
|
|
/* check for sustain markers != 0 (invalid marker no) */
|
|
|
|
if (start_marker && end_marker) {
|
|
|
|
/* find start marker */
|
2020-05-01 09:12:20 +02:00
|
|
|
loop_start = find_marker(sf, mark_offset, start_marker);
|
|
|
|
loop_end = find_marker(sf, mark_offset, end_marker);
|
2008-07-01 18:27:27 +02:00
|
|
|
|
|
|
|
/* find_marker is type uint32_t as the spec says that's the type
|
|
|
|
* of the position value, but it returns a -1 on error, and the
|
|
|
|
* loop_start and loop_end variables are int32_t, so the error
|
|
|
|
* will become apparent.
|
2020-05-01 09:12:20 +02:00
|
|
|
* We shouldn't have a loop point that overflows an int32_t anyway. */
|
2008-07-02 23:44:23 +02:00
|
|
|
loop_flag = 1;
|
2020-12-05 19:26:18 +01:00
|
|
|
if (loop_start == loop_end)
|
2018-07-22 23:13:03 +02:00
|
|
|
loop_flag = 0;
|
2008-07-01 18:27:27 +02:00
|
|
|
}
|
2008-07-01 18:11:59 +02:00
|
|
|
}
|
2020-12-05 19:26:18 +01:00
|
|
|
}
|
|
|
|
if (!loop_flag && mark_offset) {
|
|
|
|
int mark_count = read_u16be(mark_offset + 0x00,sf);
|
|
|
|
|
|
|
|
/* use "beg/end" loop comments [Battle Tryst (Arcade)]
|
|
|
|
* Relic codec has 3 "beg loop" "end loop" "start offset" comments, but always begin = 0 and end = -1 */
|
|
|
|
if (mark_count == 2) {
|
|
|
|
/* per mark:
|
|
|
|
* 00(2): id
|
|
|
|
* 02(4): sample point
|
|
|
|
* 06(1): string size
|
|
|
|
* --(-): string (non-null terminated)
|
|
|
|
* --(1): null terminator */
|
|
|
|
/* simplified... */
|
|
|
|
if (read_u32be(mark_offset + 0x09,sf) == 0x62656720 && /* "beg " */
|
|
|
|
read_u32be(mark_offset + 0x19,sf) == 0x656E6420) { /* "end " */
|
|
|
|
loop_start = read_s32be(mark_offset + 0x04, sf);
|
|
|
|
loop_end = read_s32be(mark_offset + 0x14, sf);
|
|
|
|
loop_flag = 1;
|
|
|
|
}
|
|
|
|
}
|
2008-07-01 18:11:59 +02:00
|
|
|
}
|
2008-07-01 05:23:44 +02:00
|
|
|
|
|
|
|
|
2018-06-02 16:13:37 +02:00
|
|
|
/* build the VGMSTREAM */
|
2020-05-01 16:04:23 +02:00
|
|
|
vgmstream = allocate_vgmstream(channels, loop_flag);
|
2008-07-01 05:23:44 +02:00
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
vgmstream->sample_rate = sample_rate;
|
2018-06-02 16:13:37 +02:00
|
|
|
vgmstream->num_samples = sample_count;
|
|
|
|
vgmstream->loop_start_sample = loop_start;
|
|
|
|
vgmstream->loop_end_sample = loop_end;
|
2008-07-01 05:23:44 +02:00
|
|
|
|
|
|
|
vgmstream->coding_type = coding_type;
|
2019-12-27 01:29:56 +01:00
|
|
|
switch(coding_type) {
|
|
|
|
case coding_XA:
|
|
|
|
vgmstream->layout_type = layout_blocked_xa_aiff;
|
|
|
|
/* AIFF XA can use sample rates other than 37800/18900 */
|
|
|
|
/* some Crusader: No Remorse tracks have XA headers with incorrect 0xFF, rip bug/encoder feature? */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case coding_RELIC: {
|
2020-05-01 09:12:20 +02:00
|
|
|
int bitrate = read_u16be(start_offset, sf);
|
2019-12-27 01:29:56 +01:00
|
|
|
start_offset += 0x02;
|
|
|
|
|
2020-05-01 16:04:23 +02:00
|
|
|
vgmstream->codec_data = init_relic(channels, bitrate, sample_rate);
|
2019-12-27 01:29:56 +01:00
|
|
|
if (!vgmstream->codec_data) goto fail;
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
|
|
|
|
vgmstream->sample_rate = 44100; /* fixed output */
|
|
|
|
break;
|
|
|
|
}
|
2020-05-01 09:12:20 +02:00
|
|
|
|
2020-05-01 16:04:23 +02:00
|
|
|
case coding_VADPCM:
|
|
|
|
if (channels > 1) goto fail; /* unknown layout */
|
|
|
|
if (coef_offset == 0) goto fail;
|
|
|
|
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
{
|
|
|
|
int version = read_u16be(coef_offset + 0x00, sf);
|
|
|
|
int order = read_u16be(coef_offset + 0x02, sf);
|
|
|
|
int entries = read_u16be(coef_offset + 0x04, sf);
|
|
|
|
if (version != 1) goto fail;
|
|
|
|
|
|
|
|
vadpcm_read_coefs_be(vgmstream, sf, coef_offset + 0x06, order, entries, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//vgmstream->num_samples = vadpcm_bytes_to_samples(data_size, channels); /* unneeded */
|
|
|
|
break;
|
|
|
|
|
2019-12-27 01:29:56 +01:00
|
|
|
default:
|
2020-05-01 16:04:23 +02:00
|
|
|
vgmstream->layout_type = (channels > 1) ? layout_interleave : layout_none;
|
2019-12-27 01:29:56 +01:00
|
|
|
vgmstream->interleave_block_size = interleave;
|
|
|
|
break;
|
2018-07-22 23:13:03 +02:00
|
|
|
}
|
2008-07-01 18:11:59 +02:00
|
|
|
|
2018-07-22 23:13:03 +02:00
|
|
|
if (is_aifc)
|
2008-07-01 18:11:59 +02:00
|
|
|
vgmstream->meta_type = meta_AIFC;
|
2018-07-22 23:13:03 +02:00
|
|
|
else if (is_aiff)
|
2008-07-01 18:11:59 +02:00
|
|
|
vgmstream->meta_type = meta_AIFF;
|
2008-07-01 05:23:44 +02:00
|
|
|
|
|
|
|
|
2020-05-01 09:12:20 +02:00
|
|
|
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
|
2018-06-02 16:13:37 +02:00
|
|
|
goto fail;
|
2008-07-01 05:23:44 +02:00
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
2018-06-02 16:13:37 +02:00
|
|
|
close_vgmstream(vgmstream);
|
2008-07-01 05:23:44 +02:00
|
|
|
return NULL;
|
|
|
|
}
|