mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-02-20 20:41:08 +01:00
Cleanup
This commit is contained in:
parent
95a15dafae
commit
25dfb01307
@ -2,8 +2,8 @@
|
||||
#include "../coding/coding.h"
|
||||
|
||||
/* MSF - Sony's PS3 SDK format (MultiStream File) */
|
||||
VGMSTREAM * init_vgmstream_msf(STREAMFILE *streamFile) {
|
||||
VGMSTREAM * vgmstream = NULL;
|
||||
VGMSTREAM* init_vgmstream_msf(STREAMFILE* sf) {
|
||||
VGMSTREAM* vgmstream = NULL;
|
||||
off_t start_offset;
|
||||
uint32_t data_size, loop_start = 0, loop_end = 0;
|
||||
uint32_t codec, flags;
|
||||
@ -13,24 +13,24 @@ VGMSTREAM * init_vgmstream_msf(STREAMFILE *streamFile) {
|
||||
/* checks */
|
||||
/* .msf: standard
|
||||
* .msa: Sonic & Sega All-Stars Racing (PS3)
|
||||
* .at3: Silent Hill HD Collection (PS3)
|
||||
* .at3: Silent Hill HD Collection (PS3), Z/X Zekkai no Crusade (PS3)
|
||||
* .mp3: Darkstalkers Resurrection (PS3) */
|
||||
if (!check_extensions(streamFile,"msf,msa,at3,mp3"))
|
||||
if (!check_extensions(sf,"msf,msa,at3,mp3"))
|
||||
goto fail;
|
||||
|
||||
/* check header "MSF" + version-char, usually:
|
||||
* 0x01, 0x02, 0x30 ("0"), 0x35 ("5"), 0x43 ("C") (last/most common version) */
|
||||
if ((read_32bitBE(0x00,streamFile) & 0xffffff00) != 0x4D534600) /* "MSF\0" */
|
||||
if ((read_u32be(0x00,sf) & 0xffffff00) != 0x4D534600) /* "MSF\0" */
|
||||
goto fail;
|
||||
|
||||
start_offset = 0x40;
|
||||
|
||||
codec = read_32bitBE(0x04,streamFile);
|
||||
channel_count = read_32bitBE(0x08,streamFile);
|
||||
data_size = read_32bitBE(0x0C,streamFile); /* without header */
|
||||
codec = read_u32be(0x04,sf);
|
||||
channel_count = read_s32be(0x08,sf);
|
||||
data_size = read_u32be(0x0C,sf); /* without header */
|
||||
if (data_size == 0xFFFFFFFF) /* unneeded? */
|
||||
data_size = get_streamfile_size(streamFile) - start_offset;
|
||||
sample_rate = read_32bitBE(0x10,streamFile);
|
||||
data_size = get_streamfile_size(sf) - start_offset;
|
||||
sample_rate = read_s32be(0x10,sf);
|
||||
|
||||
/* byte flags, not in MSFv1 or v2
|
||||
* 0x01/02/04/08: loop marker 0/1/2/3
|
||||
@ -38,15 +38,15 @@ VGMSTREAM * init_vgmstream_msf(STREAMFILE *streamFile) {
|
||||
* 0x20: VBR MP3 source (changed into simplified 0x1a1 CBR)
|
||||
* 0x40: joint stereo MP3 (apparently interleaved stereo for other formats)
|
||||
* 0x80+: (none/reserved) */
|
||||
flags = read_32bitBE(0x14,streamFile);
|
||||
flags = read_u32be(0x14,sf);
|
||||
/* sometimes loop_start/end is set with flag 0x10, but from tests it only loops if 0x01/02 is set
|
||||
* 0x10 often goes with 0x01 but not always (Castlevania HoD); Malicious PS3 uses flag 0x2 instead */
|
||||
loop_flag = flags != 0xffffffff && ((flags & 0x01) || (flags & 0x02));
|
||||
|
||||
/* loop markers (marker N @ 0x18 + N*(4+4), but in practice only marker 0 is used) */
|
||||
if (loop_flag) {
|
||||
loop_start = read_32bitBE(0x18,streamFile);
|
||||
loop_end = read_32bitBE(0x1C,streamFile); /* loop duration */
|
||||
loop_start = read_u32be(0x18,sf);
|
||||
loop_end = read_u32be(0x1C,sf); /* loop duration */
|
||||
loop_end = loop_start + loop_end; /* usually equals data_size but not always */
|
||||
if (loop_end > data_size)/* not seen */
|
||||
loop_end = data_size;
|
||||
@ -111,7 +111,7 @@ VGMSTREAM * init_vgmstream_msf(STREAMFILE *streamFile) {
|
||||
if (vgmstream->sample_rate == 0xFFFFFFFF) /* some MSFv1 (Digi World SP) */
|
||||
vgmstream->sample_rate = 44100; /* voice tracks seems to use 44khz, not sure about other tracks */
|
||||
|
||||
vgmstream->codec_data = init_ffmpeg_atrac3_raw(streamFile, start_offset,data_size, vgmstream->num_samples,vgmstream->channels,vgmstream->sample_rate, block_align, encoder_delay);
|
||||
vgmstream->codec_data = init_ffmpeg_atrac3_raw(sf, start_offset,data_size, vgmstream->num_samples,vgmstream->channels,vgmstream->sample_rate, block_align, encoder_delay);
|
||||
if (!vgmstream->codec_data) goto fail;
|
||||
vgmstream->coding_type = coding_FFmpeg;
|
||||
vgmstream->layout_type = layout_none;
|
||||
@ -129,7 +129,7 @@ VGMSTREAM * init_vgmstream_msf(STREAMFILE *streamFile) {
|
||||
#if defined(VGM_USE_MPEG)
|
||||
case 0x07: { /* MPEG (CBR LAME MP3) [Dengeki Bunko Fighting Climax (PS3)] */
|
||||
|
||||
vgmstream->codec_data = init_mpeg(streamFile, start_offset, &vgmstream->coding_type, vgmstream->channels);
|
||||
vgmstream->codec_data = init_mpeg(sf, start_offset, &vgmstream->coding_type, vgmstream->channels);
|
||||
if (!vgmstream->codec_data) goto fail;
|
||||
vgmstream->layout_type = layout_none;
|
||||
|
||||
@ -148,7 +148,7 @@ VGMSTREAM * init_vgmstream_msf(STREAMFILE *streamFile) {
|
||||
{ /* MPEG (CBR LAME MP3) [Dengeki Bunko Fighting Climax (PS3)] */
|
||||
ffmpeg_codec_data *ffmpeg_data = NULL;
|
||||
|
||||
ffmpeg_data = init_ffmpeg_offset(streamFile, start_offset, streamFile->get_size(streamFile));
|
||||
ffmpeg_data = init_ffmpeg_offset(sf, start_offset, sf->get_size(sf));
|
||||
if (!ffmpeg_data) goto fail;
|
||||
vgmstream->codec_data = ffmpeg_data;
|
||||
vgmstream->coding_type = coding_FFmpeg;
|
||||
@ -171,7 +171,7 @@ VGMSTREAM * init_vgmstream_msf(STREAMFILE *streamFile) {
|
||||
}
|
||||
|
||||
|
||||
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
|
||||
if (!vgmstream_open_stream(vgmstream,sf,start_offset))
|
||||
goto fail;
|
||||
return vgmstream;
|
||||
|
||||
|
@ -1,94 +1,86 @@
|
||||
#include "meta.h"
|
||||
#include "../util.h"
|
||||
#include "../coding/coding.h"
|
||||
|
||||
/* ENTH (from Enthusia - Professional Racing) */
|
||||
VGMSTREAM * init_vgmstream_ps2_enth(STREAMFILE *streamFile) {
|
||||
VGMSTREAM * vgmstream = NULL;
|
||||
char filename[PATH_LIMIT];
|
||||
/* LP/AP/LEP - from Enthusia: Professional Racing */
|
||||
VGMSTREAM* init_vgmstream_ps2_enth(STREAMFILE* sf) {
|
||||
VGMSTREAM* vgmstream = NULL;
|
||||
off_t start_offset;
|
||||
int header_check;
|
||||
int loop_flag;
|
||||
int channel_count;
|
||||
|
||||
/* check extension, case insensitive */
|
||||
streamFile->get_name(streamFile,filename,sizeof(filename));
|
||||
if (strcasecmp("enth",filename_extension(filename))) goto fail;
|
||||
|
||||
/* check header and loop_flag */
|
||||
header_check = read_32bitBE(0x00,streamFile);
|
||||
switch (header_check) {
|
||||
case 0x41502020: /* AP */
|
||||
loop_flag = (read_32bitLE(0x14,streamFile)!=0);
|
||||
break;
|
||||
case 0x4C455020: /* LEP */
|
||||
loop_flag = (read_32bitLE(0x58,streamFile)!=0);
|
||||
break;
|
||||
default:
|
||||
goto fail;
|
||||
}
|
||||
|
||||
channel_count = 2;
|
||||
|
||||
/* build the VGMSTREAM */
|
||||
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
||||
if (!vgmstream) goto fail;
|
||||
|
||||
/* fill in the vital statistics */
|
||||
header_check = read_32bitBE(0x00,streamFile);
|
||||
|
||||
switch (header_check) {
|
||||
case 0x41502020: /* AP */
|
||||
start_offset = read_32bitLE(0x1C,streamFile);
|
||||
vgmstream->channels = channel_count;
|
||||
vgmstream->sample_rate = read_32bitLE(0x08,streamFile);
|
||||
vgmstream->coding_type = coding_PSX;
|
||||
vgmstream->num_samples = (read_32bitLE(0x18,streamFile))*28/16/channel_count;
|
||||
if (loop_flag) {
|
||||
vgmstream->loop_start_sample = (read_32bitLE(0x14,streamFile))*28/16/channel_count;
|
||||
vgmstream->loop_end_sample = (read_32bitLE(0x18,streamFile))*28/16/channel_count;
|
||||
}
|
||||
vgmstream->interleave_block_size = read_32bitLE(0x0C,streamFile);
|
||||
break;
|
||||
case 0x4C455020: /* LEP */
|
||||
start_offset = 0x800;
|
||||
vgmstream->channels = channel_count;
|
||||
vgmstream->sample_rate = (uint16_t)read_16bitLE(0x12,streamFile);
|
||||
vgmstream->coding_type = coding_PSX;
|
||||
vgmstream->num_samples = (read_32bitLE(0x08,streamFile))*28/16/channel_count;
|
||||
if (loop_flag) {
|
||||
vgmstream->loop_start_sample = (read_32bitLE(0x58,streamFile))*28/16/channel_count;
|
||||
vgmstream->loop_end_sample = (read_32bitLE(0x08,streamFile))*28/16/channel_count;
|
||||
}
|
||||
vgmstream->interleave_block_size = 0x10;
|
||||
break;
|
||||
default:
|
||||
goto fail;
|
||||
}
|
||||
int loop_flag, channels, sample_rate, interleave;
|
||||
int32_t data_size, loop_start;
|
||||
uint32_t id;
|
||||
|
||||
|
||||
vgmstream->layout_type = layout_interleave;
|
||||
vgmstream->meta_type = meta_PS2_ENTH;
|
||||
/* checks */
|
||||
/* .bin/lbin: assumed (no actual extensino in bigfiles)
|
||||
* .enth: fake */
|
||||
if (!check_extensions(sf, "bin,lbin,enth"))
|
||||
goto fail;
|
||||
|
||||
/* open the file for reading */
|
||||
{
|
||||
int i;
|
||||
STREAMFILE * file;
|
||||
file = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE);
|
||||
if (!file) goto fail;
|
||||
for (i=0;i<channel_count;i++) {
|
||||
vgmstream->ch[i].streamfile = file;
|
||||
id = read_32bitBE(0x00,sf);
|
||||
switch (id) {
|
||||
case 0x41502020: /* "AP " */
|
||||
case 0x4C502020: /* "LP " */
|
||||
sample_rate = read_u32le(0x08,sf);
|
||||
interleave = read_u32le(0x0c,sf);
|
||||
loop_start = read_u32le(0x14,sf);
|
||||
data_size = read_u32le(0x18,sf);
|
||||
start_offset = read_32bitLE(0x1C,sf);
|
||||
break;
|
||||
|
||||
vgmstream->ch[i].channel_start_offset=
|
||||
vgmstream->ch[i].offset=start_offset+
|
||||
vgmstream->interleave_block_size*i;
|
||||
case 0x4C455020: /* "LEP " */
|
||||
data_size = read_u32le(0x08,sf);
|
||||
sample_rate = read_u16le(0x12,sf);
|
||||
loop_start = read_u32le(0x58,sf);
|
||||
interleave = 0x10;
|
||||
start_offset = 0x800;
|
||||
break;
|
||||
|
||||
}
|
||||
default:
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return vgmstream;
|
||||
loop_flag = loop_start != 0;
|
||||
channels = 2;
|
||||
|
||||
/* clean up anything we may have opened */
|
||||
/* build the VGMSTREAM */
|
||||
vgmstream = allocate_vgmstream(channels, loop_flag);
|
||||
if (!vgmstream) goto fail;
|
||||
|
||||
vgmstream->meta_type = meta_PS2_ENTH;
|
||||
vgmstream->sample_rate = sample_rate;
|
||||
|
||||
switch (id) {
|
||||
case 0x4C502020: /* "LP " */
|
||||
vgmstream->coding_type = coding_PCM16LE;
|
||||
vgmstream->layout_type = layout_interleave;
|
||||
vgmstream->interleave_block_size = interleave;
|
||||
|
||||
vgmstream->num_samples = pcm_bytes_to_samples(data_size, channels, 16);
|
||||
vgmstream->loop_start_sample = pcm_bytes_to_samples(loop_start, channels, 16);
|
||||
vgmstream->loop_end_sample = vgmstream->num_samples;
|
||||
/* PCM data look different or encrypted
|
||||
* some PCM16 must be xored(?) with 0x8000, not sure when */
|
||||
goto fail;
|
||||
|
||||
case 0x41502020: /* "AP " */
|
||||
case 0x4C455020: /* "LEP " */
|
||||
vgmstream->coding_type = coding_PSX;
|
||||
vgmstream->layout_type = layout_interleave;
|
||||
vgmstream->interleave_block_size = interleave;
|
||||
|
||||
vgmstream->num_samples = ps_bytes_to_samples(data_size, channels);
|
||||
vgmstream->loop_start_sample = ps_bytes_to_samples(loop_start, channels);
|
||||
vgmstream->loop_end_sample = vgmstream->num_samples;
|
||||
break;
|
||||
|
||||
default:
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
|
||||
goto fail;
|
||||
return vgmstream;
|
||||
fail:
|
||||
if (vgmstream) close_vgmstream(vgmstream);
|
||||
close_vgmstream(vgmstream);
|
||||
return NULL;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user