vgmstream/src/meta/voi.c

57 lines
1.4 KiB
C
Raw Normal View History

#include "meta.h"
2023-06-25 00:59:10 +02:00
#include "../coding/coding.h"
2023-06-25 00:59:10 +02:00
/* .VOI - from Raw Danger (PS2) */
VGMSTREAM* init_vgmstream_voi(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
int channels, loop_flag = 0;
off_t start_offset;
2023-06-25 00:59:10 +02:00
/* checks */
if (read_u32le(0x00,sf) != 1 && read_u32le(0x00,sf) != 2)
return NULL;
if (!check_extensions(sf, "voi"))
return NULL;
/* probably number of samples of all channels */
if ((read_u32le(0x04,sf) * 2 + 0x800) != get_streamfile_size(sf))
return NULL;
channels = read_s32le(0x00,sf);
loop_flag = 0;
2023-06-25 00:59:10 +02:00
start_offset = 0x800;
2023-06-25 00:59:10 +02:00
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channels, loop_flag);
if (!vgmstream) goto fail;
2023-06-25 00:59:10 +02:00
vgmstream->meta_type = meta_VOI;
vgmstream->num_samples = pcm16_bytes_to_samples(get_streamfile_size(sf) - start_offset, channels);
vgmstream->coding_type = coding_PCM16LE;
2023-06-25 00:59:10 +02:00
vgmstream->layout_type = layout_interleave;
2023-06-25 00:59:10 +02:00
if (read_32bitLE(0x08,sf) == 0) {
vgmstream->sample_rate = 48000;
vgmstream->interleave_block_size = 0x200;
}
2023-06-25 00:59:10 +02:00
else if (read_32bitLE(0x08,sf) == 1) {
vgmstream->sample_rate = 24000;
vgmstream->interleave_block_size = 0x100;
}
2023-06-25 00:59:10 +02:00
else {
goto fail;
}
2023-06-25 00:59:10 +02:00
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
goto fail;
return vgmstream;
fail:
2023-06-25 00:59:10 +02:00
close_vgmstream(vgmstream);
return NULL;
}