2010-03-31 03:57:34 +02:00
|
|
|
#include "meta.h"
|
2017-11-23 22:33:46 +01:00
|
|
|
#include "../coding/coding.h"
|
2010-03-31 03:57:34 +02:00
|
|
|
|
2017-11-26 01:54:33 +01:00
|
|
|
/* SMPL - from Homura (PS2) */
|
2010-03-31 03:57:34 +02:00
|
|
|
VGMSTREAM * init_vgmstream_ps2_smpl(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
off_t start_offset;
|
2017-11-23 22:33:46 +01:00
|
|
|
int loop_flag, channel_count;
|
|
|
|
size_t channel_size;
|
2010-03-31 03:57:34 +02:00
|
|
|
|
2017-11-23 22:33:46 +01:00
|
|
|
/* check extension (.v0: left channel, .v1: right channel, .smpl: header id) */
|
2017-11-26 01:54:33 +01:00
|
|
|
if ( !check_extensions(streamFile,"v0,v1,smpl") )
|
2017-11-23 22:33:46 +01:00
|
|
|
goto fail;
|
2010-03-31 03:57:34 +02:00
|
|
|
|
|
|
|
/* check header */
|
|
|
|
if (read_32bitBE(0x00,streamFile) != 0x534D504C) /* "SMPL" */
|
|
|
|
goto fail;
|
|
|
|
|
2017-11-26 01:54:33 +01:00
|
|
|
channel_count = 1;
|
|
|
|
loop_flag = (read_32bitLE(0x30,streamFile) != 0); /* .v1 doesn't have loop points */
|
2017-11-23 22:33:46 +01:00
|
|
|
start_offset = 0x40;
|
|
|
|
channel_size = read_32bitBE(0x0c,streamFile) - 0x10;
|
2010-03-31 03:57:34 +02:00
|
|
|
|
2017-11-23 22:33:46 +01:00
|
|
|
/* build the VGMSTREAM */
|
2010-03-31 03:57:34 +02:00
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
vgmstream->sample_rate = read_32bitBE(0x10,streamFile);
|
2017-11-23 22:33:46 +01:00
|
|
|
vgmstream->num_samples = ps_bytes_to_samples(channel_size*channel_count, channel_count);
|
|
|
|
vgmstream->loop_start_sample = read_32bitLE(0x30,streamFile);
|
|
|
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
|
|
|
|
2010-03-31 03:57:34 +02:00
|
|
|
vgmstream->meta_type = meta_PS2_SMPL;
|
2017-11-23 22:33:46 +01:00
|
|
|
vgmstream->coding_type = coding_PSX;
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
|
|
|
|
/* always, but can be null or used as special string */
|
|
|
|
read_string(vgmstream->stream_name,0x10+1, 0x20,streamFile);
|
2010-03-31 03:57:34 +02:00
|
|
|
|
|
|
|
/* open the file for reading */
|
2017-11-26 01:54:33 +01:00
|
|
|
if ( !vgmstream_open_stream(vgmstream, streamFile, start_offset) )
|
|
|
|
goto fail;
|
2010-03-31 03:57:34 +02:00
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
2017-11-23 22:33:46 +01:00
|
|
|
close_vgmstream(vgmstream);
|
2010-03-31 03:57:34 +02:00
|
|
|
return NULL;
|
|
|
|
}
|