NDS STRM format support (only decoding PCM for now)

git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@20 51a99a44-fe44-0410-b1ba-c3e57ba2b86b
This commit is contained in:
halleyscometsw 2008-02-05 07:38:00 +00:00
parent c62bb473fb
commit 2d3376e473
6 changed files with 140 additions and 16 deletions

View File

@ -24,6 +24,6 @@ void decode_pcm8(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing,
int32_t sample_count; int32_t sample_count;
for (i=first_sample,sample_count=0; i<first_sample+samples_to_do; i++,sample_count+=channelspacing) { for (i=first_sample,sample_count=0; i<first_sample+samples_to_do; i++,sample_count+=channelspacing) {
outbuf[sample_count]=read_8bit(stream->offset+i,stream->streamfile); outbuf[sample_count]=read_8bit(stream->offset+i,stream->streamfile)*0x100;
} }
} }

View File

@ -9,9 +9,6 @@ VGMSTREAM * init_vgmstream_brstm(const char * const filename) {
off_t head_offset; off_t head_offset;
size_t head_length; size_t head_length;
off_t coef_offset;
off_t coef_offset1;
off_t coef_offset2;
int codec_number; int codec_number;
int channel_count; int channel_count;
int loop_flag; int loop_flag;
@ -26,13 +23,13 @@ VGMSTREAM * init_vgmstream_brstm(const char * const filename) {
if (!infile) goto fail; if (!infile) goto fail;
/* check header */ /* check header */
if ((uint32_t)read_32bitBE(0,infile)!=0x5253544D || if ((uint32_t)read_32bitBE(0,infile)!=0x5253544D || /* "RSTM" */
(uint32_t)read_32bitBE(4,infile)!=0xFEFF0100) (uint32_t)read_32bitBE(4,infile)!=0xFEFF0100)
goto fail; goto fail;
/* get head offset, check */ /* get head offset, check */
head_offset = read_32bitBE(0x10,infile); head_offset = read_32bitBE(0x10,infile);
if ((uint32_t)read_32bitBE(head_offset,infile)!=0x48454144) if ((uint32_t)read_32bitBE(head_offset,infile)!=0x48454144) /* "HEAD" */
goto fail; goto fail;
head_length = read_32bitBE(0x14,infile); head_length = read_32bitBE(0x14,infile);
@ -80,12 +77,16 @@ VGMSTREAM * init_vgmstream_brstm(const char * const filename) {
vgmstream->interleave_block_size = read_32bitBE(head_offset+0x38,infile); vgmstream->interleave_block_size = read_32bitBE(head_offset+0x38,infile);
vgmstream->interleave_smallblock_size = read_32bitBE(head_offset+0x48,infile); vgmstream->interleave_smallblock_size = read_32bitBE(head_offset+0x48,infile);
coef_offset1=read_32bitBE(head_offset+0x1c,infile); if (vgmstream->coding_type == coding_NGC_DSP) {
coef_offset2=read_32bitBE(head_offset+0x10+coef_offset1,infile); off_t coef_offset;
coef_offset=coef_offset2+0x10; off_t coef_offset1;
off_t coef_offset2;
{
int i; int i;
coef_offset1=read_32bitBE(head_offset+0x1c,infile);
coef_offset2=read_32bitBE(head_offset+0x10+coef_offset1,infile);
coef_offset=coef_offset2+0x10;
for (i=0;i<16;i++) { for (i=0;i<16;i++) {
vgmstream->ch[0].adpcm_coef[i]=read_16bitBE(head_offset+coef_offset+i*2,infile); vgmstream->ch[0].adpcm_coef[i]=read_16bitBE(head_offset+coef_offset+i*2,infile);
} }
@ -105,10 +106,13 @@ VGMSTREAM * init_vgmstream_brstm(const char * const filename) {
{ {
int i; int i;
for (i=0;i<channel_count;i++) { for (i=0;i<channel_count;i++) {
vgmstream->ch[i].streamfile = open_streamfile_buffer(filename, if (vgmstream->layout_type==layout_interleave_shortblock)
vgmstream->interleave_block_size>0? vgmstream->ch[i].streamfile = open_streamfile_buffer(filename,
vgmstream->interleave_block_size: vgmstream->interleave_block_size);
else
vgmstream->ch[i].streamfile = open_streamfile_buffer(filename,
0x1000); 0x1000);
if (!vgmstream->ch[i].streamfile) goto fail; if (!vgmstream->ch[i].streamfile) goto fail;
vgmstream->ch[i].channel_start_offset= vgmstream->ch[i].channel_start_offset=

107
src/meta/nds_strm.c Normal file
View File

@ -0,0 +1,107 @@
#include "nds_strm.h"
#include "../util.h"
VGMSTREAM * init_vgmstream_nds_strm(const char * const filename) {
VGMSTREAM * vgmstream = NULL;
STREAMFILE * infile = NULL;
coding_t coding_type;
int codec_number;
int channel_count;
int loop_flag;
off_t start_offset;
/* check extension, case insensitive */
if (strcasecmp("strm",filename_extension(filename))) goto fail;
/* try to open the file for header reading */
infile = open_streamfile(filename);
if (!infile) goto fail;
/* check header */
if ((uint32_t)read_32bitBE(0,infile)!=0x5354524D ||
(uint32_t)read_32bitBE(4,infile)!=0xFFFE0001)
goto fail;
/* check for HEAD section */
if ((uint32_t)read_32bitBE(0x10,infile)!=0x48454144 || /* "HEAD" */
(uint32_t)read_32bitLE(0x14,infile)!=0x50) /* 0x50-sized head is all I've seen */
goto fail;
/* check type details */
codec_number = read_8bit(0x18,infile);
loop_flag = read_8bit(0x19,infile);
channel_count = read_8bit(0x1a,infile);
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 */
vgmstream->num_samples = read_32bitLE(0x24,infile);
vgmstream->sample_rate = read_16bitLE(0x1c,infile);
/* channels and loop flag are set by allocate_vgmstream */
vgmstream->loop_start_sample = read_32bitLE(0x20,infile);
vgmstream->loop_end_sample = vgmstream->num_samples;
vgmstream->coding_type = coding_type;
vgmstream->meta_type = meta_STRM;
vgmstream->interleave_block_size = read_32bitLE(0x30,infile);
vgmstream->interleave_smallblock_size = read_32bitLE(0x38,infile);
if (channel_count==1 || coding_type==coding_PCM8 || coding_type==coding_PCM16LE)
vgmstream->layout_type = layout_none;
else
vgmstream->layout_type = layout_interleave_shortblock;
start_offset = read_32bitLE(0x28,infile);
close_streamfile(infile); infile=NULL;
/* open the file for reading by each channel */
{
int i;
for (i=0;i<channel_count;i++) {
if (vgmstream->layout_type==layout_interleave_shortblock)
vgmstream->ch[i].streamfile = open_streamfile_buffer(filename,
vgmstream->interleave_block_size);
else
vgmstream->ch[i].streamfile = open_streamfile_buffer(filename,
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 (infile) close_streamfile(infile);
if (vgmstream) close_vgmstream(vgmstream);
return NULL;
}

8
src/meta/nds_strm.h Normal file
View File

@ -0,0 +1,8 @@
#include "../vgmstream.h"
#ifndef _NDS_STRM_H
#define _NDS_STRM_H
VGMSTREAM * init_vgmstream_nds_strm(const char * const filename);
#endif

View File

@ -1,6 +1,7 @@
#include "vgmstream.h" #include "vgmstream.h"
#include "meta/adx_header.h" #include "meta/adx_header.h"
#include "meta/brstm.h" #include "meta/brstm.h"
#include "meta/nds_strm.h"
#include "layout/interleave.h" #include "layout/interleave.h"
#include "layout/nolayout.h" #include "layout/nolayout.h"
#include "coding/adx_decoder.h" #include "coding/adx_decoder.h"
@ -11,10 +12,11 @@
* List of functions that will recognize files. These should correspond pretty * List of functions that will recognize files. These should correspond pretty
* directly to the metadata types * directly to the metadata types
*/ */
#define INIT_VGMSTREAM_FCNS 2 #define INIT_VGMSTREAM_FCNS 3
VGMSTREAM * (*init_vgmstream_fcns[INIT_VGMSTREAM_FCNS])(const char * const) = { VGMSTREAM * (*init_vgmstream_fcns[INIT_VGMSTREAM_FCNS])(const char * const) = {
init_vgmstream_adx, init_vgmstream_adx,
init_vgmstream_brstm, init_vgmstream_brstm,
init_vgmstream_nds_strm,
}; };
/* format detection and VGMSTREAM setup */ /* format detection and VGMSTREAM setup */
@ -264,6 +266,9 @@ void describe_vgmstream(VGMSTREAM * vgmstream) {
case meta_RSTM: case meta_RSTM:
printf("RSTM header"); printf("RSTM header");
break; break;
case meta_STRM:
printf("NDS STRM header");
break;
case meta_ADX_03: case meta_ADX_03:
printf("ADX header type 03"); printf("ADX header type 03");
break; break;

View File

@ -1,6 +1,6 @@
CFLAGS=-lm -O3 CFLAGS=-lm -O3
test: test.c ../src/streamfile.c ../src/vgmstream.c ../src/util.c ../src/meta/adx_header.c ../src/coding/adx_decoder.c ../src/coding/gcdsp_decoder.c ../src/meta/brstm.c ../src/layout/interleave.c ../src/layout/nolayout.c ../src/coding/pcm_decoder.c test: test.c ../src/streamfile.c ../src/vgmstream.c ../src/util.c ../src/meta/adx_header.c ../src/coding/adx_decoder.c ../src/coding/gcdsp_decoder.c ../src/meta/brstm.c ../src/layout/interleave.c ../src/layout/nolayout.c ../src/coding/pcm_decoder.c ../src/meta/nds_strm.c
clean: clean:
rm test rm test