alternate sample count calculation for .strs with larger CTRL block...

git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@279 51a99a44-fe44-0410-b1ba-c3e57ba2b86b
This commit is contained in:
halleyscometsw 2008-07-03 19:26:53 +00:00
parent 183089bfcb
commit 4084ee9da5

View File

@ -15,6 +15,7 @@ VGMSTREAM * init_vgmstream_str_snds(STREAMFILE *streamFile) {
int loop_flag = 0; int loop_flag = 0;
off_t SHDR_offset = -1; off_t SHDR_offset = -1;
int FoundSHDR = 0; int FoundSHDR = 0;
int CTRL_size = -1;
size_t file_size; size_t file_size;
@ -42,6 +43,10 @@ VGMSTREAM * init_vgmstream_str_snds(STREAMFILE *streamFile) {
file_size) goto fail; file_size) goto fail;
switch (read_32bitBE(current_chunk,streamFile)) { switch (read_32bitBE(current_chunk,streamFile)) {
case 0x4354524C: /* CTRL */
/* to distinguish between styles */
CTRL_size = read_32bitBE(current_chunk+4,streamFile);
break;
case 0x534e4453: /* SNDS */ case 0x534e4453: /* SNDS */
switch (read_32bitBE(current_chunk+16,streamFile)) { switch (read_32bitBE(current_chunk+16,streamFile)) {
case 0x53484452: /* SHDR */ case 0x53484452: /* SHDR */
@ -73,16 +78,16 @@ VGMSTREAM * init_vgmstream_str_snds(STREAMFILE *streamFile) {
if (!vgmstream) goto fail; if (!vgmstream) goto fail;
/* fill in the vital statistics */ /* fill in the vital statistics */
vgmstream->num_samples = if (CTRL_size == 0x1C) {
read_32bitBE(SHDR_offset+0x2c,streamFile) * /* frame count? */ vgmstream->num_samples =
read_32bitBE(SHDR_offset+0x18,streamFile); /* frame size? */ read_32bitBE(SHDR_offset+0x2c,streamFile)-1; /* sample count? */
vgmstream->sample_rate = read_32bitBE(SHDR_offset+0x1c,streamFile); } else {
/* channels and loop flag are set by allocate_vgmstream */ vgmstream->num_samples =
if (loop_flag) { read_32bitBE(SHDR_offset+0x2c,streamFile) /* frame count? */
vgmstream->loop_start_sample = 0; * 0x10;
vgmstream->loop_end_sample = vgmstream->num_samples;
} }
vgmstream->sample_rate = read_32bitBE(SHDR_offset+0x1c,streamFile);
switch (read_32bitBE(SHDR_offset+0x24,streamFile)) { switch (read_32bitBE(SHDR_offset+0x24,streamFile)) {
case 0x53445832: /* SDX2 */ case 0x53445832: /* SDX2 */
vgmstream->coding_type = coding_SDX2; vgmstream->coding_type = coding_SDX2;
@ -94,6 +99,13 @@ VGMSTREAM * init_vgmstream_str_snds(STREAMFILE *streamFile) {
vgmstream->layout_type = layout_str_snds_blocked; vgmstream->layout_type = layout_str_snds_blocked;
vgmstream->meta_type = meta_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 */ /* open the file for reading by each channel */
{ {
int i; int i;