2010-03-31 03:57:34 +02:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../util.h"
|
|
|
|
|
|
|
|
/* MSA (from Psyvariar -Complete Edition-) */
|
|
|
|
VGMSTREAM * init_vgmstream_ps2_msa(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
2017-01-27 19:32:40 +01:00
|
|
|
off_t start_offset, datasize, filesize;
|
|
|
|
int loop_flag, channel_count;
|
2010-03-31 03:57:34 +02:00
|
|
|
|
|
|
|
/* check extension, case insensitive */
|
2017-01-27 19:32:40 +01:00
|
|
|
if (!check_extensions(streamFile, "msa")) goto fail;
|
2010-03-31 03:57:34 +02:00
|
|
|
|
|
|
|
/* check header */
|
|
|
|
if (read_32bitBE(0x00,streamFile) != 0x00000000)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
loop_flag = 0;
|
|
|
|
channel_count = 2;
|
|
|
|
|
2017-01-27 19:32:40 +01:00
|
|
|
/* build the VGMSTREAM */
|
2010-03-31 03:57:34 +02:00
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
start_offset = 0x14;
|
2017-01-27 19:32:40 +01:00
|
|
|
datasize = read_32bitLE(0x4,streamFile);
|
|
|
|
filesize = get_streamfile_size(streamFile);
|
|
|
|
vgmstream->channels = channel_count;
|
|
|
|
vgmstream->sample_rate = read_32bitLE(0x10,streamFile);
|
|
|
|
vgmstream->num_samples = datasize*28/(16*channel_count);
|
2010-03-31 03:57:34 +02:00
|
|
|
vgmstream->coding_type = coding_PSX;
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
vgmstream->interleave_block_size = 0x4000;
|
|
|
|
vgmstream->meta_type = meta_PS2_MSA;
|
|
|
|
|
2017-01-27 19:32:40 +01:00
|
|
|
/* MSAs are strangely truncated, so manually calculate samples
|
|
|
|
* data after last usable block is always silence or garbage */
|
|
|
|
if (datasize > filesize) {
|
|
|
|
off_t usable_size = filesize - start_offset;
|
|
|
|
usable_size -= usable_size % (vgmstream->interleave_block_size*channel_count);/* block-aligned */
|
|
|
|
vgmstream->num_samples = usable_size * 28 / (16*channel_count);
|
2010-03-31 03:57:34 +02:00
|
|
|
}
|
|
|
|
|
2017-01-27 19:32:40 +01:00
|
|
|
|
|
|
|
/* open the file for reading */
|
|
|
|
if (!vgmstream_open_stream(vgmstream, streamFile, start_offset))
|
|
|
|
goto fail;
|
2010-03-31 03:57:34 +02:00
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
2017-01-27 19:32:40 +01:00
|
|
|
close_vgmstream(vgmstream);
|
2010-03-31 03:57:34 +02:00
|
|
|
return NULL;
|
|
|
|
}
|