Add ISACT .isb [Psychonauts (PC)]

This commit is contained in:
bnnm 2019-11-03 22:56:37 +01:00
parent bc59318157
commit e0eaffbf3f
10 changed files with 228 additions and 0 deletions

View File

@ -216,6 +216,7 @@ static const char* extension_list[] = {
"imc",
"int",
"is14",
"isb",
"isd",
"isws",
"itl",
@ -1244,6 +1245,7 @@ static const meta_info meta_info_list[] = {
{meta_XMV_VALVE, "Valve XMV header"},
{meta_UBI_HX, "Ubisoft HXx header"},
{meta_BMP_KONAMI, "Konami BMP header"},
{meta_ISB, "Creative ISACT header"},
};

View File

@ -736,6 +736,10 @@
RelativePath=".\meta\ios_psnd.c"
>
</File>
<File
RelativePath=".\meta\isb.c"
>
</File>
<File
RelativePath=".\meta\ish_isd.c"
>

View File

@ -306,6 +306,7 @@
<ClCompile Include="meta\his.c" />
<ClCompile Include="meta\idsp_ie.c" />
<ClCompile Include="meta\nub.c" />
<ClCompile Include="meta\isb.c" />
<ClCompile Include="meta\ish_isd.c" />
<ClCompile Include="meta\ivaud.c" />
<ClCompile Include="meta\ivb.c" />

View File

@ -466,6 +466,9 @@
<ClCompile Include="meta\idsp_ie.c">
<Filter>meta\Source Files</Filter>
</ClCompile>
<ClCompile Include="meta\isb.c">
<Filter>meta\Source Files</Filter>
</ClCompile>
<ClCompile Include="meta\ish_isd.c">
<Filter>meta\Source Files</Filter>
</ClCompile>

191
src/meta/isb.c Normal file
View File

@ -0,0 +1,191 @@
#include "meta.h"
#include "../coding/coding.h"
/* .ISB - Creative ISACT (Interactive Spatial Audio Composition Tools) middleware [Psychonauts (PC)] */
VGMSTREAM * init_vgmstream_isb(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
off_t start_offset = 0, name_offset = 0;
size_t stream_size = 0, name_size = 0;
int loop_flag = 0, channel_count = 0, sample_rate = 0, codec = 0, pcm_bytes = 0, bps = 0;
int total_subsongs, target_subsong = streamFile->stream_index;
/* checks */
if (!check_extensions(streamFile, "isb"))
goto fail;
if (read_32bitBE(0x00,streamFile) != 0x52494646) /* "RIFF" */
goto fail;
if (read_32bitLE(0x04,streamFile) + 0x08 != get_streamfile_size(streamFile))
goto fail;
if (read_32bitBE(0x08,streamFile) != 0x69736266) /* "isbf" */
goto fail;
/* some files have a companion .icb, seems to be a cue file pointing here */
/* format is RIFF with many custom chunks, apparently for their DAW-like editor with
* complex functions, but most seem always included by default and unused, and games
* Psychonauts seems to use the format as a simple audio bank. Mass Effect (X360)
* apparently uses ISACT, while Psychonauts Xbox/PS2 don't. */
{
off_t offset, max_offset, header_offset = 0;
size_t header_size = 0;
total_subsongs = 0; /* not specified */
if (target_subsong == 0) target_subsong = 1;
/* parse base RIFF */
offset = 0x0c;
max_offset = get_streamfile_size(streamFile);
while (offset < max_offset) {
uint32_t chunk_type = read_u32be(offset + 0x00,streamFile);
uint32_t chunk_size = read_s32le(offset + 0x04,streamFile);
offset += 0x08;
switch(chunk_type) {
case 0x4C495354: /* "LIST" */
if (read_u32be(offset, streamFile) != 0x73616D70) /* "samp" */
break; /* there are "bfob" LIST without data */
total_subsongs++;
if (target_subsong == total_subsongs && header_offset == 0) {
header_offset = offset;
header_size = chunk_size;
}
break;
default: /* most are common chunks at the start that seem to contain defaults */
break;
}
//if (offset + chunk_size+0x01 <= max_offset && chunk_size % 0x02)
// chunk_size += 0x01;
offset += chunk_size;
}
if (target_subsong < 0 || target_subsong > total_subsongs || total_subsongs < 1) goto fail;
if (header_offset == 0) goto fail;
/* parse header inside LIST */
offset = header_offset + 0x04;
max_offset = offset + header_size;
while (offset < max_offset) {
uint32_t chunk_type = read_u32be(offset + 0x00,streamFile);
uint32_t chunk_size = read_s32le(offset + 0x04,streamFile);
offset += 0x08;
switch(chunk_type) {
case 0x7469746C: /* "titl" */
name_offset = offset;
name_size = chunk_size;
break;
case 0x63686E6B: /* "chnk" */
channel_count = read_u32le(offset + 0x00, streamFile);
break;
case 0x73696E66: /* "sinf" */
/* 0x00: null? */
/* 0x04: some value? */
sample_rate = read_u32le(offset + 0x08, streamFile);
pcm_bytes = read_u32le(offset + 0x0c, streamFile);
bps = read_u16le(offset + 0x10, streamFile);
/* 0x12: some value? */
break;
case 0x636D7069: /* "cmpi" */
codec = read_u32le(offset + 0x00, streamFile);
if (read_u32le(offset + 0x04, streamFile) != codec) {
VGM_LOG("ISB: unknown compression repeat\n");
goto fail;
}
/* 0x08: extra value for some codecs? */
/* 0x0c: block size when codec is XBOX-IMA */
/* 0x10: null? */
/* 0x14: flags? */
break;
case 0x64617461: /* "data" */
start_offset = offset;
stream_size = chunk_size;
break;
default: /* most of the same default chunks */
break;
}
//if (offset + chunk_size+0x01 <= max_offset && chunk_size % 0x02)
// chunk_size += 0x01;
offset += chunk_size;
}
if (start_offset == 0)
goto fail;
}
/* some files are marked */
loop_flag = 0;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count, loop_flag);
if (!vgmstream) goto fail;
vgmstream->meta_type = meta_WAF; //todo
vgmstream->sample_rate = sample_rate;
vgmstream->num_streams = total_subsongs;
vgmstream->stream_size = stream_size;
switch(codec) {
case 0x00:
if (bps == 8) {
vgmstream->coding_type = coding_PCM8_U;
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = 0x01;
}
else {
vgmstream->coding_type = coding_PCM16LE;
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = 0x02;
}
vgmstream->num_samples = pcm_bytes_to_samples(stream_size, channel_count, bps); /* unsure about pcm_bytes */
break;
case 0x01:
vgmstream->coding_type = coding_XBOX_IMA;
vgmstream->layout_type = layout_none;
vgmstream->num_samples = xbox_ima_bytes_to_samples(stream_size, channel_count); /* pcm_bytes has excess data */
break;
#ifdef VGM_USE_VORBIS
case 0x02:
vgmstream->codec_data = init_ogg_vorbis(streamFile, start_offset, stream_size, NULL);
if (!vgmstream->codec_data) goto fail;
vgmstream->coding_type = coding_OGG_VORBIS;
vgmstream->layout_type = layout_none;
vgmstream->num_samples = pcm_bytes / channel_count / (bps/8);
break;
#endif
default: /* according to press releases ISACT may support WMA and XMA */
VGM_LOG("ISB: unknown codec %i\n", codec);
goto fail;
}
if (name_offset) { /* UTF16 but only uses lower bytes */
if (name_size > STREAM_NAME_SIZE)
name_size = STREAM_NAME_SIZE;
read_string_utf16le(vgmstream->stream_name,name_size, name_offset, streamFile);
}
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
goto fail;
return vgmstream;
fail:
close_vgmstream(vgmstream);
return NULL;
}

View File

@ -868,4 +868,6 @@ VGMSTREAM * init_vgmstream_ubi_hx(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_bmp_konami(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_isb(STREAMFILE * streamFile);
#endif /*_META_H*/

View File

@ -989,6 +989,27 @@ fail:
if (buf) buf[0] = '\0';
return 0;
}
size_t read_string_utf16le(char *buf, size_t buf_size, off_t offset, STREAMFILE *sf) {
size_t pos, offpos;
for (pos = 0, offpos = 0; pos < buf_size; pos++, offpos += 2) {
char c = read_u16le(offset + offpos, sf) & 0xFF; /* lower byte for now */
if (buf) buf[pos] = c;
if (c == '\0')
return pos;
if (pos+1 == buf_size) { /* null at maxsize and don't validate (expected to be garbage) */
if (buf) buf[pos] = '\0';
return buf_size;
}
if (c < 0x20 || (uint8_t)c > 0xA5)
goto fail;
}
fail:
if (buf) buf[0] = '\0';
return 0;
}
size_t read_key_file(uint8_t *buf, size_t buf_size, STREAMFILE *sf) {

View File

@ -330,6 +330,8 @@ size_t read_line(char *buf, int buf_size, off_t offset, STREAMFILE *sf, int *p_l
/* reads a c-string (ANSI only), up to bufsize or NULL, returning size. buf is optional (works as get_string_size). */
size_t read_string(char *buf, size_t buf_size, off_t offset, STREAMFILE *sf);
/* reads a UTF16 string... but actually only as ANSI (discards the upper byte) */
size_t read_string_utf16le(char *buf, size_t buf_size, off_t offset, STREAMFILE *sf);
/* Opens a file containing decryption keys and copies to buffer.
* Tries "(name.ext)key" (per song), "(.ext)key" (per folder) keynames.

View File

@ -481,6 +481,7 @@ VGMSTREAM * (*init_vgmstream_functions[])(STREAMFILE *streamFile) = {
init_vgmstream_bmp_konami,
init_vgmstream_opus_opusnx,
init_vgmstream_opus_sqex,
init_vgmstream_isb,
/* 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 */

View File

@ -714,6 +714,7 @@ typedef enum {
meta_XMV_VALVE,
meta_UBI_HX,
meta_BMP_KONAMI,
meta_ISB,
} meta_t;