.mjh+mjh cleanup

This commit is contained in:
bnnm 2022-01-22 22:56:35 +01:00
parent f565083502
commit 098937ffeb
2 changed files with 33 additions and 8 deletions

View File

@ -5,18 +5,33 @@
VGMSTREAM* init_vgmstream_mjb_mjh(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
STREAMFILE* sh = NULL;
STREAMFILE* sb = NULL;
off_t start_offset = 0, header_offset = 0;
size_t data_size, frame_size, frame_count;
int channels, loop_flag, sample_rate;
int total_subsongs, target_subsong = sf->stream_index;
/* for plugins that start with .mjb */
if (check_extensions(sf,"mjb")) {
sh = open_streamfile_by_ext(sf, "mjh");
if (!sh) goto fail;
}
else {
sh = sf;
}
/* checks */
/* "base" header check only has total subsongs, check expected header size */
if (read_s32le(0x00,sh) * 0x40 + 0x40 != get_streamfile_size(sh))
goto fail;
if (read_u32le(0x10,sh) != 0 || read_u32le(0x20,sh) != 0 || read_u32le(0x30,sh) != 0) /* padding until 0x40 */
goto fail;
/* only body for now */
if (!check_extensions(sf, "mjb"))
goto fail;
sh = open_streamfile_by_ext(sf, "mjh");
if (!sh) goto fail;
/* parse entries */
{
@ -42,8 +57,6 @@ VGMSTREAM* init_vgmstream_mjb_mjh(STREAMFILE* sf) {
goto fail;
}
VGM_LOG("3: %lx\n", start_offset);
/* also see MIB+MIH (same thing but this excludes padding stuff) */
if (read_u32le(header_offset + 0x00,sh) != 0x40)
goto fail;
@ -56,6 +69,16 @@ VGMSTREAM* init_vgmstream_mjb_mjh(STREAMFILE* sf) {
loop_flag = 0;
/* for plugins that start with .mjh (and don't check extensions) */
if (sf == sh) {
sb = open_streamfile_by_ext(sf, "mjb");
if (!sb) goto fail;
}
else {
sb = sf;
}
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channels, loop_flag);
if (!vgmstream) goto fail;
@ -71,13 +94,15 @@ VGMSTREAM* init_vgmstream_mjb_mjh(STREAMFILE* sf) {
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = frame_size;
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
if (!vgmstream_open_stream(vgmstream, sb, start_offset))
goto fail;
close_streamfile(sh);
if (sf != sh) close_streamfile(sh);
if (sf != sb) close_streamfile(sb);
return vgmstream;
fail:
close_streamfile(sh);
if (sf != sh) close_streamfile(sh);
if (sf != sb) close_streamfile(sb);
close_vgmstream(vgmstream);
return NULL;
}

View File

@ -499,7 +499,6 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = {
init_vgmstream_acx,
init_vgmstream_compresswave,
init_vgmstream_ktac,
init_vgmstream_mjb_mjh,
init_vgmstream_mzrt_v1,
init_vgmstream_bsnf,
init_vgmstream_tac,
@ -525,6 +524,7 @@ VGMSTREAM* (*init_vgmstream_functions[])(STREAMFILE* sf) = {
init_vgmstream_rsf,
init_vgmstream_ps2_wmus,
init_vgmstream_mib_mih,
init_vgmstream_mjb_mjh,
init_vgmstream_mic_koei,
init_vgmstream_seb,
init_vgmstream_ps2_pnb,