mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-02-20 20:41:08 +01:00
Minor code cleanup
This commit is contained in:
parent
3d1ae80f56
commit
93bcf85e9c
@ -1,27 +1,19 @@
|
||||
/*
|
||||
Capcom MADP format found in Capcom 3DS games.
|
||||
*/
|
||||
|
||||
#include "meta.h"
|
||||
#include "../util.h"
|
||||
#include "../coding/coding.h"
|
||||
|
||||
/* Capcom MADP - found in Capcom 3DS games */
|
||||
VGMSTREAM * init_vgmstream_mca(STREAMFILE *streamFile) {
|
||||
VGMSTREAM * vgmstream = NULL;
|
||||
char filename[PATH_LIMIT];
|
||||
int channel_count;
|
||||
int loop_flag;
|
||||
int version;
|
||||
int channel_count, loop_flag, version;
|
||||
size_t head_size, data_size, file_size;
|
||||
off_t start_offset, coef_offset, coef_start, coef_shift;
|
||||
int i, j;
|
||||
int coef_spacing;
|
||||
|
||||
/* check extension, case insensitive */
|
||||
streamFile->get_name(streamFile, filename, sizeof(filename));
|
||||
if (strcasecmp("mca", filename_extension(filename)))
|
||||
if (!check_extensions(streamFile,"mca"))
|
||||
goto fail;
|
||||
|
||||
|
||||
/* check header */
|
||||
if ((uint32_t)read_32bitBE(0, streamFile) != 0x4D414450) /* "MADP" */
|
||||
goto fail;
|
||||
@ -41,10 +33,7 @@ VGMSTREAM * init_vgmstream_mca(STREAMFILE *streamFile) {
|
||||
vgmstream->loop_end_sample = read_32bitLE(0x18, streamFile);
|
||||
|
||||
vgmstream->coding_type = coding_NGC_DSP;
|
||||
if (channel_count == 1)
|
||||
vgmstream->layout_type = layout_none;
|
||||
else
|
||||
vgmstream->layout_type = layout_interleave;
|
||||
vgmstream->layout_type = channel_count == 1 ? layout_none : layout_interleave;
|
||||
vgmstream->meta_type = meta_MCA;
|
||||
|
||||
|
||||
@ -78,7 +67,7 @@ VGMSTREAM * init_vgmstream_mca(STREAMFILE *streamFile) {
|
||||
coef_offset = coef_start + coef_shift * 0x14;
|
||||
}
|
||||
|
||||
/* sanity check */
|
||||
/* sanity check (for bad rips with the header manually truncated to in attempt to "fix" v5 headers) */
|
||||
file_size = get_streamfile_size(streamFile);
|
||||
|
||||
if (start_offset + data_size > file_size) {
|
||||
@ -88,40 +77,16 @@ VGMSTREAM * init_vgmstream_mca(STREAMFILE *streamFile) {
|
||||
start_offset = file_size - data_size;
|
||||
}
|
||||
|
||||
|
||||
/* set up ADPCM coefs */
|
||||
for (j = 0; j<vgmstream->channels; j++) {
|
||||
for (i = 0; i<16; i++) {
|
||||
vgmstream->ch[j].adpcm_coef[i] = read_16bitLE(coef_offset + j*coef_spacing + i * 2, streamFile);
|
||||
}
|
||||
}
|
||||
|
||||
/* set up ADPCM coefs */
|
||||
dsp_read_coefs_le(vgmstream, streamFile, coef_offset, coef_spacing);
|
||||
|
||||
/* open the file for reading by each channel */
|
||||
{
|
||||
for (i = 0; i<channel_count; i++) {
|
||||
if (vgmstream->layout_type == layout_interleave_shortblock)
|
||||
vgmstream->ch[i].streamfile = streamFile->open(streamFile, filename,
|
||||
vgmstream->interleave_block_size);
|
||||
else if (vgmstream->layout_type == layout_interleave)
|
||||
vgmstream->ch[i].streamfile = streamFile->open(streamFile, filename,
|
||||
STREAMFILE_DEFAULT_BUFFER_SIZE);
|
||||
else
|
||||
vgmstream->ch[i].streamfile = streamFile->open(streamFile, filename,
|
||||
0x1000);
|
||||
|
||||
if (!vgmstream->ch[i].streamfile) goto fail;
|
||||
|
||||
vgmstream->ch[i].channel_start_offset =
|
||||
vgmstream->ch[i].offset =
|
||||
start_offset + i*vgmstream->interleave_block_size;
|
||||
}
|
||||
}
|
||||
/* open the file for reading */
|
||||
if ( !vgmstream_open_stream(vgmstream,streamFile, start_offset) )
|
||||
goto fail;
|
||||
|
||||
return vgmstream;
|
||||
|
||||
/* clean up anything we may have opened */
|
||||
fail:
|
||||
if (vgmstream) close_vgmstream(vgmstream);
|
||||
close_vgmstream(vgmstream);
|
||||
return NULL;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user