vgmstream/src/meta/knon.c

66 lines
2.0 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) */
2021-11-18 00:21:29 +01:00
VGMSTREAM* init_vgmstream_knon(STREAMFILE* sf) {
2021-11-18 00:17:17 +01:00
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;
2021-11-18 00:21:29 +01:00
vgmstream->num_samples = dsp_bytes_to_samples(read_32bitBE(0x3C,sf), channels);
vgmstream->loop_start_sample = dsp_bytes_to_samples(read_32bitBE(0x44,sf), channels);
vgmstream->loop_end_sample = dsp_bytes_to_samples(read_32bitBE(0x48,sf), channels);
2021-11-18 00:17:17 +01:00
vgmstream->interleave_block_size = 0x10;
dsp_read_coefs_be(vgmstream, sf, 0x8c, 0x60);
break;
2021-11-18 00:21:29 +01:00
2021-11-18 00:17:17 +01:00
case 0x4B505354: /* "KPST" */
vgmstream->coding_type = coding_PCM16BE;
2021-11-18 00:21:29 +01:00
vgmstream->num_samples = pcm16_bytes_to_samples(read_32bitBE(0x3C,sf), channels);
vgmstream->loop_start_sample = pcm16_bytes_to_samples(read_32bitBE(0x44,sf), channels);
vgmstream->loop_end_sample = pcm16_bytes_to_samples(read_32bitBE(0x48,sf), channels);
2021-11-18 00:17:17 +01:00
vgmstream->interleave_block_size = 0x10;
break;
2021-11-18 00:21:29 +01:00
2021-11-18 00:17:17 +01:00
default:
goto fail;
}
vgmstream->layout_type = layout_interleave;
2021-11-18 00:21:29 +01:00
vgmstream->meta_type = meta_KNON;
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;
}