This commit is contained in:
bnnm 2021-06-21 00:30:15 +02:00
parent d49aacbf52
commit 0487cf5435
4 changed files with 236 additions and 237 deletions

View File

@ -1,55 +1,55 @@
#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_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;
}
#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* sf) {
VGMSTREAM* vgmstream = NULL;
off_t start_offset, first_offset = 0x08, chunk_offset;
int loop_flag, channels;
/* checks */
if (!check_extensions(sf, "csmp"))
goto fail;
if (!is_id32be(0x00, sf, "CSMP"))
goto fail;
if (read_u32be(0x04, sf) != 1)
goto fail;
if (!find_chunk(sf, 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 */
channels = 1;
loop_flag = read_s16be(chunk_offset+0x0c,sf);
start_offset = chunk_offset + 0x60;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channels, loop_flag);
if (!vgmstream) goto fail;
vgmstream->meta_type = meta_CSMP;
vgmstream->sample_rate = read_s32be(chunk_offset+0x08,sf);
vgmstream->num_samples = read_s32be(chunk_offset+0x00,sf);
vgmstream->loop_start_sample = dsp_nibbles_to_samples(read_u32be(chunk_offset+0x10,sf));
vgmstream->loop_end_sample = dsp_nibbles_to_samples(read_u32be(chunk_offset+0x14,sf)) + 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, sf, chunk_offset+0x1c, 0x00);
dsp_read_hist_be(vgmstream, sf, chunk_offset+0x40, 0x00);
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
goto fail;
return vgmstream;
fail:
close_vgmstream(vgmstream);
return NULL;
}

View File

@ -1,62 +1,62 @@
#include "meta.h"
#include "../coding/coding.h"
/* WMSF - Banpresto MSFx wrapper [Dai-2-Ji Super Robot Taisen OG: The Moon Dwellers (PS3)] */
VGMSTREAM * init_vgmstream_msf_banpresto_wmsf(STREAMFILE *streamFile) {
VGMSTREAM *vgmstream = NULL;
STREAMFILE *temp_streamFile = NULL;
off_t subfile_offset = 0x10;
size_t subfile_size = get_streamfile_size(streamFile) - subfile_offset;
/* checks */
if ( !check_extensions(streamFile,"msf"))
goto fail;
if (read_32bitBE(0x00,streamFile) != 0x574D5346) /* "WMSF" */
goto fail;
/* 0x04: size, 0x08: flags? 0x0c: null? */
temp_streamFile = setup_subfile_streamfile(streamFile, subfile_offset,subfile_size, NULL);
if (!temp_streamFile) goto fail;
vgmstream = init_vgmstream_msf(temp_streamFile);
if (!vgmstream) goto fail;
close_streamfile(temp_streamFile);
return vgmstream;
fail:
close_streamfile(temp_streamFile);
close_vgmstream(vgmstream);
return NULL;
}
/* 2MSF - Banpresto RIFF wrapper [Dai-2-Ji Super Robot Taisen OG: The Moon Dwellers (PS4)] */
VGMSTREAM * init_vgmstream_msf_banpresto_2msf(STREAMFILE *streamFile) {
VGMSTREAM *vgmstream = NULL;
STREAMFILE *temp_streamFile = NULL;
off_t subfile_offset = 0x14;
size_t subfile_size = get_streamfile_size(streamFile) - subfile_offset;
/* checks */
if ( !check_extensions(streamFile,"at9"))
goto fail;
if (read_32bitBE(0x00,streamFile) != 0x324D5346) /* "2MSF" */
goto fail;
/* 0x04: size, 0x08: flags? 0x0c: null?, 0x10: 0x01? (BE values even though RIFF is LE) */
temp_streamFile = setup_subfile_streamfile(streamFile, subfile_offset,subfile_size, NULL);
if (!temp_streamFile) goto fail;
vgmstream = init_vgmstream_riff(temp_streamFile);
if (!vgmstream) goto fail;
close_streamfile(temp_streamFile);
return vgmstream;
fail:
close_streamfile(temp_streamFile);
close_vgmstream(vgmstream);
return NULL;
}
#include "meta.h"
#include "../coding/coding.h"
/* WMSF - Banpresto MSFx wrapper [Dai-2-Ji Super Robot Taisen OG: The Moon Dwellers (PS3)] */
VGMSTREAM* init_vgmstream_msf_banpresto_wmsf(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
STREAMFILE* temp_sf = NULL;
off_t subfile_offset = 0x10;
size_t subfile_size = get_streamfile_size(sf) - subfile_offset;
/* checks */
if (!check_extensions(sf,"msf"))
goto fail;
if (!is_id32be(0x00,sf,"WMSF"))
goto fail;
/* 0x04: size, 0x08: flags? 0x0c: null? */
temp_sf = setup_subfile_streamfile(sf, subfile_offset,subfile_size, NULL);
if (!temp_sf) goto fail;
vgmstream = init_vgmstream_msf(temp_sf);
if (!vgmstream) goto fail;
close_streamfile(temp_sf);
return vgmstream;
fail:
close_streamfile(temp_sf);
close_vgmstream(vgmstream);
return NULL;
}
/* 2MSF - Banpresto RIFF wrapper [Dai-2-Ji Super Robot Taisen OG: The Moon Dwellers (PS4)] */
VGMSTREAM* init_vgmstream_msf_banpresto_2msf(STREAMFILE *sf) {
VGMSTREAM* vgmstream = NULL;
STREAMFILE*temp_sf = NULL;
off_t subfile_offset = 0x14;
size_t subfile_size = get_streamfile_size(sf) - subfile_offset;
/* checks */
if ( !check_extensions(sf,"at9"))
goto fail;
if (!is_id32be(0x00,sf,"2MSF"))
goto fail;
/* 0x04: size, 0x08: flags? 0x0c: null?, 0x10: 0x01? (BE values even though RIFF is LE) */
temp_sf = setup_subfile_streamfile(sf, subfile_offset,subfile_size, NULL);
if (!temp_sf) goto fail;
vgmstream = init_vgmstream_riff(temp_sf);
if (!vgmstream) goto fail;
close_streamfile(temp_sf);
return vgmstream;
fail:
close_streamfile(temp_sf);
close_vgmstream(vgmstream);
return NULL;
}

View File

@ -1,58 +1,58 @@
#include "meta.h"
#include "../coding/coding.h"
/* MSFC - Konami (Armature?) variation [Metal Gear Solid 2 HD (PS3), Metal Gear Solid 3 HD (PS3)] */
VGMSTREAM * init_vgmstream_msf_konami(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
off_t start_offset;
uint32_t codec;
int loop_flag, channel_count, sample_rate;
size_t data_size;
/* checks */
if (!check_extensions(streamFile,"msf"))
goto fail;
if (read_32bitBE(0x00,streamFile) != 0x4D534643) /* "MSFC" */
goto fail;
start_offset = 0x20;
codec = read_32bitBE(0x04,streamFile);
channel_count = read_32bitBE(0x08,streamFile);
sample_rate = read_32bitBE(0x0c,streamFile);
data_size = read_32bitBE(0x10,streamFile); /* without header */
if (data_size + start_offset != get_streamfile_size(streamFile))
goto fail;
loop_flag = 0;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
if (!vgmstream) goto fail;
vgmstream->meta_type = meta_MSF_KONAMI;
vgmstream->sample_rate = sample_rate;
switch (codec) {
case 0x01:
vgmstream->coding_type = coding_PSX;
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = 0x10;
vgmstream->num_samples = ps_bytes_to_samples(data_size, channel_count);
break;
default:
goto fail;
}
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
goto fail;
return vgmstream;
fail:
close_vgmstream(vgmstream);
return NULL;
}
#include "meta.h"
#include "../coding/coding.h"
/* MSFC - Konami (Armature?) variation [Metal Gear Solid 2 HD (PS3), Metal Gear Solid 3 HD (PS3)] */
VGMSTREAM* init_vgmstream_msf_konami(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
off_t start_offset;
uint32_t codec;
int loop_flag, channels, sample_rate;
size_t data_size;
/* checks */
if (!check_extensions(sf,"msf"))
goto fail;
if (!is_id32be(0x00,sf,"MSFC"))
goto fail;
start_offset = 0x20;
codec = read_u32be(0x04,sf);
channels = read_s32be(0x08,sf);
sample_rate = read_s32be(0x0c,sf);
data_size = read_u32be(0x10,sf); /* without header */
if (data_size + start_offset != get_streamfile_size(sf))
goto fail;
loop_flag = 0;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channels,loop_flag);
if (!vgmstream) goto fail;
vgmstream->meta_type = meta_MSF_KONAMI;
vgmstream->sample_rate = sample_rate;
switch (codec) {
case 0x01:
vgmstream->coding_type = coding_PSX;
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = 0x10;
vgmstream->num_samples = ps_bytes_to_samples(data_size, channels);
break;
default:
goto fail;
}
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
goto fail;
return vgmstream;
fail:
close_vgmstream(vgmstream);
return NULL;
}

View File

@ -1,62 +1,61 @@
#include "meta.h"
#include "../coding/coding.h"
/* UE4OPUS - from Unreal Engine 4 games [ARK: Survival Evolved (PC), Fortnite (PC)] */
VGMSTREAM * init_vgmstream_ue4opus(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
off_t start_offset;
int loop_flag = 0, channel_count, sample_rate, num_samples, skip;
size_t data_size;
/* checks*/
/* .opus/lopus: possible real extension
* .ue4opus: header id */
if (!check_extensions(streamFile, "opus,lopus,ue4opus"))
goto fail;
if (read_32bitBE(0x00, streamFile) != 0x5545344F && /* "UE4O" */
read_32bitBE(0x00, streamFile) != 0x50555300) /* "PUS\0" */
goto fail;
sample_rate = (uint16_t)read_16bitLE(0x08, streamFile);
num_samples = read_32bitLE(0x0a, streamFile); /* may be less or equal to file num_samples */
channel_count = read_8bit(0x0e, streamFile);
/* 0x0f(2): frame count */
loop_flag = 0;
start_offset = 0x11;
data_size = get_streamfile_size(streamFile) - start_offset;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count, loop_flag);
if (!vgmstream) goto fail;
vgmstream->meta_type = meta_UE4OPUS;
vgmstream->sample_rate = sample_rate;
#ifdef VGM_USE_FFMPEG
{
/* usually uses 60ms for music (delay of 360 samples) */
skip = ue4_opus_get_encoder_delay(start_offset, streamFile);
vgmstream->num_samples = num_samples - skip;
vgmstream->codec_data = init_ffmpeg_ue4_opus(streamFile, start_offset,data_size, vgmstream->channels, skip, vgmstream->sample_rate);
if (!vgmstream->codec_data) goto fail;
vgmstream->coding_type = coding_FFmpeg;
vgmstream->layout_type = layout_none;
}
#else
goto fail;
#endif
if (!vgmstream_open_stream(vgmstream, streamFile, start_offset))
goto fail;
return vgmstream;
fail:
close_vgmstream(vgmstream);
return NULL;
}
#include "meta.h"
#include "../coding/coding.h"
/* UE4OPUS - from Unreal Engine 4 games [ARK: Survival Evolved (PC), Fortnite (PC)] */
VGMSTREAM * init_vgmstream_ue4opus(STREAMFILE *sf) {
VGMSTREAM * vgmstream = NULL;
off_t start_offset;
int loop_flag = 0, channels, sample_rate, num_samples, skip;
size_t data_size;
/* checks*/
/* .opus/lopus: possible real extension
* .ue4opus: header id */
if (!check_extensions(sf, "opus,lopus,ue4opus"))
goto fail;
if (!is_id64be(0x00, sf, "UE4OPUS\0"))
goto fail;
sample_rate = read_u16le(0x08, sf);
num_samples = read_s32le(0x0a, sf); /* may be less or equal to file num_samples */
channels = read_u8(0x0e, sf);
/* 0x0f(2): frame count */
loop_flag = 0;
start_offset = 0x11;
data_size = get_streamfile_size(sf) - start_offset;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channels, loop_flag);
if (!vgmstream) goto fail;
vgmstream->meta_type = meta_UE4OPUS;
vgmstream->sample_rate = sample_rate;
#ifdef VGM_USE_FFMPEG
{
/* usually uses 60ms for music (delay of 360 samples) */
skip = ue4_opus_get_encoder_delay(start_offset, sf);
vgmstream->num_samples = num_samples - skip;
vgmstream->codec_data = init_ffmpeg_ue4_opus(sf, start_offset,data_size, vgmstream->channels, skip, vgmstream->sample_rate);
if (!vgmstream->codec_data) goto fail;
vgmstream->coding_type = coding_FFmpeg;
vgmstream->layout_type = layout_none;
}
#else
goto fail;
#endif
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
goto fail;
return vgmstream;
fail:
close_vgmstream(vgmstream);
return NULL;
}