2009-03-11 23:38:49 +01:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../util.h"
|
2017-01-26 23:31:02 +01:00
|
|
|
#include "../coding/coding.h"
|
2009-03-11 23:38:49 +01:00
|
|
|
|
2017-01-26 23:31:02 +01:00
|
|
|
/* ADS - from Gauntlet Dark Legacy (GC/Xbox) */
|
2009-03-11 23:38:49 +01:00
|
|
|
VGMSTREAM * init_vgmstream_ads(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
off_t start_offset;
|
2009-03-12 10:27:11 +01:00
|
|
|
int loop_flag;
|
|
|
|
int channel_count;
|
|
|
|
int identifer_byte;
|
2009-03-11 23:38:49 +01:00
|
|
|
|
|
|
|
/* check extension, case insensitive */
|
2017-01-26 23:31:02 +01:00
|
|
|
if (!check_extensions(streamFile,"ads")) goto fail;
|
2009-03-11 23:38:49 +01:00
|
|
|
|
|
|
|
/* check dhSS Header */
|
|
|
|
if (read_32bitBE(0x00,streamFile) != 0x64685353)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* check dbSS Header */
|
|
|
|
if (read_32bitBE(0x20,streamFile) != 0x64625353)
|
|
|
|
goto fail;
|
2009-03-12 10:27:11 +01:00
|
|
|
|
2009-03-11 23:38:49 +01:00
|
|
|
loop_flag = 1;
|
|
|
|
channel_count = read_32bitBE(0x10,streamFile);
|
|
|
|
|
2009-03-12 10:27:11 +01:00
|
|
|
if (channel_count > 0x2)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
2009-03-11 23:38:49 +01:00
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2009-03-12 10:27:11 +01:00
|
|
|
/* fill in the vital statistics */
|
|
|
|
identifer_byte = read_32bitBE(0x08,streamFile);
|
|
|
|
switch (identifer_byte) {
|
2017-01-26 23:31:02 +01:00
|
|
|
case 0x00000020: /* GC */
|
|
|
|
start_offset = 0x28 + 0x60 * channel_count;
|
2009-03-12 10:27:11 +01:00
|
|
|
vgmstream->channels = channel_count;
|
|
|
|
vgmstream->sample_rate = read_32bitBE(0x0c,streamFile);
|
|
|
|
vgmstream->coding_type = coding_NGC_DSP;
|
|
|
|
vgmstream->num_samples = read_32bitBE(0x28,streamFile);
|
2017-01-26 23:31:02 +01:00
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = 0;
|
|
|
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
|
|
|
}
|
2009-03-12 10:27:11 +01:00
|
|
|
|
2017-01-26 23:31:02 +01:00
|
|
|
if (channel_count == 1){
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
} else if (channel_count == 2){
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
vgmstream->interleave_block_size = read_32bitBE(0x14,streamFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
dsp_read_coefs_be(vgmstream, streamFile, 0x44,0x60);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x00000021: /* Xbox */
|
2009-03-12 10:27:11 +01:00
|
|
|
start_offset = 0x28;
|
|
|
|
vgmstream->channels = channel_count;
|
|
|
|
vgmstream->sample_rate = read_32bitBE(0x0c,streamFile);
|
2017-04-29 02:53:36 +02:00
|
|
|
vgmstream->coding_type = coding_XBOX_int;
|
2009-06-29 23:58:40 +02:00
|
|
|
vgmstream->num_samples = (read_32bitBE(0x24,streamFile) / 36 *64 / vgmstream->channels)-64; // to avoid the "pop" at the loop point
|
2017-01-26 23:31:02 +01:00
|
|
|
vgmstream->layout_type = channel_count == 1 ? layout_none : layout_interleave;
|
2009-03-12 10:27:11 +01:00
|
|
|
vgmstream->interleave_block_size = 0x24;
|
2017-01-26 23:31:02 +01:00
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = 0;
|
|
|
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
2009-03-11 23:38:49 +01:00
|
|
|
}
|
2017-01-26 23:31:02 +01:00
|
|
|
break;
|
2009-03-11 23:38:49 +01:00
|
|
|
|
2017-01-26 23:31:02 +01:00
|
|
|
default:
|
|
|
|
goto fail;
|
2009-03-11 23:38:49 +01:00
|
|
|
}
|
|
|
|
|
2017-01-26 23:31:02 +01:00
|
|
|
vgmstream->meta_type = meta_ADS;
|
|
|
|
|
|
|
|
if (!vgmstream_open_stream(vgmstream, streamFile, start_offset))
|
|
|
|
goto fail;
|
2009-03-11 23:38:49 +01:00
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
2017-01-26 23:31:02 +01:00
|
|
|
close_vgmstream(vgmstream);
|
2009-03-11 23:38:49 +01:00
|
|
|
return NULL;
|
|
|
|
}
|