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;
|
2018-02-17 12:30:14 +01:00
|
|
|
int loop_flag, channel_count, codec;
|
|
|
|
|
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
|
|
|
|
2018-02-17 12:30:14 +01:00
|
|
|
if (read_32bitBE(0x00,streamFile) != 0x64685353) /* "dhSS" */
|
2009-03-11 23:38:49 +01:00
|
|
|
goto fail;
|
2018-02-17 12:30:14 +01:00
|
|
|
if (read_32bitBE(0x20,streamFile) != 0x64625353) /* "dbSS" */
|
2009-03-11 23:38:49 +01:00
|
|
|
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);
|
|
|
|
|
2018-02-17 12:30:14 +01:00
|
|
|
if (channel_count > 2)
|
2009-03-12 10:27:11 +01:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
2009-03-11 23:38:49 +01:00
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2018-02-17 12:30:14 +01:00
|
|
|
vgmstream->sample_rate = read_32bitBE(0x0c,streamFile);
|
|
|
|
|
|
|
|
codec = read_32bitBE(0x08,streamFile);
|
|
|
|
switch (codec) {
|
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->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
|
|
|
|
2018-02-17 12:30:14 +01:00
|
|
|
if (channel_count == 1) {
|
2017-01-26 23:31:02 +01:00
|
|
|
vgmstream->layout_type = layout_none;
|
2018-02-17 12:30:14 +01:00
|
|
|
} else if (channel_count == 2) {
|
2017-01-26 23:31:02 +01:00
|
|
|
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;
|
2018-02-17 12:30:14 +01:00
|
|
|
vgmstream->coding_type = coding_XBOX_IMA_int;
|
|
|
|
vgmstream->num_samples = xbox_ima_bytes_to_samples(read_32bitBE(0x24,streamFile), vgmstream->channels);
|
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;
|
|
|
|
}
|