vgmstream/src/meta/ps2_smpl.c

49 lines
1.6 KiB
C
Raw Normal View History

#include "meta.h"
2017-11-23 22:33:46 +01:00
#include "../coding/coding.h"
/* SMPL - from Homura (PS2) */
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;
2017-11-23 22:33:46 +01:00
/* check extension (.v0: left channel, .v1: right channel, .smpl: header id) */
if ( !check_extensions(streamFile,"v0,v1,smpl") )
2017-11-23 22:33:46 +01:00
goto fail;
/* check header */
if (read_32bitBE(0x00,streamFile) != 0x534D504C) /* "SMPL" */
goto fail;
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;
2017-11-23 22:33:46 +01:00
/* build the VGMSTREAM */
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;
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);
/* open the file for reading */
if ( !vgmstream_open_stream(vgmstream, streamFile, start_offset) )
goto fail;
return vgmstream;
fail:
2017-11-23 22:33:46 +01:00
close_vgmstream(vgmstream);
return NULL;
}