2012-03-22 03:25:16 +01:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../coding/coding.h"
|
|
|
|
#include "../layout/layout.h"
|
|
|
|
|
|
|
|
|
2019-08-11 20:07:35 +02:00
|
|
|
/* .str - 3DO format with CTRL/SNDS/SHDR blocks [Icebreaker (3DO), Battle Pinball (3DO)] */
|
2012-03-22 03:25:16 +01:00
|
|
|
VGMSTREAM * init_vgmstream_str_snds(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
2019-08-11 20:07:35 +02:00
|
|
|
off_t start_offset, shdr_offset = -1;
|
|
|
|
int loop_flag, channel_count, found_shdr = 0;
|
|
|
|
size_t file_size, ctrl_size = -1;
|
2012-03-22 03:25:16 +01:00
|
|
|
|
|
|
|
|
2019-08-11 20:07:35 +02:00
|
|
|
/* checks */
|
|
|
|
if (!check_extensions(streamFile, "str"))
|
|
|
|
goto fail;
|
2012-03-22 03:25:16 +01:00
|
|
|
|
2019-08-11 20:07:35 +02:00
|
|
|
if (read_32bitBE(0x00,streamFile) != 0x4354524c && /* "CTRL" */
|
|
|
|
read_32bitBE(0x00,streamFile) != 0x534e4453 && /* "SNDS" */
|
|
|
|
read_32bitBE(0x00,streamFile) != 0x53484452) /* "SHDR" */
|
2012-03-22 03:25:16 +01:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
file_size = get_streamfile_size(streamFile);
|
2019-08-11 20:07:35 +02:00
|
|
|
start_offset = 0x00;
|
2012-03-22 03:25:16 +01:00
|
|
|
|
|
|
|
/* scan chunks until we find a SNDS containing a SHDR */
|
|
|
|
{
|
2019-08-11 20:07:35 +02:00
|
|
|
off_t current_chunk = 0;
|
2012-03-22 03:25:16 +01:00
|
|
|
|
2019-08-11 20:07:35 +02:00
|
|
|
while (!found_shdr && current_chunk < file_size) {
|
2012-03-22 03:25:16 +01:00
|
|
|
if (current_chunk < 0) goto fail;
|
|
|
|
|
2019-08-11 20:07:35 +02:00
|
|
|
if (current_chunk+read_32bitBE(current_chunk+0x04,streamFile) >= file_size)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
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;
|
2012-03-22 03:25:16 +01:00
|
|
|
}
|
|
|
|
break;
|
2019-08-11 20:07:35 +02:00
|
|
|
|
|
|
|
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;
|
2012-03-22 03:25:16 +01:00
|
|
|
}
|
2019-08-11 20:07:35 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2012-03-22 03:25:16 +01:00
|
|
|
/* ignore others for now */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-08-11 20:07:35 +02:00
|
|
|
current_chunk += read_32bitBE(current_chunk+0x04,streamFile);
|
2012-03-22 03:25:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-11 20:07:35 +02:00
|
|
|
if (!found_shdr) goto fail;
|
2012-03-22 03:25:16 +01:00
|
|
|
|
2019-08-11 20:07:35 +02:00
|
|
|
channel_count = read_32bitBE(shdr_offset+0x20,streamFile);
|
2012-03-22 03:25:16 +01:00
|
|
|
loop_flag = 0;
|
|
|
|
|
|
|
|
|
2019-08-11 20:07:35 +02:00
|
|
|
/* build the VGMSTREAM */
|
2012-03-22 03:25:16 +01:00
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2019-08-11 20:07:35 +02:00
|
|
|
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? */
|
2012-03-22 03:25:16 +01:00
|
|
|
}
|
2019-08-11 20:07:35 +02:00
|
|
|
else {
|
|
|
|
vgmstream->num_samples = read_32bitBE(shdr_offset+0x2c,streamFile) * 0x10; /* frame count? */
|
2012-03-22 03:25:16 +01:00
|
|
|
}
|
2019-08-11 20:07:35 +02:00
|
|
|
vgmstream->num_samples /= vgmstream->channels;
|
2012-03-22 03:25:16 +01:00
|
|
|
|
2019-08-11 20:07:35 +02:00
|
|
|
switch (read_32bitBE(shdr_offset+0x24,streamFile)) {
|
|
|
|
case 0x53445832: /* "SDX2" */
|
2012-03-22 03:25:16 +01:00
|
|
|
if (channel_count > 1) {
|
|
|
|
vgmstream->coding_type = coding_SDX2_int;
|
|
|
|
vgmstream->interleave_block_size = 1;
|
|
|
|
} else
|
|
|
|
vgmstream->coding_type = coding_SDX2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto fail;
|
|
|
|
}
|
2018-03-29 19:00:04 +02:00
|
|
|
vgmstream->layout_type = layout_blocked_str_snds;
|
2012-03-22 03:25:16 +01:00
|
|
|
|
2019-08-11 20:07:35 +02:00
|
|
|
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
|
|
|
|
goto fail;
|
2012-03-22 03:25:16 +01:00
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
2019-08-11 20:07:35 +02:00
|
|
|
close_vgmstream(vgmstream);
|
2012-03-22 03:25:16 +01:00
|
|
|
return NULL;
|
|
|
|
}
|