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"
|
|
|
|
|
2018-08-03 00:46:36 +02:00
|
|
|
/* DTK - headerless Nintendo GC DTK file [Harvest Moon: Another Wonderful Life (GC), XGRA (GC)] */
|
2021-12-11 17:35:27 +01:00
|
|
|
VGMSTREAM* init_vgmstream_dtk(STREAMFILE* sf) {
|
2020-12-01 23:21:33 +01:00
|
|
|
VGMSTREAM* vgmstream = NULL;
|
2018-08-03 00:46:36 +02:00
|
|
|
off_t start_offset;
|
2020-12-01 23:21:33 +01:00
|
|
|
int channels, loop_flag;
|
2018-08-03 00:46:36 +02:00
|
|
|
|
2008-02-13 15:31:21 +01:00
|
|
|
|
2018-03-08 22:56:06 +01:00
|
|
|
/* checks */
|
2020-12-01 23:21:33 +01:00
|
|
|
/* .dtk: standard [XGRA (GC)]
|
2023-06-01 05:03:21 +02:00
|
|
|
* .adp: standard [Harvest Moon: AWL (GC)]
|
|
|
|
* .trk: standard [Bloody Roar: Primal Fury (GC)]
|
2020-12-01 23:21:33 +01:00
|
|
|
* .wav/lwav: Alien Hominid (GC) */
|
|
|
|
if (!check_extensions(sf,"dtk,adp,wav,lwav"))
|
2017-07-15 11:27:43 +02:00
|
|
|
goto fail;
|
|
|
|
|
2018-08-03 00:46:36 +02:00
|
|
|
/* check valid frames as files have no header, and .adp/wav are common */
|
|
|
|
{
|
2022-01-12 21:14:36 +01:00
|
|
|
int i, blanks = 0;
|
2017-07-15 11:27:43 +02:00
|
|
|
for (i = 0; i < 10; i++) { /* try a bunch of frames */
|
2018-08-03 00:46:36 +02:00
|
|
|
/* header 0x00/01 are repeated in 0x02/03 (for error correction?),
|
|
|
|
* could also test header values (upper nibble should be 0..3, and lower nibble 0..C) */
|
2021-12-11 17:35:27 +01:00
|
|
|
if (read_u8(0x00 + i*0x20,sf) != read_u8(0x02 + i*0x20,sf) ||
|
|
|
|
read_u8(0x01 + i*0x20,sf) != read_u8(0x03 + i*0x20,sf))
|
2020-12-01 23:21:33 +01:00
|
|
|
goto fail;
|
|
|
|
|
2022-01-12 21:14:36 +01:00
|
|
|
/* silent frame headers are almost always 0x0C, save a few uncommon tracks [Wave Race Blue Storm (GC), 1080 Silver Storm (GC)] */
|
|
|
|
if (read_u16be(0x00 + i*0x20,sf) == 0x00)
|
|
|
|
blanks++;
|
2017-07-15 11:27:43 +02:00
|
|
|
}
|
2022-01-12 21:14:36 +01:00
|
|
|
|
|
|
|
if (blanks > 3)
|
|
|
|
goto fail;
|
2017-07-15 11:27:43 +02:00
|
|
|
}
|
2008-02-13 15:31:21 +01:00
|
|
|
|
2020-12-01 23:21:33 +01:00
|
|
|
/* DTK (Disc Track) are DVD hardware-decoded streams, always stereo and no loop.
|
|
|
|
* Some games fake looping by calling DVD commands to set position with certain timing.
|
|
|
|
* Though headerless, format is HW-wired to those specs. */
|
|
|
|
channels = 2;
|
2018-08-03 00:46:36 +02:00
|
|
|
loop_flag = 0;
|
|
|
|
start_offset = 0x00;
|
2008-02-13 15:31:21 +01:00
|
|
|
|
2020-12-01 23:21:33 +01:00
|
|
|
|
2008-02-13 15:31:21 +01:00
|
|
|
/* build the VGMSTREAM */
|
2020-12-01 23:21:33 +01:00
|
|
|
vgmstream = allocate_vgmstream(channels, loop_flag);
|
2008-02-13 15:31:21 +01:00
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2020-12-01 23:21:33 +01:00
|
|
|
vgmstream->num_samples = get_streamfile_size(sf) / 0x20 * 28;
|
2018-08-03 00:46:36 +02:00
|
|
|
vgmstream->sample_rate = 48000; /* due to a GC hardware defect this may be closer to 48043 */
|
2008-02-13 15:31:21 +01:00
|
|
|
vgmstream->coding_type = coding_NGC_DTK;
|
2017-01-08 01:09:20 +01:00
|
|
|
vgmstream->layout_type = layout_none;
|
2021-12-11 17:35:27 +01:00
|
|
|
vgmstream->meta_type = meta_DTK;
|
2008-02-13 15:31:21 +01:00
|
|
|
|
2021-12-11 17:35:27 +01:00
|
|
|
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
|
2017-07-15 11:27:43 +02:00
|
|
|
goto fail;
|
2008-02-13 15:31:21 +01:00
|
|
|
return vgmstream;
|
|
|
|
fail:
|
2017-07-15 11:27:43 +02:00
|
|
|
close_vgmstream(vgmstream);
|
2008-02-13 15:31:21 +01:00
|
|
|
return NULL;
|
|
|
|
}
|