Add .awb/afs2 for convenience

This commit is contained in:
bnnm 2019-07-07 20:46:14 +02:00
parent 0523b36a62
commit 1a4dbc83d3
7 changed files with 132 additions and 0 deletions

View File

@ -38,6 +38,7 @@ static const char* extension_list[] = {
"adw",
"adx",
"afc",
"afs2",
"agsc",
"ahx",
"ahv",
@ -68,6 +69,7 @@ static const char* extension_list[] = {
"atx",
"aud",
"aus",
"awb",
"awc",
"b1s",

View File

@ -451,6 +451,10 @@
<File
RelativePath=".\meta\atx.c"
>
</File>
<File
RelativePath=".\meta\awb.c"
>
</File>
<File
RelativePath=".\meta\awc.c"

View File

@ -150,6 +150,7 @@
<ClCompile Include="layout\layered.c" />
<ClCompile Include="layout\blocked_tra.c" />
<ClCompile Include="meta\akb.c" />
<ClCompile Include="meta\awb.c" />
<ClCompile Include="meta\awc.c" />
<ClCompile Include="meta\bcstm.c" />
<ClCompile Include="meta\bfstm.c" />

View File

@ -1567,6 +1567,9 @@
<ClCompile Include="meta\sk_aud.c">
<Filter>meta\Source Files</Filter>
</ClCompile>
<ClCompile Include="meta\awb.c">
<Filter>meta\Source Files</Filter>
</ClCompile>
<ClCompile Include="meta\awc.c">
<Filter>meta\Source Files</Filter>
</ClCompile>

119
src/meta/awb.c Normal file
View File

@ -0,0 +1,119 @@
#include "meta.h"
#include "../coding/coding.h"
typedef enum { ADX, HCA, AT9, VAG } awb_type;
/* CRI AFS2, container of streaming ADX or HCA, often (but not always) together with a .acb CUE */
VGMSTREAM * init_vgmstream_awb(STREAMFILE *streamFile) {
VGMSTREAM *vgmstream = NULL;
STREAMFILE *temp_streamFile = NULL;
off_t offset, subfile_offset, subfile_next;
size_t subfile_size;
int total_subsongs, target_subsong = streamFile->stream_index;
//uint32_t flags;
uint16_t alignment;//, derivation;
awb_type type;
char *extension = NULL;
/* checks
* .awb: standard
* .afs2: sometimes [Okami HD (PS4)] */
if (!check_extensions(streamFile, "awb,afs2"))
goto fail;
if (read_32bitBE(0x00,streamFile) != 0x41465332) /* "AFS2" */
goto fail;
//flags = read_32bitLE(0x08,streamFile);
total_subsongs = read_32bitLE(0x08,streamFile);
alignment = (uint16_t)read_16bitLE(0x0c,streamFile);
//derivation = (uint16_t)read_16bitLE(0x0e,streamFile);
if (target_subsong == 0) target_subsong = 1;
if (target_subsong > total_subsongs || total_subsongs <= 0) goto fail;
offset = 0x10;
/* id(?) table: skip */
offset += total_subsongs * 0x02;
/* offset table: find target
* offset are absolute but sometimes misaligned (specially first that just points to offset table end) */
{
off_t file_size = get_streamfile_size(streamFile);
offset += (target_subsong-1) * 0x04;
/* last offset is always file end, so table entries = total_subsongs+1 */
subfile_offset = read_32bitLE(offset+0x00,streamFile);
subfile_next = read_32bitLE(offset+0x04,streamFile);
subfile_offset += (subfile_offset % alignment) ?
alignment - (subfile_offset % alignment) : 0;
subfile_next += (subfile_next % alignment) && subfile_next < file_size ?
alignment - (subfile_next % alignment) : 0;
subfile_size = subfile_next - subfile_offset;
//todo: flags & 0x200 are uint16 offsets?
}
//;VGM_LOG("TXTH: subfile offset=%lx + %x\n", subfile_offset, subfile_size);
/* autodetect as there isn't anything, plus can mix types
* (waveid<>codec info is usually in the companion .acb) */
if ((uint16_t)read_16bitBE(subfile_offset, streamFile) == 0x8000) { /* ADX id */
type = ADX;
extension = "adx";
}
else if (((uint32_t)read_32bitBE(subfile_offset,streamFile) & 0x7f7f7f7f) == 0x48434100) { /* "HCA\0" */
type = HCA;
extension = "hca";
}
else if (read_32bitBE(subfile_offset,streamFile) == 0x52494646) { /* "RIFF" */
type = AT9;
extension = "at9";
}
else if (read_32bitBE(subfile_offset,streamFile) == 0x56414770) { /* "VAGp" */
type = VAG;
extension = "vag";
}
else {
goto fail;
}
temp_streamFile = setup_subfile_streamfile(streamFile, subfile_offset,subfile_size, extension);
if (!temp_streamFile) goto fail;
switch(type) {
case HCA: /* most common */
vgmstream = init_vgmstream_hca(temp_streamFile);
if (!vgmstream) goto fail;
break;
case ADX: /* Okami HD (PS4) */
vgmstream = init_vgmstream_adx(temp_streamFile);
if (!vgmstream) goto fail;
break;
case AT9: /* Ukiyo no Roushi (Vita) */
vgmstream = init_vgmstream_riff(temp_streamFile);
if (!vgmstream) goto fail;
break;
case VAG: /* Ukiyo no Roushi (Vita) */
vgmstream = init_vgmstream_vag(temp_streamFile);
if (!vgmstream) goto fail;
break;
default:
goto fail;
}
//todo: could try to get name in .acb for this waveid
vgmstream->num_streams = total_subsongs;
close_streamfile(temp_streamFile);
return vgmstream;
fail:
close_streamfile(temp_streamFile);
close_vgmstream(vgmstream);
return NULL;
}

View File

@ -858,4 +858,6 @@ VGMSTREAM * init_vgmstream_bwav(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_opus_prototype(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_awb(STREAMFILE * streamFile);
#endif /*_META_H*/

View File

@ -482,6 +482,7 @@ VGMSTREAM * (*init_vgmstream_functions[])(STREAMFILE *streamFile) = {
init_vgmstream_fsb5_fev_bank,
init_vgmstream_bwav,
init_vgmstream_opus_prototype,
init_vgmstream_awb,
/* lowest priority metas (should go after all metas, and TXTH should go before raw formats) */
init_vgmstream_txth, /* proper parsers should supersede TXTH, once added */