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;
|
2013-05-27 05:55:50 +02:00
|
|
|
char filename[PATH_LIMIT];
|
2008-02-05 08:38:00 +01:00
|
|
|
|
|
|
|
coding_t coding_type;
|
|
|
|
|
|
|
|
int codec_number;
|
|
|
|
int channel_count;
|
|
|
|
int loop_flag;
|
|
|
|
|
|
|
|
off_t start_offset;
|
|
|
|
|
|
|
|
/* check extension, case insensitive */
|
2008-05-20 17:18:38 +02:00
|
|
|
streamFile->get_name(streamFile,filename,sizeof(filename));
|
2008-02-05 08:38:00 +01:00
|
|
|
if (strcasecmp("strm",filename_extension(filename))) goto fail;
|
|
|
|
|
|
|
|
/* check header */
|
2017-11-10 22:22:04 +01:00
|
|
|
if ((uint32_t)read_32bitBE(0x00,streamFile)!=0x5354524D) /* STRM */
|
|
|
|
goto fail;
|
|
|
|
if ((uint32_t)read_32bitBE(0x04,streamFile)!=0xFFFE0001 && /* Old Header Check */
|
|
|
|
((uint32_t)read_32bitBE(0x04,streamFile)!=0xFEFF0001)) /* Some newer games have a new flag */
|
2008-11-23 13:08:33 +01:00
|
|
|
goto fail;
|
2008-11-24 19:27:28 +01:00
|
|
|
|
2008-11-22 22:29:16 +01:00
|
|
|
|
2008-02-05 08:38:00 +01:00
|
|
|
|
|
|
|
/* check for HEAD section */
|
2008-11-24 19:27:28 +01:00
|
|
|
if ((uint32_t)read_32bitBE(0x10,streamFile)!=0x48454144 && /* "HEAD" */
|
2008-05-20 17:18:38 +02:00
|
|
|
(uint32_t)read_32bitLE(0x14,streamFile)!=0x50) /* 0x50-sized head is all I've seen */
|
2008-02-05 08:38:00 +01:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* check type details */
|
2008-05-20 17:18:38 +02:00
|
|
|
codec_number = read_8bit(0x18,streamFile);
|
|
|
|
loop_flag = read_8bit(0x19,streamFile);
|
|
|
|
channel_count = read_8bit(0x1a,streamFile);
|
2008-02-05 08:38:00 +01:00
|
|
|
|
|
|
|
switch (codec_number) {
|
|
|
|
case 0:
|
|
|
|
coding_type = coding_PCM8;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
coding_type = coding_PCM16LE;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
coding_type = coding_NDS_IMA;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: only mono and stereo supported */
|
|
|
|
if (channel_count < 1 || channel_count > 2) goto fail;
|
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
|
|
|
|
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
/* fill in the vital statistics */
|
2008-05-20 17:18:38 +02:00
|
|
|
vgmstream->num_samples = read_32bitLE(0x24,streamFile);
|
|
|
|
vgmstream->sample_rate = (uint16_t)read_16bitLE(0x1c,streamFile);
|
2008-02-05 08:38:00 +01:00
|
|
|
/* channels and loop flag are set by allocate_vgmstream */
|
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->coding_type = coding_type;
|
|
|
|
vgmstream->meta_type = meta_STRM;
|
|
|
|
|
2008-05-20 17:18:38 +02:00
|
|
|
vgmstream->interleave_block_size = read_32bitLE(0x30,streamFile);
|
|
|
|
vgmstream->interleave_smallblock_size = read_32bitLE(0x38,streamFile);
|
2008-02-05 08:38:00 +01:00
|
|
|
|
2008-02-05 10:21:20 +01:00
|
|
|
if (coding_type==coding_PCM8 || coding_type==coding_PCM16LE)
|
2008-02-05 08:38:00 +01:00
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
else
|
|
|
|
vgmstream->layout_type = layout_interleave_shortblock;
|
|
|
|
|
2008-05-20 17:18:38 +02:00
|
|
|
start_offset = read_32bitLE(0x28,streamFile);
|
2008-02-05 08:38:00 +01:00
|
|
|
|
|
|
|
/* open the file for reading by each channel */
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=0;i<channel_count;i++) {
|
|
|
|
if (vgmstream->layout_type==layout_interleave_shortblock)
|
2008-05-20 17:18:38 +02:00
|
|
|
vgmstream->ch[i].streamfile = streamFile->open(streamFile,filename,
|
2008-02-05 08:38:00 +01:00
|
|
|
vgmstream->interleave_block_size);
|
|
|
|
else
|
2008-05-20 17:18:38 +02:00
|
|
|
vgmstream->ch[i].streamfile = streamFile->open(streamFile,filename,
|
2008-02-05 08:38:00 +01:00
|
|
|
0x1000);
|
|
|
|
if (!vgmstream->ch[i].streamfile) goto fail;
|
|
|
|
|
|
|
|
vgmstream->ch[i].channel_start_offset=
|
|
|
|
vgmstream->ch[i].offset=
|
|
|
|
start_offset + i*vgmstream->interleave_block_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
/* clean up anything we may have opened */
|
|
|
|
fail:
|
|
|
|
if (vgmstream) close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|