2008-05-15 20:57:03 +02:00
|
|
|
#include "meta.h"
|
2019-01-19 20:01:34 +01:00
|
|
|
#include "../coding/coding.h"
|
2008-05-15 20:57:03 +02:00
|
|
|
|
2019-01-19 20:01:34 +01:00
|
|
|
/* .MIC - from KOEI games [Crimson Sea 2 (PS2), Dynasty Tactics 2 (PS2)] */
|
2021-12-11 17:35:27 +01:00
|
|
|
VGMSTREAM* init_vgmstream_mic_koei(STREAMFILE* sf) {
|
|
|
|
VGMSTREAM* vgmstream = NULL;
|
2019-01-19 20:01:34 +01:00
|
|
|
off_t start_offset;
|
2021-12-11 17:35:27 +01:00
|
|
|
int loop_flag, channels, loop_start, loop_end, sample_rate;
|
2019-01-19 20:01:34 +01:00
|
|
|
size_t interleave, block_size;
|
2008-05-15 20:57:03 +02:00
|
|
|
|
|
|
|
|
2019-01-19 20:01:34 +01:00
|
|
|
/* checks */
|
2021-12-11 17:35:27 +01:00
|
|
|
if (!check_extensions(sf, "mic"))
|
2008-05-15 20:57:03 +02:00
|
|
|
goto fail;
|
|
|
|
|
2021-12-11 17:35:27 +01:00
|
|
|
/* simple header so throws some extra in some checks */
|
|
|
|
start_offset = read_u32le(0x00,sf);
|
2019-01-19 20:01:34 +01:00
|
|
|
if (start_offset != 0x800) goto fail;
|
2021-12-11 17:35:27 +01:00
|
|
|
sample_rate = read_u32le(0x04,sf);
|
|
|
|
channels = read_u32le(0x08,sf);
|
2022-02-19 12:36:54 +01:00
|
|
|
if (channels > 4) goto fail; /* 1/2/4 are known */
|
2021-12-11 17:35:27 +01:00
|
|
|
interleave = read_u32le(0x0c,sf);
|
2023-04-09 10:25:23 +02:00
|
|
|
if (interleave != 0x10 && interleave != 0x20) goto fail;
|
2021-12-11 17:35:27 +01:00
|
|
|
|
2022-02-19 12:36:54 +01:00
|
|
|
loop_end = read_s32le(0x10,sf);
|
|
|
|
loop_start = read_s32le(0x14,sf);
|
2021-12-11 17:35:27 +01:00
|
|
|
if (read_u32le(0x18,sf) != 0) goto fail;
|
|
|
|
if (read_u32le(0x1c,sf) != 0) goto fail;
|
|
|
|
|
2019-01-19 20:01:34 +01:00
|
|
|
loop_flag = (loop_start != 1);
|
2021-12-11 17:35:27 +01:00
|
|
|
block_size = interleave * channels;
|
|
|
|
|
2008-05-15 20:57:03 +02:00
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
2021-12-11 17:35:27 +01:00
|
|
|
vgmstream = allocate_vgmstream(channels, loop_flag);
|
2008-05-15 20:57:03 +02:00
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2024-05-21 23:32:04 +02:00
|
|
|
vgmstream->meta_type = meta_MIC_KOEI;
|
2019-01-19 20:01:34 +01:00
|
|
|
vgmstream->sample_rate = sample_rate;
|
2008-05-15 20:57:03 +02:00
|
|
|
|
|
|
|
vgmstream->coding_type = coding_PSX;
|
2019-01-19 20:01:34 +01:00
|
|
|
vgmstream->interleave_block_size = interleave;
|
2008-05-15 20:57:03 +02:00
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
|
2021-12-11 17:35:27 +01:00
|
|
|
vgmstream->num_samples = ps_bytes_to_samples(loop_end * block_size, channels);
|
|
|
|
vgmstream->loop_start_sample = ps_bytes_to_samples(loop_start * block_size, channels);
|
2019-01-19 20:01:34 +01:00
|
|
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
2008-05-15 20:57:03 +02:00
|
|
|
|
2021-12-11 17:35:27 +01:00
|
|
|
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
|
2019-01-19 20:01:34 +01:00
|
|
|
goto fail;
|
2008-05-15 20:57:03 +02:00
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
2019-01-19 20:01:34 +01:00
|
|
|
close_vgmstream(vgmstream);
|
2008-05-15 20:57:03 +02:00
|
|
|
return NULL;
|
|
|
|
}
|