Cleanup dsp+sck cleanup

This commit is contained in:
bnnm 2019-03-04 22:48:51 +01:00
parent 9616bdd60e
commit 186d0c8ebf
2 changed files with 28 additions and 72 deletions

View File

@ -367,7 +367,6 @@ static const char* extension_list[] = {
"sbin",
"sc",
"scd",
"sck",
"sd9",
"sdf",
"sdt",

View File

@ -1,98 +1,55 @@
#include "meta.h"
#include "../util.h"
#include "../coding/coding.h"
/*
SCK+DSP
2009-08-25 - manakoAT : Scorpion King (NGC)...
*/
//todo this was extracted from a .pak bigfile. Inside are headers then data (no extensions),
// but headers are VAGp in the PS2 version, so it would make more sense to extract pasting
// header+data together, or support as-is (.SCK is a fake extension).
/* SCK+DSP - Scorpion King (GC) */
VGMSTREAM * init_vgmstream_ngc_sck_dsp(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
STREAMFILE * streamFileDSP = NULL;
char filename[PATH_LIMIT];
char filenameDSP[PATH_LIMIT];
int i;
int channel_count;
int loop_flag;
STREAMFILE * streamHeader = NULL;
int channel_count, loop_flag;
size_t data_size;
/* check extension, case insensitive */
streamFile->get_name(streamFile,filename,sizeof(filename));
if (strcasecmp("sck",filename_extension(filename))) goto fail;
strcpy(filenameDSP,filename);
strcpy(filenameDSP+strlen(filenameDSP)-3,"dsp");
streamFileDSP = streamFile->open(streamFile,filenameDSP,STREAMFILE_DEFAULT_BUFFER_SIZE);
if (read_32bitBE(0x5C,streamFile) != 0x60A94000)
if (!check_extensions(streamFile, "dsp"))
goto fail;
if (!streamFile) goto fail;
streamHeader = open_streamfile_by_ext(streamFile, "sck");
if (!streamHeader) goto fail;
if (read_32bitBE(0x5C,streamHeader) != 0x60A94000)
goto fail;
channel_count = 2;
loop_flag = 0;
data_size = read_32bitBE(0x14,streamHeader);
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
if (!vgmstream) goto fail;
/* fill in the vital statistics */
vgmstream->channels = channel_count;
vgmstream->sample_rate = read_32bitBE(0x18,streamFile);
vgmstream->num_samples=read_32bitBE(0x14,streamFile)/8/channel_count*14;
vgmstream->sample_rate = read_32bitBE(0x18,streamHeader);
vgmstream->num_samples = dsp_bytes_to_samples(data_size, channel_count);
vgmstream->coding_type = coding_NGC_DSP;
if(loop_flag) {
vgmstream->loop_start_sample = 0;
vgmstream->loop_end_sample = read_32bitBE(0x10,streamFile)/8/channel_count*14;
}
if (channel_count == 1) {
vgmstream->layout_type = layout_none;
} else if (channel_count == 2) {
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size=read_32bitBE(0xC,streamFile);
}
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = read_32bitBE(0xC,streamHeader);
if (vgmstream->interleave_block_size > 0)
vgmstream->interleave_last_block_size = (data_size % (vgmstream->interleave_block_size * channel_count)) / channel_count;
vgmstream->meta_type = meta_NGC_SCK_DSP;
/* open the file for reading */
{
for (i=0;i<channel_count;i++) {
/* Not sure, i'll put a fake value here for now */
vgmstream->ch[i].streamfile = streamFile->open(streamFileDSP,filenameDSP,STREAMFILE_DEFAULT_BUFFER_SIZE);
vgmstream->ch[i].offset = 0;
dsp_read_coefs_be(vgmstream,streamHeader, 0x2c, 0x00);
if (!vgmstream->ch[i].streamfile) goto fail;
}
}
if (vgmstream->coding_type == coding_NGC_DSP) {
int i;
for (i=0;i<16;i++) {
vgmstream->ch[0].adpcm_coef[i] = read_16bitBE(0x2C+i*2,streamFile);
}
if (vgmstream->channels == 2) {
for (i=0;i<16;i++) {
vgmstream->ch[1].adpcm_coef[i] = read_16bitBE(0x2C+i*2,streamFile);
}
}
}
close_streamfile(streamFileDSP); streamFileDSP=NULL;
if (!vgmstream_open_stream(vgmstream,streamFile,0x00))
goto fail;
close_streamfile(streamHeader);
return vgmstream;
/* clean up anything we may have opened */
fail:
if (streamFileDSP) close_streamfile(streamFileDSP);
if (vgmstream) close_vgmstream(vgmstream);
close_streamfile(streamHeader);
close_vgmstream(vgmstream);
return NULL;
}