Merge pull request #1248 from bnnm/cpk

- Fix some CPK .awb [Puyo Puyo 20th Anniversary (3DS)]
- cleanup
This commit is contained in:
bnnm 2022-10-22 15:23:47 +02:00 committed by GitHub
commit 463c51edfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 500 additions and 468 deletions

View File

@ -17,7 +17,7 @@ void g72x_init_state(struct g72x_state* state_ptr);
/* ima_decoder */
void decode_standard_ima(VGMSTREAMCHANNEL* stream, sample_t* outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int channel, int is_stereo, int is_high_first);
void decode_3ds_ima(VGMSTREAMCHANNEL* stream, sample_t* outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
void decode_nw_ima(VGMSTREAMCHANNEL* stream, sample_t* outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
void decode_snds_ima(VGMSTREAMCHANNEL* stream, sample_t* outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int channel);
void decode_otns_ima(VGMSTREAM* vgmstream, VGMSTREAMCHANNEL* stream, sample_t* outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int channel);
void decode_wv6_ima(VGMSTREAMCHANNEL* stream, sample_t* outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);

View File

@ -108,8 +108,8 @@ static void std_ima_expand_nibble_mul(VGMSTREAMCHANNEL * stream, off_t byte_offs
if (*step_index > 88) *step_index=88;
}
/* 3DS IMA (Mario Golf, Mario Tennis; maybe other Camelot games) */
static void n3ds_ima_expand_nibble(VGMSTREAMCHANNEL * stream, off_t byte_offset, int nibble_shift, int32_t * hist1, int32_t * step_index) {
/* NintendoWare IMA (Mario Golf, Mario Tennis; maybe other Camelot games) */
static void nw_ima_expand_nibble(VGMSTREAMCHANNEL * stream, off_t byte_offset, int nibble_shift, int32_t * hist1, int32_t * step_index) {
int sample_nibble, sample_decoded, step, delta;
sample_nibble = (read_8bit(byte_offset,stream->streamfile) >> nibble_shift)&0xf;
@ -402,7 +402,7 @@ void decode_mtf_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspa
stream->adpcm_step_index = step_index;
}
void decode_3ds_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do) {
void decode_nw_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do) {
int i, sample_count;
int32_t hist1 = stream->adpcm_history1_32;
int step_index = stream->adpcm_step_index;
@ -415,7 +415,7 @@ void decode_3ds_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspa
off_t byte_offset = stream->offset + i/2;
int nibble_shift = (i&1?4:0); //low nibble order
n3ds_ima_expand_nibble(stream, byte_offset,nibble_shift, &hist1, &step_index);
nw_ima_expand_nibble(stream, byte_offset,nibble_shift, &hist1, &step_index);
outbuf[sample_count] = (short)(hist1);
}

View File

@ -425,7 +425,7 @@ int get_vgmstream_samples_per_frame(VGMSTREAM* vgmstream) {
case coding_PCM4_U:
case coding_IMA_int:
case coding_DVI_IMA_int:
case coding_3DS_IMA:
case coding_NW_IMA:
case coding_WV6_IMA:
case coding_HV_IMA:
case coding_FFTA2_IMA:
@ -638,7 +638,7 @@ int get_vgmstream_frame_size(VGMSTREAM* vgmstream) {
case coding_IMA_int:
case coding_DVI_IMA:
case coding_DVI_IMA_int:
case coding_3DS_IMA:
case coding_NW_IMA:
case coding_WV6_IMA:
case coding_HV_IMA:
case coding_FFTA2_IMA:
@ -1173,9 +1173,9 @@ void decode_vgmstream(VGMSTREAM* vgmstream, int samples_written, int samples_to_
}
break;
}
case coding_3DS_IMA:
case coding_NW_IMA:
for (ch = 0; ch < vgmstream->channels; ch++) {
decode_3ds_ima(&vgmstream->ch[ch], buffer+ch,
decode_nw_ima(&vgmstream->ch[ch], buffer+ch,
vgmstream->channels, vgmstream->samples_into_block, samples_to_do);
}
break;

View File

@ -790,7 +790,7 @@ static const coding_info coding_info_list[] = {
{coding_IMA_int, "IMA 4-bit ADPCM (mono/interleave)"},
{coding_DVI_IMA, "Intel DVI 4-bit IMA ADPCM"},
{coding_DVI_IMA_int, "Intel DVI 4-bit IMA ADPCM (mono/interleave)"},
{coding_3DS_IMA, "3DS IMA 4-bit ADPCM"},
{coding_NW_IMA, "NintendoWare IMA 4-bit ADPCM"},
{coding_SNDS_IMA, "Heavy Iron .snds 4-bit IMA ADPCM"},
{coding_QD_IMA, "Quantic Dream 4-bit IMA ADPCM"},
{coding_WV6_IMA, "Gorilla Systems WV6 4-bit IMA ADPCM"},

View File

@ -264,7 +264,7 @@ static const adxkey_info adxkey9_list[] = {
/* Shin Megami Tensei V (Switch) */
{0x0000,0x0000,0x0000, NULL,1731948526}, // 00000000673B6FEE
/* Persona 5 Royal (multi) */
/* Persona 5 Royal (PC) */
{0x0000,0x0000,0x0000, NULL,9923540143823782}, // 002341683D2FDBA6
};

View File

@ -104,7 +104,7 @@ VGMSTREAM * init_vgmstream_bcstm(STREAMFILE *streamFile) {
vgmstream->coding_type = coding_NGC_DSP;
if (is_camelot_ima) {
vgmstream->coding_type = coding_3DS_IMA;
vgmstream->coding_type = coding_NW_IMA;
}
else {
int i, c;

View File

@ -227,7 +227,7 @@ static VGMSTREAM* init_vgmstream_bxwav(STREAMFILE* sf, bxwav_type_t type) {
break;
case 0x03:
vgmstream->coding_type = coding_3DS_IMA;
vgmstream->coding_type = coding_NW_IMA;
/* hist is read below */
break;

View File

@ -18,6 +18,8 @@ VGMSTREAM* init_vgmstream_cpk_memory(STREAMFILE* sf, STREAMFILE* sf_acb) {
off_t subfile_offset = 0;
size_t subfile_size = 0;
utf_context* utf = NULL;
utf_context* utf_h = NULL;
utf_context* utf_l = NULL;
int total_subsongs, target_subsong = sf->stream_index;
int subfile_id = 0;
cpk_type_t type;
@ -40,14 +42,17 @@ VGMSTREAM* init_vgmstream_cpk_memory(STREAMFILE* sf, STREAMFILE* sf_acb) {
/* CPK .cpk is CRI's generic file container, but here we only support CPK .awb used as
* early audio bank, that like standard AFS2 .awb comes with .acb */
{
int rows, i;
int rows, rows_l, rows_h, i;
const char* name;
const char* name_l;
const char* name_h;
const char* Tvers;
uint32_t table_offset = 0, offset;
uint32_t Files = 0, FilesL = 0, FilesH = 0;
uint64_t ContentOffset = 0, ItocOffset = 0;
uint16_t Align = 0;
uint32_t DataL_offset = 0, DataL_size = 0, DataH_offset = 0, DataH_size = 0;
int id_align;
/* base header */
table_offset = 0x10;
@ -65,7 +70,7 @@ VGMSTREAM* init_vgmstream_cpk_memory(STREAMFILE* sf, STREAMFILE* sf_acb) {
utf_close(utf);
utf = NULL;
if (strncmp(Tvers, "awb", 3) != 0) /* starts with "awb" + ".(version)" (SFvTK, MGS3D) or " for (version)" (ACI) */
if (strncmp(Tvers, "awb", 3) != 0) /* starts with "awb" + ".(version)" (SFvTK, MGS3D) or " for (version)" (ACI, Puyo) */
goto fail;
if (Files <= 0)
goto fail;
@ -104,51 +109,77 @@ VGMSTREAM* init_vgmstream_cpk_memory(STREAMFILE* sf, STREAMFILE* sf_acb) {
/* DataL header */
table_offset = DataL_offset;
utf = utf_open(sf, table_offset, &rows, &name);
if (!utf || strcmp(name, "CpkItocL") != 0 || rows != FilesL)
utf_l = utf_open(sf, table_offset, &rows_l, &name_l);
if (!utf_l || strcmp(name_l, "CpkItocL") != 0 || rows_l != FilesL)
goto fail;
for (i = 0; i < rows; i++) {
/* DataH header */
table_offset = DataH_offset;
utf_h = utf_open(sf, table_offset, &rows_h, &name_h);
if (!utf_h || strcmp(name_h, "CpkItocH") != 0 || rows_h != FilesH)
goto fail;
/* rarely ID doesn't start at 0, adjust values [Puyo Puyo 20th Anniversary (3DS)-3DS_manzai_voice] */
id_align = 0;
{
uint16_t ID_l = 0;
uint16_t ID_h = 0;
/* use lower as base, one table may not exist */
utf_query_u16(utf_l, 0, "ID", &ID_l);
utf_query_u16(utf_h, 0, "ID", &ID_h);
if (rows_l > 0 && rows_h > 0) {
if (ID_l > 0 && ID_h > 0) /* one is 0 = no adjust needed */
id_align = ID_l < ID_h ? ID_l : ID_h;
}
else if (rows_l) {
id_align = ID_l;
}
else if (rows_h) {
id_align = ID_h;
}
}
/* save DataL sizes */
for (i = 0; i < rows_l; i++) {
uint16_t ID = 0;
uint16_t FileSize, ExtractSize;
if (!utf_query_u16(utf, i, "ID", &ID) ||
!utf_query_u16(utf, i, "FileSize", &FileSize) ||
!utf_query_u16(utf, i, "ExtractSize", &ExtractSize))
if (!utf_query_u16(utf_l, i, "ID", &ID) ||
!utf_query_u16(utf_l, i, "FileSize", &FileSize) ||
!utf_query_u16(utf_l, i, "ExtractSize", &ExtractSize))
goto fail;
ID -= id_align;
if (ID >= Files || FileSize != ExtractSize || sizes[ID])
goto fail;
sizes[ID] = FileSize;
}
utf_close(utf);
utf = NULL;
/* DataR header */
table_offset = DataH_offset;
utf = utf_open(sf, table_offset, &rows, &name);
if (!utf || strcmp(name, "CpkItocH") != 0 || rows != FilesH)
goto fail;
for (i = 0; i < rows; i++) {
/* save DataH sizes */
for (i = 0; i < rows_h; i++) {
uint16_t ID = 0;
uint32_t FileSize, ExtractSize;
if (!utf_query_u16(utf, i, "ID", &ID) ||
!utf_query_u32(utf, i, "FileSize", &FileSize) ||
!utf_query_u32(utf, i, "ExtractSize", &ExtractSize))
if (!utf_query_u16(utf_h, i, "ID", &ID) ||
!utf_query_u32(utf_h, i, "FileSize", &FileSize) ||
!utf_query_u32(utf_h, i, "ExtractSize", &ExtractSize))
goto fail;
ID -= id_align;
if (ID >= Files || FileSize != ExtractSize || sizes[ID])
goto fail;
sizes[ID] = FileSize;
}
utf_close(utf);
utf = NULL;
utf_close(utf_l);
utf_l = NULL;
utf_close(utf_h);
utf_h = NULL;
/* find actual offset */
@ -156,7 +187,7 @@ VGMSTREAM* init_vgmstream_cpk_memory(STREAMFILE* sf, STREAMFILE* sf_acb) {
for (i = 0; i < Files; i++) {
uint32_t size = sizes[i];
if (i + 1 == target_subsong) {
subfile_id = i;
subfile_id = i + id_align;
subfile_offset = offset;
subfile_size = size;
break;
@ -224,6 +255,8 @@ VGMSTREAM* init_vgmstream_cpk_memory(STREAMFILE* sf, STREAMFILE* sf_acb) {
fail:
free(sizes);
utf_close(utf);
utf_close(utf_l);
utf_close(utf_h);
close_streamfile(temp_sf);
close_vgmstream(vgmstream);
return NULL;

View File

@ -1055,10 +1055,10 @@ static const hcakey_info hcakey_list[] = {
// Echoes of Mana (Android)
{1090221945250803295}, // 0F213F153D026E5F
// Persona 5 Royal (multi)
// Persona 5 Royal (Switch)
{9923540143823782}, // 002341683D2FDBA6
// P Sengoku Otome 6 ~Akatsuki no Sekigahahara~ (Android)
// P Sengoku Otome 6 ~Akatsuki no Sekigahara~ (Android)
{97648135}, // 0000000005d1fe07
// CHUNITHM International Version (AC)

View File

@ -3,21 +3,21 @@
/* .PCM - from Lunar: Eternal Blue (Sega CD) */
VGMSTREAM * init_vgmstream_scd_pcm(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
VGMSTREAM* init_vgmstream_scd_pcm(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
off_t start_offset;
int loop_flag, channel_count;
int loop_flag, channels;
/* checks */
if (!check_extensions(streamFile, "pcm"))
if (!check_extensions(sf, "pcm"))
goto fail;
if (read_16bitBE(0x00,streamFile) == 0x0002) {
channel_count = 1;
if (read_u16be(0x00,sf) == 0x0002) {
channels = 1;
}
else if (read_16bitBE(0x00,streamFile) == 0x0001) {
channel_count = 2; /* RP025.PCM, RP039.PCM */
else if (read_u16be(0x00,sf) == 0x0001) {
channels = 2; /* RP025.PCM, RP039.PCM */
}
else {
goto fail;
@ -31,31 +31,31 @@ VGMSTREAM * init_vgmstream_scd_pcm(STREAMFILE *streamFile) {
off_t i;
/* should be empty up to start (~0x0a/~0x10 sometimes has unknown values) */
for (i = 0x20; i < start_offset; i++) {
if (read_8bit(i, streamFile) != 0)
if (read_u8(i, sf) != 0)
goto fail;
}
}
/* loops start 0 is possible, plus all? files loops
* (even sfx/voices loop, but those set loop start in silence near the end) */
loop_flag = (read_32bitBE(0x06,streamFile) != 0);
loop_flag = (read_u32be(0x06,sf) != 0);
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
vgmstream = allocate_vgmstream(channels,loop_flag);
if (!vgmstream) goto fail;
vgmstream->meta_type = meta_SCD_PCM;
vgmstream->sample_rate = 32500; /* looks correct compared to emu/recordings */
vgmstream->num_samples = pcm_bytes_to_samples(get_streamfile_size(streamFile) - start_offset, channel_count, 8);
vgmstream->loop_start_sample = read_32bitBE(0x02,streamFile)*0x400*2;
vgmstream->loop_end_sample = read_32bitBE(0x06,streamFile)*2;
vgmstream->num_samples = pcm_bytes_to_samples(get_streamfile_size(sf) - start_offset, channels, 8);
vgmstream->loop_start_sample = read_s32be(0x02,sf)*0x400*2;
vgmstream->loop_end_sample = read_s32be(0x06,sf)*2;
vgmstream->coding_type = coding_PCM8_SB;
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = 0x800;
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
if (!vgmstream_open_stream(vgmstream,sf,start_offset))
goto fail;
return vgmstream;

View File

@ -2,22 +2,21 @@
#include "../coding/coding.h"
/* SSCF - Square-Enix games, older version of .scd [Crisis Core -Final Fantasy VII- (PSP), Dissidia 012 (PSP)] */
VGMSTREAM * init_vgmstream_scd_sscf(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
off_t start_offset, meta_offset, stream_offset;
size_t stream_size;
int loop_flag, channel_count, sample_rate;
int total_subsongs, target_subsong = streamFile->stream_index;
VGMSTREAM* init_vgmstream_scd_sscf(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
uint32_t start_offset, meta_offset, stream_offset, stream_size;
int loop_flag, channels, sample_rate;
int total_subsongs, target_subsong = sf->stream_index;
/* checks */
if (!check_extensions(streamFile, "scd"))
if (!is_id32be(0x00,sf, "SSCF"))
goto fail;
if (!check_extensions(sf, "scd"))
goto fail;
if (read_32bitBE(0x00,streamFile) != 0x53534346) /* "SSCF" "*/
goto fail;
if (!(read_32bitBE(0x04,streamFile) == 0x002070210 || /* version? [Crisis Core (PSP)] */
read_32bitBE(0x04,streamFile) == 0x10020702)) /* inverted version? [Dissidia (PSP)] */
if (!(read_u32be(0x04,sf) == 0x02070210 || /* version? [Crisis Core (PSP)] */
read_u32be(0x04,sf) == 0x10020702)) /* inverted version? [Dissidia (PSP)] */
goto fail;
/* 0x08: file size, except for a few files that with a weird value */
/* 0x10: file id? */
@ -26,8 +25,8 @@ VGMSTREAM * init_vgmstream_scd_sscf(STREAMFILE *streamFile) {
/* find total subsongs (entries can be dummy) and target subsong */
{
int i,j, is_dupe;
int entries = read_32bitLE(0x0c,streamFile);
off_t stream_offsets[0x800];
int entries = read_s32le(0x0c,sf);
uint32_t stream_offsets[0x800];
if (entries > 0x800) /* meh */
goto fail;
@ -38,18 +37,18 @@ VGMSTREAM * init_vgmstream_scd_sscf(STREAMFILE *streamFile) {
meta_offset = 0;
total_subsongs = 0;
for (i = 0; i < entries; i++) {
off_t entry_offset = 0x20 + (0x20*i);
off_t entry_stream_offset;
uint32_t entry_offset = 0x20 + (0x20*i);
uint32_t entry_stream_offset;
/* skip dummies */
if (read_32bitLE(entry_offset+0x08,streamFile) == 0) /* size 0 */
if (read_u32le(entry_offset+0x08,sf) == 0) /* size 0 */
continue;
if (read_16bitLE(entry_offset+0x0c,streamFile) == 0) /* no sample rate */
if (read_u16le(entry_offset+0x0c,sf) == 0) /* no sample rate */
continue;
/* skip repeated sounds */
is_dupe = 0;
entry_stream_offset = read_32bitLE(entry_offset+0x04,streamFile);
entry_stream_offset = read_u32le(entry_offset+0x04,sf);
for (j = 0; j < total_subsongs; j++) {
if (entry_stream_offset == stream_offsets[j]) {
is_dupe = 1;
@ -74,9 +73,9 @@ VGMSTREAM * init_vgmstream_scd_sscf(STREAMFILE *streamFile) {
/* 0x00(2): config? usually 0x00/0x01 */
/* 0x02(2): loop config */ //todo when 1 uses PS-ADPCM uses SPU loop flags to set start/end
stream_offset = read_32bitLE(meta_offset+0x04,streamFile); /* absolute */
stream_size = read_32bitLE(meta_offset+0x08,streamFile);
sample_rate = (uint16_t)read_16bitLE(meta_offset+0x0c,streamFile);
stream_offset = read_u32le(meta_offset+0x04,sf); /* absolute */
stream_size = read_u32le(meta_offset+0x08,sf);
sample_rate = read_u16le(meta_offset+0x0c,sf);
/* 0x0e: config? */
/* 0x10: config? */
/* 0x14: 0xCA5F or 0x5FCA */
@ -84,18 +83,18 @@ VGMSTREAM * init_vgmstream_scd_sscf(STREAMFILE *streamFile) {
/* 0x1c: null / some id? */
loop_flag = 0;
channel_count = 1;
channels = 1;
start_offset = stream_offset;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count, loop_flag);
vgmstream = allocate_vgmstream(channels, loop_flag);
if (!vgmstream) goto fail;
vgmstream->sample_rate = sample_rate;
vgmstream->num_streams = total_subsongs;
vgmstream->stream_size = stream_size;
vgmstream->num_samples = ps_bytes_to_samples(stream_size, channel_count);
vgmstream->num_samples = ps_bytes_to_samples(stream_size, channels);
if (loop_flag) {
vgmstream->loop_start_sample = 0;
vgmstream->loop_end_sample = vgmstream->num_samples;
@ -105,7 +104,7 @@ VGMSTREAM * init_vgmstream_scd_sscf(STREAMFILE *streamFile) {
vgmstream->coding_type = coding_PSX;
vgmstream->layout_type = layout_none;
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
if (!vgmstream_open_stream(vgmstream,sf,start_offset))
goto fail;
return vgmstream;

View File

@ -97,7 +97,6 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = {
init_vgmstream_ps2_kces,
init_vgmstream_hxd,
init_vgmstream_vsv,
init_vgmstream_scd_pcm,
init_vgmstream_ps2_pcm,
init_vgmstream_ps2_rkv,
init_vgmstream_ps2_vas,
@ -528,6 +527,7 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = {
init_vgmstream_bigrp,
/* lower priority metas (no clean header identity, somewhat ambiguous, or need extension/companion file to identify) */
init_vgmstream_scd_pcm,
init_vgmstream_agsc,
init_vgmstream_rsf,
init_vgmstream_ps2_wmus,

View File

@ -108,7 +108,7 @@ typedef enum {
coding_IMA_int, /* IMA ADPCM (mono/interleave, low nibble first) */
coding_DVI_IMA, /* DVI IMA ADPCM (stereo or mono, high nibble first) */
coding_DVI_IMA_int, /* DVI IMA ADPCM (mono/interleave, high nibble first) */
coding_3DS_IMA, /* 3DS IMA ADPCM */
coding_NW_IMA,
coding_SNDS_IMA, /* Heavy Iron Studios .snds IMA ADPCM */
coding_QD_IMA,
coding_WV6_IMA, /* Gorilla Systems WV6 4-bit IMA ADPCM */