Tweak .svs sample rate

This commit is contained in:
bnnm 2018-11-01 16:39:53 +01:00
parent 1380faf5bb
commit ec63b8ff38
3 changed files with 31 additions and 46 deletions

View File

@ -758,7 +758,7 @@ static const meta_info meta_info_list[] = {
{meta_WS_AUD, "Westwood Studios .aud header"},
{meta_WS_AUD_old, "Westwood Studios .aud (old) header"},
{meta_PS2_IVB, "IVB/BVII header"},
{meta_PS2_SVS, "Square SVS header"},
{meta_SVS, "Square SVS header"},
{meta_RIFF_WAVE, "RIFF WAVE header"},
{meta_RIFF_WAVE_POS, "RIFF WAVE header and .pos for looping"},
{meta_NWA, "VisualArt's NWA header"},

View File

@ -1,69 +1,54 @@
#include "meta.h"
#include "../util.h"
#include "../coding/coding.h"
/* SVS (from Unlimited Saga) */
/* probably Square Vag Stream */
/* SVS - SeqVagStream from Square games [Unlimited Saga (PS2) music] */
VGMSTREAM * init_vgmstream_svs(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
char filename[PATH_LIMIT];
off_t start_offset;
int channel_count, loop_flag, pitch;
int loop_flag = 0;
int channel_count;
/* check extension, case insensitive */
streamFile->get_name(streamFile,filename,sizeof(filename));
if (strcasecmp("svs",filename_extension(filename))) goto fail;
/* check header */
/* checks */
/* .svs: header id (probably ok like The Bouncer's .vs) */
if (!check_extensions(streamFile, "svs"))
goto fail;
if (read_32bitBE(0x00,streamFile) != 0x53565300) /* "SVS\0" */
goto fail;
loop_flag = (read_32bitLE(0x08,streamFile)!=0);
/* 63.SVS has start and end on the same sample, which crashes stuff */
if (read_32bitLE(0x08,streamFile)==read_32bitLE(0x0c,streamFile))
loop_flag = 0;
/* 0x04: flags (1=stereo?, 2=loop) */
pitch = read_32bitLE(0x10,streamFile); /* usually 0x1000 = 48000 */
/* 0x14: volume? */
/* 0x18: file id (may be null) */
/* 0x1c: null */
loop_flag = (read_32bitLE(0x08,streamFile) > 0); /* loop start frame, min is 1 */
channel_count = 2;
/* build the VGMSTREAM */
start_offset = 0x20;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
if (!vgmstream) goto fail;
/* fill in the vital statistics */
start_offset = 0x40;
vgmstream->channels = channel_count;
vgmstream->sample_rate = 44100;
vgmstream->coding_type = coding_PSX;
vgmstream->num_samples = (get_streamfile_size(streamFile)-0x40)*28/16/channel_count;
vgmstream->meta_type = meta_SVS;
vgmstream->sample_rate = (48000 * pitch) / 4096; /* music = ~44100, ambience = 48000 */
vgmstream->num_samples = ps_bytes_to_samples(get_streamfile_size(streamFile) - start_offset, channel_count);
if (loop_flag) {
vgmstream->loop_start_sample = (read_32bitLE(0x08,streamFile)-1)*28;
vgmstream->loop_end_sample = (read_32bitLE(0x0c,streamFile)-1)*28;
vgmstream->loop_start_sample = read_32bitLE(0x08,streamFile) * 28; /* frame count (0x10*ch) */
vgmstream->loop_end_sample = read_32bitLE(0x0c,streamFile) * 28; /* frame count, (not exact num_samples when no loop) */
/* start/end on the same frame rarely happens too (ex. file_id 63 SVS), perhaps loop should be +1 */
}
vgmstream->coding_type = coding_PSX;
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = 0x10;
vgmstream->meta_type = meta_PS2_SVS;
/* 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;
}
}
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
goto fail;
return vgmstream;
/* clean up anything we may have opened */
fail:
if (vgmstream) close_vgmstream(vgmstream);
close_vgmstream(vgmstream);
return NULL;
}

View File

@ -342,7 +342,7 @@ typedef enum {
meta_PS2_BMDX, /* Beatmania thing */
meta_PS2_IVB, /* Langrisser 3 IVB */
meta_PS2_SND, /* some Might & Magics SSND header */
meta_PS2_SVS, /* Square SVS */
meta_SVS, /* Square SVS */
meta_XSS, /* Dino Crisis 3 */
meta_SL3, /* Test Drive Unlimited */
meta_HGC1, /* Knights of the Temple 2 */