2008-02-13 15:31:21 +01:00
|
|
|
#include <math.h>
|
2008-05-06 05:35:37 +02:00
|
|
|
#include "meta.h"
|
2008-02-13 15:31:21 +01:00
|
|
|
#include "../util.h"
|
|
|
|
|
2008-05-20 17:18:38 +02:00
|
|
|
VGMSTREAM * init_vgmstream_ngc_adpdtk(STREAMFILE *streamFile) {
|
2008-02-13 15:31:21 +01:00
|
|
|
VGMSTREAM * vgmstream = NULL;
|
2008-05-20 22:19:46 +02:00
|
|
|
STREAMFILE * chstreamfile;
|
2013-05-27 05:55:50 +02:00
|
|
|
char filename[PATH_LIMIT];
|
2008-02-13 15:31:21 +01:00
|
|
|
|
|
|
|
size_t file_size;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* check extension, case insensitive */
|
2008-05-20 17:18:38 +02:00
|
|
|
streamFile->get_name(streamFile,filename,sizeof(filename));
|
2009-03-26 00:25:30 +01:00
|
|
|
if (strcasecmp("adp",filename_extension(filename)) &&
|
|
|
|
strcasecmp("dtk",filename_extension(filename))) goto fail;
|
2008-02-13 15:31:21 +01:00
|
|
|
|
|
|
|
/* file size is the only way to determine sample count */
|
2008-05-20 17:18:38 +02:00
|
|
|
file_size = get_streamfile_size(streamFile);
|
2008-02-13 15:31:21 +01:00
|
|
|
|
|
|
|
/* .adp files have no header, so all we can do is look for a valid first frame */
|
2008-05-20 17:18:38 +02:00
|
|
|
if (read_8bit(0,streamFile)!=read_8bit(2,streamFile) || read_8bit(1,streamFile)!=read_8bit(3,streamFile)) goto fail;
|
2008-02-13 15:31:21 +01:00
|
|
|
|
|
|
|
/* Hopefully we haven't falsely detected something else... */
|
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(2,0); /* always stereo, no loop */
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
vgmstream->num_samples = file_size/32*28;
|
|
|
|
vgmstream->sample_rate = 48000;
|
|
|
|
vgmstream->coding_type = coding_NGC_DTK;
|
|
|
|
vgmstream->layout_type = layout_dtk_interleave;
|
|
|
|
vgmstream->meta_type = meta_NGC_ADPDTK;
|
|
|
|
|
2008-05-20 22:19:46 +02:00
|
|
|
/* locality is such that two streamfiles is silly */
|
|
|
|
chstreamfile = streamFile->open(streamFile,filename,32*0x400);
|
|
|
|
if (!chstreamfile) goto fail;
|
|
|
|
|
2008-02-13 15:31:21 +01:00
|
|
|
for (i=0;i<2;i++) {
|
|
|
|
vgmstream->ch[i].channel_start_offset =
|
|
|
|
vgmstream->ch[i].offset = 0;
|
|
|
|
|
2008-05-20 22:19:46 +02:00
|
|
|
vgmstream->ch[i].streamfile = chstreamfile;
|
2008-02-13 15:31:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
/* clean up anything we may have opened */
|
|
|
|
fail:
|
|
|
|
if (vgmstream) close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|