mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-02-17 19:19:16 +01:00
Clean ngc_dsp/mdsp_std
This commit is contained in:
parent
868834d52b
commit
a029bd9e1d
@ -149,30 +149,29 @@ fail:
|
||||
|
||||
/* ********************************* */
|
||||
|
||||
/* the standard .dsp, as generated by DSPADPCM.exe */
|
||||
/* .dsp - standard dsp as generated by DSPADPCM.exe */
|
||||
VGMSTREAM * init_vgmstream_ngc_dsp_std(STREAMFILE *streamFile) {
|
||||
VGMSTREAM * vgmstream = NULL;
|
||||
char filename[PATH_LIMIT];
|
||||
|
||||
struct dsp_header header;
|
||||
const off_t start_offset = 0x60;
|
||||
int i;
|
||||
const size_t header_size = 0x60;
|
||||
off_t start_offset;
|
||||
int i, channel_count;
|
||||
|
||||
/* check extension, case insensitive */
|
||||
/* checks */
|
||||
/* .dsp: standard, .adp: Dr. Muto (GC) mono files */
|
||||
streamFile->get_name(streamFile,filename,sizeof(filename));
|
||||
if (strcasecmp("dsp",filename_extension(filename)) &&
|
||||
strcasecmp("adp", filename_extension(filename))) goto fail;
|
||||
if (!check_extensions(streamFile, "dsp,adp"))
|
||||
goto fail;
|
||||
|
||||
if (read_dsp_header(&header, 0, streamFile)) goto fail;
|
||||
if (read_dsp_header(&header, 0x00, streamFile))
|
||||
goto fail;
|
||||
|
||||
channel_count = 1;
|
||||
start_offset = header_size;
|
||||
|
||||
/* check initial predictor/scale */
|
||||
if (header.initial_ps != (uint8_t)read_8bit(start_offset,streamFile))
|
||||
goto fail;
|
||||
|
||||
/* check type==0 and gain==0 */
|
||||
goto fail; /* check initial predictor/scale */
|
||||
if (header.format || header.gain)
|
||||
goto fail;
|
||||
goto fail; /* check type==0 and gain==0 */
|
||||
|
||||
/* Check for a matching second header. If we find one and it checks
|
||||
* out thoroughly, we're probably not dealing with a genuine mono DSP.
|
||||
@ -180,13 +179,14 @@ VGMSTREAM * init_vgmstream_ngc_dsp_std(STREAMFILE *streamFile) {
|
||||
* predictor/scale check if the first byte is 0 */
|
||||
{
|
||||
struct dsp_header header2;
|
||||
|
||||
read_dsp_header(&header2, 0x60, streamFile);
|
||||
read_dsp_header(&header2, header_size, streamFile);
|
||||
|
||||
if (header.sample_count == header2.sample_count &&
|
||||
header.nibble_count == header2.nibble_count &&
|
||||
header.sample_rate == header2.sample_rate &&
|
||||
header.loop_flag == header2.loop_flag) goto fail;
|
||||
header.loop_flag == header2.loop_flag) {
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
if (header.loop_flag) {
|
||||
@ -194,7 +194,7 @@ VGMSTREAM * init_vgmstream_ngc_dsp_std(STREAMFILE *streamFile) {
|
||||
/* check loop predictor/scale */
|
||||
loop_off = header.loop_start_offset/16*8;
|
||||
if (header.loop_ps != (uint8_t)read_8bit(start_offset+loop_off,streamFile)) {
|
||||
/* rarely won't match (ex ESPN 2002), not sure if header or calc problem, but doesn't seem to matter
|
||||
/* rarely won't match (ex ESPN 2002), not sure if header or calc problem, but doesn't seem to matter
|
||||
* (there may be a "click" when looping, or loop values may be too big and loop disabled anyway) */
|
||||
VGM_LOG("DSP (std): bad loop_predictor\n");
|
||||
//header.loop_flag = 0;
|
||||
@ -202,110 +202,76 @@ VGMSTREAM * init_vgmstream_ngc_dsp_std(STREAMFILE *streamFile) {
|
||||
}
|
||||
}
|
||||
|
||||
/* compare num_samples with nibble count */
|
||||
/*
|
||||
fprintf(stderr,"num samples (literal): %d\n",read_32bitBE(0,streamFile));
|
||||
fprintf(stderr,"num samples (nibbles): %d\n",dsp_nibbles_to_samples(read_32bitBE(4,streamFile)));
|
||||
*/
|
||||
|
||||
/* build the VGMSTREAM */
|
||||
|
||||
|
||||
vgmstream = allocate_vgmstream(1,header.loop_flag);
|
||||
vgmstream = allocate_vgmstream(channel_count,header.loop_flag);
|
||||
if (!vgmstream) goto fail;
|
||||
|
||||
/* fill in the vital statistics */
|
||||
vgmstream->num_samples = header.sample_count;
|
||||
vgmstream->sample_rate = header.sample_rate;
|
||||
|
||||
vgmstream->loop_start_sample = dsp_nibbles_to_samples(
|
||||
header.loop_start_offset);
|
||||
vgmstream->loop_end_sample = dsp_nibbles_to_samples(
|
||||
header.loop_end_offset)+1;
|
||||
|
||||
/* don't know why, but it does happen*/
|
||||
if (vgmstream->loop_end_sample > vgmstream->num_samples)
|
||||
vgmstream->num_samples = header.sample_count;
|
||||
vgmstream->loop_start_sample = dsp_nibbles_to_samples(header.loop_start_offset);
|
||||
vgmstream->loop_end_sample = dsp_nibbles_to_samples(header.loop_end_offset)+1;
|
||||
if (vgmstream->loop_end_sample > vgmstream->num_samples) /* don't know why, but it does happen */
|
||||
vgmstream->loop_end_sample = vgmstream->num_samples;
|
||||
|
||||
vgmstream->meta_type = meta_DSP_STD;
|
||||
vgmstream->coding_type = coding_NGC_DSP;
|
||||
vgmstream->layout_type = layout_none;
|
||||
vgmstream->meta_type = meta_DSP_STD;
|
||||
|
||||
/* coeffs */
|
||||
for (i=0;i<16;i++)
|
||||
vgmstream->ch[0].adpcm_coef[i] = header.coef[i];
|
||||
|
||||
/* initial history */
|
||||
/* always 0 that I've ever seen, but for completeness... */
|
||||
vgmstream->ch[0].adpcm_history1_16 = header.initial_hist1;
|
||||
vgmstream->ch[0].adpcm_history2_16 = header.initial_hist2;
|
||||
|
||||
/* open the file for reading */
|
||||
vgmstream->ch[0].streamfile = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE);
|
||||
|
||||
if (!vgmstream->ch[0].streamfile) goto fail;
|
||||
|
||||
vgmstream->ch[0].channel_start_offset=
|
||||
vgmstream->ch[0].offset=start_offset;
|
||||
{
|
||||
/* adpcm coeffs/history */
|
||||
for (i = 0; i < 16; i++)
|
||||
vgmstream->ch[0].adpcm_coef[i] = header.coef[i];
|
||||
vgmstream->ch[0].adpcm_history1_16 = header.initial_hist1;
|
||||
vgmstream->ch[0].adpcm_history2_16 = header.initial_hist2;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/* the standard multi-channel .dsp, as generated by DSPADPCM.exe */
|
||||
|
||||
/* .dsp - standard multi-channel dsp as generated by DSPADPCM.exe (later revisions) */
|
||||
VGMSTREAM * init_vgmstream_ngc_mdsp_std(STREAMFILE *streamFile) {
|
||||
VGMSTREAM * vgmstream = NULL;
|
||||
char filename[PATH_LIMIT];
|
||||
|
||||
struct dsp_header header;
|
||||
const off_t header_size = 0x60;
|
||||
const size_t header_size = 0x60;
|
||||
off_t start_offset;
|
||||
int i, c, channel_count;
|
||||
|
||||
/* check extension, case insensitive */
|
||||
streamFile->get_name(streamFile, filename, sizeof(filename));
|
||||
if (strcasecmp("dsp", filename_extension(filename)) &&
|
||||
strcasecmp("mdsp", filename_extension(filename))) goto fail;
|
||||
/* checks */
|
||||
if (!check_extensions(streamFile, "dsp,mdsp"))
|
||||
goto fail;
|
||||
|
||||
if (read_dsp_header(&header, 0, streamFile)) goto fail;
|
||||
if (read_dsp_header(&header, 0x00, streamFile))
|
||||
goto fail;
|
||||
|
||||
channel_count = header.channel_count==0 ? 1 : header.channel_count;
|
||||
start_offset = header_size * channel_count;
|
||||
|
||||
/* check initial predictor/scale */
|
||||
if (header.initial_ps != (uint8_t)read_8bit(start_offset, streamFile))
|
||||
goto fail;
|
||||
|
||||
/* check type==0 and gain==0 */
|
||||
goto fail; /* check initial predictor/scale */
|
||||
if (header.format || header.gain)
|
||||
goto fail;
|
||||
goto fail; /* check type==0 and gain==0 */
|
||||
|
||||
/* build the VGMSTREAM */
|
||||
|
||||
vgmstream = allocate_vgmstream(channel_count, header.loop_flag);
|
||||
if (!vgmstream) goto fail;
|
||||
|
||||
/* fill in the vital statistics */
|
||||
vgmstream->num_samples = header.sample_count;
|
||||
vgmstream->sample_rate = header.sample_rate;
|
||||
|
||||
vgmstream->loop_start_sample = dsp_nibbles_to_samples(
|
||||
header.loop_start_offset);
|
||||
vgmstream->loop_end_sample = dsp_nibbles_to_samples(
|
||||
header.loop_end_offset) + 1;
|
||||
|
||||
/* don't know why, but it does happen*/
|
||||
if (vgmstream->loop_end_sample > vgmstream->num_samples)
|
||||
vgmstream->num_samples = header.sample_count;
|
||||
vgmstream->loop_start_sample = dsp_nibbles_to_samples(header.loop_start_offset);
|
||||
vgmstream->loop_end_sample = dsp_nibbles_to_samples(header.loop_end_offset) + 1;
|
||||
if (vgmstream->loop_end_sample > vgmstream->num_samples) /* don't know why, but it does happen*/
|
||||
vgmstream->loop_end_sample = vgmstream->num_samples;
|
||||
|
||||
vgmstream->meta_type = meta_DSP_STD;
|
||||
vgmstream->coding_type = coding_NGC_DSP;
|
||||
vgmstream->layout_type = channel_count == 1 ? layout_none : layout_interleave;
|
||||
vgmstream->meta_type = meta_DSP_STD;
|
||||
vgmstream->interleave_block_size = header.block_size * 8;
|
||||
if (vgmstream->interleave_block_size)
|
||||
vgmstream->interleave_last_block_size = (header.nibble_count / 2 % vgmstream->interleave_block_size + 7) / 8 * 8;
|
||||
@ -313,12 +279,9 @@ VGMSTREAM * init_vgmstream_ngc_mdsp_std(STREAMFILE *streamFile) {
|
||||
for (i = 0; i < channel_count; i++) {
|
||||
if (read_dsp_header(&header, header_size * i, streamFile)) goto fail;
|
||||
|
||||
/* coeffs */
|
||||
/* adpcm coeffs/history */
|
||||
for (c = 0; c < 16; c++)
|
||||
vgmstream->ch[i].adpcm_coef[c] = header.coef[c];
|
||||
|
||||
/* initial history */
|
||||
/* always 0 that I've ever seen, but for completeness... */
|
||||
vgmstream->ch[i].adpcm_history1_16 = header.initial_hist1;
|
||||
vgmstream->ch[i].adpcm_history2_16 = header.initial_hist2;
|
||||
}
|
||||
@ -328,8 +291,7 @@ VGMSTREAM * init_vgmstream_ngc_mdsp_std(STREAMFILE *streamFile) {
|
||||
return vgmstream;
|
||||
|
||||
fail:
|
||||
/* clean up anything we may have opened */
|
||||
if (vgmstream) close_vgmstream(vgmstream);
|
||||
close_vgmstream(vgmstream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user