Reject EXST in .int meta and cleanup

This commit is contained in:
bnnm 2018-08-16 20:06:14 +02:00
parent 611e556809
commit 2e90f4de57

View File

@ -1,64 +1,52 @@
#include "meta.h"
#include "../util.h"
/* INT
PS2 INT format is a RAW 48khz PCM file without header
The only fact about those file, is that the raw is interleaved
The interleave value is allways 0x200
known extensions : INT
2008-05-11 - Fastelbja : First version ...
*/
#include "../coding/coding.h"
/* raw PCM file assumed by extension [PaRappa The Rapper 2 (PS2)? , Amplitude (PS2)?] */
VGMSTREAM * init_vgmstream_ps2_int(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
char filename[PATH_LIMIT];
int i,channel_count;
off_t start_offset;
int channel_count;
/* check extension, case insensitive */
streamFile->get_name(streamFile,filename,sizeof(filename));
if (strcasecmp("int",filename_extension(filename)) &&
strcasecmp("wp2",filename_extension(filename))) goto fail;
/* checks */
if (!check_extensions(streamFile, "int,wp2"))
goto fail;
if(!strcasecmp("int",filename_extension(filename)))
channel_count = 2;
else
channel_count = 4;
if (check_extensions(streamFile, "int"))
channel_count = 2;
else
channel_count = 4;
/* try to skip known .int (a horrible idea this parser exists) */
{
/* ignore A2M .int */
if (read_32bitBE(0x00,streamFile) == 0x41324D00) /* "A2M\0" */
goto fail;
/* ignore EXST .int */
if (read_32bitBE(0x10,streamFile) == 0x0C020000 &&
read_32bitBE(0x20,streamFile) == 0x0C020000 &&
read_32bitBE(0x30,streamFile) == 0x0C020000 &&
read_32bitBE(0x40,streamFile) == 0x0C020000) /* check a few empty PS-ADPCM frames */
goto fail;
}
start_offset = 0x00;
/* ignore A2M .int */
if (read_32bitBE(0x00,streamFile) == 0x41324D00) /* "A2M\0" */
goto fail;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,0);
if (!vgmstream) goto fail;
/* fill in the vital statistics */
vgmstream->channels=channel_count;
vgmstream->sample_rate = 48000;
vgmstream->coding_type = coding_PCM16LE;
vgmstream->num_samples = (int32_t)(get_streamfile_size(streamFile)/(vgmstream->channels*2));
vgmstream->interleave_block_size = 0x200;
vgmstream->layout_type = layout_interleave;
vgmstream->meta_type = meta_PS2_RAW;
vgmstream->num_samples = pcm_bytes_to_samples(get_streamfile_size(streamFile), vgmstream->channels, 16);
vgmstream->coding_type = coding_PCM16LE;
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = 0x200;
/* open the file for reading by each channel */
{
for (i=0;i<vgmstream->channels;i++) {
vgmstream->ch[i].streamfile = streamFile->open(streamFile,filename,0x8000);
if (!vgmstream->ch[i].streamfile) goto fail;
vgmstream->ch[i].channel_start_offset=
vgmstream->ch[i].offset=i*vgmstream->interleave_block_size;
}
}
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);
return NULL;