2008-05-06 05:35:37 +02:00
|
|
|
#include "meta.h"
|
2008-05-04 22:36:40 +02:00
|
|
|
#include "../util.h"
|
|
|
|
|
|
|
|
/* Sony .ADS with SShd & SSbd Headers */
|
|
|
|
|
|
|
|
VGMSTREAM * init_vgmstream_ps2_ads(const char * const filename) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
STREAMFILE * infile = NULL;
|
|
|
|
|
|
|
|
int loop_flag=0;
|
2008-05-05 00:10:30 +02:00
|
|
|
int channel_count;
|
2008-05-04 22:36:40 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* check extension, case insensitive */
|
|
|
|
if (strcasecmp("ads",filename_extension(filename)) &&
|
2008-05-05 00:10:30 +02:00
|
|
|
strcasecmp("ss2",filename_extension(filename))) goto fail;
|
2008-05-04 22:36:40 +02:00
|
|
|
|
|
|
|
/* try to open the file for header reading */
|
|
|
|
infile = open_streamfile(filename);
|
|
|
|
if (!infile) goto fail;
|
|
|
|
|
|
|
|
/* check SShd Header */
|
|
|
|
if (read_32bitBE(0x00,infile) != 0x53536864)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* check SSbd Header */
|
|
|
|
if (read_32bitBE(0x20,infile) != 0x53536264)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* check if file is not corrupt */
|
|
|
|
if (get_streamfile_size(infile)<(size_t)(read_32bitLE(0x24,infile) + 0x28))
|
|
|
|
goto fail;
|
2008-05-05 00:10:30 +02:00
|
|
|
|
|
|
|
/* check loop */
|
|
|
|
loop_flag = (read_32bitLE(0x18,infile)!=0xFFFFFFFF);
|
2008-05-04 22:36:40 +02:00
|
|
|
|
|
|
|
channel_count=read_32bitLE(0x10,infile);
|
2008-05-05 00:10:30 +02:00
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
2008-05-04 22:36:40 +02:00
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2008-05-05 00:10:30 +02:00
|
|
|
/* fill in the vital statistics */
|
|
|
|
vgmstream->channels = read_32bitLE(0x10,infile);
|
2008-05-04 22:36:40 +02:00
|
|
|
vgmstream->sample_rate = read_32bitLE(0x0C,infile);
|
|
|
|
|
2008-05-05 00:10:30 +02:00
|
|
|
/* Check for Compression Scheme */
|
|
|
|
vgmstream->coding_type = coding_PSX;
|
2008-05-04 22:36:40 +02:00
|
|
|
vgmstream->num_samples = read_32bitLE(0x24,infile)/16*28/vgmstream->channels;
|
|
|
|
|
2008-05-05 00:10:30 +02:00
|
|
|
/* SS2 container with RAW Interleaved PCM */
|
|
|
|
if (read_32bitLE(0x08,infile)==0x01) {
|
|
|
|
vgmstream->coding_type=coding_PCM16LE;
|
|
|
|
vgmstream->num_samples = read_32bitLE(0x24,infile)/2/vgmstream->channels;
|
|
|
|
}
|
2008-05-04 22:36:40 +02:00
|
|
|
|
2008-05-05 00:10:30 +02:00
|
|
|
/* Get loop point values */
|
|
|
|
if(vgmstream->loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = read_32bitLE(0x18,infile);
|
|
|
|
vgmstream->loop_end_sample = read_32bitLE(0x1C,infile);
|
|
|
|
}
|
2008-05-04 22:36:40 +02:00
|
|
|
|
|
|
|
/* don't know why, but it does happen, in ps2 too :( */
|
|
|
|
if (vgmstream->loop_end_sample > vgmstream->num_samples)
|
|
|
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
|
|
|
|
2008-05-05 00:10:30 +02:00
|
|
|
vgmstream->interleave_block_size = read_32bitLE(0x14,infile);
|
2008-05-04 22:36:40 +02:00
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
vgmstream->meta_type = meta_PS2_SShd;
|
|
|
|
|
|
|
|
close_streamfile(infile); infile=NULL;
|
|
|
|
|
|
|
|
/* open the file for reading by each channel */
|
|
|
|
{
|
|
|
|
for (i=0;i<channel_count;i++) {
|
|
|
|
vgmstream->ch[i].streamfile = open_streamfile_buffer(filename,0x8000);
|
|
|
|
|
|
|
|
if (!vgmstream->ch[i].streamfile) goto fail;
|
|
|
|
|
|
|
|
vgmstream->ch[i].channel_start_offset=
|
|
|
|
vgmstream->ch[i].offset=
|
|
|
|
0x28+vgmstream->interleave_block_size*i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
/* clean up anything we may have opened */
|
|
|
|
fail:
|
|
|
|
if (infile) close_streamfile(infile);
|
|
|
|
if (vgmstream) close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|