Fix SWAV .adpcm [Merlin: A Servant of Two Masters (DS)]

This commit is contained in:
bnnm 2020-06-21 01:17:19 +02:00
parent e619ad7831
commit 2a3f17cfa5
5 changed files with 42 additions and 70 deletions

View File

@ -1036,7 +1036,7 @@ static const meta_info meta_info_list[] = {
{meta_RIFF_WAVE_MWV, "RIFF WAVE header with .mwv flavoring"}, {meta_RIFF_WAVE_MWV, "RIFF WAVE header with .mwv flavoring"},
{meta_FFCC_STR, "Final Fantasy: Crystal Chronicles STR header"}, {meta_FFCC_STR, "Final Fantasy: Crystal Chronicles STR header"},
{meta_SAT_BAKA, "BAKA header from Crypt Killer"}, {meta_SAT_BAKA, "BAKA header from Crypt Killer"},
{meta_NDS_SWAV, "SWAV Header"}, {meta_SWAV, "Gameloft SWAV header"},
{meta_VSF, "Square-Enix VSF header"}, {meta_VSF, "Square-Enix VSF header"},
{meta_NDS_RRDS, "Ridger Racer DS Header"}, {meta_NDS_RRDS, "Ridger Racer DS Header"},
{meta_PS2_TK5, "Tekken 5 Stream Header"}, {meta_PS2_TK5, "Tekken 5 Stream Header"},

View File

@ -363,7 +363,7 @@ VGMSTREAM * init_vgmstream_ngc_ffcc_str(STREAMFILE *streamFile);
VGMSTREAM * init_vgmstream_sat_baka(STREAMFILE *streamFile); VGMSTREAM * init_vgmstream_sat_baka(STREAMFILE *streamFile);
VGMSTREAM * init_vgmstream_nds_swav(STREAMFILE *streamFile); VGMSTREAM * init_vgmstream_swav(STREAMFILE *streamFile);
VGMSTREAM * init_vgmstream_vsf(STREAMFILE *streamFile); VGMSTREAM * init_vgmstream_vsf(STREAMFILE *streamFile);

View File

@ -1,45 +1,39 @@
#include "meta.h" #include "meta.h"
#include "../util.h" #include "../util.h"
/* 28.01.2009 - bxaimc :
SWAV - found in Asphalt Urban GT & Asphalt Urban GT 2 */ /* SWAV - from Gameloft(?) games [Asphalt Urban GT (DS), Asphalt Urban GT 2 (DS)] */
VGMSTREAM * init_vgmstream_nds_swav(STREAMFILE *streamFile) { VGMSTREAM* init_vgmstream_swav(STREAMFILE* sf) {
VGMSTREAM * vgmstream = NULL; VGMSTREAM* vgmstream = NULL;
char filename[PATH_LIMIT]; int channel_count, loop_flag;
int codec_number;
int channel_count;
int loop_flag;
coding_t coding_type;
off_t start_offset; off_t start_offset;
int bits_per_sample; int codec_number, bits_per_sample;
coding_t coding_type;
/* check extension, case insensitive */
streamFile->get_name(streamFile,filename,sizeof(filename));
if (strcasecmp("swav",filename_extension(filename))) goto fail;
/* check header */ /* checks */
if ((uint32_t)read_32bitBE(0x00,streamFile)!=0x53574156) /* SWAV */ /* .swav: standard
* .adpcm: Merlin - A Servant of Two Masters (DS) */
if (!check_extensions(sf, "swav,adpcm"))
goto fail; goto fail;
/* check for DATA section */ if (read_u32be(0x00,sf) != 0x53574156) /* "SWAV" */
if ((uint32_t)read_32bitBE(0x10,streamFile)!=0x44415441) /* "DATA" */ goto fail;
if (read_u32be(0x10,sf) != 0x44415441) /* "DATA" */
goto fail; goto fail;
/* check type details */ /* check type details */
codec_number = read_8bit(0x18,streamFile); codec_number = read_8bit(0x18,sf);
loop_flag = read_8bit(0x19,streamFile); loop_flag = read_8bit(0x19,sf);
channel_count = 1; channel_count = 1;
if (get_streamfile_size(streamFile) != read_32bitLE(0x8,streamFile)) if (get_streamfile_size(sf) != read_s32le(0x08,sf)) {
{ if (get_streamfile_size(sf) != (read_s32le(0x08,sf) - 0x24) * 2 + 0x24)
if (get_streamfile_size(streamFile) !=
(read_32bitLE(0x8,streamFile) - 0x24) * 2 + 0x24)
goto fail; goto fail;
channel_count = 2; channel_count = 2;
} }
switch (codec_number) { switch (codec_number) {
case 0: case 0:
coding_type = coding_PCM8; coding_type = coding_PCM8;
bits_per_sample = 8; bits_per_sample = 8;
@ -55,24 +49,19 @@ VGMSTREAM * init_vgmstream_nds_swav(STREAMFILE *streamFile) {
default: default:
goto fail; goto fail;
} }
start_offset = 0x24;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag); /* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count, loop_flag);
if (!vgmstream) goto fail; if (!vgmstream) goto fail;
/* fill in the vital statistics */ vgmstream->num_samples = (read_s32le(0x14,sf) - 0x14) * 8 / bits_per_sample;
start_offset = 0x24; vgmstream->sample_rate = read_u16le(0x1A,sf);
vgmstream->num_samples = if (loop_flag) {
(read_32bitLE(0x14,streamFile) - 0x14) * 8 / bits_per_sample; vgmstream->loop_start_sample = read_u16le(0x1E,sf) * 32 / bits_per_sample;
vgmstream->sample_rate = (uint16_t)read_16bitLE(0x1A,streamFile); vgmstream->loop_end_sample = read_s32le(0x20,sf) * 32 / bits_per_sample + vgmstream->loop_start_sample;
}
if (loop_flag) {
vgmstream->loop_start_sample =
(uint16_t)read_16bitLE(0x1E,streamFile) * 32 / bits_per_sample;
vgmstream->loop_end_sample =
read_32bitLE(0x20,streamFile) * 32 / bits_per_sample +
vgmstream->loop_start_sample;
}
if (coding_type == coding_IMA_int) { if (coding_type == coding_IMA_int) {
/* handle IMA frame header */ /* handle IMA frame header */
@ -82,19 +71,17 @@ VGMSTREAM * init_vgmstream_nds_swav(STREAMFILE *streamFile) {
{ {
int i; int i;
for (i=0; i<channel_count; i++) { for (i = 0; i < channel_count; i++) {
vgmstream->ch[i].adpcm_history1_32 = vgmstream->ch[i].adpcm_history1_32 = read_s16le(start_offset + 0 + 4*i, sf);
read_16bitLE(start_offset + 0 + 4*i, streamFile); vgmstream->ch[i].adpcm_step_index = read_s16le(start_offset + 2 + 4*i, sf);
vgmstream->ch[i].adpcm_step_index =
read_16bitLE(start_offset + 2 + 4*i, streamFile);
} }
} }
start_offset += 4 * channel_count; start_offset += 4 * channel_count;
} }
vgmstream->coding_type = coding_type; vgmstream->coding_type = coding_type;
vgmstream->meta_type = meta_NDS_SWAV; vgmstream->meta_type = meta_SWAV;
if (channel_count == 2) { if (channel_count == 2) {
vgmstream->layout_type = layout_interleave; vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = 1; vgmstream->interleave_block_size = 1;
@ -102,26 +89,11 @@ VGMSTREAM * init_vgmstream_nds_swav(STREAMFILE *streamFile) {
vgmstream->layout_type = layout_none; vgmstream->layout_type = layout_none;
} }
/* open the file for reading by each channel */ if (!vgmstream_open_stream(vgmstream, sf, start_offset))
goto fail;
{
int i;
STREAMFILE * file;
file = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE);
if (!file) goto fail;
for (i=0;i<channel_count;i++) {
vgmstream->ch[i].streamfile = file;
vgmstream->ch[i].channel_start_offset=
vgmstream->ch[i].offset=start_offset+
vgmstream->interleave_block_size*i;
}
}
return vgmstream; return vgmstream;
/* clean up anything we may have opened */
fail: fail:
if (vgmstream) close_vgmstream(vgmstream); close_vgmstream(vgmstream);
return NULL; return NULL;
} }

View File

@ -187,7 +187,7 @@ VGMSTREAM * (*init_vgmstream_functions[])(STREAMFILE *streamFile) = {
init_vgmstream_utf_dsp, init_vgmstream_utf_dsp,
init_vgmstream_ngc_ffcc_str, init_vgmstream_ngc_ffcc_str,
init_vgmstream_sat_baka, init_vgmstream_sat_baka,
init_vgmstream_nds_swav, init_vgmstream_swav,
init_vgmstream_vsf, init_vgmstream_vsf,
init_vgmstream_nds_rrds, init_vgmstream_nds_rrds,
init_vgmstream_ps2_tk5, init_vgmstream_ps2_tk5,

View File

@ -321,7 +321,7 @@ typedef enum {
meta_RSTM_SPM, /* RSTM with 44->22khz hack */ meta_RSTM_SPM, /* RSTM with 44->22khz hack */
meta_THP, /* THP movie files */ meta_THP, /* THP movie files */
meta_RSTM_shrunken, /* Atlus' mutant shortened RSTM */ meta_RSTM_shrunken, /* Atlus' mutant shortened RSTM */
meta_NDS_SWAV, /* Asphalt Urban GT 1 & 2 */ meta_SWAV,
meta_NDS_RRDS, /* Ridge Racer DS */ meta_NDS_RRDS, /* Ridge Racer DS */
meta_WII_BNS, /* Wii BNS Banner Sound (similar to RSTM) */ meta_WII_BNS, /* Wii BNS Banner Sound (similar to RSTM) */
meta_WIIU_BTSND, /* Wii U Boot Sound */ meta_WIIU_BTSND, /* Wii U Boot Sound */