vgmstream/src/meta/ps2_svag_snk.c

81 lines
2.2 KiB
C
Raw Normal View History

2016-10-27 23:21:12 +02:00
#include "meta.h"
#include "../util.h"
/* PS2 SVAG (SNK)
*
* Found in SNK's World Heroes Anthology and Fatal Fury Battle Archives 2, maybe others
* No relation with Konami's SVAG.
*/
VGMSTREAM * init_vgmstream_ps2_svag_snk(STREAMFILE* streamFile) {
VGMSTREAM * vgmstream = NULL;
char filename[PATH_LIMIT];
2016-10-30 10:36:29 +01:00
off_t start_offset = 0x20;
int loop_flag;
int channel_count;
int loop_start_block;
int loop_end_block;
2016-10-27 23:21:12 +02:00
/* check extension, case insensitive */
streamFile->get_name(streamFile,filename,sizeof(filename));
if (strcasecmp("svag",filename_extension(filename))) goto fail;
/* check SNK SVAG Header ("VAGm") */
if (read_32bitBE(0x00,streamFile) != 0x5641476D)
goto fail;
2016-10-30 10:36:29 +01:00
channel_count = read_32bitLE(0x0c,streamFile);
2016-10-27 23:21:12 +02:00
2016-10-30 10:36:29 +01:00
loop_start_block = read_32bitLE(0x18,streamFile);
loop_end_block = read_32bitLE(0x1c,streamFile);
loop_flag = loop_end_block > 0; /* loop_start_block can be 0 */
2016-10-27 23:21:12 +02:00
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
if (!vgmstream) goto fail;
/* header data */
vgmstream->coding_type = coding_PSX;
vgmstream->meta_type = meta_PS2_SVAG_SNK;
vgmstream->channels = channel_count;
2016-10-30 10:36:29 +01:00
vgmstream->sample_rate = read_32bitLE(0x08,streamFile);
vgmstream->num_samples = read_32bitLE(0x10,streamFile) * 28; /* size in blocks */
2016-10-27 23:21:12 +02:00
if( vgmstream->loop_flag ) {
vgmstream->loop_start_sample = loop_start_block * 28;
vgmstream->loop_end_sample = loop_end_block * 28;
}
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = 0x10;
/* open the file for reading */
{
int i;
STREAMFILE * file;
file = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE);
if (!file) goto fail;
for (i=0;i<channel_count;i++) {
vgmstream->ch[i].streamfile = file;
vgmstream->ch[i].channel_start_offset =
vgmstream->ch[i].offset =
start_offset + vgmstream->interleave_block_size*i;
}
}
return vgmstream;
/* clean up anything we may have opened */
fail:
if (vgmstream) close_vgmstream(vgmstream);
return NULL;
}