diff --git a/src/meta/agsc.c b/src/meta/agsc.c new file mode 100644 index 00000000..33eea62d --- /dev/null +++ b/src/meta/agsc.c @@ -0,0 +1,81 @@ +#include "agsc.h" +#include "../util.h" + +/* .agsc - from Metroid Prime 2 */ + +VGMSTREAM * init_vgmstream_agsc(const char * const filename) { + VGMSTREAM * vgmstream = NULL; + STREAMFILE * infile = NULL; + + coding_t coding_type; + + off_t header_offset; + off_t start_offset; + int channel_count; + int i; + + /* check extension, case insensitive */ + if (strcasecmp("agsc",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)!=0x00000001) + goto fail; + + /* count length of name, including terminating 0 */ + for (header_offset=4;header_offset < get_streamfile_size(infile) && read_8bit(header_offset,infile)!='\0';header_offset++); + + header_offset ++; + + channel_count = 1; + + /* build the VGMSTREAM */ + + vgmstream = allocate_vgmstream(1,1); + if (!vgmstream) goto fail; + + /* fill in the vital statistics */ + vgmstream->num_samples = read_32bitBE(header_offset+0xda,infile); + vgmstream->sample_rate = read_16bitBE(header_offset+0xd8,infile); + + vgmstream->loop_start_sample = read_32bitBE(header_offset+0xde,infile); + /* this is cute, we actually have a "loop length" */ + vgmstream->loop_end_sample = (vgmstream->loop_start_sample + read_32bitBE(header_offset+0xe2,infile))-1; + + vgmstream->coding_type = coding_NGC_DSP; + vgmstream->layout_type = layout_none; + vgmstream->meta_type = meta_DSP_AGSC; + + for (i=0;i<16;i++) { + vgmstream->ch[0].adpcm_coef[i]=read_16bitBE(header_offset+0xf6+i*2,infile); + } + + start_offset = header_offset+0x116; + + close_streamfile(infile); infile=NULL; + + /* open the file for reading by each channel */ + { + int i; + for (i=0;ich[i].streamfile = open_streamfile(filename); + + if (!vgmstream->ch[i].streamfile) goto fail; + + vgmstream->ch[i].channel_start_offset= + vgmstream->ch[i].offset= + start_offset; + } + } + + return vgmstream; + + /* clean up anything we may have opened */ +fail: + if (infile) close_streamfile(infile); + if (vgmstream) close_vgmstream(vgmstream); + return NULL; +} diff --git a/src/meta/agsc.h b/src/meta/agsc.h new file mode 100644 index 00000000..0911f150 --- /dev/null +++ b/src/meta/agsc.h @@ -0,0 +1,8 @@ +#include "../vgmstream.h" + +#ifndef _AGSC_H +#define _AGSC_H + +VGMSTREAM * init_vgmstream_agsc(const char * const filename); + +#endif diff --git a/src/vgmstream.c b/src/vgmstream.c index a38a2fa8..f0000898 100644 --- a/src/vgmstream.c +++ b/src/vgmstream.c @@ -2,6 +2,7 @@ #include "meta/adx_header.h" #include "meta/brstm.h" #include "meta/nds_strm.h" +#include "meta/agsc.h" #include "layout/interleave.h" #include "layout/nolayout.h" #include "coding/adx_decoder.h" @@ -12,11 +13,12 @@ * List of functions that will recognize files. These should correspond pretty * directly to the metadata types */ -#define INIT_VGMSTREAM_FCNS 3 +#define INIT_VGMSTREAM_FCNS 4 VGMSTREAM * (*init_vgmstream_fcns[INIT_VGMSTREAM_FCNS])(const char * const) = { init_vgmstream_adx, init_vgmstream_brstm, init_vgmstream_nds_strm, + init_vgmstream_agsc, }; /* format detection and VGMSTREAM setup */ @@ -255,6 +257,13 @@ int vgmstream_do_loop(VGMSTREAM * vgmstream) { /* if (vgmstream->loop_flag) {*/ /* is this the loop end? */ if (vgmstream->current_sample==vgmstream->loop_end_sample) { + int i; + /* + for (i=0;ichannels;i++) { + vgmstream->loop_ch[i].adpcm_history1_32 = vgmstream->ch[i].adpcm_history1_32; + vgmstream->loop_ch[i].adpcm_history2_32 = vgmstream->ch[i].adpcm_history2_32; + } + */ /* restore! */ memcpy(vgmstream->ch,vgmstream->loop_ch,sizeof(VGMSTREAMCHANNEL)*vgmstream->channels); vgmstream->current_sample=vgmstream->loop_sample; @@ -304,6 +313,9 @@ void describe_vgmstream(VGMSTREAM * vgmstream) { case meta_ADX_04: printf("ADX header type 04"); break; + case meta_DSP_AGSC: + printf("AGSC header"); + break; default: printf("THEY SHOULD HAVE SENT A POET"); } diff --git a/src/vgmstream.h b/src/vgmstream.h index 653ce996..469e45e4 100644 --- a/src/vgmstream.h +++ b/src/vgmstream.h @@ -50,6 +50,7 @@ typedef enum { meta_DSP_RS03, /* Metroid Prime 2 "RS03" */ meta_DSP_STM, /* Paper Mario 2 STM */ meta_DSP_HALP, /* SSB:M "HALPST" */ + meta_DSP_AGSC, /* Nintendo */ meta_AST, /* AST */ meta_STRM, /* STRM */