2008-07-25 19:49:09 +02:00
|
|
|
#include "meta.h"
|
2018-08-26 16:36:08 +02:00
|
|
|
#include "../coding/coding.h"
|
2008-07-25 19:49:09 +02:00
|
|
|
|
2008-07-31 00:13:25 +02:00
|
|
|
|
2018-08-26 16:36:08 +02:00
|
|
|
/* .PCM - from Lunar: Eternal Blue (Sega CD) */
|
|
|
|
VGMSTREAM * init_vgmstream_scd_pcm(STREAMFILE *streamFile) {
|
2017-11-10 22:22:04 +01:00
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
off_t start_offset;
|
2018-08-26 16:36:08 +02:00
|
|
|
int loop_flag, channel_count;
|
2008-07-31 00:13:25 +02:00
|
|
|
|
|
|
|
|
2018-08-26 16:36:08 +02:00
|
|
|
/* checks */
|
|
|
|
if (!check_extensions(streamFile, "pcm"))
|
|
|
|
goto fail;
|
2008-07-31 00:13:25 +02:00
|
|
|
|
2018-08-26 16:36:08 +02:00
|
|
|
if (read_16bitBE(0x00,streamFile) == 0x0002) {
|
|
|
|
channel_count = 1;
|
|
|
|
}
|
|
|
|
else if (read_16bitBE(0x00,streamFile) == 0x0001) {
|
|
|
|
channel_count = 2; /* RP025.PCM, RP039.PCM */
|
|
|
|
}
|
|
|
|
else {
|
2017-11-10 22:22:04 +01:00
|
|
|
goto fail;
|
2018-08-26 16:36:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
start_offset = 0x800;
|
|
|
|
|
|
|
|
|
|
|
|
/* extra validations since .pcm it's kinda generic */
|
|
|
|
{
|
|
|
|
off_t i;
|
|
|
|
/* should be empty up to start (~0x0a/~0x10 sometimes has unknown values) */
|
|
|
|
for (i = 0x20; i < start_offset; i++) {
|
|
|
|
if (read_8bit(i, streamFile) != 0)
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* loops start 0 is possible, plus all? files loops
|
|
|
|
* (even sfx/voices loop, but those set loop start in silence near the end) */
|
|
|
|
loop_flag = (read_32bitBE(0x06,streamFile) != 0);
|
2017-11-10 22:22:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2017-11-16 00:41:06 +01:00
|
|
|
vgmstream->meta_type = meta_SCD_PCM;
|
2018-08-26 16:36:08 +02:00
|
|
|
vgmstream->sample_rate = 32500; /* looks correct compared to emu/recordings */
|
|
|
|
vgmstream->num_samples = pcm_bytes_to_samples(get_streamfile_size(streamFile) - start_offset, channel_count, 8);
|
|
|
|
vgmstream->loop_start_sample = read_32bitBE(0x02,streamFile)*0x400*2;
|
|
|
|
vgmstream->loop_end_sample = read_32bitBE(0x06,streamFile)*2;
|
2008-07-31 00:13:25 +02:00
|
|
|
|
2018-08-26 16:36:08 +02:00
|
|
|
vgmstream->coding_type = coding_PCM8_SB;
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
vgmstream->interleave_block_size = 0x800;
|
2008-07-25 19:49:09 +02:00
|
|
|
|
2018-08-26 16:36:08 +02:00
|
|
|
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
|
|
|
|
goto fail;
|
2017-11-10 22:22:04 +01:00
|
|
|
return vgmstream;
|
2008-07-25 19:49:09 +02:00
|
|
|
|
|
|
|
fail:
|
2018-08-26 16:36:08 +02:00
|
|
|
close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
2008-08-11 09:19:44 +02:00
|
|
|
}
|