vgmstream/src/meta/waf.c

49 lines
1.3 KiB
C
Raw Normal View History

2018-03-03 18:46:12 +01:00
#include "meta.h"
#include "../coding/coding.h"
/* WAF - KID's earlier PC games [ever17 (PC)] (for RLE-compressed WAFs see https://github.com/dsp2003/e17p) */
2021-07-29 17:08:30 +02:00
VGMSTREAM* init_vgmstream_waf(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
2018-03-03 18:46:12 +01:00
off_t start_offset;
2021-07-29 17:08:30 +02:00
int loop_flag, channels;
2018-03-03 18:46:12 +01:00
2018-03-24 16:58:43 +01:00
/* checks */
2021-07-29 17:08:30 +02:00
if (!check_extensions(sf, "waf"))
2018-03-24 16:58:43 +01:00
goto fail;
2018-03-03 18:46:12 +01:00
2021-07-29 17:08:30 +02:00
if (!is_id32be(0x00,sf, "WAF\0"))
2018-03-03 18:46:12 +01:00
goto fail;
2021-07-29 17:08:30 +02:00
if (read_u32le(0x34,sf) + 0x38 != get_streamfile_size(sf))
2018-03-03 18:46:12 +01:00
goto fail;
2021-07-29 17:08:30 +02:00
channels = read_u16le(0x06,sf);
loop_flag = 0;
2018-03-03 18:46:12 +01:00
start_offset = 0x38;
2021-07-29 17:08:30 +02:00
2018-03-24 16:58:43 +01:00
/* build the VGMSTREAM */
2021-07-29 17:08:30 +02:00
vgmstream = allocate_vgmstream(channels, loop_flag);
2018-03-03 18:46:12 +01:00
if (!vgmstream) goto fail;
vgmstream->meta_type = meta_WAF;
2021-07-29 17:08:30 +02:00
vgmstream->sample_rate = read_s32le(0x08, sf);
2018-03-03 18:46:12 +01:00
vgmstream->coding_type = coding_MSADPCM;
vgmstream->layout_type = layout_none;
2021-07-29 17:08:30 +02:00
vgmstream->frame_size = read_u16le(0x10, sf);
/* 0x04: null?, 0x0c: avg br, 0x12: bps, 0x14: s_p_f, 0x16~34: coefs (a modified RIFF fmt) */
2021-07-29 17:08:30 +02:00
if (!msadpcm_check_coefs(sf, 0x16))
goto fail;
2021-07-29 17:08:30 +02:00
vgmstream->num_samples = msadpcm_bytes_to_samples(read_u32le(0x34,sf), vgmstream->frame_size, channels);
2018-03-03 18:46:12 +01:00
2021-07-29 17:08:30 +02:00
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
2018-03-24 16:58:43 +01:00
goto fail;
2018-03-03 18:46:12 +01:00
return vgmstream;
fail:
close_vgmstream(vgmstream);
return NULL;
}