Fix PS2 VGS/ASS/VPK/etc samples, glitches and cleanup

This commit is contained in:
bnnm 2018-08-22 19:19:31 +02:00
parent 27038c9ec8
commit 75fb12eed4
6 changed files with 127 additions and 327 deletions

View File

@ -707,11 +707,9 @@ static const meta_info meta_info_list[] = {
{meta_IDSP_TT, "Traveller's Tales IDSP header"},
{meta_RSTM_SPM, "Nintendo RSTM header (brstmspm)"},
{meta_RAW, "assumed RAW PCM file by .raw extension"},
{meta_PS2_VAGi, "Sony VAG Interleaved header (VAGi)"},
{meta_PS2_VAGp, "Sony VAG Mono header (VAGp)"},
{meta_PS2_VAGs, "Sony VAG Stereo header (VAGp)"},
{meta_PS2_VAGm, "Sony VAG Mono header (VAGm)"},
{meta_PS2_pGAV, "Sony VAG Stereo Little Endian header (pGAV)"},
{meta_PS2_VAGi, "Sony VAGi header"},
{meta_PS2_VAGp, "Sony VAGp header"},
{meta_PS2_pGAV, "Sony pGAV header"},
{meta_PSX_GMS, "assumed Grandia GMS file by .gms extension"},
{meta_STR_WAV, "Blitz Games STR+WAV header"},
{meta_PS2_ILD, "ILD header"},
@ -823,7 +821,7 @@ static const meta_info meta_info_list[] = {
{meta_NAOMI_SPSD, "Naomi SPSD header"},
{meta_FFXI_BGW, "BGW BGMStream header"},
{meta_FFXI_SPW, "SPW SeWave header"},
{meta_PS2_ASS, "ASS Header"},
{meta_PS2_ASS, "SystemSoft .ASS header"},
{meta_NUB_IDSP, "Namco NUB IDSP header"},
{meta_IDSP_NL, "Next Level IDSP header"},
{meta_IDSP_IE, "Inevitable Entertainment IDSP Header"},
@ -955,8 +953,8 @@ static const meta_info meta_info_list[] = {
{meta_EB_SF0, "assumed Excitebots .sf0 by extension"},
{meta_PS3_KLBS, "klBS Header"},
{meta_PS2_MTAF, "Konami MTAF header"},
{meta_PS2_VAG1, "Konami VAG Mono header (VAG1)"},
{meta_PS2_VAG2, "Konami VAG Stereo header (VAG2)"},
{meta_PS2_VAG1, "Konami VAG1 header"},
{meta_PS2_VAG2, "Konami VAG2 header"},
{meta_TUN, "Lego Racers ALP header"},
{meta_WPD, "WPD 'DPW' header"},
{meta_MN_STR, "Mini Ninjas 'STR' header"},

View File

@ -1,92 +1,51 @@
#include "meta.h"
#include "../util.h"
#include "../coding/coding.h"
/* SVS (from Dai Senryaku VII - Exceed) */
/* .ASS - from Dai Senryaku VII: Exceed (PS2) */
VGMSTREAM * init_vgmstream_ps2_ass(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
char filename[PATH_LIMIT];
off_t start_offset;
uint8_t testBuffer[0x10];
off_t loopStart = 0;
off_t loopEnd = 0;
off_t readOffset = 0;
size_t fileLength;
int loop_flag;
int channel_count;
size_t channel_size, interleave;
int loop_flag, channel_count, sample_rate;
int32_t num_samples, loop_start = 0, loop_end = 0;
/* check extension, case insensitive */
streamFile->get_name(streamFile,filename,sizeof(filename));
if (strcasecmp("ass",filename_extension(filename))) goto fail;
/* check header */
if (read_32bitBE(0x00,streamFile) != 0x02000000) /* "0x02000000" */
/* checks */
if (!check_extensions(streamFile, "ass"))
goto fail;
loop_flag = 1;
channel_count = 2;
start_offset = 0x800;
channel_count = read_32bitLE(0x00,streamFile); /* assumed */
if (channel_count != 2) goto fail;
sample_rate = read_32bitLE(0x04,streamFile);
channel_size = read_32bitLE(0x08,streamFile);
interleave = read_32bitLE(0x0c,streamFile);
num_samples = ps_bytes_to_samples(channel_size,1);
loop_flag = ps_find_loop_offsets(streamFile, start_offset, channel_size*channel_count, channel_count, interleave, &loop_start, &loop_end);
loop_flag = loop_flag && (num_samples > 10*sample_rate); /* disable looping for smaller files (in seconds) */
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
if (!vgmstream) goto fail;
/* fill in the vital statistics */
start_offset = 0x800;
vgmstream->channels = channel_count;
vgmstream->sample_rate = read_32bitLE(0x04,streamFile);
vgmstream->coding_type = coding_PSX;
vgmstream->num_samples = (read_32bitLE(0x08,streamFile)*2)*28/16/channel_count;
fileLength = get_streamfile_size(streamFile);
do {
readOffset+=(off_t)read_streamfile(testBuffer,readOffset,0x10,streamFile);
/* Loop Start */
if(testBuffer[0x01]==0x06) {
if(loopStart == 0) loopStart = readOffset-0x10;
/* break; */
}
/* Loop End */
if(testBuffer[0x01]==0x03) {
if(loopEnd == 0) loopEnd = readOffset-0x10;
/* break; */
}
} while (streamFile->get_offset(streamFile)<(int32_t)fileLength);
if(loopStart == 0) {
loop_flag = 0;
vgmstream->num_samples = read_32bitLE(0x4,streamFile)*28/16/channel_count;
} else {
loop_flag = 1;
vgmstream->loop_start_sample = (loopStart-start_offset)*28/16/channel_count;
vgmstream->loop_end_sample = (loopEnd-start_offset)*28/16/channel_count;
}
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = read_32bitLE(0x0C,streamFile);
vgmstream->meta_type = meta_PS2_ASS;
vgmstream->sample_rate = sample_rate;
vgmstream->num_samples = num_samples;
vgmstream->loop_start_sample = loop_start;
vgmstream->loop_end_sample = loop_end;
/* 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;
}
}
vgmstream->coding_type = coding_PSX;
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = interleave;
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

@ -5,7 +5,8 @@
VGMSTREAM * init_vgmstream_ps2_joe(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
off_t start_offset;
int channel_count, loop_flag, sample_rate, num_samples;
int channel_count, loop_flag, sample_rate;
int32_t num_samples, loop_start = 0, loop_end = 0;
size_t file_size, data_size, unknown1, unknown2, interleave;
@ -20,37 +21,41 @@ VGMSTREAM * init_vgmstream_ps2_joe(STREAMFILE *streamFile) {
/* detect version */
if (data_size/2 == file_size - 0x10
&& unknown1 == 0x0045039A && unknown2 == 0x00108920) { /* Super Farm */
&& unknown1 == 0x0045039A && unknown2 == 0x00108920) { /* Super Farm (PS2) */
data_size = data_size / 2;
interleave = 0x4000;
start_offset = 0x10;
}
else if (data_size/2 == file_size - 0x10
&& unknown1 == 0xCCCCCCCC && unknown2 == 0xCCCCCCCC) { /* Sitting Ducks */
&& unknown1 == 0xCCCCCCCC && unknown2 == 0xCCCCCCCC) { /* Sitting Ducks (PS2) */
data_size = data_size / 2;
interleave = 0x8000;
start_offset = 0x10;
}
else if (data_size == file_size - 0x10
&& unknown1 == 0xCCCCCCCC && unknown2 == 0xCCCCCCCC) { /* The Mummy: The Animated Series */
&& unknown1 == 0xCCCCCCCC && unknown2 == 0xCCCCCCCC) { /* The Mummy: The Animated Series (PS2) */
interleave = 0x8000;
start_offset = 0x10;
}
else if (data_size == file_size - 0x4020) { /* CT Special Forces (and all games beyond) */
else if (data_size == file_size - 0x4020) { /* CT Special Forces (PS2), and all games beyond */
interleave = unknown1; /* always 0? */
if (!interleave)
interleave = 0x10;
/* header padding contains garbage */
start_offset = 0x4020; /* header padding contains garbage */
}
else {
goto fail;
}
start_offset = file_size - data_size;
//start_offset = file_size - data_size; /* also ok */
channel_count = 2;
sample_rate = read_32bitLE(0x00,streamFile);
num_samples = ps_bytes_to_samples(data_size, channel_count);
loop_flag = ps_find_loop_offsets(streamFile, start_offset, data_size, channel_count, interleave,&loop_start, &loop_end);
/* most songs simply repeat except a few jingles (PS-ADPCM flags are always set) */
loop_flag = (num_samples > 20*sample_rate); /* in seconds */
loop_flag = loop_flag && (num_samples > 20*sample_rate); /* in seconds */
/* build the VGMSTREAM */
@ -59,52 +64,8 @@ VGMSTREAM * init_vgmstream_ps2_joe(STREAMFILE *streamFile) {
vgmstream->sample_rate = sample_rate;
vgmstream->num_samples = num_samples;
//todo improve, not working 100% with early .joe
{
uint8_t testBuffer[0x10];
off_t blockOffset = 0;
off_t sampleOffset = 0;
off_t readOffset = 0;
off_t loopStart = 0, loopEnd = 0;
readOffset = start_offset;
do {
off_t blockRead = (off_t)read_streamfile(testBuffer,readOffset,0x10,streamFile);
readOffset += blockRead;
blockOffset += blockRead;
if (blockOffset >= interleave) {
readOffset += interleave;
blockOffset -= interleave;
}
/* Loop Start */
if(testBuffer[0x01]==0x06) {
if(loopStart == 0)
loopStart = sampleOffset;
/* break; */
}
sampleOffset += 28;
/* Loop End */
if(testBuffer[0x01]==0x03) {
if(loopEnd == 0)
loopEnd = sampleOffset;
/* break; */
}
} while (streamFile->get_offset(streamFile)<(int32_t)file_size);
if (loopStart == 0 && loopEnd == 0) {
vgmstream->loop_flag = 0;
} else {
vgmstream->loop_start_sample = loopStart;
vgmstream->loop_end_sample = loopEnd;
}
}
vgmstream->loop_start_sample = loop_start;
vgmstream->loop_end_sample = loop_end;
vgmstream->coding_type = coding_PSX;
vgmstream->layout_type = layout_interleave;

View File

@ -1,111 +1,66 @@
#include "meta.h"
#include "../util.h"
#include "../coding/coding.h"
//#include <windows.h>
//#include <tchar.h>
/* VBK (from Disney's Stitch - Experiment 626) */
VGMSTREAM * init_vgmstream_ps2_vbk(STREAMFILE *streamFile)
{
/* VBK - from Disney's Stitch - Experiment 626 (PS2) */
VGMSTREAM * init_vgmstream_ps2_vbk(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
char filename[PATH_LIMIT];
off_t start_offset;
uint8_t testBuffer[0x10];
off_t loopStart = 0;
off_t loopEnd = 0;
off_t readOffset = 0;
size_t fileLength;
int loop_flag;
int channel_count;
off_t start_offset, header_offset, stream_offset;
size_t stream_size, interleave;
int loop_flag, channel_count, sample_rate;
int32_t num_samples, loop_start = 0, loop_end = 0;
int total_subsongs, target_subsong = streamFile->stream_index;
//_TCHAR szBuffer[100];
/* check extension, case insensitive */
streamFile->get_name(streamFile,filename,sizeof(filename));
if (strcasecmp("vbk",filename_extension(filename))) goto fail;
/* check header */
if (read_32bitBE(0x00,streamFile) != 0x2E56424B) /* .VBK */
/* checks */
if (!check_extensions(streamFile, "vbk"))
goto fail;
if (read_32bitBE(0x00,streamFile) != 0x2E56424B) /* ".VBK" */
goto fail;
/* 0x04: version? always 0x02? */
start_offset = read_32bitLE(0x0C, streamFile);
/* 0x10: file size */
loop_flag = 1;
channel_count = read_32bitLE(0x28,streamFile) + 1;
total_subsongs = read_32bitLE(0x08,streamFile);
if (target_subsong == 0) target_subsong = 1;
if (target_subsong < 0 || target_subsong > total_subsongs || total_subsongs < 1) goto fail;
header_offset = 0x14 + (target_subsong-1)*0x18;
stream_size = read_32bitLE(header_offset+0x00,streamFile);
/* 0x04: id? */
stream_offset = read_32bitLE(header_offset+0x08,streamFile);
sample_rate = read_32bitLE(header_offset+0x0c,streamFile);
interleave = read_32bitLE(header_offset+0x10,streamFile);
channel_count = read_32bitLE(header_offset+0x14,streamFile) + 1; /* 4ch is common, 1ch sfx too */
start_offset += stream_offset;
num_samples = ps_bytes_to_samples(stream_size,channel_count);
loop_flag = ps_find_loop_offsets(streamFile, start_offset, stream_size, channel_count, interleave, &loop_start, &loop_end);
loop_flag = loop_flag && (num_samples > 10*sample_rate); /* disable looping for smaller files (in seconds) */
//_stprintf(szBuffer, _T("%x"), channel_count);
//MessageBox(NULL, szBuffer, _T("Foo"), MB_OK);
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
if (!vgmstream) goto fail;
/* fill in the vital statistics */
fileLength = get_streamfile_size(streamFile);
start_offset = read_32bitLE(0x0C, streamFile);
vgmstream->channels = channel_count;
vgmstream->sample_rate = read_32bitLE(0x20,streamFile);
vgmstream->coding_type = coding_PSX;
vgmstream->num_samples = (fileLength - start_offset)*28/16/channel_count;
// get loop start
do {
readOffset+=(off_t)read_streamfile(testBuffer,readOffset,0x10,streamFile);
if(testBuffer[0x01]==0x06)
{
loopStart = readOffset-0x10;
break;
}
} while (streamFile->get_offset(streamFile)<(int32_t)fileLength);
// get loop end
readOffset = fileLength - 0x10;
do {
readOffset-=(off_t)read_streamfile(testBuffer,readOffset,0x10,streamFile);
/* Loop End */
if(testBuffer[0x01]==0x03)
{
loopEnd = readOffset-0x10;
break;
}
} while (readOffset > 0);
loop_flag = 1;
vgmstream->loop_start_sample = (loopStart-start_offset)*28/16/channel_count;
vgmstream->loop_end_sample = (loopEnd-start_offset)*28/16/channel_count;
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = read_32bitLE(0x24,streamFile);
vgmstream->meta_type = meta_PS2_VBK;
vgmstream->sample_rate = sample_rate;
vgmstream->num_samples = num_samples;
vgmstream->loop_start_sample = loop_start;
vgmstream->loop_end_sample = loop_end;
vgmstream->num_streams = total_subsongs;
vgmstream->stream_size = stream_size;
/* 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;
}
}
vgmstream->coding_type = coding_PSX;
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = interleave;
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

@ -1,122 +1,51 @@
#include "meta.h"
#include "../util.h"
#include "../coding/coding.h"
/* VGS (Phantom of Inferno)
This format is used in _many_ Princess Soft games.
*/
/* VGS - from Princess Soft games [Gin no Eclipse (PS2), Metal Wolf REV (PS2)] */
VGMSTREAM * init_vgmstream_ps2_vgs(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
char filename[PATH_LIMIT];
size_t fileLength;
off_t readOffset = 0;
off_t start_offset;
off_t loop_start_offset = 0;
off_t loop_end_offset = 0;
size_t data_size, channel_size, interleave;
int loop_flag, channel_count;
int32_t loop_start = 0, loop_end = 0;
uint8_t testBuffer[0x10];
int loop_flag = 0;
int channel_count;
/* check extension, case insensitive */
streamFile->get_name(streamFile,filename,sizeof(filename));
if (strcasecmp("vgs",filename_extension(filename))) goto fail;
/* check header */
if (read_32bitBE(0x00,streamFile) != 0x56475300)
/* check */
if ( !check_extensions(streamFile,"vgs") )
goto fail;
if (read_32bitBE(0x00,streamFile) != 0x56475300) /* "VGS\0" ('VAG stereo', presumably) */
goto fail;
// get file length
fileLength = get_streamfile_size(streamFile);
// Find loop start
do {
readOffset += (off_t)read_streamfile(testBuffer, readOffset, 0x10, streamFile);
// Loop Start ...
if(testBuffer[0x01] == 0x06)
{
loop_start_offset = readOffset - 0x10;
break;
}
} while (streamFile->get_offset(streamFile)<((int32_t)fileLength));
// start at last line of file and move up
readOffset = (int32_t)fileLength - 0x10;
// Find loop end
do {
readOffset -= (off_t)read_streamfile(testBuffer, readOffset, 0x10, streamFile);
// Loop End ...
if((testBuffer[0x01]==0x03) && (testBuffer[0x03]!=0x77))
{
loop_end_offset = readOffset + 0x20;
break;
}
} while (readOffset > 0);
// setup loops
if (loop_start_offset > 0)
{
loop_flag = 1;
// if we have a start loop, use EOF if end loop is not found
if (loop_end_offset == 0)
{
loop_end_offset = (int32_t)fileLength - 0x10;
}
}
else
{
loop_flag = 0;
}
start_offset = 0x30;
data_size = get_streamfile_size(streamFile) - start_offset;
interleave = 0x20000;
channel_count = 2;
channel_size = read_32bitBE(0x0c,streamFile);
loop_flag = 0; /* all files have loop flags but simply fade out normally and repeat */
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
if (!vgmstream) goto fail;
/* fill in the vital statistics */
start_offset = 0x30;
vgmstream->channels = channel_count;
vgmstream->sample_rate = read_32bitBE(0x10,streamFile);
vgmstream->coding_type = coding_PSX;
vgmstream->num_samples = ((get_streamfile_size(streamFile)-0x30)/16/channel_count*28);
if (loop_flag)
{
vgmstream->loop_start_sample = loop_start_offset/16/channel_count*28;
vgmstream->loop_end_sample = loop_end_offset/16/channel_count*28;
}
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = read_32bitBE(0x04,streamFile)*0x1000;
vgmstream->meta_type = meta_PS2_VGS;
vgmstream->sample_rate = read_32bitBE(0x10,streamFile);
vgmstream->num_samples = ps_bytes_to_samples(channel_size,1);
vgmstream->loop_start_sample = loop_start;
vgmstream->loop_end_sample = loop_end;
/* 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;
}
}
vgmstream->coding_type = coding_PSX;
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = interleave;
if (vgmstream->interleave_block_size)
vgmstream->interleave_last_block_size = (data_size % (vgmstream->interleave_block_size*vgmstream->channels)) / vgmstream->channels;
read_string(vgmstream->stream_name,0x10+1, 0x20,streamFile); /* always, can be null */
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

@ -336,13 +336,11 @@ typedef enum {
meta_PS2_MIC, /* KOEI MIC File */
meta_PS2_VAGi, /* VAGi Interleaved File */
meta_PS2_VAGp, /* VAGp Mono File */
meta_PS2_VAGm, /* VAGp Mono File */
meta_PS2_pGAV, /* VAGp with Little Endian Header */
meta_PSX_GMS, /* GMS File (used in PS1 & PS2) [no header_id] */
meta_STR_WAV, /* Blitz Games STR+WAV files */
meta_PS2_ILD, /* ILD File */
meta_PS2_PNB, /* PsychoNauts Bgm File */
meta_PS2_VAGs, /* VAG Stereo from Kingdom Hearts */
meta_VPK, /* VPK Audio File */
meta_PS2_BMDX, /* Beatmania thing */
meta_PS2_IVB, /* Langrisser 3 IVB */