Improve Guitar Hero II multi-streams with block layout

Fixes partially by ignoring last stream, as it can be half sample rate
This commit is contained in:
bnnm 2017-08-28 20:05:03 +02:00
parent b758e8f60d
commit d46996a642
11 changed files with 97 additions and 72 deletions

View File

@ -535,6 +535,7 @@ static const layout_info layout_info_list[] = {
{layout_scd_int, "SCD multistream interleave"},
{layout_ea_sns_blocked, "Electronic Arts SNS blocked"},
{layout_blocked_awc, "blocked (AWC)"},
{layout_blocked_vgs, "blocked (VGS)"},
#ifdef VGM_USE_VORBIS
{layout_ogg_vorbis, "Ogg"},
#endif
@ -719,7 +720,7 @@ static const meta_info meta_info_list[] = {
{meta_MSVP, "MSVP Header"},
{meta_NGC_SSM, "SSM DSP Header"},
{meta_PS2_JOE, "Disney/Pixar JOE Header"},
{meta_VGS, "Guitar Hero Encore Rocks the 80's Header"},
{meta_VGS, "Guitar Hero VGS Header"},
{meta_DC_DCSW_DCS, "Evil Twin DCS file with helper"},
{meta_WII_SMP, "SMP DSP Header"},
{meta_EMFF_PS2, "Eidos Music File Format Header"},

View File

@ -146,6 +146,9 @@ void render_vgmstream_blocked(sample * buffer, int32_t sample_count, VGMSTREAM *
break;
case layout_blocked_awc:
block_update_awc(vgmstream->next_block_offset,vgmstream);
break;
case layout_blocked_vgs:
block_update_vgs(vgmstream->next_block_offset,vgmstream);
break;
default:
break;

View File

@ -1,7 +1,9 @@
#include "layout.h"
#include "../coding/coding.h"
#include "../layout/layout.h"
#include "../vgmstream.h"
static size_t get_block_header_size(STREAMFILE *streamFile, off_t offset, int channels, int big_endian);
/* AWC music chunks */

32
src/layout/blocked_vgs.c Normal file
View File

@ -0,0 +1,32 @@
#include "layout.h"
#include "../coding/coding.h"
#include "../layout/layout.h"
#include "../vgmstream.h"
/* VGS multistream frames */
void block_update_vgs(off_t block_offset, VGMSTREAM * vgmstream) {
STREAMFILE* streamFile = vgmstream->ch[0].streamfile;
size_t file_size = get_streamfile_size(vgmstream->ch[0].streamfile);
int i;
size_t channel_size = 0x10;
/* set offsets */
for (i = 0; i < vgmstream->channels; i++) {
vgmstream->ch[i].offset = block_offset + channel_size*i;
}
vgmstream->current_block_size = channel_size;
vgmstream->current_block_offset = block_offset;
vgmstream->next_block_offset = block_offset + channel_size*vgmstream->channels;
/* skip unhandled tracks: flag can be 0x0n per track, of 0x8x for last frame */
while (vgmstream->next_block_offset < file_size) {
if ((read_8bit(vgmstream->next_block_offset + 0x01, streamFile) & 0x0F) == 0x00)
break;
vgmstream->next_block_offset += channel_size;
}
}

View File

@ -65,7 +65,8 @@ void hwas_block_update(off_t block_offset, VGMSTREAM * vgmstream);
void ea_sns_block_update(off_t block_offset, VGMSTREAM * vgmstream);
void block_update_awc(off_t block_ofset, VGMSTREAM * vgmstream);
void block_update_awc(off_t block_offset, VGMSTREAM * vgmstream);
void block_update_vgs(off_t block_offset, VGMSTREAM * vgmstream);
/* other layouts */
void render_vgmstream_interleave(sample * buffer, int32_t sample_count, VGMSTREAM * vgmstream);

View File

@ -1537,6 +1537,10 @@
<File
RelativePath=".\layout\blocked_awc.c"
>
</File>
<File
RelativePath=".\layout\blocked_vgs.c"
>
</File>
<File
RelativePath=".\layout\caf_blocked.c"

View File

@ -455,6 +455,7 @@
<ClCompile Include="layout\bdsp_blocked.c" />
<ClCompile Include="layout\blocked.c" />
<ClCompile Include="layout\blocked_awc.c" />
<ClCompile Include="layout\blocked_vgs.c" />
<ClCompile Include="layout\caf_blocked.c" />
<ClCompile Include="layout\de2_blocked.c" />
<ClCompile Include="layout\ea_block.c" />

View File

@ -901,6 +901,9 @@
<ClCompile Include="layout\blocked_awc.c">
<Filter>layout\Source Files</Filter>
</ClCompile>
<ClCompile Include="layout\blocked_vgs.c">
<Filter>layout\Source Files</Filter>
</ClCompile>
<ClCompile Include="layout\caf_blocked.c">
<Filter>layout\Source Files</Filter>
</ClCompile>

View File

@ -1,100 +1,76 @@
#include "meta.h"
#include "../util.h"
#include "../coding/coding.h"
#include "../layout/layout.h"
/* VGS (from Guitar Hero Encore - Rocks the 80s) */
/* VGS - from Guitar Hero Encore - Rocks the 80s, Guitar Hero II PS2 */
VGMSTREAM * init_vgmstream_vgs(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
char filename[PATH_LIMIT];
off_t start_offset;
size_t channel_size = 0, stream_data_size, stream_frame_count;
int channel_count = 0, loop_flag = 0, sample_rate = 0, stream_sample_rate;
int i;
int loop_flag;
int channel_flag;
int channel_flag_offset;
int channel_count;
/* check extension, case insensitive */
streamFile->get_name(streamFile,filename,sizeof(filename));
if (strcasecmp("vgs",filename_extension(filename))) goto fail;
if (!check_extensions(streamFile,"vgs"))
goto fail;
/* check header */
if (read_32bitBE(0x00,streamFile) != 0x56675321) /* "VgS!" */
goto fail;
/* 0x04: version? */
loop_flag = 0;
channel_flag_offset = get_streamfile_size(streamFile)-0x10;
channel_flag = read_32bitBE(channel_flag_offset,streamFile);
/* Only seen files up to 5 channels, but just
to be sure we will look up to 8 chanels */
switch (channel_flag) {
case 0x00800000:
channel_count = 1;
break;
case 0x00810000:
channel_count = 2;
break;
case 0x00820000:
channel_count = 3;
break;
case 0x00830000:
channel_count = 4;
break;
case 0x00840000:
channel_count = 5;
break;
case 0x00850000:
channel_count = 6;
break;
case 0x00860000:
channel_count = 7;
break;
case 0x00870000:
channel_count = 8;
break;
default:
goto fail;
}
/* contains N streams, which can have one less frame, or half frame and sample rate */
for (i = 0; i < 8; i++) {
stream_sample_rate = read_32bitLE(0x08 + 0x08*i + 0x00,streamFile);
stream_frame_count = read_32bitLE(0x08 + 0x08*i + 0x04,streamFile);
stream_data_size = stream_frame_count*0x10;
if (stream_sample_rate == 0)
break;
if (!sample_rate || !channel_size) {
sample_rate = stream_sample_rate;
channel_size = stream_data_size;
}
/* some streams end 1 frame early */
if (channel_size - 0x10 == stream_data_size) {
channel_size -= 0x10;
}
/* Guitar Hero II sometimes uses half sample rate for last stream */
if (sample_rate != stream_sample_rate) {
VGM_LOG("VGS: ignoring stream %i\n", i);
//total_streams++; // todo handle substreams
break;
}
channel_count++;
}
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
if (!vgmstream) goto fail;
/* fill in the vital statistics */
start_offset = 0x80;
vgmstream->channels = channel_count;
vgmstream->sample_rate = read_32bitLE(0x08,streamFile);
vgmstream->coding_type = coding_PSX_badflags;
vgmstream->num_samples = (read_32bitLE(0x0C,streamFile)*channel_count*0x10)*28/16/channel_count;
if (loop_flag) {
vgmstream->loop_start_sample = 0;
vgmstream->loop_end_sample = (read_32bitLE(0x0C,streamFile)*channel_count*0x10)*28/16/channel_count;
}
vgmstream->sample_rate = sample_rate;
vgmstream->num_samples = ps_bytes_to_samples(channel_size*channel_count, channel_count);
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = 0x10;
vgmstream->coding_type = coding_PSX_badflags; /* flag = stream/channel number */
vgmstream->layout_type = layout_blocked_vgs;
vgmstream->meta_type = meta_VGS;
/* 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;
vgmstream->ch[i].channel_start_offset=
vgmstream->ch[i].offset=start_offset+
vgmstream->interleave_block_size*i;
}
}
/* open files; channel offsets are updated below */
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
goto fail;
block_update_vgs(start_offset, vgmstream);
return vgmstream;
/* clean up anything we may have opened */
fail:
if (vgmstream) close_vgmstream(vgmstream);
close_vgmstream(vgmstream);
return NULL;
}

View File

@ -936,6 +936,7 @@ void render_vgmstream(sample * buffer, int32_t sample_count, VGMSTREAM * vgmstre
case layout_hwas_blocked:
case layout_ea_sns_blocked:
case layout_blocked_awc:
case layout_blocked_vgs:
render_vgmstream_blocked(buffer,sample_count,vgmstream);
break;
case layout_interleave_byte:

View File

@ -238,6 +238,7 @@ typedef enum {
layout_hwas_blocked,
layout_ea_sns_blocked, /* newest Electronic Arts blocks, found in SNS/SNU/SPS/etc formats */
layout_blocked_awc, /* Rockstar AWC */
layout_blocked_vgs, /* Guitar Hero II */
/* otherwise odd */
layout_acm, /* libacm layout */