Minor cleanup

This commit is contained in:
bnnm 2019-08-11 20:07:35 +02:00
parent f0151cc26f
commit 7f240f4c45
2 changed files with 59 additions and 100 deletions

View File

@ -834,7 +834,7 @@ static const meta_info meta_info_list[] = {
{meta_DSP_WSI, "Alone in the Dark .WSI header"},
{meta_AIFC, "Apple AIFF-C (Audio Interchange File Format) header"},
{meta_AIFF, "Apple AIFF (Audio Interchange File Format) header"},
{meta_STR_SNDS, ".str SNDS SHDR chunk"},
{meta_STR_SNDS, "3DO .str header"},
{meta_WS_AUD, "Westwood Studios .aud header"},
{meta_WS_AUD_old, "Westwood Studios .aud (old) header"},
{meta_PS2_IVB, "IVB/BVII header"},

View File

@ -1,118 +1,98 @@
#include "meta.h"
#include "../coding/coding.h"
#include "../layout/layout.h"
#include "../util.h"
/* 3DO format, .str extension and possibly a CTRL header, blocks and
* AIFF-C style format specifier. Blocks are not IFF-compliant. Interesting
* blocks are all SNDS
*/
/* .str - 3DO format with CTRL/SNDS/SHDR blocks [Icebreaker (3DO), Battle Pinball (3DO)] */
VGMSTREAM * init_vgmstream_str_snds(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
char filename[PATH_LIMIT];
off_t start_offset, shdr_offset = -1;
int loop_flag, channel_count, found_shdr = 0;
size_t file_size, ctrl_size = -1;
int channel_count;
int loop_flag = 0;
off_t SHDR_offset = -1;
int FoundSHDR = 0;
int CTRL_size = -1;
size_t file_size;
/* checks */
if (!check_extensions(streamFile, "str"))
goto fail;
/* check extension, case insensitive */
streamFile->get_name(streamFile,filename,sizeof(filename));
if (strcasecmp("str",filename_extension(filename))) goto fail;
/* check for opening CTRL or SNDS chunk */
if (read_32bitBE(0x0,streamFile) != 0x4354524c && /* CTRL */
read_32bitBE(0x0,streamFile) != 0x534e4453 && // SNDS
read_32bitBE(0x0,streamFile) != 0x53484452) // SHDR
if (read_32bitBE(0x00,streamFile) != 0x4354524c && /* "CTRL" */
read_32bitBE(0x00,streamFile) != 0x534e4453 && /* "SNDS" */
read_32bitBE(0x00,streamFile) != 0x53484452) /* "SHDR" */
goto fail;
file_size = get_streamfile_size(streamFile);
start_offset = 0x00;
/* scan chunks until we find a SNDS containing a SHDR */
{
off_t current_chunk;
off_t current_chunk = 0;
current_chunk = 0;
while (!FoundSHDR && current_chunk < file_size) {
while (!found_shdr && current_chunk < file_size) {
if (current_chunk < 0) goto fail;
if (current_chunk+read_32bitBE(current_chunk+4,streamFile) >=
file_size) goto fail;
if (current_chunk+read_32bitBE(current_chunk+0x04,streamFile) >= file_size)
goto fail;
switch (read_32bitBE(current_chunk,streamFile))
{
case 0x4354524C: /* CTRL */
switch (read_32bitBE(current_chunk,streamFile)) {
case 0x4354524C: /* "CTRL" */
ctrl_size = read_32bitBE(current_chunk+4,streamFile);
break;
case 0x534e4453: /* "SNDS" */
switch (read_32bitBE(current_chunk+16,streamFile)) {
case 0x53484452: /* SHDR */
found_shdr = 1;
shdr_offset = current_chunk+16;
break;
default:
break;
}
break;
case 0x53484452: /* "SHDR" */
switch (read_32bitBE(current_chunk+0x7C, streamFile)) {
case 0x4354524C: /* "CTRL" */
/* to distinguish between styles */
CTRL_size = read_32bitBE(current_chunk+4,streamFile);
break;
case 0x534e4453: /* SNDS */
switch (read_32bitBE(current_chunk+16,streamFile))
{
case 0x53484452: /* SHDR */
FoundSHDR = 1;
SHDR_offset = current_chunk+16;
ctrl_size = read_32bitBE(current_chunk + 0x80, streamFile);
break;
default:
break;
}
break;
case 0x53484452: /* SHDR */
switch (read_32bitBE(current_chunk+0x7C, streamFile))
{
case 0x4354524C: /* CTRL */
// to distinguish between styles
CTRL_size = read_32bitBE(current_chunk + 0x80, streamFile);
break;
default:
break;
}
break;
default:
/* ignore others for now */
break;
}
current_chunk += read_32bitBE(current_chunk+4,streamFile);
current_chunk += read_32bitBE(current_chunk+0x04,streamFile);
}
}
if (!FoundSHDR) goto fail;
if (!found_shdr) goto fail;
/* details */
channel_count = read_32bitBE(SHDR_offset+0x20,streamFile);
channel_count = read_32bitBE(shdr_offset+0x20,streamFile);
loop_flag = 0;
/* build the VGMSTREAM */
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
if (!vgmstream) goto fail;
/* fill in the vital statistics */
if ((CTRL_size == 0x1C) ||
(CTRL_size == 0x0B) ||
(CTRL_size == -1))
{
vgmstream->num_samples =
read_32bitBE(SHDR_offset+0x2c,streamFile)-1; /* sample count? */
vgmstream->meta_type = meta_STR_SNDS;
vgmstream->sample_rate = read_32bitBE(shdr_offset+0x1c,streamFile);
if (ctrl_size == 0x1C || ctrl_size == 0x0B || ctrl_size == -1) {
vgmstream->num_samples = read_32bitBE(shdr_offset+0x2c,streamFile) - 1; /* sample count? */
}
else {
vgmstream->num_samples =
read_32bitBE(SHDR_offset+0x2c,streamFile) /* frame count? */
* 0x10;
vgmstream->num_samples = read_32bitBE(shdr_offset+0x2c,streamFile) * 0x10; /* frame count? */
}
vgmstream->num_samples /= vgmstream->channels;
vgmstream->sample_rate = read_32bitBE(SHDR_offset+0x1c,streamFile);
switch (read_32bitBE(SHDR_offset+0x24,streamFile)) {
case 0x53445832: /* SDX2 */
switch (read_32bitBE(shdr_offset+0x24,streamFile)) {
case 0x53445832: /* "SDX2" */
if (channel_count > 1) {
vgmstream->coding_type = coding_SDX2_int;
vgmstream->interleave_block_size = 1;
@ -123,33 +103,12 @@ VGMSTREAM * init_vgmstream_str_snds(STREAMFILE *streamFile) {
goto fail;
}
vgmstream->layout_type = layout_blocked_str_snds;
vgmstream->meta_type = meta_STR_SNDS;
/* channels and loop flag are set by allocate_vgmstream */
if (loop_flag) {
/* just guessin', no way to set loop flag anyway */
vgmstream->loop_start_sample = 0;
vgmstream->loop_end_sample = vgmstream->num_samples;
}
/* open the file for reading by each channel */
{
int i;
vgmstream->ch[0].streamfile = streamFile->open(streamFile,filename,
STREAMFILE_DEFAULT_BUFFER_SIZE);
if (!vgmstream->ch[0].streamfile) goto fail;
for (i=0;i<channel_count;i++) {
vgmstream->ch[i].streamfile = vgmstream->ch[0].streamfile;
}
}
/* start me up */
block_update_str_snds(0,vgmstream);
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
goto fail;
return vgmstream;
/* clean up anything we may have opened */
fail:
if (vgmstream) close_vgmstream(vgmstream);
close_vgmstream(vgmstream);
return NULL;
}