mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-01-17 23:36:41 +01:00
Add iNiS .IMC [Gitaroo Man (PS2)]
This commit is contained in:
parent
28ce248992
commit
9245dc8a15
@ -175,6 +175,7 @@ static const char* extension_list[] = {
|
||||
"idx",
|
||||
"ikm",
|
||||
"ild",
|
||||
"imc",
|
||||
"int",
|
||||
"isd",
|
||||
"isws",
|
||||
@ -1125,6 +1126,7 @@ static const meta_info meta_info_list[] = {
|
||||
{meta_ZSND, "Vicarious Visions ZSND header"},
|
||||
{meta_DSP_ADPCMX, "AQUASTYLE ADPY header"},
|
||||
{meta_OGG_OPUS, "Ogg Opus header"},
|
||||
{meta_IMC, "iNiS .IMC header"},
|
||||
|
||||
};
|
||||
|
||||
|
@ -619,6 +619,10 @@
|
||||
<File
|
||||
RelativePath=".\meta\nub_idsp.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\meta\imc.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\meta\ios_psnd.c"
|
||||
|
@ -146,6 +146,7 @@
|
||||
<ClCompile Include="meta\ezw.c" />
|
||||
<ClCompile Include="meta\ffmpeg.c" />
|
||||
<ClCompile Include="meta\g1l.c" />
|
||||
<ClCompile Include="meta\imc.c" />
|
||||
<ClCompile Include="meta\ios_psnd.c" />
|
||||
<ClCompile Include="meta\ktss.c" />
|
||||
<ClCompile Include="meta\lsf.c" />
|
||||
|
@ -1360,6 +1360,9 @@
|
||||
<ClCompile Include="meta\ios_psnd.c">
|
||||
<Filter>meta\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="meta\imc.c">
|
||||
<Filter>meta\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="meta\pc_adp.c">
|
||||
<Filter>meta\Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
130
src/meta/imc.c
Normal file
130
src/meta/imc.c
Normal file
@ -0,0 +1,130 @@
|
||||
#include "meta.h"
|
||||
#include "../coding/coding.h"
|
||||
|
||||
/* .IMC - from iNiS Gitaroo Man (PS2) */
|
||||
VGMSTREAM * init_vgmstream_imc(STREAMFILE *streamFile) {
|
||||
VGMSTREAM * vgmstream = NULL;
|
||||
off_t start_offset;
|
||||
int loop_flag, channel_count, sample_rate, interleave, blocks;
|
||||
size_t file_size, data_size;
|
||||
|
||||
|
||||
/* checks */
|
||||
/* .imc: extension from the main container */
|
||||
if (!check_extensions(streamFile, "imc"))
|
||||
goto fail;
|
||||
|
||||
channel_count = read_32bitLE(0x00, streamFile);
|
||||
sample_rate = read_32bitLE(0x04, streamFile);
|
||||
interleave = read_32bitLE(0x08, streamFile) * 0x10; /* number of frames in a block */
|
||||
blocks = read_32bitLE(0x0c, streamFile); /* number of interleave blocks (even in mono) */
|
||||
|
||||
file_size = get_streamfile_size(streamFile);
|
||||
loop_flag = 0;
|
||||
start_offset = 0x10;
|
||||
VGM_LOG("3\n");
|
||||
/* extra checks since the header is so simple */
|
||||
if (channel_count < 1 || channel_count > 8 || sample_rate < 22000 || sample_rate > 48000)
|
||||
goto fail;
|
||||
VGM_LOG("4\n");
|
||||
if (interleave*blocks + start_offset != file_size)
|
||||
goto fail;
|
||||
VGM_LOG("5\n");
|
||||
|
||||
/* remove padding (important to play gapless subsongs, happens even for mono) */
|
||||
{
|
||||
off_t min_offset = file_size - interleave;
|
||||
off_t offset = file_size - 0x10;
|
||||
|
||||
data_size = file_size - start_offset;
|
||||
while (offset > min_offset) {
|
||||
if (read_32bitLE(offset, streamFile) != 0)
|
||||
break;
|
||||
data_size -= 0x10*channel_count;
|
||||
offset -= 0x10;
|
||||
}
|
||||
}
|
||||
|
||||
/* build the VGMSTREAM */
|
||||
vgmstream = allocate_vgmstream(channel_count, loop_flag);
|
||||
if (!vgmstream) goto fail;
|
||||
|
||||
vgmstream->meta_type = meta_IMC;
|
||||
vgmstream->sample_rate = sample_rate;
|
||||
vgmstream->num_samples = ps_bytes_to_samples(data_size, channel_count);
|
||||
vgmstream->coding_type = coding_PSX;
|
||||
vgmstream->layout_type = layout_interleave;
|
||||
vgmstream->interleave_block_size = interleave;
|
||||
|
||||
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
|
||||
goto fail;
|
||||
return vgmstream;
|
||||
|
||||
fail:
|
||||
close_vgmstream(vgmstream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* ****************************************************************************** */
|
||||
|
||||
/* .IMC in containers */
|
||||
VGMSTREAM * init_vgmstream_imc_container(STREAMFILE *streamFile) {
|
||||
VGMSTREAM *vgmstream = NULL;
|
||||
STREAMFILE *temp_streamFile = NULL;
|
||||
off_t header_offset, subfile_offset, next_offset, name_offset;
|
||||
uint32_t flags1, flags2;
|
||||
|
||||
size_t subfile_size;
|
||||
int total_subsongs, target_subsong = streamFile->stream_index;
|
||||
|
||||
/* checks */
|
||||
if (!check_extensions(streamFile, "imc"))
|
||||
goto fail;
|
||||
|
||||
total_subsongs = read_32bitLE(0x00, streamFile);
|
||||
if (target_subsong == 0) target_subsong = 1;
|
||||
if (target_subsong < 0 || target_subsong > total_subsongs || total_subsongs < 1) goto fail;
|
||||
|
||||
|
||||
header_offset = 0x04 + 0x20*(target_subsong-1);
|
||||
|
||||
name_offset = header_offset + 0x00;
|
||||
//flags1 = (uint32_t)read_32bitLE(header_offset + 0x08, streamFile);
|
||||
/* 0x0c: same for all songs in single .imc but varies between .imc */
|
||||
subfile_offset = read_32bitLE(header_offset + 0x10,streamFile);
|
||||
//flags2 = (uint32_t)read_32bitLE(header_offset + 0x14, streamFile);
|
||||
/* 0x18: same for all songs in single .imc but varies between .imc */
|
||||
/* 0x1c: flags? (0 or 2) */
|
||||
//VGM_LOG("1: %x, %x\n", flags1, flags2);
|
||||
// if (!(flags1 == 0x77DE2A70 || flags1 == 0x77DE2A00 || flags1 == 0x00000020 || flags1 == 0x00000000))
|
||||
// goto fail;
|
||||
// if (!(flags2 == 0x0000F095 || flags2 == 0x0012FA3C))
|
||||
// goto fail;
|
||||
//VGM_LOG("2\n");
|
||||
|
||||
if (target_subsong == total_subsongs) {
|
||||
next_offset = get_streamfile_size(streamFile);
|
||||
}
|
||||
else {
|
||||
next_offset = read_32bitLE(header_offset + 0x20 + 0x10,streamFile);
|
||||
}
|
||||
subfile_size = next_offset - subfile_offset;
|
||||
|
||||
|
||||
temp_streamFile = setup_subfile_streamfile(streamFile, subfile_offset,subfile_size, NULL);
|
||||
if (!temp_streamFile) goto fail;
|
||||
|
||||
vgmstream = init_vgmstream_imc(temp_streamFile);
|
||||
if (!vgmstream) goto fail;
|
||||
|
||||
close_streamfile(temp_streamFile);
|
||||
vgmstream->num_streams = total_subsongs;
|
||||
read_string(vgmstream->stream_name,0x08+1, name_offset,streamFile);
|
||||
|
||||
return vgmstream;
|
||||
|
||||
fail:
|
||||
close_streamfile(temp_streamFile);
|
||||
close_vgmstream(vgmstream);
|
||||
return NULL;
|
||||
}
|
@ -820,4 +820,7 @@ VGMSTREAM * init_vgmstream_ogg_opus(STREAMFILE * streamFile);
|
||||
|
||||
VGMSTREAM * init_vgmstream_nus3audio(STREAMFILE * streamFile);
|
||||
|
||||
VGMSTREAM * init_vgmstream_imc(STREAMFILE * streamFile);
|
||||
VGMSTREAM * init_vgmstream_imc_container(STREAMFILE * streamFile);
|
||||
|
||||
#endif /*_META_H*/
|
||||
|
@ -456,6 +456,8 @@ VGMSTREAM * (*init_vgmstream_functions[])(STREAMFILE *streamFile) = {
|
||||
init_vgmstream_dsp_adpcmx,
|
||||
init_vgmstream_ogg_opus,
|
||||
init_vgmstream_nus3audio,
|
||||
init_vgmstream_imc,
|
||||
init_vgmstream_imc_container,
|
||||
|
||||
/* lowest priority metas (should go after all metas, and TXTH should go before raw formats) */
|
||||
init_vgmstream_txth, /* proper parsers should supersede TXTH, once added */
|
||||
|
@ -707,7 +707,8 @@ typedef enum {
|
||||
meta_XPS_DAT,
|
||||
meta_ZSND,
|
||||
meta_DSP_ADPCMX,
|
||||
meta_OGG_OPUS
|
||||
meta_OGG_OPUS,
|
||||
meta_IMC,
|
||||
|
||||
} meta_t;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user