2008-09-24 18:36:19 +02:00
|
|
|
#include "meta.h"
|
2018-03-04 00:17:58 +01:00
|
|
|
#include "../coding/coding.h"
|
2008-09-24 18:36:19 +02:00
|
|
|
|
2018-06-09 19:30:20 +02:00
|
|
|
/* MIC/MIHB - SCEE MultiStream interleaved bank (merged MIH+MIB) [Rogue Trooper (PS2), The Sims 2 (PS2)] */
|
2008-09-24 18:36:19 +02:00
|
|
|
VGMSTREAM * init_vgmstream_ps2_mihb(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
off_t start_offset;
|
2018-03-04 00:17:58 +01:00
|
|
|
size_t data_size, frame_size, frame_last, frame_count;
|
|
|
|
int channel_count, loop_flag;
|
2008-09-24 18:36:19 +02:00
|
|
|
|
2018-03-04 00:17:58 +01:00
|
|
|
/* check extension */
|
2018-06-09 19:30:20 +02:00
|
|
|
/* .mic: official extension, .mihb: assumed? */
|
2018-03-04 00:17:58 +01:00
|
|
|
if (!check_extensions(streamFile, "mic,mihb"))
|
|
|
|
goto fail;
|
|
|
|
if (read_32bitBE(0x00,streamFile) != 0x40000000) /* header size */
|
2008-09-24 18:36:19 +02:00
|
|
|
goto fail;
|
2017-11-10 22:22:04 +01:00
|
|
|
|
2008-09-24 18:36:19 +02:00
|
|
|
loop_flag = 0;
|
|
|
|
channel_count = read_32bitLE(0x08,streamFile);
|
|
|
|
start_offset = 0x40;
|
|
|
|
|
2018-03-04 00:17:58 +01:00
|
|
|
/* frame_size * frame_count * channels = data_size, but last frame has less usable data */
|
|
|
|
{
|
2018-06-09 19:30:20 +02:00
|
|
|
/* 0x04: padding (0x20, MIH header must be multiple of 0x40) */
|
2018-03-04 00:17:58 +01:00
|
|
|
frame_last = (uint16_t)read_16bitLE(0x05,streamFile);
|
|
|
|
frame_size = read_32bitLE(0x10,streamFile);
|
|
|
|
frame_count = read_32bitLE(0x14,streamFile);
|
|
|
|
|
|
|
|
data_size = frame_count * frame_size;
|
|
|
|
data_size -= frame_last ? (frame_size-frame_last) : 0;
|
|
|
|
data_size *= channel_count;
|
2009-03-18 21:50:35 +01:00
|
|
|
}
|
2008-09-24 18:36:19 +02:00
|
|
|
|
2018-03-04 00:17:58 +01:00
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
2008-09-24 18:36:19 +02:00
|
|
|
|
2018-03-04 00:17:58 +01:00
|
|
|
vgmstream->sample_rate = read_32bitLE(0x0C,streamFile);
|
|
|
|
vgmstream->num_samples = ps_bytes_to_samples(data_size, channel_count);
|
2008-09-24 18:36:19 +02:00
|
|
|
|
2018-03-04 00:17:58 +01:00
|
|
|
vgmstream->meta_type = meta_PS2_MIHB;
|
|
|
|
vgmstream->coding_type = coding_PSX;
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
vgmstream->interleave_block_size = frame_size;
|
2008-09-24 18:36:19 +02:00
|
|
|
|
2018-03-04 00:17:58 +01:00
|
|
|
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
|
|
|
|
goto fail;
|
2008-09-24 18:36:19 +02:00
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
2018-03-04 00:17:58 +01:00
|
|
|
close_vgmstream(vgmstream);
|
2008-09-24 18:36:19 +02:00
|
|
|
return NULL;
|
|
|
|
}
|