Merge pull request #1276 from bnnm/his-adp

- Fix some .his [Nancy Drew: Ghost Dogs of Moon Lake (PC)]
- Fix some dual .adp [Tale of Despereaux (Wii)]
This commit is contained in:
bnnm 2022-12-07 21:59:40 +01:00 committed by GitHub
commit f1f883f751
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 114 additions and 39 deletions

View File

@ -500,11 +500,22 @@ static size_t make_opus_header(uint8_t* buf, int buf_size, opus_config *cfg) {
size_t header_size = 0x13;
int mapping_family = 0;
/* special multichannel config */
/* Opus can't play a Nch file unless the channel mapping is properly configured (not implicit).
* A 8ch file may be 2ch+2ch+1ch+1ch+2ch; this is defined with a "channel mapping":
* - mapping family:
* 0 = standard (single stream mono/stereo, >2ch = error, and table MUST be ommited)
* 1 = standard multichannel (1..8ch), using Vorbis channel layout (needs table)
* 255 = undefined (1..255ch) application defined (needs table)
* - mapping table:
* - stream count: internal opus streams (>= 1), of 1/2ch
* - coupled count: internal stereo streams (<= streams)
* - mappings: one byte per channel with the channel position (0..Nch), or 255 (silence)
*/
/* set mapping family */
if (cfg->channels > 2 || cfg->stream_count > 1) {
/* channel config: 0=standard (single stream mono/stereo), 1=vorbis, 255: not defined */
mapping_family = 1;
header_size += 0x01+0x01+cfg->channels;
mapping_family = 1; //todo test 255
header_size += 0x01 + 0x01 + cfg->channels; /* table size */
}
if (cfg->skip < 0) {
@ -526,14 +537,15 @@ static size_t make_opus_header(uint8_t* buf, int buf_size, opus_config *cfg) {
put_u16le(buf+0x10, 0); /* output gain */
put_u8 (buf+0x12, mapping_family);
/* set mapping table */
if (mapping_family > 0) {
int i;
/* internal mono/stereo streams (N mono/stereo streams that make M channels) */
/* total streams (mono/stereo) */
put_u8(buf+0x13, cfg->stream_count);
/* joint stereo streams (rest would be mono, so 6ch can be 2ch+2ch+1ch+1ch = 2 coupled in 4 streams */
/* stereo streams (6ch can be 2ch+2ch+1ch+1ch = 2 coupled in 4 streams) */
put_u8(buf+0x14, cfg->coupled_count);
/* mapping per channel (order of channels, ex: 0x000104050203) */
/* mapping per channel (order of channels, ex: 00 01 04 05 02 03) */
for (i = 0; i < cfg->channels; i++) {
put_u8(buf+0x15+i, cfg->channel_mapping[i]);
}

View File

@ -43,6 +43,9 @@ ogg_vorbis_codec_data* init_ogg_vorbis(STREAMFILE* sf, off_t start, off_t size,
callbacks.close_func = ov_close_func;
callbacks.tell_func = ov_tell_func;
if (!size)
size = get_streamfile_size(sf) - start;
/* test if this is a proper Ogg Vorbis file, with the current (from init_x) STREAMFILE
* (quick test without having to malloc first, though if one invoked this it'll probably success) */
{

View File

@ -3,10 +3,10 @@
/* HIS - Her Interactive games [Nancy Drew series (PC)] */
VGMSTREAM * init_vgmstream_his(STREAMFILE *sf) {
VGMSTREAM * vgmstream = NULL;
int channels, loop_flag = 0, bps, sample_rate, num_samples, version;
off_t start_offset;
VGMSTREAM* init_vgmstream_his(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
int channels, loop_flag = 0, bps, sample_rate, num_samples, version, codec;
uint32_t start_offset;
/* checks */
@ -17,8 +17,10 @@ VGMSTREAM * init_vgmstream_his(STREAMFILE *sf) {
goto fail;
if (is_id32be(0x00,sf, "Her ")) { /* "Her Interactive Sound\x1a" */
/* Nancy Drew: Secrets Can Kill (PC) */
version = 0;
codec = 1;
/* Nancy Drew: Secrets Can Kill (PC) */
channels = read_u16le(0x16,sf);
sample_rate = read_u32le(0x18,sf);
/* 0x1c: bitrate */
@ -34,7 +36,7 @@ VGMSTREAM * init_vgmstream_his(STREAMFILE *sf) {
else if (is_id32be(0x00,sf, "HIS\0")) {
/* most(?) others */
version = read_u32le(0x04,sf);
/* 0x08: codec */
/* 0x08: format? (always 1) */
channels = read_u16le(0x0a,sf);
sample_rate = read_u32le(0x0c,sf);
/* 0x10: bitrate */
@ -42,28 +44,51 @@ VGMSTREAM * init_vgmstream_his(STREAMFILE *sf) {
bps = read_u16le(0x16,sf);
num_samples = pcm_bytes_to_samples(read_u32le(0x18,sf), channels, bps); /* true even for Ogg */
if (version >= 2) {
codec = read_u16le(0x1c,sf); /* 1:pcm, 2:ogg */
/* 0x1e: data or null in later(?) games */
}
else {
codec = 1;
}
/* later games use "OggS" */
if (version == 1)
if (version == 1) {
start_offset = 0x1c; /* Nancy Drew: The Final Scene (PC) */
else if (version == 2 && is_id32be(0x1e,sf, "OggS"))
start_offset = 0x1e; /* Nancy Drew: The Haunted Carousel (PC) */
else if (version == 2 && is_id32be(0x20,sf, "OggS"))
start_offset = 0x20; /* Nancy Drew: The Silent Spy (PC) */
else
}
else if (version == 2) {
if (codec == 1) {
uint32_t left_size = get_streamfile_size(sf) - 0x1e;
if (num_samples == pcm_bytes_to_samples(left_size, channels, bps))
start_offset = 0x1e; /* Nancy Drew: Ghost Dogs of Moon Lake (PC) */
else
start_offset = 0x20; /* assumed */
}
else if (codec == 2) {
if (read_u16le(0x1e, sf) != 0)
start_offset = 0x1e; /* Nancy Drew: The Haunted Carousel (PC) */
else
start_offset = 0x20; /* Nancy Drew: The Silent Spy (PC) */
}
else {
goto fail;
}
}
else {
goto fail;
}
}
else {
goto fail;
}
if (version == 2) {
/*
if (codec == 2) {
ogg_vorbis_meta_info_t ovmi = {0};
ovmi.meta_type = meta_HIS;
return init_vgmstream_ogg_vorbis_config(sf, start_offset, &ovmi);
}
*/
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channels, loop_flag);
@ -73,17 +98,32 @@ VGMSTREAM * init_vgmstream_his(STREAMFILE *sf) {
vgmstream->sample_rate = sample_rate;
vgmstream->num_samples = num_samples;
switch (bps) {
case 8:
vgmstream->coding_type = coding_PCM8_U;
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = 0x01;
switch (codec) {
case 1:
switch (bps) {
case 8:
vgmstream->coding_type = coding_PCM8_U;
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = 0x01;
break;
case 16:
vgmstream->coding_type = coding_PCM16LE;
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = 0x02;
break;
default:
goto fail;
}
break;
case 16:
vgmstream->coding_type = coding_PCM16LE;
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = 0x02;
case 2:
#ifdef VGM_USE_VORBIS
vgmstream->codec_data = init_ogg_vorbis(sf, start_offset, 0, NULL);
if (!vgmstream->codec_data) goto fail;
vgmstream->coding_type = coding_OGG_VORBIS;
vgmstream->layout_type = layout_none;
break;
#endif
default:
goto fail;
}

View File

@ -11,8 +11,8 @@ struct dsp_header {
uint32_t sample_rate; /* 0x08 (generally 22/32/44/48kz but games like Wario World set 32028hz to adjust for GC's rate) */
uint16_t loop_flag; /* 0x0c */
uint16_t format; /* 0x0e (always 0 for ADPCM) */
uint32_t loop_start_offset; /* 0x10 */
uint32_t loop_end_offset; /* 0x14 */
uint32_t loop_start_offset; /* 0x10 (in nibbles, should be 2 if 0/not set) */
uint32_t loop_end_offset; /* 0x14 (in nibbles) */
uint32_t initial_offset; /* 0x18 ("ca", in nibbles, should be 2) */
int16_t coef[16]; /* 0x1c (eight pairs) */
uint16_t gain; /* 0x3c (always 0 for ADPCM) */
@ -291,7 +291,7 @@ fail:
/* ********************************* */
/* .dsp - standard dsp as generated by DSPADPCM.exe */
/* .dsp - standard mono dsp as generated by DSPADPCM.exe */
VGMSTREAM* init_vgmstream_ngc_dsp_std(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
struct dsp_header header;
@ -304,7 +304,7 @@ VGMSTREAM* init_vgmstream_ngc_dsp_std(STREAMFILE* sf) {
goto fail;
/* .dsp: standard
* .adp: Dr. Muto/Battalion Wars (GC) mono files
* .adp: Dr. Muto/Battalion Wars (GC), Tale of Despereaux (Wii)
* (extensionless): Tony Hawk's Downhill Jam (Wii) */
if (!check_extensions(sf, "dsp,adp,"))
goto fail;
@ -319,7 +319,8 @@ VGMSTREAM* init_vgmstream_ngc_dsp_std(STREAMFILE* sf) {
* out thoroughly, we're probably not dealing with a genuine mono DSP.
* In many cases these will pass all the other checks, including the
* predictor/scale check if the first byte is 0 */
//todo maybe this meta should be after others, so they have a chance to detect >1ch .dsp
//TODO: maybe this meta should be after others, so they have a better chance to detect >1ch .dsp
// (but .dsp is the common case, so it'd be slower)
{
int ko;
struct dsp_header header2;
@ -344,6 +345,21 @@ VGMSTREAM* init_vgmstream_ngc_dsp_std(STREAMFILE* sf) {
header.loop_flag == header2.loop_flag) {
goto fail;
}
/* ignore ddsp, that set samples/nibbles counting both channels so can't be detected
* (could check for .dsp but most files don't need this) */
if (check_extensions(sf, "adp")) {
uint32_t interleave = (get_streamfile_size(sf) / 2);
ko = !read_dsp_header_be(&header2, interleave, sf);
if (!ko &&
header.sample_count == header2.sample_count &&
header.nibble_count == header2.nibble_count &&
header.sample_rate == header2.sample_rate &&
header.loop_flag == header2.loop_flag) {
goto fail;
}
}
}
if (header.loop_flag) {
@ -822,14 +838,15 @@ fail:
return NULL;
}
/* .ddsp - full interleaved dsp [Shark Tale, (GC), The Sims 2: Pets (Wii), Wacky Races: Crash & Dash (Wii)] */
/* .ddsp - full interleaved dsp [Shark Tale (GC), The Sims 2: Pets (Wii), Wacky Races: Crash & Dash (Wii)] */
VGMSTREAM* init_vgmstream_dsp_ddsp(STREAMFILE* sf) {
dsp_meta dspm = {0};
/* checks */
/* .ddsp: assumed?
/* .adp: Tale of Despereaux (Wii) */
/* .ddsp: fake extension (games have bigfiles without names, but has references to .wav)
* .wav: Wacky Races: Crash & Dash (Wii) */
if (!check_extensions(sf, "ddsp,wav,lwav"))
if (!check_extensions(sf, "adp,ddsp,wav,lwav"))
goto fail;
dspm.channels = 2;
@ -840,6 +857,9 @@ VGMSTREAM* init_vgmstream_dsp_ddsp(STREAMFILE* sf) {
dspm.start_offset = 0x60;
dspm.interleave = dspm.header_spacing;
/* this format has nibbles in both headers matching all data (not just for that channel),
* and interleave is exact half even for files that aren't aligned to 0x10 */
dspm.meta_type = meta_DSP_DDSP;
return init_vgmstream_dsp_common(sf, &dspm);
fail: