2008-08-10 00:38:44 +02:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../coding/coding.h"
|
|
|
|
|
2009-01-23 15:06:14 +01:00
|
|
|
|
2023-09-02 12:27:06 +02:00
|
|
|
/* .STR - Sega Dreamcast's "Audio64 AM (AICA Manager) driver" streams */
|
|
|
|
VGMSTREAM* init_vgmstream_str_sega(STREAMFILE* sf) {
|
|
|
|
VGMSTREAM* vgmstream = NULL;
|
|
|
|
uint32_t start_offset, data_size;
|
|
|
|
int loop_flag, channels, track_channels, tracks, sample_rate, bps, interleave, blocks;
|
2008-08-10 00:38:44 +02:00
|
|
|
|
|
|
|
|
2023-09-02 12:27:06 +02:00
|
|
|
/* checks */
|
|
|
|
tracks = read_u32le(0x00,sf);
|
|
|
|
if (tracks < 1 || tracks > 16) /* official limits */
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* "Sega Stream Asset Builder Revision ..." long text with program info, after header */
|
|
|
|
if (!is_id64be(0xD4,sf, "\0Sega St"))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!check_extensions(sf, "str"))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
sample_rate = read_s32le(0x04,sf);
|
|
|
|
bps = read_u32le(0x08,sf);
|
|
|
|
interleave = read_s32le(0x0C,sf); /* multiples of 0x800 (sector size) */
|
|
|
|
blocks = read_s32le(0x10,sf); /* interruptsTillEnd, "how may irqs until the end of that tracks data" AKA interleaved blocks */
|
2008-08-10 00:38:44 +02:00
|
|
|
|
2023-09-02 12:27:06 +02:00
|
|
|
/* per track info (channels must be the same per track, and data_size may be inaccurate for other tracks) */
|
|
|
|
data_size = read_u32le(0x14,sf);
|
|
|
|
track_channels = read_s32le(0x18,sf); /* max 2 for AICA, N for PCM */
|
|
|
|
/* 0x08: blocks / interruptsTillEnd (not including padding) */
|
|
|
|
/* header track data reserved up to max 16 * 0x0c = 0xC0 + 0x18 = 0xD4 */
|
|
|
|
/* after track headers there may be one phantom entry with empty data/channels but repeated interruptsTillEnd (bug?) */
|
|
|
|
|
|
|
|
channels = track_channels * tracks;
|
|
|
|
|
|
|
|
loop_flag = 0; /* no loop info */
|
|
|
|
start_offset = 0x800;
|
|
|
|
|
|
|
|
/* all tracks/data is padded */
|
|
|
|
if (blocks * channels * interleave != get_streamfile_size(sf) - start_offset)
|
2009-01-12 22:38:23 +01:00
|
|
|
goto fail;
|
|
|
|
|
2023-09-02 12:27:06 +02:00
|
|
|
/* streams start with a "leadIn" silence that defaults to 2 blocks, but it's configurable */
|
|
|
|
//start_offset += (interleave * channels) * 2;
|
2009-01-12 22:38:23 +01:00
|
|
|
|
2008-08-21 19:35:19 +02:00
|
|
|
|
2023-09-02 12:27:06 +02:00
|
|
|
vgmstream = allocate_vgmstream(channels,loop_flag);
|
2008-08-10 00:38:44 +02:00
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2023-09-02 12:27:06 +02:00
|
|
|
vgmstream->meta_type = meta_STR_SEGA;
|
|
|
|
vgmstream->sample_rate = sample_rate;
|
2008-08-21 19:35:19 +02:00
|
|
|
|
2023-09-02 12:27:06 +02:00
|
|
|
switch (bps) {
|
|
|
|
case 4: /* common [GTA2 (DC)] */
|
2019-09-21 19:15:01 +02:00
|
|
|
vgmstream->coding_type = coding_AICA_int;
|
2023-09-02 12:27:06 +02:00
|
|
|
vgmstream->num_samples = yamaha_bytes_to_samples(data_size, track_channels);
|
|
|
|
|
|
|
|
for (int i = 0; i < channels; i++) {
|
|
|
|
vgmstream->ch[i].adpcm_step_index = 0x7f;
|
|
|
|
}
|
2009-01-05 12:58:27 +01:00
|
|
|
break;
|
2023-09-02 12:27:06 +02:00
|
|
|
|
|
|
|
case 8: /* not seen (encoder only) */
|
|
|
|
vgmstream->coding_type = coding_PCM8_U;
|
|
|
|
vgmstream->num_samples = pcm8_bytes_to_samples(data_size, track_channels);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 16: /* common [San Francisco Rush 2049 (DC)] */
|
2009-01-05 12:58:27 +01:00
|
|
|
vgmstream->coding_type = coding_PCM16LE;
|
2023-09-02 12:27:06 +02:00
|
|
|
vgmstream->num_samples = pcm16_bytes_to_samples(data_size, track_channels);
|
2009-01-05 12:58:27 +01:00
|
|
|
break;
|
2009-01-12 22:38:23 +01:00
|
|
|
|
2023-09-02 12:27:06 +02:00
|
|
|
default:
|
|
|
|
goto fail;
|
2009-01-12 22:38:23 +01:00
|
|
|
}
|
2009-01-23 15:06:14 +01:00
|
|
|
|
2023-09-02 12:27:06 +02:00
|
|
|
vgmstream->interleave_block_size = interleave;
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
2008-08-10 00:38:44 +02:00
|
|
|
|
2023-09-02 12:27:06 +02:00
|
|
|
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
|
|
|
|
goto fail;
|
2008-08-10 00:38:44 +02:00
|
|
|
return vgmstream;
|
|
|
|
fail:
|
2023-09-02 12:27:06 +02:00
|
|
|
close_vgmstream(vgmstream);
|
2008-08-10 00:38:44 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2009-01-23 15:06:14 +01:00
|
|
|
|
2023-09-02 12:27:06 +02:00
|
|
|
/* .STR - mutant Sega Dreamcast stream [102 Dalmatians: Puppies to the Rescue (DC)] */
|
|
|
|
VGMSTREAM* init_vgmstream_str_sega_custom(STREAMFILE* sf) {
|
|
|
|
VGMSTREAM* vgmstream = NULL;
|
2009-01-23 15:06:14 +01:00
|
|
|
off_t start_offset;
|
2023-09-02 12:27:06 +02:00
|
|
|
int loop_flag, channels, sample_rate, interleave;
|
|
|
|
uint32_t data_size;
|
2010-02-27 23:10:52 +01:00
|
|
|
|
2023-09-02 12:27:06 +02:00
|
|
|
/* checks */
|
|
|
|
if (read_u32le(0x00,sf) != 0x2)
|
2010-02-27 23:10:52 +01:00
|
|
|
goto fail;
|
2009-01-23 15:06:14 +01:00
|
|
|
|
2023-09-02 12:27:06 +02:00
|
|
|
if (read_u64be(0xD4,sf) != 0x00)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!check_extensions(sf, "str"))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* this looks vaguely like a STR and could be a fully new thing, but game does include Audio64.drv */
|
|
|
|
|
|
|
|
loop_flag = 0;
|
|
|
|
channels = 2;
|
|
|
|
sample_rate = read_s32le(0x04,sf);
|
|
|
|
if (read_u32le(0x08,sf) != 16)
|
|
|
|
return NULL;
|
|
|
|
interleave = read_s32le(0x0c,sf);
|
|
|
|
if (read_u32le(0x10,sf) != 0x10000 ||
|
|
|
|
read_u32le(0x14,sf) != 0x00 ||
|
|
|
|
read_u32le(0x18,sf) != 0x00 ||
|
|
|
|
read_u32le(0x1C,sf) != 0x1F)
|
|
|
|
return NULL;
|
2009-01-23 15:06:14 +01:00
|
|
|
|
|
|
|
start_offset = 0x800;
|
2023-09-02 12:27:06 +02:00
|
|
|
data_size = get_streamfile_size(sf) - start_offset;
|
|
|
|
|
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(channels, loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
2009-01-23 15:06:14 +01:00
|
|
|
|
2023-09-02 12:27:06 +02:00
|
|
|
vgmstream->meta_type = meta_STR_SEGA_custom;
|
|
|
|
vgmstream->sample_rate =sample_rate;
|
|
|
|
vgmstream->coding_type = coding_PCM16LE;
|
|
|
|
vgmstream->num_samples = pcm16_bytes_to_samples(data_size, channels);
|
2009-01-23 15:06:14 +01:00
|
|
|
vgmstream->layout_type = layout_interleave;
|
2023-09-02 12:27:06 +02:00
|
|
|
vgmstream->interleave_block_size = interleave;
|
2009-01-23 15:06:14 +01:00
|
|
|
|
2023-09-02 12:27:06 +02:00
|
|
|
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
|
|
|
|
goto fail;
|
2009-01-23 15:06:14 +01:00
|
|
|
return vgmstream;
|
|
|
|
fail:
|
2023-09-02 12:27:06 +02:00
|
|
|
close_vgmstream(vgmstream);
|
2009-01-23 15:06:14 +01:00
|
|
|
return NULL;
|
|
|
|
}
|