mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-02-17 11:18:31 +01:00
Clean RIFF parser for future changes
- move blocks around so it's easier to init codecs - removed .SGB with FFMpeg is disabled, should't be needed - remove references to MSIMA/MSADPCM/etc in RIFX, num_samples was only filled for PCM so any other codec would fail (most other RIFX should be wwise)
This commit is contained in:
parent
ae71256c68
commit
002de7efe0
684
src/meta/riff.c
684
src/meta/riff.c
@ -4,10 +4,10 @@
|
|||||||
#include "../util.h"
|
#include "../util.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* Resource Interchange File Format */
|
/* RIFF - Resource Interchange File Format, standard container used in many games */
|
||||||
|
|
||||||
/* return milliseconds */
|
/* return milliseconds */
|
||||||
static long parse_marker(unsigned char * marker) {
|
static long parse_adtl_marker(unsigned char * marker) {
|
||||||
long hh,mm,ss,ms;
|
long hh,mm,ss,ms;
|
||||||
if (memcmp("Marker ",marker,7)) return -1;
|
if (memcmp("Marker ",marker,7)) return -1;
|
||||||
|
|
||||||
@ -21,7 +21,6 @@ static long parse_marker(unsigned char * marker) {
|
|||||||
static void parse_adtl(off_t adtl_offset, off_t adtl_length, STREAMFILE *streamFile, long *loop_start, long *loop_end, int *loop_flag) {
|
static void parse_adtl(off_t adtl_offset, off_t adtl_length, STREAMFILE *streamFile, long *loop_start, long *loop_end, int *loop_flag) {
|
||||||
int loop_start_found = 0;
|
int loop_start_found = 0;
|
||||||
int loop_end_found = 0;
|
int loop_end_found = 0;
|
||||||
|
|
||||||
off_t current_chunk = adtl_offset+4;
|
off_t current_chunk = adtl_offset+4;
|
||||||
|
|
||||||
while (current_chunk < adtl_offset+adtl_length) {
|
while (current_chunk < adtl_offset+adtl_length) {
|
||||||
@ -31,39 +30,31 @@ static void parse_adtl(off_t adtl_offset, off_t adtl_length, STREAMFILE *stream
|
|||||||
if (current_chunk+8+chunk_size > adtl_offset+adtl_length) return;
|
if (current_chunk+8+chunk_size > adtl_offset+adtl_length) return;
|
||||||
|
|
||||||
switch(chunk_type) {
|
switch(chunk_type) {
|
||||||
case 0x6c61626c: /* labl */
|
case 0x6c61626c: { /* labl */
|
||||||
{
|
unsigned char *labelcontent;
|
||||||
unsigned char *labelcontent;
|
labelcontent = malloc(chunk_size-4);
|
||||||
labelcontent = malloc(chunk_size-4);
|
if (!labelcontent) return;
|
||||||
if (!labelcontent) return;
|
if (read_streamfile(labelcontent,current_chunk+0xc, chunk_size-4,streamFile)!=chunk_size-4) {
|
||||||
if (read_streamfile(labelcontent,current_chunk+0xc,
|
|
||||||
chunk_size-4,streamFile)!=chunk_size-4) {
|
|
||||||
free(labelcontent);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (read_32bitLE(current_chunk+8,streamFile)) {
|
|
||||||
case 1:
|
|
||||||
if (!loop_start_found &&
|
|
||||||
(*loop_start = parse_marker(labelcontent))>=0)
|
|
||||||
{
|
|
||||||
loop_start_found = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
if (!loop_end_found &&
|
|
||||||
(*loop_end = parse_marker(labelcontent))>=0)
|
|
||||||
{
|
|
||||||
loop_end_found = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(labelcontent);
|
free(labelcontent);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (read_32bitLE(current_chunk+8,streamFile)) {
|
||||||
|
case 1:
|
||||||
|
if (!loop_start_found && (*loop_start = parse_adtl_marker(labelcontent))>=0)
|
||||||
|
loop_start_found = 1;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
if (!loop_end_found && (*loop_end = parse_adtl_marker(labelcontent))>=0)
|
||||||
|
loop_end_found = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(labelcontent);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -71,7 +62,8 @@ static void parse_adtl(off_t adtl_offset, off_t adtl_length, STREAMFILE *stream
|
|||||||
current_chunk += 8 + chunk_size;
|
current_chunk += 8 + chunk_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loop_start_found && loop_end_found) *loop_flag = 1;
|
if (loop_start_found && loop_end_found)
|
||||||
|
*loop_flag = 1;
|
||||||
|
|
||||||
/* labels don't seem to be consistently ordered */
|
/* labels don't seem to be consistently ordered */
|
||||||
if (*loop_start > *loop_end) {
|
if (*loop_start > *loop_end) {
|
||||||
@ -81,29 +73,21 @@ static void parse_adtl(off_t adtl_offset, off_t adtl_length, STREAMFILE *stream
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct riff_fmt_chunk {
|
typedef struct {
|
||||||
off_t offset;
|
off_t offset;
|
||||||
off_t size;
|
off_t size;
|
||||||
int sample_rate;
|
int sample_rate;
|
||||||
int channel_count;
|
int channel_count;
|
||||||
uint32_t block_size;
|
uint32_t block_size;
|
||||||
|
|
||||||
int coding_type;
|
int coding_type;
|
||||||
int interleave;
|
int interleave;
|
||||||
};
|
} riff_fmt_chunk;
|
||||||
|
|
||||||
static int read_fmt(int big_endian, STREAMFILE * streamFile, off_t current_chunk, struct riff_fmt_chunk * fmt, int sns, int mwv) {
|
|
||||||
|
|
||||||
|
static int read_fmt(int big_endian, STREAMFILE * streamFile, off_t current_chunk, riff_fmt_chunk * fmt, int sns, int mwv) {
|
||||||
int codec, bps;
|
int codec, bps;
|
||||||
int32_t (*read_32bit)(off_t,STREAMFILE*) = NULL;
|
int32_t (*read_32bit)(off_t,STREAMFILE*) = big_endian ? read_32bitBE : read_32bitLE;
|
||||||
int16_t (*read_16bit)(off_t,STREAMFILE*) = NULL;
|
int16_t (*read_16bit)(off_t,STREAMFILE*) = big_endian ? read_16bitBE : read_16bitLE;
|
||||||
|
|
||||||
if (big_endian) {
|
|
||||||
read_32bit = read_32bitBE;
|
|
||||||
read_16bit = read_16bitBE;
|
|
||||||
} else {
|
|
||||||
read_32bit = read_32bitLE;
|
|
||||||
read_16bit = read_16bitLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt->offset = current_chunk;
|
fmt->offset = current_chunk;
|
||||||
fmt->size = read_32bit(current_chunk+0x4,streamFile);
|
fmt->size = read_32bit(current_chunk+0x4,streamFile);
|
||||||
@ -111,6 +95,7 @@ static int read_fmt(int big_endian, STREAMFILE * streamFile, off_t current_chunk
|
|||||||
fmt->sample_rate = read_32bit(current_chunk+0x0c,streamFile);
|
fmt->sample_rate = read_32bit(current_chunk+0x0c,streamFile);
|
||||||
fmt->channel_count = read_16bit(current_chunk+0x0a,streamFile);
|
fmt->channel_count = read_16bit(current_chunk+0x0a,streamFile);
|
||||||
fmt->block_size = read_16bit(current_chunk+0x14,streamFile);
|
fmt->block_size = read_16bit(current_chunk+0x14,streamFile);
|
||||||
|
fmt->interleave = 0;
|
||||||
|
|
||||||
bps = read_16bit(current_chunk+0x16,streamFile);
|
bps = read_16bit(current_chunk+0x16,streamFile);
|
||||||
codec = (uint16_t)read_16bit(current_chunk+0x8,streamFile);
|
codec = (uint16_t)read_16bit(current_chunk+0x8,streamFile);
|
||||||
@ -119,11 +104,7 @@ static int read_fmt(int big_endian, STREAMFILE * streamFile, off_t current_chunk
|
|||||||
case 0x01: /* PCM */
|
case 0x01: /* PCM */
|
||||||
switch (bps) {
|
switch (bps) {
|
||||||
case 16:
|
case 16:
|
||||||
if (big_endian) {
|
fmt->coding_type = big_endian ? coding_PCM16BE : coding_PCM16LE;
|
||||||
fmt->coding_type = coding_PCM16BE;
|
|
||||||
} else {
|
|
||||||
fmt->coding_type = coding_PCM16LE;
|
|
||||||
}
|
|
||||||
fmt->interleave = 2;
|
fmt->interleave = 2;
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
@ -136,24 +117,18 @@ static int read_fmt(int big_endian, STREAMFILE * streamFile, off_t current_chunk
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x02: /* MS ADPCM */
|
case 0x02: /* MS ADPCM */
|
||||||
if (bps != 4) /* ensure 4bps */
|
if (bps != 4) goto fail;
|
||||||
goto fail;
|
|
||||||
fmt->coding_type = coding_MSADPCM;
|
fmt->coding_type = coding_MSADPCM;
|
||||||
fmt->interleave = 0;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x11: /* MS IMA ADPCM */
|
case 0x11: /* MS IMA ADPCM */
|
||||||
if (bps != 4) /* ensure 4bps */
|
if (bps != 4) goto fail;
|
||||||
goto fail;
|
|
||||||
fmt->coding_type = coding_MS_IMA;
|
fmt->coding_type = coding_MS_IMA;
|
||||||
fmt->interleave = 0;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x69: /* MS IMA ADPCM - Rayman Raving Rabbids 2 (PC) */
|
case 0x69: /* MS IMA ADPCM (XBOX) - Rayman Raving Rabbids 2 (PC) */
|
||||||
if (bps != 4) /* ensure 4bps */
|
if (bps != 4) goto fail;
|
||||||
goto fail;
|
|
||||||
fmt->coding_type = coding_MS_IMA;
|
fmt->coding_type = coding_MS_IMA;
|
||||||
fmt->interleave = 0;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x007A: /* MS IMA ADPCM (LA Rush, Psi Ops PC) */
|
case 0x007A: /* MS IMA ADPCM (LA Rush, Psi Ops PC) */
|
||||||
@ -167,7 +142,6 @@ static int read_fmt(int big_endian, STREAMFILE * streamFile, off_t current_chunk
|
|||||||
goto fail; //fmt->coding_type = coding_MS_IMA_3BIT;
|
goto fail; //fmt->coding_type = coding_MS_IMA_3BIT;
|
||||||
else
|
else
|
||||||
goto fail;
|
goto fail;
|
||||||
fmt->interleave = 0;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x0555: /* Level-5 0x555 ADPCM */
|
case 0x0555: /* Level-5 0x555 ADPCM */
|
||||||
@ -179,34 +153,38 @@ static int read_fmt(int big_endian, STREAMFILE * streamFile, off_t current_chunk
|
|||||||
case 0x5050: /* Ubisoft .sns uses this for DSP */
|
case 0x5050: /* Ubisoft .sns uses this for DSP */
|
||||||
if (!sns) goto fail;
|
if (!sns) goto fail;
|
||||||
fmt->coding_type = coding_NGC_DSP;
|
fmt->coding_type = coding_NGC_DSP;
|
||||||
fmt->interleave = 8;
|
fmt->interleave = 0x08;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 0x270: /* ATRAC3 */
|
||||||
#ifdef VGM_USE_FFMPEG
|
#ifdef VGM_USE_FFMPEG
|
||||||
case 0x270: /* ATRAC3 */
|
fmt->coding_type = coding_FFmpeg;
|
||||||
#if defined(VGM_USE_FFMPEG) && !defined(VGM_USE_MAIATRAC3PLUS)
|
break;
|
||||||
case 0xFFFE: /* WAVEFORMATEXTENSIBLE / ATRAC3plus */
|
#else
|
||||||
#endif /* defined */
|
goto fail;
|
||||||
fmt->coding_type = coding_FFmpeg;
|
|
||||||
fmt->interleave = 0;
|
|
||||||
break;
|
|
||||||
#endif /* VGM_USE_FFMPEG */
|
|
||||||
|
|
||||||
#ifdef VGM_USE_MAIATRAC3PLUS
|
|
||||||
case 0xFFFE: /* WAVEFORMATEXTENSIBLE / ATRAC3plus */
|
|
||||||
if (read_32bit(current_chunk+0x20,streamFile) == 0xE923AABF &&
|
|
||||||
read_16bit(current_chunk+0x24,streamFile) == (int16_t)0xCB58 &&
|
|
||||||
read_16bit(current_chunk+0x26,streamFile) == 0x4471 &&
|
|
||||||
read_32bitLE(current_chunk+0x28,streamFile) == 0xFAFF19A1 &&
|
|
||||||
read_32bitLE(current_chunk+0x2C,streamFile) == 0x62CEE401) {
|
|
||||||
uint16_t bztmp = read_16bit(current_chunk+0x32,streamFile);
|
|
||||||
bztmp = (bztmp >> 8) | (bztmp << 8);
|
|
||||||
fmt->coding_type = coding_AT3plus;
|
|
||||||
fmt->block_size = (bztmp & 0x3FF) * 8 + 8;
|
|
||||||
fmt->interleave = 0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
case 0xFFFE: /* WAVEFORMATEXTENSIBLE */
|
||||||
|
|
||||||
|
/* ATRAC3plus GUID (0xBFAA23E9 58CB7144 A119FFFA 01E4CE62) */
|
||||||
|
if (read_32bit(current_chunk+0x20,streamFile) == 0xE923AABF &&
|
||||||
|
read_16bit(current_chunk+0x24,streamFile) == (int16_t)0xCB58 &&
|
||||||
|
read_16bit(current_chunk+0x26,streamFile) == 0x4471 &&
|
||||||
|
read_32bitLE(current_chunk+0x28,streamFile) == 0xFAFF19A1 &&
|
||||||
|
read_32bitLE(current_chunk+0x2C,streamFile) == 0x62CEE401) {
|
||||||
|
#ifdef VGM_USE_MAIATRAC3PLUS
|
||||||
|
uint16_t bztmp = read_16bit(current_chunk+0x32,streamFile);
|
||||||
|
bztmp = (bztmp >> 8) | (bztmp << 8);
|
||||||
|
fmt->coding_type = coding_AT3plus;
|
||||||
|
fmt->block_size = (bztmp & 0x3FF) * 8 + 8; //should match fmt->block_size
|
||||||
|
#elif defined(VGM_USE_FFMPEG)
|
||||||
|
fmt->coding_type = coding_FFmpeg;
|
||||||
|
#else
|
||||||
|
goto fail;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
@ -219,82 +197,60 @@ fail:
|
|||||||
|
|
||||||
VGMSTREAM * init_vgmstream_riff(STREAMFILE *streamFile) {
|
VGMSTREAM * init_vgmstream_riff(STREAMFILE *streamFile) {
|
||||||
VGMSTREAM * vgmstream = NULL;
|
VGMSTREAM * vgmstream = NULL;
|
||||||
char filename[PATH_LIMIT];
|
riff_fmt_chunk fmt = {0};
|
||||||
|
|
||||||
struct riff_fmt_chunk fmt;
|
size_t file_size, riff_size, data_size = 0;
|
||||||
|
off_t start_offset = 0;
|
||||||
|
|
||||||
#ifdef VGM_USE_FFMPEG
|
|
||||||
ffmpeg_codec_data *ffmpeg_data = NULL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
off_t file_size = -1;
|
|
||||||
int sample_count = 0;
|
|
||||||
int fact_sample_count = -1;
|
int fact_sample_count = -1;
|
||||||
int fact_sample_skip = -1;
|
int fact_sample_skip = -1;
|
||||||
off_t start_offset = -1;
|
|
||||||
|
|
||||||
int loop_flag = 0;
|
int loop_flag = 0;
|
||||||
long loop_start_ms = -1;
|
long loop_start_ms = -1;
|
||||||
long loop_end_ms = -1;
|
long loop_end_ms = -1;
|
||||||
off_t loop_start_offset = -1;
|
off_t loop_start_offset = -1;
|
||||||
off_t loop_end_offset = -1;
|
off_t loop_end_offset = -1;
|
||||||
uint32_t riff_size;
|
|
||||||
uint32_t data_size = 0;
|
|
||||||
|
|
||||||
int FormatChunkFound = 0, DataChunkFound = 0, JunkFound = 0;
|
int FormatChunkFound = 0, DataChunkFound = 0, JunkFound = 0;
|
||||||
|
|
||||||
/* Level-5 mwv */
|
int mwv = 0; /* Level-5 .mwv (Dragon Quest VIII, Rogue Galaxy) */
|
||||||
int mwv = 0;
|
|
||||||
off_t mwv_pflt_offset = -1;
|
off_t mwv_pflt_offset = -1;
|
||||||
off_t mwv_ctrl_offset = -1;
|
off_t mwv_ctrl_offset = -1;
|
||||||
|
int sns = 0; /* Ubisoft .sns LyN engine (Red Steel 2, Just Dance 3) */
|
||||||
|
int at3 = 0; /* Sony ATRAC3 / ATRAC3plus */
|
||||||
|
|
||||||
/* Ubisoft sns */
|
|
||||||
int sns = 0;
|
|
||||||
|
|
||||||
/* Sony atrac3 / 3plus */
|
/* check extension, case insensitive
|
||||||
int at3 = 0;
|
* .da: The Great Battle VI (PS), .cd: Exector (PS), .med: Psi Ops (PC) */
|
||||||
|
if ( check_extensions(streamFile, "wav,lwav,da,cd,med") ) {
|
||||||
/* check extension, case insensitive */
|
;
|
||||||
streamFile->get_name(streamFile,filename,sizeof(filename));
|
}
|
||||||
if (strcasecmp("wav",filename_extension(filename))
|
else if ( check_extensions(streamFile, "mwv") ) {
|
||||||
&& strcasecmp("lwav",filename_extension(filename))
|
mwv = 1;
|
||||||
&& strcasecmp("da",filename_extension(filename)) /* SD Gundam - Over Galaxian, The Great Battle VI (PS) */
|
}
|
||||||
&& strcasecmp("cd",filename_extension(filename)) /* Exector (PS) */
|
else if ( check_extensions(streamFile, "sns") ) {
|
||||||
#ifndef VGM_USE_FFMPEG
|
sns = 1;
|
||||||
&& strcasecmp("sgb",filename_extension(filename)) /* SGB has proper support with FFmpeg in sgxd */
|
}
|
||||||
#endif
|
|
||||||
&& strcasecmp("med",filename_extension(filename))
|
|
||||||
)
|
|
||||||
{
|
|
||||||
if (!strcasecmp("mwv",filename_extension(filename))) {
|
|
||||||
mwv = 1;
|
|
||||||
}
|
|
||||||
else if (!strcasecmp("sns",filename_extension(filename))) {
|
|
||||||
sns = 1;
|
|
||||||
}
|
|
||||||
#if defined(VGM_USE_MAIATRAC3PLUS) || defined(VGM_USE_FFMPEG)
|
#if defined(VGM_USE_MAIATRAC3PLUS) || defined(VGM_USE_FFMPEG)
|
||||||
/* .RWS: AT3 found in Climax games (Silent Hill Origins PSP, Oblivion PSP)
|
/* .rws: Climax games (Silent Hill Origins PSP, Oblivion PSP), .aud: EA Replay */
|
||||||
* .AUD: EA Replay */
|
else if ( check_extensions(streamFile, "at3,rws,aud") ) {
|
||||||
else if ( check_extensions(streamFile, "at3,rws,aud") ) {
|
at3 = 1;
|
||||||
at3 = 1;
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
else {
|
else {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check header */
|
/* check header */
|
||||||
if ((uint32_t)read_32bitBE(0,streamFile)!=0x52494646) /* "RIFF" */
|
if (read_32bitBE(0x00,streamFile) != 0x52494646) /* "RIFF" */
|
||||||
goto fail;
|
goto fail;
|
||||||
/* check for WAVE form */
|
if (read_32bitBE(0x08,streamFile) != 0x57415645) /* "WAVE" */
|
||||||
if ((uint32_t)read_32bitBE(8,streamFile)!=0x57415645) /* "WAVE" */
|
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
riff_size = read_32bitLE(4,streamFile);
|
riff_size = read_32bitLE(0x04,streamFile);
|
||||||
file_size = get_streamfile_size(streamFile);
|
file_size = get_streamfile_size(streamFile);
|
||||||
|
|
||||||
/* check for tructated RIFF */
|
/* check for truncated RIFF */
|
||||||
if (file_size < riff_size+8) goto fail;
|
if (file_size < riff_size+8) goto fail;
|
||||||
|
|
||||||
/* read through chunks to verify format and find metadata */
|
/* read through chunks to verify format and find metadata */
|
||||||
@ -344,42 +300,34 @@ VGMSTREAM * init_vgmstream_riff(STREAMFILE *streamFile) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0x736D706C: /* smpl */
|
case 0x736D706C: /* smpl */
|
||||||
/* check loop count */
|
/* check loop count and loop info */
|
||||||
if (read_32bitLE(current_chunk+0x24, streamFile)==1)
|
if (read_32bitLE(current_chunk+0x24, streamFile)==1) {
|
||||||
{
|
if (read_32bitLE(current_chunk+0x2c+4, streamFile)==0) {
|
||||||
/* check loop info */
|
|
||||||
if (read_32bitLE(current_chunk+0x2c+4, streamFile)==0)
|
|
||||||
{
|
|
||||||
loop_flag = 1;
|
loop_flag = 1;
|
||||||
loop_start_offset =
|
loop_start_offset = read_32bitLE(current_chunk+0x2c+8, streamFile);
|
||||||
read_32bitLE(current_chunk+0x2c+8, streamFile);
|
loop_end_offset = read_32bitLE(current_chunk+0x2c+0xc,streamFile);
|
||||||
loop_end_offset =
|
|
||||||
read_32bitLE(current_chunk+0x2c+0xc,streamFile);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0x70666c74: /* pflt */
|
case 0x70666c74: /* pflt */
|
||||||
if (!mwv) break; /* ignore if not in an mwv */
|
if (!mwv) break; /* ignore if not in an mwv */
|
||||||
/* predictor filters */
|
|
||||||
mwv_pflt_offset = current_chunk;
|
mwv_pflt_offset = current_chunk; /* predictor filters */
|
||||||
break;
|
break;
|
||||||
case 0x6374726c: /* ctrl */
|
case 0x6374726c: /* ctrl */
|
||||||
if (!mwv) break; /* ignore if not in an mwv */
|
if (!mwv) break;
|
||||||
/* loops! */
|
|
||||||
if (read_32bitLE(current_chunk+8, streamFile))
|
loop_flag = read_32bitLE(current_chunk+0x08, streamFile);
|
||||||
{
|
|
||||||
loop_flag = 1;
|
|
||||||
}
|
|
||||||
mwv_ctrl_offset = current_chunk;
|
mwv_ctrl_offset = current_chunk;
|
||||||
break;
|
break;
|
||||||
case 0x66616374: /* fact */
|
case 0x66616374: /* fact */
|
||||||
if (sns && chunk_size == 0x10) {
|
if (sns && chunk_size == 0x10) {
|
||||||
fact_sample_count = read_32bitLE(current_chunk+0x8, streamFile);
|
fact_sample_count = read_32bitLE(current_chunk+0x08, streamFile);
|
||||||
} else if (at3 && chunk_size == 0x8) {
|
} else if (at3 && chunk_size == 0x08) {
|
||||||
fact_sample_count = read_32bitLE(current_chunk+0x8, streamFile);
|
fact_sample_count = read_32bitLE(current_chunk+0x08, streamFile);
|
||||||
fact_sample_skip = read_32bitLE(current_chunk+0xc, streamFile);
|
fact_sample_skip = read_32bitLE(current_chunk+0x0c, streamFile);
|
||||||
} else if (at3 && chunk_size == 0xc) {
|
} else if (at3 && chunk_size == 0x0c) {
|
||||||
fact_sample_count = read_32bitLE(current_chunk+0x8, streamFile);
|
fact_sample_count = read_32bitLE(current_chunk+0x08, streamFile);
|
||||||
fact_sample_skip = read_32bitLE(current_chunk+0x10, streamFile);
|
fact_sample_skip = read_32bitLE(current_chunk+0x10, streamFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,103 +356,119 @@ VGMSTREAM * init_vgmstream_riff(STREAMFILE *streamFile) {
|
|||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
|
||||||
|
/* build the VGMSTREAM */
|
||||||
|
vgmstream = allocate_vgmstream(fmt.channel_count,loop_flag);
|
||||||
|
if (!vgmstream) goto fail;
|
||||||
|
|
||||||
|
vgmstream->sample_rate = fmt.sample_rate;
|
||||||
|
|
||||||
|
/* init, samples */
|
||||||
switch (fmt.coding_type) {
|
switch (fmt.coding_type) {
|
||||||
case coding_PCM16LE:
|
case coding_PCM16LE:
|
||||||
sample_count = data_size/2/fmt.channel_count;
|
vgmstream->num_samples = pcm_bytes_to_samples(data_size, fmt.channel_count, 16);
|
||||||
break;
|
break;
|
||||||
case coding_PCM8_U_int:
|
case coding_PCM8_U_int:
|
||||||
sample_count = data_size/fmt.channel_count;
|
vgmstream->num_samples = pcm_bytes_to_samples(data_size, vgmstream->channels, 8);
|
||||||
break;
|
break;
|
||||||
case coding_L5_555:
|
case coding_L5_555:
|
||||||
sample_count = data_size/0x12/fmt.channel_count*32;
|
vgmstream->num_samples = data_size / 0x12 / fmt.channel_count * 32;
|
||||||
break;
|
|
||||||
case coding_MSADPCM:
|
|
||||||
sample_count = msadpcm_bytes_to_samples(data_size, fmt.block_size, fmt.channel_count);
|
|
||||||
break;
|
|
||||||
case coding_MS_IMA:
|
|
||||||
sample_count = (data_size / fmt.block_size) * (fmt.block_size - 4 * fmt.channel_count) * 2 / fmt.channel_count +
|
|
||||||
((data_size % fmt.block_size) ? (data_size % fmt.block_size - 4 * fmt.channel_count) * 2 / fmt.channel_count : 0);
|
|
||||||
break;
|
|
||||||
case coding_NGC_DSP:
|
|
||||||
//sample_count = data_size / fmt.channel_count / 8 * 14; /* expected from the "fact" chunk */
|
|
||||||
break;
|
|
||||||
#ifdef VGM_USE_FFMPEG
|
|
||||||
case coding_FFmpeg:
|
|
||||||
{
|
|
||||||
ffmpeg_data = init_ffmpeg_offset(streamFile, 0, streamFile->get_size(streamFile) );
|
|
||||||
if ( !ffmpeg_data ) goto fail;
|
|
||||||
|
|
||||||
sample_count = ffmpeg_data->totalSamples; /* fact_sample_count */
|
/* coefs */
|
||||||
|
if (mwv) {
|
||||||
|
int i, ch;
|
||||||
|
const int filter_order = 3;
|
||||||
|
int filter_count = read_32bitLE(mwv_pflt_offset+0x0c, streamFile);
|
||||||
|
if (filter_count > 0x20) goto fail;
|
||||||
|
|
||||||
if (at3) {
|
if (mwv_pflt_offset == -1 ||
|
||||||
/* the encoder introduces some garbage (not always silent) samples to skip before the stream */
|
read_32bitLE(mwv_pflt_offset+0x08, streamFile) != filter_order ||
|
||||||
/* manually set skip_samples if FFmpeg didn't do it */
|
read_32bitLE(mwv_pflt_offset+0x04, streamFile) < 8 + filter_count * 4 * filter_order)
|
||||||
if (ffmpeg_data->skipSamples <= 0) {
|
goto fail;
|
||||||
ffmpeg_set_skip_samples(ffmpeg_data, fact_sample_skip);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* RIFF loop/sample values are absolute (with skip samples), adjust */
|
for (ch = 0; ch < fmt.channel_count; ch++) {
|
||||||
if (loop_flag) {
|
for (i = 0; i < filter_count * filter_order; i++) {
|
||||||
loop_start_offset -= ffmpeg_data->skipSamples;
|
int coef = read_32bitLE(mwv_pflt_offset+0x10+i*0x04, streamFile);
|
||||||
loop_end_offset -= ffmpeg_data->skipSamples;
|
vgmstream->ch[ch].adpcm_coef_3by32[i] = coef;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
case coding_MSADPCM:
|
||||||
|
vgmstream->num_samples = msadpcm_bytes_to_samples(data_size, fmt.block_size, fmt.channel_count);
|
||||||
|
break;
|
||||||
|
case coding_MS_IMA:
|
||||||
|
vgmstream->num_samples = ms_ima_bytes_to_samples(data_size, fmt.block_size, fmt.channel_count);
|
||||||
|
break;
|
||||||
|
case coding_NGC_DSP:
|
||||||
|
//sample_count = dsp_bytes_to_samples(data_size, fmt.channel_count); /* expected from the "fact" chunk */
|
||||||
|
|
||||||
|
/* coefs */
|
||||||
|
if (sns) {
|
||||||
|
int i, ch;
|
||||||
|
static const int16_t coef[16] = { /* common codebook? */
|
||||||
|
0x04ab,0xfced,0x0789,0xfedf,0x09a2,0xfae5,0x0c90,0xfac1,
|
||||||
|
0x084d,0xfaa4,0x0982,0xfdf7,0x0af6,0xfafa,0x0be6,0xfbf5
|
||||||
|
};
|
||||||
|
|
||||||
|
for (ch = 0; ch < fmt.channel_count; ch++) {
|
||||||
|
for (i = 0; i < 16; i++) {
|
||||||
|
vgmstream->ch[ch].adpcm_coef[i] = coef[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
#ifdef VGM_USE_FFMPEG
|
||||||
|
case coding_FFmpeg: {
|
||||||
|
ffmpeg_codec_data *ffmpeg_data = init_ffmpeg_offset(streamFile, 0x00, streamFile->get_size(streamFile));
|
||||||
|
if ( !ffmpeg_data ) goto fail;
|
||||||
|
vgmstream->codec_data = ffmpeg_data;
|
||||||
|
|
||||||
|
vgmstream->num_samples = ffmpeg_data->totalSamples; /* fact_sample_count */
|
||||||
|
|
||||||
|
if (at3) {
|
||||||
|
/* the encoder introduces some garbage (not always silent) samples to skip before the stream */
|
||||||
|
/* manually set skip_samples if FFmpeg didn't do it */
|
||||||
|
if (ffmpeg_data->skipSamples <= 0) {
|
||||||
|
ffmpeg_set_skip_samples(ffmpeg_data, fact_sample_skip);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* RIFF loop/sample values are absolute (with skip samples), adjust */
|
||||||
|
if (loop_flag) {
|
||||||
|
loop_start_offset -= ffmpeg_data->skipSamples;
|
||||||
|
loop_end_offset -= ffmpeg_data->skipSamples;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef VGM_USE_MAIATRAC3PLUS
|
#ifdef VGM_USE_MAIATRAC3PLUS
|
||||||
case coding_AT3plus:
|
case coding_AT3plus: {
|
||||||
/* rough total samples (block_size may be incorrect if not using joint stereo) */
|
maiatrac3plus_codec_data *data = malloc(sizeof(maiatrac3plus_codec_data));
|
||||||
sample_count = (data_size / fmt.block_size) * 2048;
|
data->buffer = 0;
|
||||||
/* favor fact_samples if available (skip isn't correctly handled for now) */
|
data->samples_discard = 0;
|
||||||
if (fact_sample_count > 0 && fact_sample_count + fact_sample_skip < sample_count)
|
data->handle = Atrac3plusDecoder_openContext();
|
||||||
sample_count = fact_sample_count + fact_sample_skip;
|
vgmstream->codec_data = data;
|
||||||
|
|
||||||
break;
|
/* get rough total samples but favor fact_samples if available (skip isn't correctly handled for now) */
|
||||||
|
vgmstream->num_samples = atrac3plus_bytes_to_samples(data_size, fmt.block_size);
|
||||||
|
if (fact_sample_count > 0 && fact_sample_count + fact_sample_skip < vgmstream->num_samples)
|
||||||
|
vgmstream->num_samples = fact_sample_count + fact_sample_skip;
|
||||||
|
break;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* .sns uses fact chunk */
|
/* .sns uses fact chunk */
|
||||||
if (sns)
|
if (sns) {
|
||||||
{
|
|
||||||
if (-1 == fact_sample_count) goto fail;
|
if (-1 == fact_sample_count) goto fail;
|
||||||
sample_count = fact_sample_count;
|
vgmstream->num_samples = fact_sample_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* build the VGMSTREAM */
|
/* coding, layout, interleave */
|
||||||
|
|
||||||
vgmstream = allocate_vgmstream(fmt.channel_count,loop_flag);
|
|
||||||
if (!vgmstream) goto fail;
|
|
||||||
|
|
||||||
/* fill in the vital statistics */
|
|
||||||
vgmstream->num_samples = sample_count;
|
|
||||||
vgmstream->sample_rate = fmt.sample_rate;
|
|
||||||
|
|
||||||
vgmstream->coding_type = fmt.coding_type;
|
vgmstream->coding_type = fmt.coding_type;
|
||||||
|
|
||||||
vgmstream->layout_type = layout_none;
|
|
||||||
if (fmt.channel_count > 1) {
|
|
||||||
switch (fmt.coding_type) {
|
|
||||||
case coding_PCM8_U_int:
|
|
||||||
case coding_MS_IMA:
|
|
||||||
case coding_MSADPCM:
|
|
||||||
#ifdef VGM_USE_FFMPEG
|
|
||||||
case coding_FFmpeg:
|
|
||||||
#endif
|
|
||||||
#ifdef VGM_USE_MAIATRAC3PLUS
|
|
||||||
case coding_AT3plus:
|
|
||||||
#endif
|
|
||||||
// use layout_none from above
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
vgmstream->layout_type = layout_interleave;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vgmstream->interleave_block_size = fmt.interleave;
|
|
||||||
switch (fmt.coding_type) {
|
switch (fmt.coding_type) {
|
||||||
case coding_MSADPCM:
|
case coding_MSADPCM:
|
||||||
case coding_MS_IMA:
|
case coding_MS_IMA:
|
||||||
@ -512,171 +476,81 @@ VGMSTREAM * init_vgmstream_riff(STREAMFILE *streamFile) {
|
|||||||
case coding_FFmpeg:
|
case coding_FFmpeg:
|
||||||
#endif
|
#endif
|
||||||
#ifdef VGM_USE_MAIATRAC3PLUS
|
#ifdef VGM_USE_MAIATRAC3PLUS
|
||||||
case coding_AT3plus:
|
case coding_AT3plus:
|
||||||
#endif
|
#endif
|
||||||
// override interleave_block_size with frame size
|
vgmstream->layout_type = layout_none;
|
||||||
vgmstream->interleave_block_size = fmt.block_size;
|
vgmstream->interleave_block_size = fmt.block_size;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// use interleave from above
|
vgmstream->layout_type = layout_interleave;
|
||||||
|
vgmstream->interleave_block_size = fmt.interleave;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef VGM_USE_FFMPEG
|
/* meta, loops */
|
||||||
if (fmt.coding_type == coding_FFmpeg) {
|
vgmstream->meta_type = meta_RIFF_WAVE;
|
||||||
vgmstream->codec_data = ffmpeg_data;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VGM_USE_MAIATRAC3PLUS
|
|
||||||
if (fmt.coding_type == coding_AT3plus) {
|
|
||||||
maiatrac3plus_codec_data *data = malloc(sizeof(maiatrac3plus_codec_data));
|
|
||||||
data->buffer = 0;
|
|
||||||
data->samples_discard = 0;
|
|
||||||
data->handle = Atrac3plusDecoder_openContext();
|
|
||||||
vgmstream->codec_data = data;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (loop_flag) {
|
if (loop_flag) {
|
||||||
if (loop_start_ms >= 0)
|
if (loop_start_ms >= 0) {
|
||||||
{
|
vgmstream->loop_start_sample = (long long)loop_start_ms*fmt.sample_rate/1000;
|
||||||
vgmstream->loop_start_sample =
|
vgmstream->loop_end_sample = (long long)loop_end_ms*fmt.sample_rate/1000;
|
||||||
(long long)loop_start_ms*fmt.sample_rate/1000;
|
|
||||||
vgmstream->loop_end_sample =
|
|
||||||
(long long)loop_end_ms*fmt.sample_rate/1000;
|
|
||||||
vgmstream->meta_type = meta_RIFF_WAVE_labl;
|
vgmstream->meta_type = meta_RIFF_WAVE_labl;
|
||||||
}
|
}
|
||||||
else if (loop_start_offset >= 0)
|
else if (loop_start_offset >= 0) {
|
||||||
{
|
|
||||||
vgmstream->loop_start_sample = loop_start_offset;
|
vgmstream->loop_start_sample = loop_start_offset;
|
||||||
vgmstream->loop_end_sample = loop_end_offset;
|
vgmstream->loop_end_sample = loop_end_offset;
|
||||||
vgmstream->meta_type = meta_RIFF_WAVE_smpl;
|
vgmstream->meta_type = meta_RIFF_WAVE_smpl;
|
||||||
}
|
}
|
||||||
else if (mwv && mwv_ctrl_offset != -1)
|
else if (mwv && mwv_ctrl_offset != -1) {
|
||||||
{
|
vgmstream->loop_start_sample = read_32bitLE(mwv_ctrl_offset+12, streamFile);
|
||||||
vgmstream->loop_start_sample = read_32bitLE(mwv_ctrl_offset+12,
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
||||||
streamFile);
|
|
||||||
vgmstream->loop_end_sample = sample_count;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
if (mwv) {
|
||||||
{
|
|
||||||
vgmstream->meta_type = meta_RIFF_WAVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mwv)
|
|
||||||
{
|
|
||||||
int i, c;
|
|
||||||
if (fmt.coding_type == coding_L5_555)
|
|
||||||
{
|
|
||||||
const int filter_order = 3;
|
|
||||||
int filter_count = read_32bitLE(mwv_pflt_offset+12, streamFile);
|
|
||||||
|
|
||||||
if (mwv_pflt_offset == -1 ||
|
|
||||||
read_32bitLE(mwv_pflt_offset+8, streamFile) != filter_order ||
|
|
||||||
read_32bitLE(mwv_pflt_offset+4, streamFile) < 8 + filter_count * 4 * filter_order)
|
|
||||||
goto fail;
|
|
||||||
if (filter_count > 0x20) goto fail;
|
|
||||||
for (c = 0; c < fmt.channel_count; c++)
|
|
||||||
{
|
|
||||||
for (i = 0; i < filter_count * filter_order; i++)
|
|
||||||
{
|
|
||||||
vgmstream->ch[c].adpcm_coef_3by32[i] = read_32bitLE(
|
|
||||||
mwv_pflt_offset+16+i*4, streamFile
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
vgmstream->meta_type = meta_RIFF_WAVE_MWV;
|
vgmstream->meta_type = meta_RIFF_WAVE_MWV;
|
||||||
}
|
}
|
||||||
|
if (sns) {
|
||||||
if (sns)
|
|
||||||
{
|
|
||||||
int c;
|
|
||||||
/* common codebook? */
|
|
||||||
static const int16_t coef[16] =
|
|
||||||
{0x04ab,0xfced,0x0789,0xfedf,0x09a2,0xfae5,0x0c90,0xfac1,
|
|
||||||
0x084d,0xfaa4,0x0982,0xfdf7,0x0af6,0xfafa,0x0be6,0xfbf5};
|
|
||||||
|
|
||||||
for (c = 0; c < fmt.channel_count; c++)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < 16; i++)
|
|
||||||
{
|
|
||||||
vgmstream->ch[c].adpcm_coef[i] = coef[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
vgmstream->meta_type = meta_RIFF_WAVE_SNS;
|
vgmstream->meta_type = meta_RIFF_WAVE_SNS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* open the file, set up each channel */
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
vgmstream->ch[0].streamfile = streamFile->open(streamFile,filename,
|
|
||||||
STREAMFILE_DEFAULT_BUFFER_SIZE);
|
|
||||||
if (!vgmstream->ch[0].streamfile) goto fail;
|
|
||||||
|
|
||||||
for (i=0;i<fmt.channel_count;i++) {
|
|
||||||
vgmstream->ch[i].streamfile = vgmstream->ch[0].streamfile;
|
|
||||||
vgmstream->ch[i].offset = vgmstream->ch[i].channel_start_offset =
|
|
||||||
start_offset+i*fmt.interleave;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if ( !vgmstream_open_stream(vgmstream,streamFile,start_offset) )
|
||||||
|
goto fail;
|
||||||
return vgmstream;
|
return vgmstream;
|
||||||
|
|
||||||
/* clean up anything we may have opened */
|
|
||||||
fail:
|
fail:
|
||||||
#ifdef VGM_USE_FFMPEG
|
close_vgmstream(vgmstream);
|
||||||
if (ffmpeg_data) {
|
|
||||||
free_ffmpeg(ffmpeg_data);
|
|
||||||
if (vgmstream) vgmstream->codec_data = NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (vgmstream) close_vgmstream(vgmstream);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
VGMSTREAM * init_vgmstream_rifx(STREAMFILE *streamFile) {
|
VGMSTREAM * init_vgmstream_rifx(STREAMFILE *streamFile) {
|
||||||
VGMSTREAM * vgmstream = NULL;
|
VGMSTREAM * vgmstream = NULL;
|
||||||
char filename[PATH_LIMIT];
|
riff_fmt_chunk fmt = {0};
|
||||||
|
|
||||||
struct riff_fmt_chunk fmt;
|
size_t file_size, riff_size, data_size = 0;
|
||||||
|
off_t start_offset = 0;
|
||||||
off_t file_size = -1;
|
|
||||||
int sample_count = 0;
|
|
||||||
//int fact_sample_count = -1;
|
|
||||||
off_t start_offset = -1;
|
|
||||||
|
|
||||||
int loop_flag = 0;
|
int loop_flag = 0;
|
||||||
off_t loop_start_offset = -1;
|
off_t loop_start_offset = -1;
|
||||||
off_t loop_end_offset = -1;
|
off_t loop_end_offset = -1;
|
||||||
uint32_t riff_size;
|
|
||||||
uint32_t data_size = 0;
|
|
||||||
|
|
||||||
int FormatChunkFound = 0, DataChunkFound = 0, JunkFound = 0;
|
int FormatChunkFound = 0, DataChunkFound = 0;
|
||||||
|
|
||||||
|
|
||||||
/* check extension, case insensitive */
|
/* check extension, case insensitive */
|
||||||
streamFile->get_name(streamFile,filename,sizeof(filename));
|
if ( !check_extensions(streamFile, "wav,lwav") )
|
||||||
if (strcasecmp("wav",filename_extension(filename)) &&
|
|
||||||
strcasecmp("lwav",filename_extension(filename)))
|
|
||||||
{
|
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
|
||||||
|
|
||||||
/* check header */
|
/* check header */
|
||||||
if ((uint32_t)read_32bitBE(0,streamFile)!=0x52494658) /* "RIFX" */
|
if (read_32bitBE(0x00,streamFile) != 0x52494658) /* "RIFX" */
|
||||||
goto fail;
|
goto fail;
|
||||||
/* check for WAVE form */
|
if (read_32bitBE(0x08,streamFile) != 0x57415645) /* "WAVE" */
|
||||||
if ((uint32_t)read_32bitBE(8,streamFile)!=0x57415645) /* "WAVE" */
|
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
riff_size = read_32bitBE(4,streamFile);
|
riff_size = read_32bitBE(0x04,streamFile);
|
||||||
file_size = get_streamfile_size(streamFile);
|
file_size = get_streamfile_size(streamFile);
|
||||||
|
|
||||||
/* check for tructated RIFF */
|
/* check for truncated RIFF */
|
||||||
if (file_size < riff_size+8) goto fail;
|
if (file_size < riff_size+8) goto fail;
|
||||||
|
|
||||||
/* read through chunks to verify format and find metadata */
|
/* read through chunks to verify format and find metadata */
|
||||||
@ -713,27 +587,15 @@ VGMSTREAM * init_vgmstream_rifx(STREAMFILE *streamFile) {
|
|||||||
data_size = chunk_size;
|
data_size = chunk_size;
|
||||||
break;
|
break;
|
||||||
case 0x736D706C: /* smpl */
|
case 0x736D706C: /* smpl */
|
||||||
/* check loop count */
|
/* check loop count and loop info */
|
||||||
if (read_32bitBE(current_chunk+0x24, streamFile)==1)
|
if (read_32bitBE(current_chunk+0x24, streamFile)==1) {
|
||||||
{
|
if (read_32bitBE(current_chunk+0x2c+4, streamFile)==0) {
|
||||||
/* check loop info */
|
|
||||||
if (read_32bitBE(current_chunk+0x2c+4, streamFile)==0)
|
|
||||||
{
|
|
||||||
loop_flag = 1;
|
loop_flag = 1;
|
||||||
loop_start_offset =
|
loop_start_offset = read_32bitBE(current_chunk+0x2c+8, streamFile);
|
||||||
read_32bitBE(current_chunk+0x2c+8, streamFile);
|
loop_end_offset = read_32bitBE(current_chunk+0x2c+0xc,streamFile);
|
||||||
loop_end_offset =
|
|
||||||
read_32bitBE(current_chunk+0x2c+0xc,streamFile);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0x66616374: /* fact */
|
|
||||||
if (chunk_size != 4) break;
|
|
||||||
//fact_sample_count = read_32bitBE(current_chunk+8, streamFile);
|
|
||||||
break;
|
|
||||||
case 0x4A554E4B: /* JUNK */
|
|
||||||
JunkFound = 1;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
/* ignorance is bliss */
|
/* ignorance is bliss */
|
||||||
break;
|
break;
|
||||||
@ -745,98 +607,50 @@ VGMSTREAM * init_vgmstream_rifx(STREAMFILE *streamFile) {
|
|||||||
|
|
||||||
if (!FormatChunkFound || !DataChunkFound) goto fail;
|
if (!FormatChunkFound || !DataChunkFound) goto fail;
|
||||||
|
|
||||||
/* JUNK is an optional Wwise chunk, and Wwise hijacks the MSADPCM/MS_IMA/XBOX IMA ids (how nice).
|
|
||||||
* To ensure their stuff is parsed in wwise.c we reject their JUNK, which they put almost always.
|
|
||||||
* As JUNK is legal (if unusual) we only reject those codecs.
|
|
||||||
* (ex. Cave PC games have PCM16LE + JUNK + smpl created by "Samplitude software") */
|
|
||||||
if (JunkFound && (fmt.coding_type==coding_MSADPCM || fmt.coding_type==coding_MS_IMA)) goto fail;
|
|
||||||
|
|
||||||
|
/* build the VGMSTREAM */
|
||||||
|
vgmstream = allocate_vgmstream(fmt.channel_count,loop_flag);
|
||||||
|
if (!vgmstream) goto fail;
|
||||||
|
|
||||||
|
vgmstream->sample_rate = fmt.sample_rate;
|
||||||
|
|
||||||
|
/* init, samples */
|
||||||
switch (fmt.coding_type) {
|
switch (fmt.coding_type) {
|
||||||
case coding_PCM16BE:
|
case coding_PCM16BE:
|
||||||
sample_count = data_size/2/fmt.channel_count;
|
vgmstream->num_samples = pcm_bytes_to_samples(data_size, vgmstream->channels, 16);
|
||||||
break;
|
break;
|
||||||
case coding_PCM8_U_int:
|
case coding_PCM8_U_int:
|
||||||
sample_count = data_size/fmt.channel_count;
|
vgmstream->num_samples = pcm_bytes_to_samples(data_size, vgmstream->channels, 8);
|
||||||
break;
|
|
||||||
case coding_NGC_DSP:
|
|
||||||
//sample_count = data_size / fmt.channel_count / 8 * 14; /* expected from the "fact" chunk */
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* build the VGMSTREAM */
|
/* coding, layout, interleave */
|
||||||
|
|
||||||
vgmstream = allocate_vgmstream(fmt.channel_count,loop_flag);
|
|
||||||
if (!vgmstream) goto fail;
|
|
||||||
|
|
||||||
/* fill in the vital statistics */
|
|
||||||
vgmstream->num_samples = sample_count;
|
|
||||||
vgmstream->sample_rate = fmt.sample_rate;
|
|
||||||
|
|
||||||
vgmstream->coding_type = fmt.coding_type;
|
vgmstream->coding_type = fmt.coding_type;
|
||||||
|
|
||||||
vgmstream->layout_type = layout_none;
|
|
||||||
if (fmt.channel_count > 1) {
|
|
||||||
switch (fmt.coding_type) {
|
|
||||||
case coding_PCM8_U_int:
|
|
||||||
case coding_MS_IMA:
|
|
||||||
case coding_MSADPCM:
|
|
||||||
// use layout_none from above
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
vgmstream->layout_type = layout_interleave;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vgmstream->interleave_block_size = fmt.interleave;
|
|
||||||
switch (fmt.coding_type) {
|
switch (fmt.coding_type) {
|
||||||
case coding_MSADPCM:
|
|
||||||
case coding_MS_IMA:
|
|
||||||
// override interleave_block_size with frame size
|
|
||||||
vgmstream->interleave_block_size = fmt.block_size;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
// use interleave from above
|
vgmstream->layout_type = layout_interleave;
|
||||||
|
vgmstream->interleave_block_size = fmt.interleave;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fmt.coding_type == coding_MS_IMA)
|
/* meta, loops */
|
||||||
vgmstream->interleave_block_size = fmt.block_size;
|
vgmstream->meta_type = meta_RIFX_WAVE;
|
||||||
|
|
||||||
if (loop_flag) {
|
if (loop_flag) {
|
||||||
if (loop_start_offset >= 0)
|
if (loop_start_offset >= 0) {
|
||||||
{
|
|
||||||
vgmstream->loop_start_sample = loop_start_offset;
|
vgmstream->loop_start_sample = loop_start_offset;
|
||||||
vgmstream->loop_end_sample = loop_end_offset;
|
vgmstream->loop_end_sample = loop_end_offset;
|
||||||
vgmstream->meta_type = meta_RIFX_WAVE_smpl;
|
vgmstream->meta_type = meta_RIFX_WAVE_smpl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
vgmstream->meta_type = meta_RIFX_WAVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* open the file, set up each channel */
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
vgmstream->ch[0].streamfile = streamFile->open(streamFile,filename,
|
|
||||||
STREAMFILE_DEFAULT_BUFFER_SIZE);
|
|
||||||
if (!vgmstream->ch[0].streamfile) goto fail;
|
|
||||||
|
|
||||||
for (i=0;i<fmt.channel_count;i++) {
|
|
||||||
vgmstream->ch[i].streamfile = vgmstream->ch[0].streamfile;
|
|
||||||
vgmstream->ch[i].offset = vgmstream->ch[i].channel_start_offset =
|
|
||||||
start_offset+i*fmt.interleave;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if ( !vgmstream_open_stream(vgmstream,streamFile,start_offset) )
|
||||||
|
goto fail;
|
||||||
return vgmstream;
|
return vgmstream;
|
||||||
|
|
||||||
/* clean up anything we may have opened */
|
|
||||||
fail:
|
fail:
|
||||||
if (vgmstream) close_vgmstream(vgmstream);
|
close_vgmstream(vgmstream);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user