2010-06-29 17:52:07 +02:00
|
|
|
#include "meta.h"
|
2019-10-20 16:35:52 +02:00
|
|
|
#include "../coding/coding.h"
|
2010-06-29 17:52:07 +02:00
|
|
|
|
2019-10-20 01:24:59 +02:00
|
|
|
/* 2DX9 - from Konami arcade games [beatmaniaIIDX16: EMPRESS (AC), BeatStream (AC), REFLEC BEAT (AC)] */
|
2010-06-29 17:52:07 +02:00
|
|
|
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;
|
2010-06-29 17:52:07 +02:00
|
|
|
|
|
|
|
|
2019-10-20 01:24:59 +02:00
|
|
|
/* checks */
|
|
|
|
if (!check_extensions(streamFile, "2dx9"))
|
|
|
|
goto fail;
|
2010-06-29 17:52:07 +02:00
|
|
|
|
|
|
|
/* 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;
|
2010-06-29 17:52:07 +02:00
|
|
|
if (read_32bitBE(0x6a,streamFile) != 0x64617461) /* data */
|
2019-10-20 01:24:59 +02:00
|
|
|
goto fail;
|
2010-06-29 17:52:07 +02:00
|
|
|
|
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);
|
2010-06-29 17:52:07 +02:00
|
|
|
channel_count = read_16bitLE(0x2e,streamFile);
|
2019-10-20 01:24:59 +02:00
|
|
|
start_offset = 0x72;
|
2010-06-29 17:52:07 +02:00
|
|
|
|
2019-10-20 01:24:59 +02:00
|
|
|
/* build the VGMSTREAM */
|
2010-06-29 17:52:07 +02:00
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2019-10-20 01:24:59 +02:00
|
|
|
vgmstream->meta_type = meta_2DX9;
|
2010-06-29 17:52:07 +02:00
|
|
|
vgmstream->sample_rate = read_32bitLE(0x30,streamFile);
|
|
|
|
vgmstream->num_samples = read_32bitLE(0x66,streamFile);
|
2022-04-21 05:05:37 +02:00
|
|
|
if (loop_flag) {
|
2022-06-25 06:22:45 +02:00
|
|
|
vgmstream->loop_start_sample = read_32bitLE(0x14,streamFile) / 2 / channel_count;
|
2022-04-21 05:05:37 +02:00
|
|
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
|
|
|
}
|
|
|
|
|
2019-10-20 01:24:59 +02:00
|
|
|
vgmstream->coding_type = coding_MSADPCM;
|
2010-06-29 17:52:07 +02:00
|
|
|
vgmstream->layout_type = layout_none;
|
2019-10-20 01:24:59 +02:00
|
|
|
vgmstream->frame_size = read_16bitLE(0x38,streamFile);
|
2019-10-20 16:35:52 +02:00
|
|
|
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;
|
2010-06-29 17:52:07 +02:00
|
|
|
|
|
|
|
fail:
|
2019-10-20 01:24:59 +02:00
|
|
|
close_vgmstream(vgmstream);
|
2010-06-29 17:52:07 +02:00
|
|
|
return NULL;
|
|
|
|
}
|