2009-05-01 17:03:51 +02:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../util.h"
|
|
|
|
|
2018-03-24 19:27:24 +01:00
|
|
|
/* SND - Might and Magic games [Warriors of M&M (PS2), Heroes of M&M: Quest for the DragonBone Staff (PS2)] */
|
2009-05-01 17:03:51 +02:00
|
|
|
VGMSTREAM * init_vgmstream_ps2_snd(STREAMFILE *streamFile) {
|
2018-03-24 19:27:24 +01:00
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
off_t start_offset;
|
|
|
|
size_t data_size;
|
|
|
|
int loop_flag, channel_count;
|
2009-05-01 17:03:51 +02:00
|
|
|
|
2018-03-24 19:27:24 +01:00
|
|
|
/* checks */
|
|
|
|
if (!check_extensions(streamFile, "snd"))
|
|
|
|
goto fail;
|
|
|
|
if (read_32bitBE(0x00,streamFile) != 0x53534E44) /* "SSND" */
|
|
|
|
goto fail;
|
2009-05-01 17:03:51 +02:00
|
|
|
|
2018-03-24 19:27:24 +01:00
|
|
|
start_offset = read_32bitLE(0x04,streamFile)+0x08;
|
|
|
|
data_size = get_streamfile_size(streamFile) - start_offset;
|
2009-05-01 17:03:51 +02:00
|
|
|
|
2018-03-24 19:27:24 +01:00
|
|
|
loop_flag = 1; /* force full Loop */
|
2009-05-01 17:03:51 +02:00
|
|
|
channel_count = read_16bitLE(0x0a,streamFile);
|
2018-03-24 19:27:24 +01:00
|
|
|
|
2009-05-01 17:03:51 +02:00
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2018-03-24 19:27:24 +01:00
|
|
|
vgmstream->sample_rate = (uint16_t)read_16bitLE(0x0e,streamFile);
|
2009-08-30 00:45:51 +02:00
|
|
|
vgmstream->num_samples = read_32bitLE(0x16,streamFile);
|
2018-03-24 19:27:24 +01:00
|
|
|
vgmstream->loop_start_sample = 0;
|
|
|
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
2009-08-30 00:45:51 +02:00
|
|
|
|
2009-05-01 17:03:51 +02:00
|
|
|
vgmstream->meta_type = meta_PS2_SND;
|
|
|
|
|
2018-03-24 19:27:24 +01:00
|
|
|
if (read_8bit(0x08,streamFile)==1) {
|
|
|
|
vgmstream->coding_type = coding_DVI_IMA_int; /* Warriors of M&M DragonBone */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
vgmstream->coding_type = coding_PCM16LE; /* Heroes of M&M */
|
|
|
|
}
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
vgmstream->interleave_block_size = (uint16_t)read_16bitLE(0x12,streamFile);
|
|
|
|
if (vgmstream->interleave_block_size)
|
|
|
|
vgmstream->interleave_last_block_size = (data_size % (vgmstream->interleave_block_size*vgmstream->channels)) / vgmstream->channels;
|
2009-05-01 17:03:51 +02:00
|
|
|
|
|
|
|
|
2018-03-24 19:27:24 +01:00
|
|
|
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
|
|
|
|
goto fail;
|
|
|
|
return vgmstream;
|
2009-05-01 17:03:51 +02:00
|
|
|
|
|
|
|
fail:
|
2018-03-24 19:27:24 +01:00
|
|
|
close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
2009-05-01 17:03:51 +02:00
|
|
|
}
|