From 7593da74229390d919af784e3d1f9116c59f1382 Mon Sep 17 00:00:00 2001 From: bnnm Date: Sun, 20 Oct 2019 01:24:59 +0200 Subject: [PATCH] Add frame_size for MSADPCM --- src/meta/2dx9.c | 70 ++++++++++++++++++------------------------------- src/vgmstream.c | 22 +++++++++++----- src/vgmstream.h | 1 + 3 files changed, 41 insertions(+), 52 deletions(-) diff --git a/src/meta/2dx9.c b/src/meta/2dx9.c index 14912d71..ba20f271 100644 --- a/src/meta/2dx9.c +++ b/src/meta/2dx9.c @@ -1,69 +1,49 @@ #include "meta.h" #include "../util.h" -/* 2DX9 (found in beatmaniaIIDX16 - EMPRESS (Arcade) */ +/* 2DX9 - from Konami arcade games [beatmaniaIIDX16: EMPRESS (AC), BeatStream (AC), REFLEC BEAT (AC)] */ VGMSTREAM * init_vgmstream_2dx9(STREAMFILE *streamFile) { VGMSTREAM * vgmstream = NULL; - char filename[PATH_LIMIT]; off_t start_offset; + int channel_count, loop_flag; - int loop_flag; - int channel_count; - /* check extension, case insensitive */ - streamFile->get_name(streamFile,filename,sizeof(filename)); - if (strcasecmp("2dx9",filename_extension(filename))) goto fail; + /* checks */ + if (!check_extensions(streamFile, "2dx9")) + goto fail; /* check header */ - if (read_32bitBE(0x0,streamFile) != 0x32445839) /* 2DX9 */ - goto fail; - if (read_32bitBE(0x18,streamFile) != 0x52494646) /* RIFF */ - goto fail; - if (read_32bitBE(0x20,streamFile) != 0x57415645) /* WAVE */ - goto fail; - if (read_32bitBE(0x24,streamFile) != 0x666D7420) /* fmt */ - goto fail; + if (read_32bitBE(0x00,streamFile) != 0x32445839) /* 2DX9 */ + goto fail; + if (read_32bitBE(0x18,streamFile) != 0x52494646) /* RIFF */ + goto fail; + if (read_32bitBE(0x20,streamFile) != 0x57415645) /* WAVE */ + goto fail; + if (read_32bitBE(0x24,streamFile) != 0x666D7420) /* fmt */ + goto fail; if (read_32bitBE(0x6a,streamFile) != 0x64617461) /* data */ - goto fail; + goto fail; loop_flag = 0; channel_count = read_16bitLE(0x2e,streamFile); + start_offset = 0x72; - /* build the VGMSTREAM */ + /* build the VGMSTREAM */ vgmstream = allocate_vgmstream(channel_count,loop_flag); if (!vgmstream) goto fail; - /* fill in the vital statistics */ - start_offset = 0x72; - vgmstream->channels = channel_count; - vgmstream->sample_rate = read_32bitLE(0x30,streamFile); - vgmstream->coding_type = coding_MSADPCM; - vgmstream->num_samples = read_32bitLE(0x66,streamFile); - vgmstream->layout_type = layout_none; - vgmstream->interleave_block_size = read_16bitLE(0x38,streamFile); vgmstream->meta_type = meta_2DX9; - - /* open the file for reading */ - { - int i; - STREAMFILE * file; - file = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE); - if (!file) goto fail; - for (i=0;ich[i].streamfile = file; - - vgmstream->ch[i].channel_start_offset= - vgmstream->ch[i].offset=start_offset+ - vgmstream->interleave_block_size*i; - - } - } - + vgmstream->sample_rate = read_32bitLE(0x30,streamFile); + vgmstream->num_samples = read_32bitLE(0x66,streamFile); + vgmstream->coding_type = coding_MSADPCM; + vgmstream->layout_type = layout_none; + vgmstream->frame_size = read_16bitLE(0x38,streamFile); - return vgmstream; + if (!vgmstream_open_stream(vgmstream, streamFile, start_offset)) + goto fail; + return vgmstream; fail: - /* clean up anything we may have opened */ - if (vgmstream) close_vgmstream(vgmstream); + close_vgmstream(vgmstream); return NULL; } diff --git a/src/vgmstream.c b/src/vgmstream.c index f13b7c0e..4bec02e9 100644 --- a/src/vgmstream.c +++ b/src/vgmstream.c @@ -1215,10 +1215,10 @@ int get_vgmstream_samples_per_frame(VGMSTREAM * vgmstream) { return 128; case coding_MSADPCM: - return (vgmstream->interleave_block_size - 0x07*vgmstream->channels)*2 / vgmstream->channels + 2; + return (vgmstream->frame_size - 0x07*vgmstream->channels)*2 / vgmstream->channels + 2; case coding_MSADPCM_int: case coding_MSADPCM_ck: - return (vgmstream->interleave_block_size - 0x07)*2 + 2; + return (vgmstream->frame_size - 0x07)*2 + 2; case coding_WS: /* only works if output sample size is 8 bit, which always is for WS ADPCM */ return vgmstream->ws_output_size; case coding_AICA: @@ -1407,7 +1407,7 @@ int get_vgmstream_frame_size(VGMSTREAM * vgmstream) { case coding_MSADPCM: case coding_MSADPCM_int: case coding_MSADPCM_ck: - return vgmstream->interleave_block_size; + return vgmstream->frame_size; case coding_WS: return vgmstream->current_block_size; case coding_AICA: @@ -2393,7 +2393,8 @@ void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length) { } /* codecs with configurable frame size */ - if (vgmstream->interleave_block_size > 0) { + if (vgmstream->frame_size > 0 || vgmstream->interleave_block_size > 0) { + int32_t frame_size = vgmstream->frame_size > 0 ? vgmstream->frame_size : vgmstream->interleave_block_size; switch (vgmstream->coding_type) { case coding_MSADPCM: case coding_MSADPCM_int: @@ -2403,7 +2404,7 @@ void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length) { case coding_WWISE_IMA: case coding_REF_IMA: case coding_PSX_cfg: - snprintf(temp,TEMPSIZE, "frame size: %#x bytes\n", (int32_t)vgmstream->interleave_block_size); + snprintf(temp,TEMPSIZE, "frame size: %#x bytes\n", frame_size); concatn(length,desc,temp); break; default: @@ -2792,7 +2793,7 @@ int vgmstream_open_stream(VGMSTREAM * vgmstream, STREAMFILE *streamFile, off_t s vgmstream->coding_type == coding_PSX_pivotal) && (vgmstream->interleave_block_size == 0 || vgmstream->interleave_block_size > 0x50)) { VGM_LOG("VGMSTREAM: PSX-cfg decoder with wrong frame size %x\n", vgmstream->interleave_block_size); - return 0; + goto fail; } if ((vgmstream->coding_type == coding_CRI_ADX || @@ -2802,7 +2803,14 @@ int vgmstream_open_stream(VGMSTREAM * vgmstream, STREAMFILE *streamFile, off_t s vgmstream->coding_type == coding_CRI_ADX_fixed) && (vgmstream->interleave_block_size == 0 || vgmstream->interleave_block_size > 0x12)) { VGM_LOG("VGMSTREAM: ADX decoder with wrong frame size %x\n", vgmstream->interleave_block_size); - return 0; + goto fail; + } + + if ((vgmstream->coding_type == coding_MSADPCM || + vgmstream->coding_type == coding_MSADPCM_ck || + vgmstream->coding_type == coding_MSADPCM_int) && + vgmstream->frame_size == 0) { + vgmstream->frame_size = vgmstream->interleave_block_size; } /* if interleave is big enough keep a buffer per channel */ diff --git a/src/vgmstream.h b/src/vgmstream.h index 44c15930..531dda29 100644 --- a/src/vgmstream.h +++ b/src/vgmstream.h @@ -828,6 +828,7 @@ typedef struct { size_t interleave_first_block_size; /* different interleave for first block */ size_t interleave_first_skip; /* data skipped before interleave first (needed to skip other channels) */ size_t interleave_last_block_size; /* smaller interleave for last block */ + size_t frame_size; /* for codecs with configurable size */ /* subsong config */ int num_streams; /* for multi-stream formats (0=not set/one stream, 1=one stream) */