mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-01-29 19:37:30 +01:00
Move csmp to its own file, since it's not very standard either
This commit is contained in:
parent
f2a5b5954f
commit
ce6722181a
@ -383,6 +383,10 @@
|
||||
<File
|
||||
RelativePath=".\meta\ck.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\meta\csmp.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\meta\cstr.c"
|
||||
|
@ -213,7 +213,7 @@
|
||||
<ClCompile Include="meta\brstm.c" />
|
||||
<ClCompile Include="meta\btsnd.c" />
|
||||
<ClCompile Include="meta\capdsp.c" />
|
||||
<ClCompile Include="meta\ck.c" />
|
||||
<ClCompile Include="meta\csmp.c" />
|
||||
<ClCompile Include="meta\cstr.c" />
|
||||
<ClCompile Include="meta\dc_asd.c" />
|
||||
<ClCompile Include="meta\dc_dcsw_dcs.c" />
|
||||
|
@ -229,7 +229,7 @@
|
||||
<ClCompile Include="meta\capdsp.c">
|
||||
<Filter>meta\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="meta\ck.c">
|
||||
<ClCompile Include="meta\csmp.c">
|
||||
<Filter>meta\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="meta\cstr.c">
|
||||
|
56
src/meta/csmp.c
Normal file
56
src/meta/csmp.c
Normal file
@ -0,0 +1,56 @@
|
||||
#include "meta.h"
|
||||
#include "../coding/coding.h"
|
||||
|
||||
|
||||
/* CSMP - Retro Studios sample [Metroid Prime 3 (Wii), Donkey Kong Country Returns (Wii)] */
|
||||
VGMSTREAM * init_vgmstream_csmp(STREAMFILE *streamFile) {
|
||||
VGMSTREAM * vgmstream = NULL;
|
||||
off_t start_offset, first_offset = 0x08, chunk_offset;
|
||||
int loop_flag, channel_count;
|
||||
|
||||
|
||||
/* checks */
|
||||
if (!check_extensions(streamFile, "csmp"))
|
||||
goto fail;
|
||||
if (read_32bitBE(0x00, streamFile) != 0x43534D50) /* "CSMP" */
|
||||
goto fail;
|
||||
if (read_32bitBE(0x04, streamFile) != 1) /* version? */
|
||||
goto fail;
|
||||
|
||||
if (!find_chunk(streamFile, 0x44415441,first_offset,0, &chunk_offset,NULL, 1, 0)) /*"DATA"*/
|
||||
goto fail;
|
||||
|
||||
/* contains standard DSP header, but somehow some validations (start/loop ps)
|
||||
* don't seem to work, so no point to handle as standard DSP */
|
||||
|
||||
channel_count = 1;
|
||||
loop_flag = read_16bitBE(chunk_offset+0x0c,streamFile);
|
||||
start_offset = chunk_offset + 0x60;
|
||||
|
||||
|
||||
/* build the VGMSTREAM */
|
||||
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
||||
if (!vgmstream) goto fail;
|
||||
|
||||
vgmstream->meta_type = meta_DSP_CSMP;
|
||||
vgmstream->sample_rate = read_32bitBE(chunk_offset+0x08,streamFile);
|
||||
vgmstream->num_samples = read_32bitBE(chunk_offset+0x00,streamFile);
|
||||
vgmstream->loop_start_sample = dsp_nibbles_to_samples(read_32bitBE(chunk_offset+0x10,streamFile));
|
||||
vgmstream->loop_end_sample = dsp_nibbles_to_samples(read_32bitBE(chunk_offset+0x14,streamFile))+1;
|
||||
if (vgmstream->loop_end_sample > vgmstream->num_samples) /* ? */
|
||||
vgmstream->loop_end_sample = vgmstream->num_samples;
|
||||
|
||||
vgmstream->coding_type = coding_NGC_DSP;
|
||||
vgmstream->layout_type = layout_none;
|
||||
dsp_read_coefs_be(vgmstream, streamFile, chunk_offset+0x1c, 0x00);
|
||||
dsp_read_hist_be(vgmstream, streamFile, chunk_offset+0x40, 0x00);
|
||||
|
||||
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
|
||||
goto fail;
|
||||
return vgmstream;
|
||||
|
||||
fail:
|
||||
close_vgmstream(vgmstream);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ VGMSTREAM * init_vgmstream_ngc_mpdsp(STREAMFILE *streamFile);
|
||||
|
||||
VGMSTREAM * init_vgmstream_ngc_dsp_std_int(STREAMFILE *streamFile);
|
||||
|
||||
VGMSTREAM * init_vgmstream_ngc_dsp_csmp(STREAMFILE *streamFile);
|
||||
VGMSTREAM * init_vgmstream_csmp(STREAMFILE *streamFile);
|
||||
|
||||
VGMSTREAM * init_vgmstream_ps2_ads(STREAMFILE *streamFile);
|
||||
VGMSTREAM * init_vgmstream_ps2_ads_container(STREAMFILE *streamFile);
|
||||
|
@ -1063,106 +1063,6 @@ fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//todo might be only part of a full header?
|
||||
/* CSMP - Retro Studios header + interleaved DSPs [Metroid Prime 3 (Wii), Donkey Kong Country Returns (Wii)] */
|
||||
VGMSTREAM * init_vgmstream_ngc_dsp_csmp(STREAMFILE *streamFile) {
|
||||
VGMSTREAM * vgmstream = NULL;
|
||||
off_t start_offset;
|
||||
char filename[PATH_LIMIT];
|
||||
long current_offset;
|
||||
int tries;
|
||||
struct dsp_header header;
|
||||
int chanel_count, i;
|
||||
|
||||
/* check extension, case insensitive */
|
||||
streamFile->get_name(streamFile,filename,sizeof(filename));
|
||||
if (strcasecmp("csmp",filename_extension(filename))) goto fail;
|
||||
|
||||
if (read_32bitBE(0x00, streamFile) != 0x43534D50) /* "CSMP" */
|
||||
goto fail;
|
||||
if (read_32bitBE(0x04, streamFile) != 1) /* version? */
|
||||
goto fail;
|
||||
|
||||
chanel_count = 1;
|
||||
start_offset = 0x60;
|
||||
|
||||
current_offset = 0x08;
|
||||
tries = 0;
|
||||
while (1) {
|
||||
uint32_t chunk_id, chunk_size;
|
||||
|
||||
if (tries > 4)
|
||||
goto fail;
|
||||
|
||||
chunk_id = read_32bitBE(current_offset + 0x00, streamFile);
|
||||
chunk_size = read_32bitBE(current_offset + 0x04, streamFile);
|
||||
current_offset += 0x08;
|
||||
if (chunk_id != 0x44415441) { /* "DATA" */
|
||||
current_offset += chunk_size;
|
||||
tries++;
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (read_dsp_header(&header, current_offset, streamFile)) goto fail;
|
||||
|
||||
|
||||
|
||||
/* check initial predictor/scale */
|
||||
/* Retro doesn't seem to abide by this */
|
||||
//if (header.initial_ps != (uint8_t)read_8bit(current_offset + start_offset,streamFile))
|
||||
// goto fail;
|
||||
|
||||
/* check type==0 and gain==0 */
|
||||
if (header.format || header.gain)
|
||||
goto fail;
|
||||
|
||||
/* Retro doesn't seem to abide by this */
|
||||
/* check loop predictor/scale */
|
||||
if (header.loop_flag) {
|
||||
// off_t loop_off = header.loop_start_offset/16*8;
|
||||
// if (header.loop_ps != (uint8_t)read_8bit(current_offset + start_offset+loop_off,streamFile))
|
||||
// goto fail;
|
||||
}
|
||||
|
||||
/* build the VGMSTREAM */
|
||||
vgmstream = allocate_vgmstream(chanel_count,header.loop_flag);
|
||||
if (!vgmstream) goto fail;
|
||||
|
||||
vgmstream->sample_rate = header.sample_rate;
|
||||
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;
|
||||
|
||||
/* don't know why, but it does happen*/
|
||||
if (vgmstream->loop_end_sample > vgmstream->num_samples)
|
||||
vgmstream->loop_end_sample = vgmstream->num_samples;
|
||||
|
||||
vgmstream->coding_type = coding_NGC_DSP;
|
||||
vgmstream->layout_type = layout_none;
|
||||
vgmstream->meta_type = meta_DSP_CSMP;
|
||||
|
||||
/* coeffs */
|
||||
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;
|
||||
|
||||
/* 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=current_offset + start_offset;
|
||||
|
||||
return vgmstream;
|
||||
|
||||
fail:
|
||||
close_vgmstream(vgmstream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* .mcadpcm - Custom header + full interleaved dsp [Skyrim (Switch)] */
|
||||
VGMSTREAM * init_vgmstream_dsp_mcadpcm(STREAMFILE *streamFile) {
|
||||
dsp_meta dspm = {0};
|
||||
|
@ -32,7 +32,7 @@ VGMSTREAM * (*init_vgmstream_functions[])(STREAMFILE *streamFile) = {
|
||||
init_vgmstream_ngc_dsp_std,
|
||||
init_vgmstream_ngc_dsp_std_le,
|
||||
init_vgmstream_ngc_mdsp_std,
|
||||
init_vgmstream_ngc_dsp_csmp,
|
||||
init_vgmstream_csmp,
|
||||
init_vgmstream_cstr,
|
||||
init_vgmstream_gcsw,
|
||||
init_vgmstream_ps2_ads,
|
||||
|
Loading…
x
Reference in New Issue
Block a user