vgmstream/src/meta/str_asr.c

64 lines
1.9 KiB
C
Raw Normal View History

#include "meta.h"
2021-11-18 00:17:17 +01:00
#include "../coding/coding.h"
2021-11-18 00:17:17 +01:00
/* KNON - from Donkey Kong: Barrel Blast (Wii) */
VGMSTREAM* init_vgmstream_str_asr(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
off_t start_offset;
2021-11-18 00:17:17 +01:00
int loop_flag, channels;
/* checks*/
if (!is_id32be(0x00,sf, "KNON"))
goto fail;
/* .str: PCM files
* .asr: DSP files */
if (!check_extensions(sf, "str,asr"))
goto fail;
2021-11-18 00:17:17 +01:00
if (!is_id32be(0x08,sf, "WII "))
goto fail;
2021-11-18 00:17:17 +01:00
loop_flag = (read_32bitBE(0x44,sf) != 0);
channels = 2;
start_offset = 0x800;
2021-11-18 00:17:17 +01:00
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channels, loop_flag);
if (!vgmstream) goto fail;
2021-11-18 00:17:17 +01:00
vgmstream->sample_rate = read_32bitBE(0x40,sf);
2021-11-18 00:17:17 +01:00
switch (read_32bitBE(0x20,sf)) {
case 0x4B415354: /* "KAST" */
vgmstream->coding_type = coding_NGC_DSP;
vgmstream->num_samples = (read_32bitBE(0x3C,sf))*14/8/channels;
vgmstream->loop_start_sample = (read_32bitBE(0x44,sf))*14/8/channels;
vgmstream->loop_end_sample = (read_32bitBE(0x48,sf))*14/8/channels;
vgmstream->interleave_block_size = 0x10;
dsp_read_coefs_be(vgmstream, sf, 0x8c, 0x60);
break;
case 0x4B505354: /* "KPST" */
vgmstream->coding_type = coding_PCM16BE;
vgmstream->num_samples = (read_32bitBE(0x3C,sf))/2/channels;
vgmstream->loop_start_sample = (read_32bitBE(0x44,sf))/2/channels;
vgmstream->loop_end_sample = (read_32bitBE(0x48,sf))/2/channels;
vgmstream->interleave_block_size = 0x10;
break;
default:
goto fail;
}
vgmstream->layout_type = layout_interleave;
vgmstream->meta_type = meta_STR_ASR;
2021-11-18 00:17:17 +01:00
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
goto fail;
return vgmstream;
fail:
2021-11-18 00:17:17 +01:00
close_vgmstream(vgmstream);
return NULL;
}