2008-11-02 17:43:12 +01:00
|
|
|
#include "meta.h"
|
2018-03-28 22:58:25 +02:00
|
|
|
#include "../coding/coding.h"
|
2008-11-02 17:43:12 +01:00
|
|
|
|
2018-10-27 22:33:26 +02:00
|
|
|
/* SPSD - Naomi (arcade) and early Dreamcast streams [Guilty Gear X (Naomi), Crazy Taxi (Naomi), Virtua Tennis 2 (Naomi)] */
|
2023-01-29 22:58:13 +01:00
|
|
|
VGMSTREAM* init_vgmstream_spsd(STREAMFILE *sf) {
|
|
|
|
VGMSTREAM* vgmstream = NULL;
|
2008-11-02 17:43:12 +01:00
|
|
|
off_t start_offset;
|
2018-03-24 19:27:24 +01:00
|
|
|
size_t data_size;
|
2023-01-29 22:58:13 +01:00
|
|
|
int loop_flag, channels, codec, flags, index;
|
2008-11-02 17:43:12 +01:00
|
|
|
|
|
|
|
|
2018-03-24 19:27:24 +01:00
|
|
|
/* checks */
|
2023-01-29 22:58:13 +01:00
|
|
|
if (!is_id32be(0x00,sf, "SPSD"))
|
2023-09-02 12:23:05 +02:00
|
|
|
return NULL;
|
2023-01-29 22:58:13 +01:00
|
|
|
/* .str: actual extension, rare [Shenmue (DC)]
|
|
|
|
* .spsd: header id (maybe real ext is .PSD, similar to "SMLT" > .MLT) */
|
|
|
|
if (!check_extensions(sf, "str,spsd"))
|
2023-09-02 12:23:05 +02:00
|
|
|
return NULL;
|
2008-11-02 17:43:12 +01:00
|
|
|
|
2023-09-02 12:23:05 +02:00
|
|
|
if (read_u32be(0x04,sf) != 0x01010004 && /* standard version */
|
|
|
|
read_u32be(0x04,sf) != 0x00010004) /* uncommon version [Crazy Taxi (Naomi)] */
|
|
|
|
return NULL;
|
2018-03-28 22:58:25 +02:00
|
|
|
|
|
|
|
|
2023-09-02 12:23:05 +02:00
|
|
|
codec = read_u8(0x08,sf);
|
|
|
|
flags = read_u8(0x09,sf);
|
|
|
|
index = read_u16le(0x0a,sf);
|
|
|
|
data_size = read_u32le(0x0c,sf);
|
2018-03-28 22:58:25 +02:00
|
|
|
//if (data_size + start_offset != get_streamfile_size(streamFile))
|
|
|
|
// goto fail; /* some rips out there have incorrect padding */
|
2023-09-02 12:23:05 +02:00
|
|
|
/* At 0x30(4*ch) is some config per channel but doesn't seem to affect ADPCM (found with PCM too) */
|
|
|
|
|
2018-03-24 19:27:24 +01:00
|
|
|
|
2018-03-28 22:58:25 +02:00
|
|
|
//todo with 0x80 seems 0x2c is a loop_start_sample but must be adjusted to +1 block? (uncommon flag though)
|
|
|
|
loop_flag = (flags & 0x80);
|
2023-09-02 12:23:05 +02:00
|
|
|
channels = ((flags & 0x01) || (flags & 0x02)) ? 2 : 1; /* 0x02 is rare (Virtua Tennis 2) */
|
2018-03-24 19:27:24 +01:00
|
|
|
start_offset = 0x40;
|
2018-03-28 22:58:25 +02:00
|
|
|
|
2018-03-24 19:27:24 +01:00
|
|
|
|
2010-05-10 10:02:22 +02:00
|
|
|
/* build the VGMSTREAM */
|
2023-01-29 22:58:13 +01:00
|
|
|
vgmstream = allocate_vgmstream(channels,loop_flag);
|
2008-11-02 17:43:12 +01:00
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2023-09-02 12:23:05 +02:00
|
|
|
vgmstream->sample_rate = read_u16le(0x2A,sf);
|
2010-05-10 10:02:22 +02:00
|
|
|
|
2023-01-29 22:58:13 +01:00
|
|
|
vgmstream->meta_type = meta_SPSD;
|
2018-03-28 22:58:25 +02:00
|
|
|
switch (codec) {
|
2023-01-29 22:58:13 +01:00
|
|
|
case 0x00: /* [Virtua Tennis 2 (Naomi), Club Kart: European Session (Naomi)] */
|
2018-03-28 22:58:25 +02:00
|
|
|
vgmstream->coding_type = coding_PCM16LE;
|
2023-09-02 12:23:05 +02:00
|
|
|
vgmstream->num_samples = pcm16_bytes_to_samples(data_size, channels);
|
|
|
|
vgmstream->loop_start_sample = read_s32le(0x2c,sf) + pcm16_bytes_to_samples(0x2000,1);
|
2018-03-28 22:58:25 +02:00
|
|
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
|
|
|
break;
|
|
|
|
|
2018-03-24 19:27:24 +01:00
|
|
|
case 0x01: /* [Virtua Tennis 2 (Naomi)] */
|
|
|
|
vgmstream->coding_type = coding_PCM8;
|
2023-09-02 12:23:05 +02:00
|
|
|
vgmstream->num_samples = pcm8_bytes_to_samples(data_size, channels);
|
|
|
|
vgmstream->loop_start_sample = read_s32le(0x2c,sf) + pcm8_bytes_to_samples(0x2000,1);
|
2018-03-28 22:58:25 +02:00
|
|
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
|
|
|
|
2018-03-24 19:27:24 +01:00
|
|
|
break;
|
2018-03-28 22:58:25 +02:00
|
|
|
|
|
|
|
case 0x03: /* standard */
|
2019-09-21 19:15:01 +02:00
|
|
|
vgmstream->coding_type = coding_AICA_int;
|
2023-09-02 12:23:05 +02:00
|
|
|
vgmstream->num_samples = yamaha_bytes_to_samples(data_size, channels);
|
|
|
|
vgmstream->loop_start_sample = /*read_s32le(0x2c,streamFile) +*/ yamaha_bytes_to_samples(0x2000,1);
|
2018-03-28 22:58:25 +02:00
|
|
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
2018-03-24 19:27:24 +01:00
|
|
|
break;
|
2018-03-28 22:58:25 +02:00
|
|
|
|
2018-03-24 19:27:24 +01:00
|
|
|
default:
|
|
|
|
goto fail;
|
2008-11-02 17:43:12 +01:00
|
|
|
}
|
2018-03-28 22:58:25 +02:00
|
|
|
|
|
|
|
/* interleave index, maybe */
|
|
|
|
switch(index) {
|
|
|
|
case 0x0000:
|
2023-01-29 22:58:13 +01:00
|
|
|
if (channels != 1) goto fail;
|
2018-03-28 22:58:25 +02:00
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x000d:
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
vgmstream->interleave_block_size = 0x2000;
|
|
|
|
if (vgmstream->interleave_block_size)
|
|
|
|
vgmstream->interleave_last_block_size = (data_size % (vgmstream->interleave_block_size*vgmstream->channels)) / vgmstream->channels;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x00ff:
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
2023-01-29 22:58:13 +01:00
|
|
|
vgmstream->interleave_block_size = data_size / channels;
|
2018-03-28 22:58:25 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
int i;
|
2023-01-29 22:58:13 +01:00
|
|
|
for (i = 0; i < channels; i++) {
|
2018-03-28 22:58:25 +02:00
|
|
|
vgmstream->ch[i].adpcm_step_index = 0x7f;
|
|
|
|
}
|
|
|
|
}
|
2008-11-02 17:43:12 +01:00
|
|
|
|
|
|
|
|
2023-01-29 22:58:13 +01:00
|
|
|
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
|
2018-03-24 19:27:24 +01:00
|
|
|
goto fail;
|
2008-11-02 17:43:12 +01:00
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
2018-03-24 19:27:24 +01:00
|
|
|
close_vgmstream(vgmstream);
|
2008-11-02 17:43:12 +01:00
|
|
|
return NULL;
|
|
|
|
}
|