vgmstream/src/meta/2dx9.c

58 lines
1.9 KiB
C
Raw Normal View History

#include "meta.h"
#include "../coding/coding.h"
2019-10-20 01:24:59 +02:00
/* 2DX9 - from Konami arcade games [beatmaniaIIDX16: EMPRESS (AC), BeatStream (AC), REFLEC BEAT (AC)] */
VGMSTREAM * init_vgmstream_2dx9(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
off_t start_offset;
2019-10-20 01:24:59 +02:00
int channel_count, loop_flag;
2019-10-20 01:24:59 +02:00
/* checks */
if (!check_extensions(streamFile, "2dx9"))
goto fail;
/* check header */
2019-10-20 01:24:59 +02:00
if (read_32bitBE(0x00,streamFile) != 0x32445839) /* 2DX9 */
goto fail;
if (read_32bitBE(0x18,streamFile) != 0x52494646) /* RIFF */
goto fail;
if (read_32bitBE(0x20,streamFile) != 0x57415645) /* WAVE */
goto fail;
if (read_32bitBE(0x24,streamFile) != 0x666D7420) /* fmt */
goto fail;
if (read_32bitBE(0x6a,streamFile) != 0x64617461) /* data */
2019-10-20 01:24:59 +02:00
goto fail;
2022-06-25 06:22:45 +02:00
/* Some data loop from beginning to the end by hardcoded flag so cannot be recognized from sound file */
loop_flag = (read_32bitLE(0x14,streamFile) > 0);
channel_count = read_16bitLE(0x2e,streamFile);
2019-10-20 01:24:59 +02:00
start_offset = 0x72;
2019-10-20 01:24:59 +02:00
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
if (!vgmstream) goto fail;
2019-10-20 01:24:59 +02:00
vgmstream->meta_type = meta_2DX9;
vgmstream->sample_rate = read_32bitLE(0x30,streamFile);
vgmstream->num_samples = read_32bitLE(0x66,streamFile);
if (loop_flag) {
2022-06-25 06:22:45 +02:00
vgmstream->loop_start_sample = read_32bitLE(0x14,streamFile) / 2 / channel_count;
vgmstream->loop_end_sample = vgmstream->num_samples;
}
2019-10-20 01:24:59 +02:00
vgmstream->coding_type = coding_MSADPCM;
vgmstream->layout_type = layout_none;
2019-10-20 01:24:59 +02:00
vgmstream->frame_size = read_16bitLE(0x38,streamFile);
if (!msadpcm_check_coefs(streamFile, 0x40))
goto fail;
2019-10-20 01:24:59 +02:00
if (!vgmstream_open_stream(vgmstream, streamFile, start_offset))
goto fail;
return vgmstream;
fail:
2019-10-20 01:24:59 +02:00
close_vgmstream(vgmstream);
return NULL;
}