2017-04-02 12:27:21 +02:00
|
|
|
#include "meta.h"
|
|
|
|
#include "../util.h"
|
|
|
|
#include "../coding/coding.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Wwise uses a custom RIFF/RIFX header, non-standard enough that it's parsed it here.
|
|
|
|
* There is some repetition from other metas, but not enough to bother me.
|
|
|
|
*
|
|
|
|
* Some info: https://www.audiokinetic.com/en/library/edge/
|
|
|
|
*/
|
2017-09-24 18:55:25 +02:00
|
|
|
typedef enum { PCM, IMA, VORBIS, DSP, XMA2, XWMA, AAC, HEVAG, ATRAC9, OPUS } wwise_codec;
|
2017-04-02 12:27:21 +02:00
|
|
|
typedef struct {
|
|
|
|
int big_endian;
|
|
|
|
size_t file_size;
|
2017-04-14 01:05:55 +02:00
|
|
|
int truncated;
|
2017-04-02 12:27:21 +02:00
|
|
|
|
|
|
|
/* chunks references */
|
|
|
|
off_t fmt_offset;
|
|
|
|
size_t fmt_size;
|
|
|
|
off_t data_offset;
|
|
|
|
size_t data_size;
|
Fix XMA gapless/looping/samples
fixes: standard, wem, xwc, xwb, xnb, xwx, rak, pk, txth, genh, seg, rsd, past, p3d, nub-xma, gtd, gsp, fsb, eaac, cxs, awc, aac
2018-11-18 17:01:31 +01:00
|
|
|
off_t chunk_offset;
|
2017-04-02 12:27:21 +02:00
|
|
|
|
|
|
|
/* standard fmt stuff */
|
|
|
|
wwise_codec codec;
|
|
|
|
int format;
|
|
|
|
int channels;
|
|
|
|
int sample_rate;
|
|
|
|
int block_align;
|
2017-04-07 20:21:55 +02:00
|
|
|
int average_bps;
|
|
|
|
int bits_per_sample;
|
2019-03-02 15:57:41 +01:00
|
|
|
uint32_t channel_layout;
|
2017-04-02 12:27:21 +02:00
|
|
|
size_t extra_size;
|
|
|
|
|
2017-04-08 13:40:23 +02:00
|
|
|
int32_t num_samples;
|
2017-04-02 12:27:21 +02:00
|
|
|
int loop_flag;
|
2017-04-08 13:40:23 +02:00
|
|
|
int32_t loop_start_sample;
|
|
|
|
int32_t loop_end_sample;
|
2017-04-02 12:27:21 +02:00
|
|
|
} wwise_header;
|
|
|
|
|
|
|
|
|
|
|
|
/* Wwise - Audiokinetic Wwise (Wave Works Interactive Sound Engine) middleware */
|
|
|
|
VGMSTREAM * init_vgmstream_wwise(STREAMFILE *streamFile) {
|
|
|
|
VGMSTREAM * vgmstream = NULL;
|
2018-05-19 11:21:40 +02:00
|
|
|
wwise_header ww = {0};
|
2017-04-02 12:27:21 +02:00
|
|
|
off_t start_offset, first_offset = 0xc;
|
|
|
|
int32_t (*read_32bit)(off_t,STREAMFILE*) = NULL;
|
|
|
|
int16_t (*read_16bit)(off_t,STREAMFILE*) = NULL;
|
|
|
|
|
|
|
|
/* basic checks */
|
|
|
|
/* .wem (Wwise Encoded Media) is "newer Wwise", used after the 2011.2 SDK (~july)
|
2017-04-11 20:01:17 +02:00
|
|
|
* .wav (ex. Shadowrun X360) and .ogg (ex. KOF XII X360), .xma (ex. Tron Evolution X360) are used in older Wwise */
|
|
|
|
if (!check_extensions(streamFile,"wem,wav,lwav,ogg,logg,xma")) goto fail;
|
2017-04-02 12:27:21 +02:00
|
|
|
|
|
|
|
if ((read_32bitBE(0x00,streamFile) != 0x52494646) && /* "RIFF" (LE) */
|
|
|
|
(read_32bitBE(0x00,streamFile) != 0x52494658)) /* "RIFX" (BE) */
|
|
|
|
goto fail;
|
2017-04-07 20:21:55 +02:00
|
|
|
if ((read_32bitBE(0x08,streamFile) != 0x57415645) && /* "WAVE" */
|
|
|
|
(read_32bitBE(0x08,streamFile) != 0x58574D41)) /* "XWMA" */
|
2017-04-02 12:27:21 +02:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
|
|
ww.big_endian = read_32bitBE(0x00,streamFile) == 0x52494658;/* RIFX */
|
|
|
|
if (ww.big_endian) { /* Wwise honors machine's endianness (PC=RIFF, X360=RIFX --unlike XMA) */
|
|
|
|
read_32bit = read_32bitBE;
|
|
|
|
read_16bit = read_16bitBE;
|
|
|
|
} else {
|
|
|
|
read_32bit = read_32bitLE;
|
|
|
|
read_16bit = read_16bitLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ww.file_size = streamFile->get_size(streamFile);
|
|
|
|
|
|
|
|
#if 0
|
2017-04-08 13:40:23 +02:00
|
|
|
/* sometimes uses a RIFF size that doesn't count chunks/sizes, has LE size in RIFX, or is just wrong...? */
|
2017-04-02 12:27:21 +02:00
|
|
|
if (4+4+read_32bit(0x04,streamFile) != ww.file_size) {
|
|
|
|
VGM_LOG("WWISE: bad riff size (real=0x%x vs riff=0x%x)\n", 4+4+read_32bit(0x04,streamFile), ww.file_size);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-04-07 11:37:44 +02:00
|
|
|
/* ignore LyN RIFF */
|
|
|
|
{
|
|
|
|
off_t fact_offset;
|
|
|
|
size_t fact_size;
|
|
|
|
|
|
|
|
if (find_chunk(streamFile, 0x66616374,first_offset,0, &fact_offset,&fact_size, 0, 0)) { /* "fact" */
|
|
|
|
if (fact_size == 0x10 && read_32bitBE(fact_offset+0x04, streamFile) == 0x4C794E20) /* "LyN " */
|
|
|
|
goto fail; /* parsed elsewhere */
|
|
|
|
/* Wwise doesn't use "fact", though */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-02 12:27:21 +02:00
|
|
|
|
2017-04-08 13:40:23 +02:00
|
|
|
/* parse format (roughly spec-compliant but some massaging is needed) */
|
2017-04-02 12:27:21 +02:00
|
|
|
{
|
|
|
|
off_t loop_offset;
|
|
|
|
size_t loop_size;
|
|
|
|
|
|
|
|
/* find basic chunks */
|
|
|
|
if (!find_chunk(streamFile, 0x666d7420,first_offset,0, &ww.fmt_offset,&ww.fmt_size, ww.big_endian, 0)) goto fail; /*"fmt "*/
|
|
|
|
if (!find_chunk(streamFile, 0x64617461,first_offset,0, &ww.data_offset,&ww.data_size, ww.big_endian, 0)) goto fail; /*"data"*/
|
|
|
|
|
|
|
|
/* base fmt */
|
|
|
|
if (ww.fmt_size < 0x12) goto fail;
|
|
|
|
ww.format = (uint16_t)read_16bit(ww.fmt_offset+0x00,streamFile);
|
|
|
|
|
2019-03-02 15:57:41 +01:00
|
|
|
if (ww.format == 0x0165) { /* pseudo-XMA2WAVEFORMAT (always "fmt"+"XMA2", unlike .xma that may only have "XMA2") */
|
Fix XMA gapless/looping/samples
fixes: standard, wem, xwc, xwb, xnb, xwx, rak, pk, txth, genh, seg, rsd, past, p3d, nub-xma, gtd, gsp, fsb, eaac, cxs, awc, aac
2018-11-18 17:01:31 +01:00
|
|
|
if (!find_chunk(streamFile, 0x584D4132,first_offset,0, &ww.chunk_offset,NULL, ww.big_endian, 0))
|
|
|
|
goto fail;
|
|
|
|
xma2_parse_xma2_chunk(streamFile, ww.chunk_offset,&ww.channels,&ww.sample_rate, &ww.loop_flag, &ww.num_samples, &ww.loop_start_sample, &ww.loop_end_sample);
|
2019-03-02 15:57:41 +01:00
|
|
|
}
|
|
|
|
else { /* pseudo-WAVEFORMATEX */
|
2017-04-08 13:40:23 +02:00
|
|
|
ww.channels = read_16bit(ww.fmt_offset+0x02,streamFile);
|
|
|
|
ww.sample_rate = read_32bit(ww.fmt_offset+0x04,streamFile);
|
|
|
|
ww.average_bps = read_32bit(ww.fmt_offset+0x08,streamFile);/* bytes per sec */
|
|
|
|
ww.block_align = (uint16_t)read_16bit(ww.fmt_offset+0x0c,streamFile);
|
|
|
|
ww.bits_per_sample = (uint16_t)read_16bit(ww.fmt_offset+0x0e,streamFile);
|
|
|
|
if (ww.fmt_size > 0x10 && ww.format != 0x0165 && ww.format != 0x0166) /* ignore XMAWAVEFORMAT */
|
|
|
|
ww.extra_size = (uint16_t)read_16bit(ww.fmt_offset+0x10,streamFile);
|
2019-03-09 21:31:15 +01:00
|
|
|
if (ww.extra_size >= 0x06) { /* always present (actual RIFFs only have it in WAVEFORMATEXTENSIBLE) */
|
|
|
|
/* mostly WAVEFORMATEXTENSIBLE's bitmask (see AkSpeakerConfig.h) */
|
2019-03-02 15:57:41 +01:00
|
|
|
ww.channel_layout = read_32bit(ww.fmt_offset+0x14,streamFile);
|
2019-03-09 21:31:15 +01:00
|
|
|
/* latest games have a pseudo-format instead to handle more cases:
|
|
|
|
* - 8b: uNumChannels
|
|
|
|
* - 4b: eConfigType (0=none, 1=standard, 2=ambisonic)
|
|
|
|
* - 19b: uChannelMask */
|
|
|
|
if ((ww.channel_layout & 0xFF) == ww.channels) {
|
|
|
|
ww.channel_layout = (ww.channel_layout >> 12);
|
|
|
|
}
|
2019-03-02 15:57:41 +01:00
|
|
|
}
|
2017-04-08 13:40:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* find loop info */
|
|
|
|
if (ww.format == 0x0166) { /* XMA2WAVEFORMATEX */
|
Fix XMA gapless/looping/samples
fixes: standard, wem, xwc, xwb, xnb, xwx, rak, pk, txth, genh, seg, rsd, past, p3d, nub-xma, gtd, gsp, fsb, eaac, cxs, awc, aac
2018-11-18 17:01:31 +01:00
|
|
|
ww.chunk_offset = ww.fmt_offset;
|
|
|
|
xma2_parse_fmt_chunk_extra(streamFile, ww.chunk_offset, &ww.loop_flag, &ww.num_samples, &ww.loop_start_sample, &ww.loop_end_sample, ww.big_endian);
|
2017-04-08 13:40:23 +02:00
|
|
|
}
|
Fix XMA gapless/looping/samples
fixes: standard, wem, xwc, xwb, xnb, xwx, rak, pk, txth, genh, seg, rsd, past, p3d, nub-xma, gtd, gsp, fsb, eaac, cxs, awc, aac
2018-11-18 17:01:31 +01:00
|
|
|
else if (find_chunk(streamFile, 0x736D706C,first_offset,0, &loop_offset,&loop_size, ww.big_endian, 0)) { /*"smpl", common */
|
2017-04-02 12:27:21 +02:00
|
|
|
if (loop_size >= 0x34
|
|
|
|
&& read_32bit(loop_offset+0x1c, streamFile)==1 /*loop count*/
|
|
|
|
&& read_32bit(loop_offset+0x24+4, streamFile)==0) {
|
|
|
|
ww.loop_flag = 1;
|
|
|
|
ww.loop_start_sample = read_32bit(loop_offset+0x24+0x8, streamFile);
|
|
|
|
ww.loop_end_sample = read_32bit(loop_offset+0x24+0xc,streamFile);
|
|
|
|
//todo fix repeat looping
|
|
|
|
}
|
2017-04-08 13:40:23 +02:00
|
|
|
}
|
2018-02-23 23:01:44 +01:00
|
|
|
//else if (find_chunk(streamFile, 0x4C495354,first_offset,0, &loop_offset,&loop_size, ww.big_endian, 0)) { /*"LIST", common */
|
|
|
|
// /* usually contains "cue"s with sample positions for events (ex. Platinum Games) but no real looping info */
|
|
|
|
//}
|
2017-04-02 12:27:21 +02:00
|
|
|
|
|
|
|
/* other Wwise specific: */
|
Fix XMA gapless/looping/samples
fixes: standard, wem, xwc, xwb, xnb, xwx, rak, pk, txth, genh, seg, rsd, past, p3d, nub-xma, gtd, gsp, fsb, eaac, cxs, awc, aac
2018-11-18 17:01:31 +01:00
|
|
|
//"JUNK": optional padding for aligment (0-size JUNK exists too)
|
2017-11-10 19:30:25 +01:00
|
|
|
//"akd ": seem to store extra info for Wwise editor (wave peaks/loudness/HDR envelope?)
|
2017-04-02 12:27:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* format to codec */
|
|
|
|
switch(ww.format) {
|
|
|
|
case 0x0001: ww.codec = PCM; break; /* older Wwise */
|
2017-04-07 20:21:55 +02:00
|
|
|
case 0x0002: ww.codec = IMA; break; /* newer Wwise (conflicts with MSADPCM, probably means "platform's ADPCM") */
|
2018-11-17 15:52:02 +01:00
|
|
|
//case 0x0011: ww.codec = IMA; break; /* older Wwise (used?) */
|
2017-04-15 23:07:15 +02:00
|
|
|
case 0x0069: ww.codec = IMA; break; /* older Wwise (Spiderman Web of Shadows X360, LotR Conquest PC) */
|
2017-10-08 17:34:07 +02:00
|
|
|
case 0x0161: ww.codec = XWMA; break; /* WMAv2 */
|
|
|
|
case 0x0162: ww.codec = XWMA; break; /* WMAPro */
|
2017-04-07 20:21:55 +02:00
|
|
|
case 0x0165: ww.codec = XMA2; break; /* always with the "XMA2" chunk, Wwise doesn't use XMA1 */
|
2017-04-02 12:27:21 +02:00
|
|
|
case 0x0166: ww.codec = XMA2; break;
|
2018-11-17 15:52:02 +01:00
|
|
|
case 0x3039: ww.codec = OPUS; break; /* later renamed to "OPUSNX" */
|
|
|
|
//case 0x3040: ww.codec = OPUS; break; /* same for other platforms, supposedly */
|
2017-04-02 12:27:21 +02:00
|
|
|
case 0xAAC0: ww.codec = AAC; break;
|
|
|
|
case 0xFFF0: ww.codec = DSP; break;
|
|
|
|
case 0xFFFB: ww.codec = HEVAG; break;
|
|
|
|
case 0xFFFC: ww.codec = ATRAC9; break;
|
2017-04-15 23:07:15 +02:00
|
|
|
case 0xFFFE: ww.codec = PCM; break; /* "PCM for Wwise Authoring" */
|
2017-04-02 12:27:21 +02:00
|
|
|
case 0xFFFF: ww.codec = VORBIS; break;
|
|
|
|
default:
|
|
|
|
goto fail;
|
|
|
|
}
|
2018-05-19 11:21:40 +02:00
|
|
|
|
2017-04-02 12:27:21 +02:00
|
|
|
/* fix for newer Wwise DSP with coefs: Epic Mickey 2 (Wii), Batman Arkham Origins Blackgate (3DS) */
|
|
|
|
if (ww.format == 0x0002 && ww.extra_size == 0x0c + ww.channels * 0x2e) {
|
|
|
|
ww.codec = DSP;
|
|
|
|
}
|
2018-05-19 11:21:40 +02:00
|
|
|
else if (ww.format == 0x0002 && ww.block_align == 0x104 * ww.channels) {
|
|
|
|
//ww.codec = SWITCH_ADPCM;
|
|
|
|
/* unknown codec, found in Bayonetta 2 (Switch)
|
2018-08-26 13:47:02 +02:00
|
|
|
* frames of 0x104 per ch, possibly frame header is hist1(2)/hist2(2)/index(1)
|
|
|
|
* (may write 2 header samples + FF*2 nibbles = 0x200 samples per block?)
|
|
|
|
* index only goes up to ~0xb, may be a shift/scale value */
|
2018-05-19 11:21:40 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2017-04-02 12:27:21 +02:00
|
|
|
|
2017-11-10 19:30:25 +01:00
|
|
|
/* Some Wwise files (ex. Oddworld PSV, Bayonetta 2 WiiU, often in BGM.bnk) are truncated mirrors of another file.
|
2017-04-14 01:05:55 +02:00
|
|
|
* They come in RAM banks, probably to play the beginning while the rest of the real stream loads.
|
|
|
|
* We'll add basic support to avoid complaints of this or that .wem not playing */
|
2017-04-11 20:01:17 +02:00
|
|
|
if (ww.data_size > ww.file_size) {
|
2017-04-14 01:05:55 +02:00
|
|
|
//VGM_LOG("WWISE: truncated data size (prefetch): (real=0x%x > riff=0x%x)\n", ww.data_size, ww.file_size);
|
2018-11-09 21:03:16 +01:00
|
|
|
if (ww.codec == IMA || ww.codec == VORBIS || ww.codec == XMA2) /* only seen those, probably others exist */
|
2017-04-14 01:05:55 +02:00
|
|
|
ww.truncated = 1;
|
2017-04-11 20:01:17 +02:00
|
|
|
else
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2019-03-02 15:57:41 +01:00
|
|
|
start_offset = ww.data_offset;
|
2017-04-02 12:27:21 +02:00
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
|
|
|
vgmstream = allocate_vgmstream(ww.channels,ww.loop_flag);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
vgmstream->sample_rate = ww.sample_rate;
|
|
|
|
vgmstream->loop_start_sample = ww.loop_start_sample;
|
|
|
|
vgmstream->loop_end_sample = ww.loop_end_sample;
|
2019-03-02 15:57:41 +01:00
|
|
|
vgmstream->channel_layout = ww.channel_layout;
|
2017-04-02 12:27:21 +02:00
|
|
|
vgmstream->meta_type = meta_WWISE_RIFF;
|
|
|
|
|
|
|
|
switch(ww.codec) {
|
|
|
|
case PCM: /* common */
|
|
|
|
/* normally riff.c has priority but it's needed when .wem is used */
|
2018-07-14 23:04:17 +02:00
|
|
|
if (ww.fmt_size != 0x10 && ww.fmt_size != 0x18 && ww.fmt_size != 0x28) goto fail; /* old, new/Limbo (PC) */
|
2017-04-07 20:21:55 +02:00
|
|
|
if (ww.bits_per_sample != 16) goto fail;
|
2017-04-02 12:27:21 +02:00
|
|
|
|
|
|
|
vgmstream->coding_type = (ww.big_endian ? coding_PCM16BE : coding_PCM16LE);
|
|
|
|
vgmstream->layout_type = ww.channels > 1 ? layout_interleave : layout_none;
|
|
|
|
vgmstream->interleave_block_size = 0x02;
|
|
|
|
|
2017-04-07 20:21:55 +02:00
|
|
|
vgmstream->num_samples = pcm_bytes_to_samples(ww.data_size, ww.channels, ww.bits_per_sample);
|
2017-04-02 12:27:21 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IMA: /* common */
|
2018-02-23 23:01:44 +01:00
|
|
|
/* slightly modified XBOX-IMA */
|
|
|
|
/* Wwise reuses common codec ids (ex. 0x0002 MSADPCM) for IMA so this parser should go AFTER riff.c avoid misdetection */
|
2017-04-11 20:01:17 +02:00
|
|
|
|
2018-05-19 11:21:40 +02:00
|
|
|
if (ww.fmt_size != 0x28 && ww.fmt_size != 0x18) goto fail; /* old, new */
|
2017-04-07 20:21:55 +02:00
|
|
|
if (ww.bits_per_sample != 4) goto fail;
|
2018-02-17 19:46:15 +01:00
|
|
|
if (ww.block_align != 0x24 * ww.channels) goto fail;
|
2018-05-19 11:21:40 +02:00
|
|
|
|
2017-04-02 12:27:21 +02:00
|
|
|
vgmstream->coding_type = coding_WWISE_IMA;
|
2018-02-23 23:01:44 +01:00
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
vgmstream->interleave_block_size = ww.block_align / ww.channels;
|
2017-04-11 20:01:17 +02:00
|
|
|
vgmstream->codec_endian = ww.big_endian;
|
2017-04-02 12:27:21 +02:00
|
|
|
|
2018-11-09 21:03:16 +01:00
|
|
|
/* enough to get real samples */
|
|
|
|
if (ww.truncated) {
|
2017-04-14 01:05:55 +02:00
|
|
|
ww.data_size = ww.file_size - ww.data_offset;
|
2018-11-09 21:03:16 +01:00
|
|
|
}
|
2017-04-14 01:05:55 +02:00
|
|
|
|
2018-02-17 19:46:15 +01:00
|
|
|
vgmstream->num_samples = xbox_ima_bytes_to_samples(ww.data_size, ww.channels);
|
2017-04-02 12:27:21 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef VGM_USE_VORBIS
|
|
|
|
case VORBIS: { /* common */
|
2017-04-13 15:05:06 +02:00
|
|
|
/* Wwise uses custom Vorbis, which changed over time (config must be detected to pass to the decoder). */
|
|
|
|
off_t vorb_offset, data_offsets, block_offsets;
|
|
|
|
size_t vorb_size, setup_offset, audio_offset;
|
2018-05-19 11:21:40 +02:00
|
|
|
vorbis_custom_config cfg = {0};
|
2017-04-13 15:05:06 +02:00
|
|
|
|
2017-07-28 23:26:58 +02:00
|
|
|
cfg.channels = ww.channels;
|
|
|
|
cfg.sample_rate = ww.sample_rate;
|
|
|
|
cfg.big_endian = ww.big_endian;
|
2017-04-02 12:27:21 +02:00
|
|
|
|
2017-04-11 20:01:17 +02:00
|
|
|
if (ww.block_align != 0 || ww.bits_per_sample != 0) goto fail; /* always 0 for Worbis */
|
2017-04-02 12:27:21 +02:00
|
|
|
|
Fix XMA gapless/looping/samples
fixes: standard, wem, xwc, xwb, xnb, xwx, rak, pk, txth, genh, seg, rsd, past, p3d, nub-xma, gtd, gsp, fsb, eaac, cxs, awc, aac
2018-11-18 17:01:31 +01:00
|
|
|
/* autodetect format (fields are mostly common, see the end of the file) */
|
2017-04-02 12:27:21 +02:00
|
|
|
if (find_chunk(streamFile, 0x766F7262,first_offset,0, &vorb_offset,&vorb_size, ww.big_endian, 0)) { /*"vorb"*/
|
2017-04-13 15:05:06 +02:00
|
|
|
/* older Wwise (~<2012) */
|
2017-04-02 12:27:21 +02:00
|
|
|
|
2017-04-13 15:05:06 +02:00
|
|
|
switch(vorb_size) {
|
2018-08-12 01:04:44 +02:00
|
|
|
case 0x2C: /* earliest (~2009), [UFC Undisputed 2009 (PS3), some EVE Online Apocrypha (PC)?] */
|
|
|
|
case 0x28: /* early (~2009) [The Lord of the Rings: Conquest (PC)] */
|
2017-04-13 15:05:06 +02:00
|
|
|
data_offsets = 0x18;
|
2017-04-13 20:53:49 +02:00
|
|
|
block_offsets = 0; /* no need, full headers are present */
|
2018-01-28 00:47:06 +01:00
|
|
|
cfg.header_type = WWV_TYPE_8;
|
|
|
|
cfg.packet_type = WWV_STANDARD;
|
|
|
|
cfg.setup_type = WWV_HEADER_TRIAD;
|
2017-04-13 15:05:06 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x34: /* common (2010~2011) */
|
2018-08-12 01:04:44 +02:00
|
|
|
case 0x32: /* very rare (mid 2011) [Saints Row the 3rd (PC)] */
|
2017-04-13 15:05:06 +02:00
|
|
|
data_offsets = 0x18;
|
|
|
|
block_offsets = 0x30;
|
2018-01-28 00:47:06 +01:00
|
|
|
cfg.header_type = WWV_TYPE_6;
|
|
|
|
cfg.packet_type = WWV_STANDARD;
|
|
|
|
cfg.setup_type = WWV_EXTERNAL_CODEBOOKS; /* setup_type will be corrected later */
|
2017-04-13 15:05:06 +02:00
|
|
|
break;
|
2018-08-12 01:04:44 +02:00
|
|
|
|
Fix XMA gapless/looping/samples
fixes: standard, wem, xwc, xwb, xnb, xwx, rak, pk, txth, genh, seg, rsd, past, p3d, nub-xma, gtd, gsp, fsb, eaac, cxs, awc, aac
2018-11-18 17:01:31 +01:00
|
|
|
case 0x2a: /* uncommon (mid 2011) [inFamous 2 (PS3)] */
|
2017-04-13 15:05:06 +02:00
|
|
|
data_offsets = 0x10;
|
|
|
|
block_offsets = 0x28;
|
2018-01-28 00:47:06 +01:00
|
|
|
cfg.header_type = WWV_TYPE_2;
|
|
|
|
cfg.packet_type = WWV_MODIFIED;
|
|
|
|
cfg.setup_type = WWV_EXTERNAL_CODEBOOKS;
|
2017-04-13 15:05:06 +02:00
|
|
|
break;
|
2018-08-12 01:04:44 +02:00
|
|
|
|
2017-04-13 15:05:06 +02:00
|
|
|
default:
|
|
|
|
VGM_LOG("WWISE: unknown vorb size 0x%x\n", vorb_size);
|
|
|
|
goto fail;
|
|
|
|
}
|
2017-04-11 20:01:17 +02:00
|
|
|
|
2017-04-13 15:05:06 +02:00
|
|
|
vgmstream->num_samples = read_32bit(vorb_offset + 0x00, streamFile);
|
|
|
|
setup_offset = read_32bit(vorb_offset + data_offsets + 0x00, streamFile); /* within data (0 = no seek table) */
|
|
|
|
audio_offset = read_32bit(vorb_offset + data_offsets + 0x04, streamFile); /* within data */
|
|
|
|
if (block_offsets) {
|
2017-07-28 23:26:58 +02:00
|
|
|
cfg.blocksize_1_exp = read_8bit(vorb_offset + block_offsets + 0x00, streamFile); /* small */
|
|
|
|
cfg.blocksize_0_exp = read_8bit(vorb_offset + block_offsets + 0x01, streamFile); /* big */
|
2017-04-13 15:05:06 +02:00
|
|
|
}
|
2017-09-29 23:27:21 +02:00
|
|
|
ww.data_size -= audio_offset;
|
2017-04-02 12:27:21 +02:00
|
|
|
|
2017-04-13 15:05:06 +02:00
|
|
|
/* detect setup type:
|
Fix XMA gapless/looping/samples
fixes: standard, wem, xwc, xwb, xnb, xwx, rak, pk, txth, genh, seg, rsd, past, p3d, nub-xma, gtd, gsp, fsb, eaac, cxs, awc, aac
2018-11-18 17:01:31 +01:00
|
|
|
* - full inline: ~2009, ex. The King of Fighters XII (X360), The Saboteur (PC)
|
|
|
|
* - trimmed inline: ~2010, ex. Army of Two: 40 days (X360) some multiplayer files
|
|
|
|
* - external: ~2010, ex. Assassin's Creed Brotherhood (X360), Dead Nation (X360) */
|
2017-04-13 15:05:06 +02:00
|
|
|
if (vorb_size == 0x34) {
|
|
|
|
size_t setup_size = (uint16_t)read_16bit(start_offset + setup_offset, streamFile);
|
|
|
|
uint32_t id = (uint32_t)read_32bitBE(start_offset + setup_offset + 0x06, streamFile);
|
|
|
|
|
|
|
|
/* if the setup after header starts with "(data)BCV" it's an inline codebook) */
|
|
|
|
if ((id & 0x00FFFFFF) == 0x00424356) { /* 0"BCV" */
|
2018-01-28 00:47:06 +01:00
|
|
|
cfg.setup_type = WWV_FULL_SETUP;
|
2017-04-13 15:05:06 +02:00
|
|
|
}
|
|
|
|
/* if the setup is suspiciously big it's probably trimmed inline codebooks */
|
|
|
|
else if (setup_size > 0x200) { /* an external setup it's ~0x100 max + some threshold */
|
2018-01-28 00:47:06 +01:00
|
|
|
cfg.setup_type = WWV_INLINE_CODEBOOKS;
|
2017-04-13 15:05:06 +02:00
|
|
|
}
|
|
|
|
}
|
2017-04-02 12:27:21 +02:00
|
|
|
|
2018-01-04 23:22:03 +01:00
|
|
|
vgmstream->codec_data = init_vorbis_custom(streamFile, start_offset + setup_offset, VORBIS_WWISE, &cfg);
|
2017-04-13 15:05:06 +02:00
|
|
|
if (!vgmstream->codec_data) goto fail;
|
2017-04-02 12:27:21 +02:00
|
|
|
}
|
2017-04-13 15:05:06 +02:00
|
|
|
else {
|
|
|
|
/* newer Wwise (>2012) */
|
|
|
|
off_t extra_offset = ww.fmt_offset + 0x18; /* after flag + channels */
|
|
|
|
int is_wem = check_extensions(streamFile,"wem");
|
|
|
|
|
|
|
|
switch(ww.extra_size) {
|
|
|
|
case 0x30:
|
|
|
|
data_offsets = 0x10;
|
|
|
|
block_offsets = 0x28;
|
2018-01-28 00:47:06 +01:00
|
|
|
cfg.header_type = WWV_TYPE_2;
|
|
|
|
cfg.packet_type = WWV_MODIFIED;
|
2017-04-13 15:05:06 +02:00
|
|
|
|
|
|
|
/* setup not detectable by header, so we'll try both; hopefully libvorbis will reject wrong codebooks
|
Fix XMA gapless/looping/samples
fixes: standard, wem, xwc, xwb, xnb, xwx, rak, pk, txth, genh, seg, rsd, past, p3d, nub-xma, gtd, gsp, fsb, eaac, cxs, awc, aac
2018-11-18 17:01:31 +01:00
|
|
|
* - standard: early (<2012), ex. The King of Fighters XIII (X360)-2011/11, .ogg (cbs are from aoTuV, too)
|
|
|
|
* - aoTuV603: later (>2012), ex. Sonic & All-Stars Racing Transformed (PC)-2012/11, .wem */
|
2018-01-28 00:47:06 +01:00
|
|
|
cfg.setup_type = is_wem ? WWV_AOTUV603_CODEBOOKS : WWV_EXTERNAL_CODEBOOKS; /* aoTuV came along .wem */
|
2017-04-13 15:05:06 +02:00
|
|
|
break;
|
2017-04-15 23:07:15 +02:00
|
|
|
|
Fix XMA gapless/looping/samples
fixes: standard, wem, xwc, xwb, xnb, xwx, rak, pk, txth, genh, seg, rsd, past, p3d, nub-xma, gtd, gsp, fsb, eaac, cxs, awc, aac
2018-11-18 17:01:31 +01:00
|
|
|
//case 0x2a: /* Rocksmith 2011 (X360)? */
|
2017-04-15 23:07:15 +02:00
|
|
|
//non mod packets? TYPE_06? (possibly detectable by checking setup's granule, should be 0)
|
2017-04-13 15:05:06 +02:00
|
|
|
default:
|
|
|
|
VGM_LOG("WWISE: unknown extra size 0x%x\n", vorb_size);
|
|
|
|
goto fail;
|
|
|
|
}
|
2017-04-02 12:27:21 +02:00
|
|
|
|
2017-04-13 15:05:06 +02:00
|
|
|
vgmstream->num_samples = read_32bit(extra_offset + 0x00, streamFile);
|
2017-07-28 23:26:58 +02:00
|
|
|
setup_offset = read_32bit(extra_offset + data_offsets + 0x00, streamFile); /* within data */
|
|
|
|
audio_offset = read_32bit(extra_offset + data_offsets + 0x04, streamFile); /* within data */
|
|
|
|
cfg.blocksize_1_exp = read_8bit(extra_offset + block_offsets + 0x00, streamFile); /* small */
|
|
|
|
cfg.blocksize_0_exp = read_8bit(extra_offset + block_offsets + 0x01, streamFile); /* big */
|
2017-09-29 23:27:21 +02:00
|
|
|
ww.data_size -= audio_offset;
|
2017-04-13 15:05:06 +02:00
|
|
|
|
Fix XMA gapless/looping/samples
fixes: standard, wem, xwc, xwb, xnb, xwx, rak, pk, txth, genh, seg, rsd, past, p3d, nub-xma, gtd, gsp, fsb, eaac, cxs, awc, aac
2018-11-18 17:01:31 +01:00
|
|
|
/* Normal packets are used rarely (ex. Oddworld New 'n' Tasty! (PSV)). They are hard to detect (decoding
|
2017-04-13 20:53:49 +02:00
|
|
|
* will mostly work with garbage results) but we'll try. Setup size and "fmt" bitrate fields may matter too. */
|
|
|
|
if (ww.extra_size == 0x30) {
|
Fix XMA gapless/looping/samples
fixes: standard, wem, xwc, xwb, xnb, xwx, rak, pk, txth, genh, seg, rsd, past, p3d, nub-xma, gtd, gsp, fsb, eaac, cxs, awc, aac
2018-11-18 17:01:31 +01:00
|
|
|
/* all blocksizes I've seen are 0x08+0x0B except Oddworld (PSV), that uses 0x09+0x09
|
2017-04-13 20:53:49 +02:00
|
|
|
* (maybe lower spec machines = needs simpler packets) */
|
2017-07-28 23:26:58 +02:00
|
|
|
if (cfg.blocksize_0_exp == cfg.blocksize_1_exp)
|
2018-01-28 00:47:06 +01:00
|
|
|
cfg.packet_type = WWV_STANDARD;
|
2017-04-13 20:53:49 +02:00
|
|
|
}
|
|
|
|
|
2017-04-13 15:05:06 +02:00
|
|
|
/* try with the selected codebooks */
|
2018-01-04 23:22:03 +01:00
|
|
|
vgmstream->codec_data = init_vorbis_custom(streamFile, start_offset + setup_offset, VORBIS_WWISE, &cfg);
|
2017-04-13 15:05:06 +02:00
|
|
|
if (!vgmstream->codec_data) {
|
|
|
|
/* codebooks failed: try again with the other type */
|
2018-01-28 00:47:06 +01:00
|
|
|
cfg.setup_type = is_wem ? WWV_EXTERNAL_CODEBOOKS : WWV_AOTUV603_CODEBOOKS;
|
2018-01-04 23:22:03 +01:00
|
|
|
vgmstream->codec_data = init_vorbis_custom(streamFile, start_offset + setup_offset, VORBIS_WWISE, &cfg);
|
2017-04-13 15:05:06 +02:00
|
|
|
if (!vgmstream->codec_data) goto fail;
|
|
|
|
}
|
|
|
|
}
|
2017-04-02 12:27:21 +02:00
|
|
|
vgmstream->layout_type = layout_none;
|
2017-07-28 23:26:58 +02:00
|
|
|
vgmstream->coding_type = coding_VORBIS_custom;
|
2017-04-11 20:01:17 +02:00
|
|
|
vgmstream->codec_endian = ww.big_endian;
|
2017-04-13 15:05:06 +02:00
|
|
|
|
2017-09-24 18:55:25 +02:00
|
|
|
start_offset += audio_offset;
|
2017-04-14 01:05:55 +02:00
|
|
|
|
2018-10-27 22:26:21 +02:00
|
|
|
/* Vorbis is VBR so this is very approximate percent, meh */
|
2018-11-09 21:03:16 +01:00
|
|
|
if (ww.truncated) {
|
2018-10-27 22:26:21 +02:00
|
|
|
vgmstream->num_samples = (int32_t)(vgmstream->num_samples *
|
|
|
|
(double)(ww.file_size - start_offset) / (double)ww.data_size);
|
2018-11-09 21:03:16 +01:00
|
|
|
}
|
2017-10-08 17:34:07 +02:00
|
|
|
|
2017-04-02 12:27:21 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case DSP: { /* Wii/3DS/WiiU */
|
|
|
|
off_t wiih_offset;
|
|
|
|
size_t wiih_size;
|
|
|
|
int i;
|
|
|
|
|
2018-05-19 11:21:40 +02:00
|
|
|
//if (ww.fmt_size != 0x28 && ww.fmt_size != ?) goto fail; /* old, new */
|
2017-04-07 20:21:55 +02:00
|
|
|
if (ww.bits_per_sample != 4) goto fail;
|
2017-04-02 12:27:21 +02:00
|
|
|
|
|
|
|
vgmstream->coding_type = coding_NGC_DSP;
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
2018-05-19 11:21:40 +02:00
|
|
|
vgmstream->interleave_block_size = 0x08; /* ww.block_align = 0x8 in older Wwise, samples per block in newer Wwise */
|
2017-04-02 12:27:21 +02:00
|
|
|
|
|
|
|
/* find coef position */
|
Fix XMA gapless/looping/samples
fixes: standard, wem, xwc, xwb, xnb, xwx, rak, pk, txth, genh, seg, rsd, past, p3d, nub-xma, gtd, gsp, fsb, eaac, cxs, awc, aac
2018-11-18 17:01:31 +01:00
|
|
|
if (find_chunk(streamFile, 0x57696948,first_offset,0, &wiih_offset,&wiih_size, ww.big_endian, 0)) { /*"WiiH", older Wwise */
|
2017-04-07 20:21:55 +02:00
|
|
|
vgmstream->num_samples = dsp_bytes_to_samples(ww.data_size, ww.channels);
|
2017-04-02 12:27:21 +02:00
|
|
|
if (wiih_size != 0x2e * ww.channels) goto fail;
|
|
|
|
}
|
|
|
|
else if (ww.extra_size == 0x0c + ww.channels * 0x2e) { /* newer Wwise */
|
|
|
|
vgmstream->num_samples = read_32bit(ww.fmt_offset + 0x18, streamFile);
|
|
|
|
wiih_offset = ww.fmt_offset + 0x1c;
|
|
|
|
wiih_size = 0x2e * ww.channels;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get coefs and default history */
|
|
|
|
dsp_read_coefs(vgmstream,streamFile,wiih_offset, 0x2e, ww.big_endian);
|
|
|
|
for (i=0; i < ww.channels; i++) {
|
|
|
|
vgmstream->ch[i].adpcm_history1_16 = read_16bitBE(wiih_offset + i * 0x2e + 0x24,streamFile);
|
|
|
|
vgmstream->ch[i].adpcm_history2_16 = read_16bitBE(wiih_offset + i * 0x2e + 0x26,streamFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef VGM_USE_FFMPEG
|
|
|
|
case XMA2: { /* X360/XBone */
|
2017-04-08 13:40:23 +02:00
|
|
|
uint8_t buf[0x100];
|
|
|
|
int bytes;
|
|
|
|
off_t xma2_offset;
|
|
|
|
size_t xma2_size;
|
2017-04-02 12:27:21 +02:00
|
|
|
|
2018-06-17 00:50:42 +02:00
|
|
|
/* endian check should be enough */
|
|
|
|
//if (ww.fmt_size != ...) goto fail; /* XMA1 0x20, XMA2old: 0x34, XMA2new: 0x40, XMA2 Guitar Hero Live/padded: 0x64, etc */
|
2017-04-08 13:40:23 +02:00
|
|
|
if (!ww.big_endian) goto fail; /* must be Wwise (real XMA are LE and parsed elsewhere) */
|
2017-04-07 20:21:55 +02:00
|
|
|
|
2017-04-08 13:40:23 +02:00
|
|
|
if (find_chunk(streamFile, 0x584D4132,first_offset,0, &xma2_offset,&xma2_size, ww.big_endian, 0)) { /*"XMA2"*/ /* older Wwise */
|
|
|
|
bytes = ffmpeg_make_riff_xma2_from_xma2_chunk(buf,0x100, xma2_offset, xma2_size, ww.data_size, streamFile);
|
|
|
|
} else { /* newer Wwise */
|
2017-04-15 23:58:19 +02:00
|
|
|
bytes = ffmpeg_make_riff_xma_from_fmt_chunk(buf,0x100, ww.fmt_offset, ww.fmt_size, ww.data_size, streamFile, ww.big_endian);
|
2017-04-08 13:40:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
vgmstream->codec_data = init_ffmpeg_header_offset(streamFile, buf,bytes, ww.data_offset,ww.data_size);
|
|
|
|
if ( !vgmstream->codec_data ) goto fail;
|
|
|
|
vgmstream->coding_type = coding_FFmpeg;
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
|
|
|
|
vgmstream->num_samples = ww.num_samples; /* set while parsing XMAWAVEFORMATs */
|
|
|
|
|
Fix XMA gapless/looping/samples
fixes: standard, wem, xwc, xwb, xnb, xwx, rak, pk, txth, genh, seg, rsd, past, p3d, nub-xma, gtd, gsp, fsb, eaac, cxs, awc, aac
2018-11-18 17:01:31 +01:00
|
|
|
/* Wwise loops are always pre-adjusted (old or new) and only num_samples is off */
|
|
|
|
xma_fix_raw_samples(vgmstream, streamFile, ww.data_offset,ww.data_size, ww.chunk_offset, 1,0);
|
|
|
|
|
2017-04-13 15:05:06 +02:00
|
|
|
/* "XMAc": rare Wwise extension, XMA2 physical loop regions (loop_start_b, loop_end_b, loop_subframe_data)
|
|
|
|
* Can appear even in the file doesn't loop, maybe it's meant to be the playable physical region */
|
|
|
|
//VGM_ASSERT(find_chunk(streamFile, 0x584D4163,first_offset,0, NULL,NULL, ww.big_endian, 0), "WWISE: XMAc chunk found\n");
|
2017-04-08 13:40:23 +02:00
|
|
|
/* other chunks: "seek", regular XMA2 seek table */
|
|
|
|
|
2018-11-09 21:03:16 +01:00
|
|
|
/* XMA is VBR so this is very approximate percent, meh */
|
|
|
|
if (ww.truncated) {
|
|
|
|
vgmstream->num_samples = (int32_t)(vgmstream->num_samples *
|
|
|
|
(double)(ww.file_size - start_offset) / (double)ww.data_size);
|
|
|
|
}
|
|
|
|
|
2017-04-08 13:40:23 +02:00
|
|
|
break;
|
2017-04-02 12:27:21 +02:00
|
|
|
}
|
|
|
|
|
2017-04-07 20:21:55 +02:00
|
|
|
case XWMA: { /* X360 */
|
|
|
|
ffmpeg_codec_data *ffmpeg_data = NULL;
|
2017-04-08 13:40:23 +02:00
|
|
|
uint8_t buf[0x100];
|
2017-04-07 20:21:55 +02:00
|
|
|
int bytes;
|
|
|
|
|
2018-05-19 11:21:40 +02:00
|
|
|
if (ww.fmt_size != 0x18) goto fail;
|
2017-04-07 20:21:55 +02:00
|
|
|
if (!ww.big_endian) goto fail; /* must be from Wwise X360 (PC LE XWMA is parsed elsewhere) */
|
|
|
|
|
2017-04-08 13:40:23 +02:00
|
|
|
bytes = ffmpeg_make_riff_xwma(buf,0x100, ww.format, ww.data_size, vgmstream->channels, vgmstream->sample_rate, ww.average_bps, ww.block_align);
|
2017-04-07 20:21:55 +02:00
|
|
|
ffmpeg_data = init_ffmpeg_header_offset(streamFile, buf,bytes, ww.data_offset,ww.data_size);
|
|
|
|
if ( !ffmpeg_data ) goto fail;
|
|
|
|
vgmstream->codec_data = ffmpeg_data;
|
|
|
|
vgmstream->coding_type = coding_FFmpeg;
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
|
2017-10-08 17:34:07 +02:00
|
|
|
|
2017-04-07 20:21:55 +02:00
|
|
|
/* manually find total samples, why don't they put this in the header is beyond me */
|
2017-04-22 11:31:04 +02:00
|
|
|
{
|
2018-05-19 11:21:40 +02:00
|
|
|
ms_sample_data msd = {0};
|
2017-04-07 20:21:55 +02:00
|
|
|
|
|
|
|
msd.channels = ww.channels;
|
|
|
|
msd.data_offset = ww.data_offset;
|
|
|
|
msd.data_size = ww.data_size;
|
|
|
|
|
2017-04-22 11:31:04 +02:00
|
|
|
if (ww.format == 0x0162)
|
2017-10-08 17:34:07 +02:00
|
|
|
wmapro_get_samples(&msd, streamFile, ww.block_align, ww.sample_rate,0x00E0);
|
2017-04-22 11:31:04 +02:00
|
|
|
else
|
2017-10-08 17:34:07 +02:00
|
|
|
wma_get_samples(&msd, streamFile, ww.block_align, ww.sample_rate,0x001F);
|
2017-04-22 11:31:04 +02:00
|
|
|
|
2017-10-08 17:34:07 +02:00
|
|
|
vgmstream->num_samples = msd.num_samples;
|
|
|
|
if (!vgmstream->num_samples)
|
2018-03-03 19:07:59 +01:00
|
|
|
vgmstream->num_samples = (int32_t)ffmpeg_data->totalSamples; /* very wrong, from avg-br */
|
2017-10-08 17:34:07 +02:00
|
|
|
//num_samples seem to be found in the last "seek" table entry too, as: entry / channels / 2
|
2017-04-07 20:21:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2017-04-02 12:27:21 +02:00
|
|
|
|
|
|
|
case AAC: { /* iOS/Mac */
|
|
|
|
ffmpeg_codec_data * ffmpeg_data = NULL;
|
2018-05-19 11:21:40 +02:00
|
|
|
|
|
|
|
if (ww.fmt_size != 0x24) goto fail;
|
2017-04-07 20:21:55 +02:00
|
|
|
if (ww.block_align != 0 || ww.bits_per_sample != 0) goto fail;
|
2017-04-02 12:27:21 +02:00
|
|
|
|
|
|
|
/* extra: size 0x12, unknown values */
|
|
|
|
|
|
|
|
ffmpeg_data = init_ffmpeg_offset(streamFile, ww.data_offset,ww.data_size);
|
|
|
|
if (!ffmpeg_data) goto fail;
|
|
|
|
vgmstream->codec_data = ffmpeg_data;
|
|
|
|
vgmstream->coding_type = coding_FFmpeg;
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
|
2018-03-03 19:07:59 +01:00
|
|
|
vgmstream->num_samples = (int32_t)ffmpeg_data->totalSamples;
|
2017-04-02 12:27:21 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-09-24 18:55:25 +02:00
|
|
|
|
2018-11-17 15:52:02 +01:00
|
|
|
case OPUS: { /* Switch */
|
2018-09-27 23:40:42 +02:00
|
|
|
size_t skip;
|
2017-09-24 18:55:25 +02:00
|
|
|
|
|
|
|
/* values up to 0x14 seem fixed and similar to HEVAG's (block_align 0x02/04, bits_per_sample 0x10) */
|
|
|
|
if (ww.fmt_size == 0x28) {
|
|
|
|
size_t seek_size;
|
|
|
|
|
|
|
|
vgmstream->num_samples += read_32bit(ww.fmt_offset + 0x18, streamFile);
|
2017-09-29 23:27:21 +02:00
|
|
|
/* 0x1c: null? 0x20: data_size without seek_size */
|
2017-09-24 18:55:25 +02:00
|
|
|
seek_size = read_32bit(ww.fmt_offset + 0x24, streamFile);
|
|
|
|
|
|
|
|
start_offset += seek_size;
|
|
|
|
ww.data_size -= seek_size;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2018-09-27 23:40:42 +02:00
|
|
|
skip = switch_opus_get_encoder_delay(start_offset, streamFile); /* should be 120 */
|
|
|
|
|
2018-09-10 01:23:34 +02:00
|
|
|
vgmstream->codec_data = init_ffmpeg_switch_opus(streamFile, start_offset,ww.data_size, vgmstream->channels, skip, vgmstream->sample_rate);
|
2017-09-24 18:55:25 +02:00
|
|
|
if (!vgmstream->codec_data) goto fail;
|
|
|
|
vgmstream->coding_type = coding_FFmpeg;
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
break;
|
|
|
|
}
|
2017-04-02 12:27:21 +02:00
|
|
|
#endif
|
|
|
|
case HEVAG: /* PSV */
|
2017-04-02 15:22:03 +02:00
|
|
|
/* changed values, another bizarre Wwise quirk */
|
|
|
|
//ww.block_align /* unknown (1ch=2, 2ch=4) */
|
2017-09-24 18:55:25 +02:00
|
|
|
//ww.bits_per_sample; /* unknown (0x10) */
|
2017-04-07 20:21:55 +02:00
|
|
|
//if (ww.bits_per_sample != 4) goto fail;
|
2017-04-02 12:27:21 +02:00
|
|
|
|
2018-05-19 11:21:40 +02:00
|
|
|
if (ww.fmt_size != 0x18) goto fail;
|
2017-04-02 12:27:21 +02:00
|
|
|
if (ww.big_endian) goto fail;
|
|
|
|
|
2017-04-07 20:21:55 +02:00
|
|
|
/* extra_data: size 0x06, @0x00: samples per block (0x1c), @0x04: channel config */
|
2017-04-02 15:22:03 +02:00
|
|
|
|
2017-04-02 12:27:21 +02:00
|
|
|
vgmstream->coding_type = coding_HEVAG;
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
2017-04-02 15:22:03 +02:00
|
|
|
vgmstream->interleave_block_size = 0x10;
|
2017-04-02 12:27:21 +02:00
|
|
|
|
2017-04-07 20:21:55 +02:00
|
|
|
vgmstream->num_samples = ps_bytes_to_samples(ww.data_size, ww.channels);
|
2017-04-02 12:27:21 +02:00
|
|
|
break;
|
|
|
|
|
2017-12-28 23:37:18 +01:00
|
|
|
#ifdef VGM_USE_ATRAC9
|
|
|
|
case ATRAC9: { /* PSV/PS4 */
|
|
|
|
atrac9_config cfg = {0};
|
2018-05-19 11:21:40 +02:00
|
|
|
|
|
|
|
if (ww.fmt_size != 0x24) goto fail;
|
2017-12-28 23:37:18 +01:00
|
|
|
if (ww.extra_size != 0x12) goto fail;
|
|
|
|
|
|
|
|
cfg.channels = vgmstream->channels;
|
|
|
|
cfg.config_data = read_32bitBE(ww.fmt_offset+0x18,streamFile);
|
|
|
|
cfg.encoder_delay = read_32bit(ww.fmt_offset+0x20,streamFile);
|
|
|
|
|
|
|
|
vgmstream->codec_data = init_atrac9(&cfg);
|
|
|
|
if (!vgmstream->codec_data) goto fail;
|
|
|
|
vgmstream->coding_type = coding_ATRAC9;
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
|
|
|
|
vgmstream->num_samples = read_32bit(ww.fmt_offset+0x1c,streamFile);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2017-04-02 12:27:21 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( !vgmstream_open_stream(vgmstream,streamFile,start_offset) )
|
|
|
|
goto fail;
|
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-04-13 15:05:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* VORBIS FORMAT RESEARCH */
|
|
|
|
/*
|
|
|
|
- old format
|
|
|
|
"fmt" size 0x28, extra size 0x16 / size 0x18, extra size 0x06
|
|
|
|
0x12 (2): flag? (00,10,18): not related to seek table, codebook type, chunk count, looping
|
|
|
|
0x14 (4): channel config
|
|
|
|
0x18-24 (16): ? (fixed: 0x01000000 00001000 800000AA 00389B71) [removed when extra size is 0x06]
|
|
|
|
|
|
|
|
"vorb" size 0x34
|
|
|
|
0x00 (4): num_samples
|
|
|
|
0x04 (4): skip samples?
|
|
|
|
0x08 (4): ? (small if loop, 0 otherwise)
|
2017-11-10 19:30:25 +01:00
|
|
|
0x0c (4): data start offset after seek table+setup, or loop start when "smpl" is present
|
2017-04-13 15:05:06 +02:00
|
|
|
0x10 (4): ? (small, 0..~0x400)
|
|
|
|
0x14 (4): approximate data size without seek table? (almost setup+packets)
|
|
|
|
0x18 (4): setup_offset within data (0 = no seek table)
|
|
|
|
0x1c (4): audio_offset within data
|
2017-11-10 19:30:25 +01:00
|
|
|
0x20 (2): biggest packet size (not including header)?
|
|
|
|
0x22 (2): ? (small, N..~0x100) uLastGranuleExtra?
|
|
|
|
0x24 (4): ? (mid, 0~0x5000) dwDecodeAllocSize?
|
|
|
|
0x28 (4): ? (mid, 0~0x5000) dwDecodeX64AllocSize?
|
|
|
|
0x2c (4): parent bank/event id? uHashCodebook? (shared by several .wem a game, but not all need to share it)
|
2017-04-13 15:05:06 +02:00
|
|
|
0x30 (1): blocksize_1_exp (small)
|
|
|
|
0x31 (1): blocksize_0_exp (large)
|
|
|
|
0x32 (2): empty
|
|
|
|
|
2018-03-23 16:00:23 +01:00
|
|
|
"vorb" size 0x28 / 0x2c / 0x2a
|
2017-04-13 15:05:06 +02:00
|
|
|
0x00 (4): num_samples
|
2017-11-10 19:30:25 +01:00
|
|
|
0x04 (4): data start offset after seek table+setup, or loop start when "smpl" is present
|
|
|
|
0x08 (4): data end offset after seek table (setup+packets), or loop end when "smpl" is present
|
2018-03-23 16:00:23 +01:00
|
|
|
0x0c (2): ? (small, 0..~0x400) [(4) when size is 0x2C]
|
2017-04-13 15:05:06 +02:00
|
|
|
0x10 (4): setup_offset within data (0 = no seek table)
|
|
|
|
0x14 (4): audio_offset within data
|
2017-11-10 19:30:25 +01:00
|
|
|
0x18 (2): biggest packet size (not including header)?
|
2018-03-23 16:00:23 +01:00
|
|
|
0x1a (2): ? (small, N..~0x100) uLastGranuleExtra? [(4) when size is 0x2C]
|
2017-11-10 19:30:25 +01:00
|
|
|
0x1c (4): ? (mid, 0~0x5000) dwDecodeAllocSize?
|
|
|
|
0x20 (4): ? (mid, 0~0x5000) dwDecodeX64AllocSize?
|
|
|
|
0x24 (4): parent bank/event id? uHashCodebook? (shared by several .wem a game, but not all need to share it)
|
|
|
|
0x28 (1): blocksize_1_exp (small) [removed when size is 0x28]
|
|
|
|
0x29 (1): blocksize_0_exp (large) [removed when size is 0x28]
|
2017-04-13 15:05:06 +02:00
|
|
|
|
|
|
|
- new format:
|
|
|
|
"fmt" size 0x42, extra size 0x30
|
|
|
|
0x12 (2): flag? (00,10,18): not related to seek table, codebook type, chunk count, looping, etc
|
|
|
|
0x14 (4): channel config
|
|
|
|
0x18 (4): num_samples
|
2017-11-10 19:30:25 +01:00
|
|
|
0x1c (4): data start offset after seek table+setup, or loop start when "smpl" is present
|
|
|
|
0x20 (4): data end offset after seek table (setup+packets), or loop end when "smpl" is present
|
2017-04-13 15:05:06 +02:00
|
|
|
0x24 (2): ?1 (small, 0..~0x400)
|
|
|
|
0x26 (2): ?2 (small, N..~0x100): not related to seek table, codebook type, chunk count, looping, packet size, samples, etc
|
|
|
|
0x28 (4): setup offset within data (0 = no seek table)
|
|
|
|
0x2c (4): audio offset within data
|
|
|
|
0x30 (2): biggest packet size (not including header)
|
2017-11-10 19:30:25 +01:00
|
|
|
0x32 (2): (small, 0..~0x100) uLastGranuleExtra?
|
|
|
|
0x34 (4): ? (mid, 0~0x5000) dwDecodeAllocSize?
|
|
|
|
0x38 (4): ? (mid, 0~0x5000) dwDecodeX64AllocSize?
|
2017-04-13 15:05:06 +02:00
|
|
|
0x40 (1): blocksize_1_exp (small)
|
|
|
|
0x41 (1): blocksize_0_exp (large)
|
|
|
|
|
|
|
|
Wwise encoder options, unknown fields above may be reflect these:
|
|
|
|
https://www.audiokinetic.com/library/edge/?source=Help&id=vorbis_encoder_parameters
|
|
|
|
*/
|