Add frame_size for MSADPCM

This commit is contained in:
bnnm 2019-10-20 01:24:59 +02:00
parent e35bbf59cf
commit 7593da7422
3 changed files with 41 additions and 52 deletions

View File

@ -1,69 +1,49 @@
#include "meta.h" #include "meta.h"
#include "../util.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 * init_vgmstream_2dx9(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL; VGMSTREAM * vgmstream = NULL;
char filename[PATH_LIMIT];
off_t start_offset; off_t start_offset;
int channel_count, loop_flag;
int loop_flag;
int channel_count;
/* check extension, case insensitive */ /* checks */
streamFile->get_name(streamFile,filename,sizeof(filename)); if (!check_extensions(streamFile, "2dx9"))
if (strcasecmp("2dx9",filename_extension(filename))) goto fail; goto fail;
/* check header */ /* check header */
if (read_32bitBE(0x0,streamFile) != 0x32445839) /* 2DX9 */ if (read_32bitBE(0x00,streamFile) != 0x32445839) /* 2DX9 */
goto fail; goto fail;
if (read_32bitBE(0x18,streamFile) != 0x52494646) /* RIFF */ if (read_32bitBE(0x18,streamFile) != 0x52494646) /* RIFF */
goto fail; goto fail;
if (read_32bitBE(0x20,streamFile) != 0x57415645) /* WAVE */ if (read_32bitBE(0x20,streamFile) != 0x57415645) /* WAVE */
goto fail; goto fail;
if (read_32bitBE(0x24,streamFile) != 0x666D7420) /* fmt */ if (read_32bitBE(0x24,streamFile) != 0x666D7420) /* fmt */
goto fail; goto fail;
if (read_32bitBE(0x6a,streamFile) != 0x64617461) /* data */ if (read_32bitBE(0x6a,streamFile) != 0x64617461) /* data */
goto fail; goto fail;
loop_flag = 0; loop_flag = 0;
channel_count = read_16bitLE(0x2e,streamFile); channel_count = read_16bitLE(0x2e,streamFile);
start_offset = 0x72;
/* build the VGMSTREAM */ /* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag); vgmstream = allocate_vgmstream(channel_count,loop_flag);
if (!vgmstream) goto fail; 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; vgmstream->meta_type = meta_2DX9;
vgmstream->sample_rate = read_32bitLE(0x30,streamFile);
/* open the file for reading */ vgmstream->num_samples = read_32bitLE(0x66,streamFile);
{ vgmstream->coding_type = coding_MSADPCM;
int i; vgmstream->layout_type = layout_none;
STREAMFILE * file; vgmstream->frame_size = read_16bitLE(0x38,streamFile);
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; if (!vgmstream_open_stream(vgmstream, streamFile, start_offset))
goto fail;
return vgmstream;
fail: fail:
/* clean up anything we may have opened */ close_vgmstream(vgmstream);
if (vgmstream) close_vgmstream(vgmstream);
return NULL; return NULL;
} }

View File

@ -1215,10 +1215,10 @@ int get_vgmstream_samples_per_frame(VGMSTREAM * vgmstream) {
return 128; return 128;
case coding_MSADPCM: 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_int:
case coding_MSADPCM_ck: 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 */ case coding_WS: /* only works if output sample size is 8 bit, which always is for WS ADPCM */
return vgmstream->ws_output_size; return vgmstream->ws_output_size;
case coding_AICA: case coding_AICA:
@ -1407,7 +1407,7 @@ int get_vgmstream_frame_size(VGMSTREAM * vgmstream) {
case coding_MSADPCM: case coding_MSADPCM:
case coding_MSADPCM_int: case coding_MSADPCM_int:
case coding_MSADPCM_ck: case coding_MSADPCM_ck:
return vgmstream->interleave_block_size; return vgmstream->frame_size;
case coding_WS: case coding_WS:
return vgmstream->current_block_size; return vgmstream->current_block_size;
case coding_AICA: case coding_AICA:
@ -2393,7 +2393,8 @@ void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length) {
} }
/* codecs with configurable frame size */ /* 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) { switch (vgmstream->coding_type) {
case coding_MSADPCM: case coding_MSADPCM:
case coding_MSADPCM_int: case coding_MSADPCM_int:
@ -2403,7 +2404,7 @@ void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length) {
case coding_WWISE_IMA: case coding_WWISE_IMA:
case coding_REF_IMA: case coding_REF_IMA:
case coding_PSX_cfg: 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); concatn(length,desc,temp);
break; break;
default: default:
@ -2792,7 +2793,7 @@ int vgmstream_open_stream(VGMSTREAM * vgmstream, STREAMFILE *streamFile, off_t s
vgmstream->coding_type == coding_PSX_pivotal) && vgmstream->coding_type == coding_PSX_pivotal) &&
(vgmstream->interleave_block_size == 0 || vgmstream->interleave_block_size > 0x50)) { (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); 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 || 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->coding_type == coding_CRI_ADX_fixed) &&
(vgmstream->interleave_block_size == 0 || vgmstream->interleave_block_size > 0x12)) { (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); 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 */ /* if interleave is big enough keep a buffer per channel */

View File

@ -828,6 +828,7 @@ typedef struct {
size_t interleave_first_block_size; /* different interleave for first block */ 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_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 interleave_last_block_size; /* smaller interleave for last block */
size_t frame_size; /* for codecs with configurable size */
/* subsong config */ /* subsong config */
int num_streams; /* for multi-stream formats (0=not set/one stream, 1=one stream) */ int num_streams; /* for multi-stream formats (0=not set/one stream, 1=one stream) */