2008-05-06 05:35:37 +02:00
|
|
|
#include "meta.h"
|
2008-02-05 08:38:00 +01:00
|
|
|
#include "../util.h"
|
|
|
|
|
2017-07-08 11:02:22 +02:00
|
|
|
/* STRM - common Nintendo NDS streaming format */
|
2008-05-20 17:18:38 +02:00
|
|
|
VGMSTREAM * init_vgmstream_nds_strm(STREAMFILE *streamFile) {
|
2008-02-05 08:38:00 +01:00
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
off_t start_offset;
|
2018-03-24 19:27:24 +01:00
|
|
|
int channel_count, loop_flag, codec;
|
2008-02-05 08:38:00 +01:00
|
|
|
|
|
|
|
|
2018-03-24 19:27:24 +01:00
|
|
|
/* checks */
|
|
|
|
if (!check_extensions(streamFile, "strm"))
|
2008-11-23 13:08:33 +01:00
|
|
|
goto fail;
|
2008-11-24 19:27:28 +01:00
|
|
|
|
2018-03-24 19:27:24 +01:00
|
|
|
if (read_32bitBE(0x00,streamFile) != 0x5354524D) /* "STRM" */
|
|
|
|
goto fail;
|
|
|
|
if (read_32bitBE(0x04,streamFile) != 0xFFFE0001 && /* Old Header Check */
|
|
|
|
(read_32bitBE(0x04,streamFile) != 0xFEFF0001)) /* Some newer games have a new flag */
|
|
|
|
goto fail;
|
2008-11-22 22:29:16 +01:00
|
|
|
|
2018-03-24 19:27:24 +01:00
|
|
|
if (read_32bitBE(0x10,streamFile) != 0x48454144 && /* "HEAD" */
|
|
|
|
read_32bitLE(0x14,streamFile) != 0x50) /* 0x50-sized head is all I've seen */
|
2008-02-05 08:38:00 +01:00
|
|
|
goto fail;
|
|
|
|
|
2018-03-24 19:27:24 +01:00
|
|
|
codec = read_8bit(0x18,streamFile);
|
2008-05-20 17:18:38 +02:00
|
|
|
loop_flag = read_8bit(0x19,streamFile);
|
|
|
|
channel_count = read_8bit(0x1a,streamFile);
|
2018-03-24 19:27:24 +01:00
|
|
|
if (channel_count > 2) goto fail;
|
2008-02-05 08:38:00 +01:00
|
|
|
|
2018-03-24 19:27:24 +01:00
|
|
|
start_offset = read_32bitLE(0x28,streamFile);
|
2008-02-05 08:38:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2008-05-20 17:18:38 +02:00
|
|
|
vgmstream->sample_rate = (uint16_t)read_16bitLE(0x1c,streamFile);
|
2018-03-24 19:27:24 +01:00
|
|
|
vgmstream->num_samples = read_32bitLE(0x24,streamFile);
|
2008-05-20 17:18:38 +02:00
|
|
|
vgmstream->loop_start_sample = read_32bitLE(0x20,streamFile);
|
2008-02-05 08:38:00 +01:00
|
|
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
|
|
|
|
|
|
|
vgmstream->meta_type = meta_STRM;
|
|
|
|
|
2018-03-24 19:27:24 +01:00
|
|
|
switch (codec) {
|
|
|
|
case 0x00: /* [Bleach - Dark Souls (DS)] */
|
|
|
|
vgmstream->coding_type = coding_PCM8;
|
|
|
|
break;
|
|
|
|
case 0x01:
|
|
|
|
vgmstream->coding_type = coding_PCM16LE;
|
|
|
|
break;
|
|
|
|
case 0x02: /* [SaGa 2 (DS)] */
|
|
|
|
vgmstream->coding_type = coding_NDS_IMA;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
2008-05-20 17:18:38 +02:00
|
|
|
vgmstream->interleave_block_size = read_32bitLE(0x30,streamFile);
|
2018-03-24 19:27:24 +01:00
|
|
|
vgmstream->interleave_last_block_size = read_32bitLE(0x38,streamFile);
|
2008-02-05 08:38:00 +01:00
|
|
|
|
|
|
|
|
2018-03-24 19:27:24 +01:00
|
|
|
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
|
|
|
|
goto fail;
|
2008-02-05 08:38:00 +01:00
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
2018-03-24 19:27:24 +01:00
|
|
|
close_vgmstream(vgmstream);
|
2008-02-05 08:38:00 +01:00
|
|
|
return NULL;
|
|
|
|
}
|