2019-10-19 11:13:02 +02:00
|
|
|
#include <string.h>
|
2008-07-06 20:05:04 +02:00
|
|
|
#include "meta.h"
|
2011-12-14 01:04:03 +01:00
|
|
|
#include "../coding/coding.h"
|
2008-07-06 20:05:04 +02:00
|
|
|
#include "../layout/layout.h"
|
|
|
|
#include "../util.h"
|
2023-05-07 22:00:30 +02:00
|
|
|
#include "../util/channel_mappings.h"
|
2019-10-19 11:13:02 +02:00
|
|
|
#include "riff_ogg_streamfile.h"
|
2008-07-06 20:05:04 +02:00
|
|
|
|
2017-12-27 00:43:52 +01:00
|
|
|
/* RIFF - Resource Interchange File Format, standard container used in many games */
|
2008-07-06 20:05:04 +02:00
|
|
|
|
2019-01-19 23:08:26 +01:00
|
|
|
|
2008-07-21 07:03:16 +02:00
|
|
|
/* return milliseconds */
|
2020-06-30 23:20:36 +02:00
|
|
|
static long parse_adtl_marker(unsigned char* marker) {
|
2008-07-21 07:03:16 +02:00
|
|
|
long hh,mm,ss,ms;
|
2018-08-26 13:47:02 +02:00
|
|
|
|
2008-07-21 07:03:16 +02:00
|
|
|
if (memcmp("Marker ",marker,7)) return -1;
|
|
|
|
|
|
|
|
if (4 != sscanf((char*)marker+7,"%ld:%ld:%ld.%ld",&hh,&mm,&ss,&ms))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return ((hh*60+mm)*60+ss)*1000+ms;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* loop points have been found hiding here */
|
2020-06-30 23:20:36 +02:00
|
|
|
static void parse_adtl(off_t adtl_offset, off_t adtl_length, STREAMFILE* sf, long* loop_start, long* loop_end, int* loop_flag) {
|
2008-07-21 07:03:16 +02:00
|
|
|
int loop_start_found = 0;
|
|
|
|
int loop_end_found = 0;
|
2018-08-26 13:47:02 +02:00
|
|
|
off_t current_chunk = adtl_offset+0x04;
|
2008-07-21 07:03:16 +02:00
|
|
|
|
2018-08-26 13:47:02 +02:00
|
|
|
while (current_chunk < adtl_offset + adtl_length) {
|
2021-08-22 12:17:45 +02:00
|
|
|
uint32_t chunk_type = read_u32be(current_chunk+0x00,sf);
|
|
|
|
uint32_t chunk_size = read_u32le(current_chunk+0x04,sf);
|
2008-07-21 07:03:16 +02:00
|
|
|
|
2018-08-26 13:47:02 +02:00
|
|
|
if (current_chunk+0x08+chunk_size > adtl_offset+adtl_length)
|
|
|
|
return;
|
2008-07-21 07:03:16 +02:00
|
|
|
|
|
|
|
switch(chunk_type) {
|
2018-08-26 13:47:02 +02:00
|
|
|
case 0x6c61626c: { /* "labl" */
|
|
|
|
unsigned char *labelcontent = malloc(chunk_size-0x04);
|
2017-12-27 00:43:52 +01:00
|
|
|
if (!labelcontent) return;
|
2020-06-30 23:20:36 +02:00
|
|
|
if (read_streamfile(labelcontent,current_chunk+0x0c, chunk_size-0x04,sf) != chunk_size-0x04) {
|
2008-07-21 07:03:16 +02:00
|
|
|
free(labelcontent);
|
2017-12-27 00:43:52 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-30 23:20:36 +02:00
|
|
|
switch (read_32bitLE(current_chunk+8,sf)) {
|
2017-12-27 00:43:52 +01:00
|
|
|
case 1:
|
2018-08-26 13:47:02 +02:00
|
|
|
if (!loop_start_found && (*loop_start = parse_adtl_marker(labelcontent)) >= 0)
|
2017-12-27 00:43:52 +01:00
|
|
|
loop_start_found = 1;
|
|
|
|
break;
|
|
|
|
case 2:
|
2018-08-26 13:47:02 +02:00
|
|
|
if (!loop_end_found && (*loop_end = parse_adtl_marker(labelcontent)) >= 0)
|
2017-12-27 00:43:52 +01:00
|
|
|
loop_end_found = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2008-07-21 07:03:16 +02:00
|
|
|
}
|
2017-12-27 00:43:52 +01:00
|
|
|
|
|
|
|
free(labelcontent);
|
2008-07-21 07:03:16 +02:00
|
|
|
break;
|
2017-12-27 00:43:52 +01:00
|
|
|
}
|
2008-07-21 07:03:16 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
current_chunk += 8 + chunk_size;
|
|
|
|
}
|
|
|
|
|
2017-12-27 00:43:52 +01:00
|
|
|
if (loop_start_found && loop_end_found)
|
|
|
|
*loop_flag = 1;
|
2008-07-21 07:03:16 +02:00
|
|
|
|
|
|
|
/* labels don't seem to be consistently ordered */
|
|
|
|
if (*loop_start > *loop_end) {
|
|
|
|
long temp = *loop_start;
|
|
|
|
*loop_start = *loop_end;
|
|
|
|
*loop_end = temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-27 00:43:52 +01:00
|
|
|
typedef struct {
|
2014-02-26 07:12:24 +01:00
|
|
|
off_t offset;
|
|
|
|
off_t size;
|
2018-01-21 01:47:02 +01:00
|
|
|
uint32_t codec;
|
2012-08-20 07:17:52 +02:00
|
|
|
int sample_rate;
|
2021-08-22 12:17:45 +02:00
|
|
|
int channels;
|
2012-08-20 07:17:52 +02:00
|
|
|
uint32_t block_size;
|
2018-01-21 01:47:02 +01:00
|
|
|
int bps;
|
2019-03-02 16:16:02 +01:00
|
|
|
off_t extra_size;
|
|
|
|
uint32_t channel_layout;
|
2017-12-27 00:43:52 +01:00
|
|
|
|
2012-08-20 07:17:52 +02:00
|
|
|
int coding_type;
|
|
|
|
int interleave;
|
2019-03-24 15:34:49 +01:00
|
|
|
|
|
|
|
int is_at3;
|
2019-08-25 20:46:29 +02:00
|
|
|
int is_at3p;
|
2019-03-24 15:34:49 +01:00
|
|
|
int is_at9;
|
2017-12-27 00:43:52 +01:00
|
|
|
} riff_fmt_chunk;
|
2012-08-20 07:17:52 +02:00
|
|
|
|
2022-12-31 17:31:20 +01:00
|
|
|
static int read_fmt(int big_endian, STREAMFILE* sf, off_t offset, riff_fmt_chunk* fmt) {
|
2021-08-22 12:17:45 +02:00
|
|
|
uint32_t (*read_u32)(off_t,STREAMFILE*) = big_endian ? read_u32be : read_u32le;
|
|
|
|
uint16_t (*read_u16)(off_t,STREAMFILE*) = big_endian ? read_u16be : read_u16le;
|
2012-08-20 07:17:52 +02:00
|
|
|
|
2021-08-22 12:17:45 +02:00
|
|
|
fmt->offset = offset;
|
|
|
|
fmt->size = read_u32(offset+0x04,sf);
|
2014-02-26 07:12:24 +01:00
|
|
|
|
2019-03-02 16:16:02 +01:00
|
|
|
/* WAVEFORMAT */
|
2022-01-08 21:00:13 +01:00
|
|
|
fmt->codec = read_u16(offset+0x08+0x00,sf);
|
|
|
|
fmt->channels = read_u16(offset+0x08+0x02,sf);
|
|
|
|
fmt->sample_rate = read_u32(offset+0x08+0x04,sf);
|
|
|
|
//fmt->avg_bps = read_u32(offset+0x08+0x08,sf);
|
|
|
|
fmt->block_size = read_u16(offset+0x08+0x0c,sf);
|
|
|
|
fmt->bps = read_u16(offset+0x08+0x0e,sf);
|
2019-03-02 16:16:02 +01:00
|
|
|
/* WAVEFORMATEX */
|
|
|
|
if (fmt->size >= 0x10) {
|
2022-01-08 21:00:13 +01:00
|
|
|
fmt->extra_size = read_u16(offset+0x08+0x10,sf);
|
2019-03-02 16:16:02 +01:00
|
|
|
/* 0x1a+ depends on codec (ex. coef table for MSADPCM, samples_per_frame in MS-IMA, etc) */
|
|
|
|
}
|
|
|
|
/* WAVEFORMATEXTENSIBLE */
|
|
|
|
if (fmt->codec == 0xFFFE && fmt->extra_size >= 0x16) {
|
2022-01-08 21:00:13 +01:00
|
|
|
//fmt->extra_samples = read_u16(offset+0x08+0x12,sf); /* valid_bits_per_sample or samples_per_block */
|
|
|
|
fmt->channel_layout = read_u32(offset+0x08+0x14,sf);
|
2019-03-02 16:16:02 +01:00
|
|
|
/* 0x10 guid at 0x20 */
|
2019-05-01 23:21:59 +02:00
|
|
|
|
2019-08-26 23:00:17 +02:00
|
|
|
/* happens in various .at3/at9, may be a bug in their encoder b/c MS's defs set mono as FC */
|
2021-08-22 12:17:45 +02:00
|
|
|
if (fmt->channels == 1 && fmt->channel_layout == speaker_FL) { /* other channels are fine */
|
2019-05-01 23:21:59 +02:00
|
|
|
fmt->channel_layout = speaker_FC;
|
|
|
|
}
|
2019-08-26 23:00:17 +02:00
|
|
|
|
|
|
|
/* happens in few at3p, may be a bug in older tools as other games have ok flags [Ridge Racer 7 (PS3)] */
|
2021-08-22 12:17:45 +02:00
|
|
|
if (fmt->channels == 6 && fmt->channel_layout == 0x013f) {
|
2019-08-26 23:00:17 +02:00
|
|
|
fmt->channel_layout = 0x3f;
|
|
|
|
}
|
2019-03-02 16:16:02 +01:00
|
|
|
}
|
2017-06-24 23:09:30 +02:00
|
|
|
|
2021-11-12 18:45:18 +01:00
|
|
|
if (!fmt->channels)
|
|
|
|
goto fail;
|
|
|
|
|
2018-01-21 01:47:02 +01:00
|
|
|
switch (fmt->codec) {
|
2022-01-08 21:00:13 +01:00
|
|
|
case 0x0000: /* Yamaha AICA ADPCM [Headhunter (DC), Bomber hehhe (DC), Rayman 2 (DC)] (unofficial) */
|
2018-03-28 22:58:37 +02:00
|
|
|
if (fmt->bps != 4) goto fail;
|
2021-08-22 12:17:45 +02:00
|
|
|
if (fmt->block_size != 0x02*fmt->channels &&
|
|
|
|
fmt->block_size != 0x01*fmt->channels) goto fail;
|
2019-09-21 19:15:01 +02:00
|
|
|
fmt->coding_type = coding_AICA_int;
|
2018-03-28 22:58:37 +02:00
|
|
|
fmt->interleave = 0x01;
|
|
|
|
break;
|
|
|
|
|
2022-01-08 21:00:13 +01:00
|
|
|
case 0x0001: /* PCM */
|
2018-01-21 01:47:02 +01:00
|
|
|
switch (fmt->bps) {
|
2023-08-18 07:20:22 +02:00
|
|
|
case 32:
|
|
|
|
fmt->coding_type = coding_PCM32LE;
|
|
|
|
break;
|
2021-11-12 18:45:18 +01:00
|
|
|
case 24: /* Omori (PC) */
|
|
|
|
fmt->coding_type = coding_PCM24LE;
|
|
|
|
break;
|
2012-08-20 07:17:52 +02:00
|
|
|
case 16:
|
2017-12-27 00:43:52 +01:00
|
|
|
fmt->coding_type = big_endian ? coding_PCM16BE : coding_PCM16LE;
|
2022-02-06 13:15:10 +01:00
|
|
|
/* broken block size [Rayman 2 (DC)] */
|
|
|
|
if (fmt->block_size == 0x02 && fmt->channels > 1)
|
|
|
|
fmt->block_size = 0x02 * fmt->channels;
|
2012-08-20 07:17:52 +02:00
|
|
|
break;
|
|
|
|
case 8:
|
2019-09-14 12:42:08 +02:00
|
|
|
fmt->coding_type = coding_PCM8_U;
|
2012-08-20 07:17:52 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto fail;
|
|
|
|
}
|
2021-11-12 18:45:18 +01:00
|
|
|
fmt->interleave = fmt->block_size / fmt->channels;
|
2012-08-20 07:17:52 +02:00
|
|
|
break;
|
2014-02-26 07:12:24 +01:00
|
|
|
|
2022-01-08 21:00:13 +01:00
|
|
|
case 0x0002: /* MSADPCM */
|
2018-09-22 16:12:36 +02:00
|
|
|
if (fmt->bps == 4) {
|
2023-09-15 17:29:42 +02:00
|
|
|
/* ADPCMWAVEFORMAT extra data:
|
|
|
|
* - samples per frame (16b)
|
|
|
|
* - num coefs (16b), always 7
|
|
|
|
* - N x2 coefs (configurable but in practice fixed) */
|
2018-09-22 16:12:36 +02:00
|
|
|
fmt->coding_type = coding_MSADPCM;
|
2020-06-30 23:20:36 +02:00
|
|
|
if (!msadpcm_check_coefs(sf, fmt->offset + 0x08 + 0x14))
|
2019-10-20 16:35:52 +02:00
|
|
|
goto fail;
|
2018-09-22 16:12:36 +02:00
|
|
|
}
|
2021-08-22 12:17:45 +02:00
|
|
|
else if (fmt->bps == 16 && fmt->block_size == 0x02 * fmt->channels && fmt->size == 0x14) {
|
2018-09-22 16:12:36 +02:00
|
|
|
fmt->coding_type = coding_IMA; /* MX vs ATV Unleashed (PC) codec hijack */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
goto fail;
|
|
|
|
}
|
2012-08-20 07:17:52 +02:00
|
|
|
break;
|
2023-09-15 17:29:42 +02:00
|
|
|
case 0x0003: /* floating point PCM */
|
2023-08-18 06:44:37 +02:00
|
|
|
if (fmt->bps == 32) {
|
|
|
|
fmt->coding_type = coding_PCMFLOAT;
|
|
|
|
} else {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
fmt->interleave = fmt->block_size / fmt->channels;
|
|
|
|
break;
|
2017-07-01 22:44:00 +02:00
|
|
|
|
2022-01-08 21:00:13 +01:00
|
|
|
case 0x0011: /* MS-IMA ADPCM [Layton Brothers: Mystery Room (iOS/Android)] */
|
2023-09-15 17:29:42 +02:00
|
|
|
/* IMAADPCMWAVEFORMAT extra data:
|
|
|
|
* - samples per frame (16b) */
|
2018-01-21 01:47:02 +01:00
|
|
|
if (fmt->bps != 4) goto fail;
|
2012-08-20 07:17:52 +02:00
|
|
|
fmt->coding_type = coding_MS_IMA;
|
|
|
|
break;
|
2017-07-01 22:44:00 +02:00
|
|
|
|
2022-01-08 21:00:13 +01:00
|
|
|
case 0x0020: /* Yamaha AICA ADPCM [Takuyo/Dynamix/etc DC games] (official-ish) */
|
2018-03-28 22:58:37 +02:00
|
|
|
if (fmt->bps != 4) goto fail;
|
2019-09-21 19:15:01 +02:00
|
|
|
fmt->coding_type = coding_AICA;
|
|
|
|
/* official RIFF spec has 0x20 as 'Yamaha ADPCM', but data is probably not pure AICA
|
|
|
|
* (maybe with headered frames and would need extra detection?) */
|
2018-03-28 22:58:37 +02:00
|
|
|
break;
|
|
|
|
|
2022-01-08 21:00:13 +01:00
|
|
|
#ifdef VGM_USE_MPEG
|
2023-06-24 14:55:25 +02:00
|
|
|
case 0x0055: /* MP3 [Bear in the Big Blue House: Bear's Imagine That! (PC), Eclipse (PC)] (official) */
|
2022-01-08 21:00:13 +01:00
|
|
|
fmt->coding_type = coding_MPEG_custom;
|
2023-06-24 14:55:25 +02:00
|
|
|
/* some oddities, unsure if part of standard:
|
2022-01-08 21:00:13 +01:00
|
|
|
* - block size is 1 (in mono)
|
2023-06-24 14:55:25 +02:00
|
|
|
* - bps is 16 for some games
|
2022-01-08 21:00:13 +01:00
|
|
|
* - extra size 0x0c, has channels? and (possibly) approx frame size */
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case 0x0069: /* XBOX IMA ADPCM [Dynasty Warriors 5 (Xbox)] */
|
2018-01-21 01:47:02 +01:00
|
|
|
if (fmt->bps != 4) goto fail;
|
2018-02-17 12:30:14 +01:00
|
|
|
fmt->coding_type = coding_XBOX_IMA;
|
2012-08-20 07:17:52 +02:00
|
|
|
break;
|
2017-07-01 22:44:00 +02:00
|
|
|
|
2018-03-28 22:58:37 +02:00
|
|
|
case 0x007A: /* MS IMA ADPCM [LA Rush (PC), Psi Ops (PC)] (unofficial) */
|
2018-02-17 17:32:58 +01:00
|
|
|
/* 0x007A is apparently "Voxware SC3" but in .MED it's just MS-IMA (0x11) */
|
2020-06-30 23:20:36 +02:00
|
|
|
if (!check_extensions(sf,"med"))
|
2017-07-01 22:44:00 +02:00
|
|
|
goto fail;
|
|
|
|
|
2018-01-21 01:47:02 +01:00
|
|
|
if (fmt->bps == 4) /* normal MS IMA */
|
2017-07-01 22:44:00 +02:00
|
|
|
fmt->coding_type = coding_MS_IMA;
|
2018-01-21 01:47:02 +01:00
|
|
|
else if (fmt->bps == 3) /* 3-bit MS IMA, used in a very few files */
|
2017-07-01 22:44:00 +02:00
|
|
|
goto fail; //fmt->coding_type = coding_MS_IMA_3BIT;
|
|
|
|
else
|
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
2019-12-14 19:54:22 +01:00
|
|
|
case 0x0300: /* IMA ADPCM [Chrono Ma:gia (Android)] (unofficial) */
|
|
|
|
if (fmt->bps != 4) goto fail;
|
2021-08-22 12:17:45 +02:00
|
|
|
if (fmt->block_size != 0x0400*fmt->channels) goto fail;
|
2019-12-14 19:54:22 +01:00
|
|
|
if (fmt->size != 0x14) goto fail;
|
2021-08-22 12:17:45 +02:00
|
|
|
if (fmt->channels != 1) goto fail; /* not seen */
|
2019-12-14 19:54:22 +01:00
|
|
|
fmt->coding_type = coding_DVI_IMA;
|
|
|
|
/* real 0x300 is "Fujitsu FM Towns SND" with block align 0x01 */
|
|
|
|
break;
|
|
|
|
|
2018-03-28 22:58:37 +02:00
|
|
|
case 0x0555: /* Level-5 0x555 ADPCM (unofficial) */
|
2012-08-20 07:17:52 +02:00
|
|
|
fmt->coding_type = coding_L5_555;
|
|
|
|
fmt->interleave = 0x12;
|
|
|
|
break;
|
2017-07-01 22:44:00 +02:00
|
|
|
|
2018-01-21 01:47:02 +01:00
|
|
|
#ifdef VGM_USE_VORBIS
|
2021-09-19 23:52:33 +02:00
|
|
|
//case 0x674f: /* Ogg Vorbis (mode 1) */
|
|
|
|
//case 0x6750: /* Ogg Vorbis (mode 2) */
|
|
|
|
//case 0x6751: /* Ogg Vorbis (mode 3) */
|
|
|
|
case 0x676f: /* Ogg Vorbis (mode 1+) [Only One 2 (PC)] */
|
2022-02-04 03:11:49 +01:00
|
|
|
case 0x6770: /* Ogg Vorbis (mode 2+) [Only One (PC)]*/
|
2021-09-19 23:52:33 +02:00
|
|
|
case 0x6771: /* Ogg Vorbis (mode 3+) [Liar-soft games] */
|
|
|
|
/* vorbis.acm codecs (official-ish, "+" = CBR-style modes?) */
|
2018-03-08 23:32:58 +01:00
|
|
|
fmt->coding_type = coding_OGG_VORBIS;
|
2018-01-21 01:47:02 +01:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2016-07-17 08:02:27 +02:00
|
|
|
#ifdef VGM_USE_FFMPEG
|
2021-08-22 12:17:45 +02:00
|
|
|
case 0x0270: /* ATRAC3 */
|
2017-12-27 00:43:52 +01:00
|
|
|
fmt->coding_type = coding_FFmpeg;
|
2019-03-24 15:34:49 +01:00
|
|
|
fmt->is_at3 = 1;
|
2017-12-27 00:43:52 +01:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2019-05-01 23:21:59 +02:00
|
|
|
case 0xFFFE: { /* WAVEFORMATEXTENSIBLE (see ksmedia.h for known GUIDs) */
|
2021-08-22 12:17:45 +02:00
|
|
|
uint32_t guid1 = read_u32 (offset+0x20,sf);
|
|
|
|
uint32_t guid2 = (read_u16 (offset+0x24,sf) << 16u) |
|
|
|
|
(read_u16 (offset+0x26,sf));
|
|
|
|
uint32_t guid3 = read_u32be(offset+0x28,sf);
|
|
|
|
uint32_t guid4 = read_u32be(offset+0x2c,sf);
|
2021-09-19 23:52:33 +02:00
|
|
|
//;VGM_LOG("riff: guid %08x %08x %08x %08x\n", guid1, guid2, guid3, guid4);
|
2019-03-02 16:16:02 +01:00
|
|
|
|
|
|
|
/* PCM GUID (0x00000001,0000,0010,80,00,00,AA,00,38,9B,71) */
|
|
|
|
if (guid1 == 0x00000001 && guid2 == 0x00000010 && guid3 == 0x800000AA && guid4 == 0x00389B71) {
|
|
|
|
switch (fmt->bps) {
|
|
|
|
case 16:
|
|
|
|
fmt->coding_type = big_endian ? coding_PCM16BE : coding_PCM16LE;
|
|
|
|
fmt->interleave = 0x02;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-07-01 22:44:00 +02:00
|
|
|
|
2019-03-02 16:16:02 +01:00
|
|
|
/* ATRAC3plus GUID (0xE923AABF,CB58,4471,A1,19,FF,FA,01,E4,CE,62) */
|
|
|
|
if (guid1 == 0xE923AABF && guid2 == 0xCB584471 && guid3 == 0xA119FFFA && guid4 == 0x01E4CE62) {
|
2021-08-22 12:17:45 +02:00
|
|
|
#ifdef VGM_USE_FFMPEG
|
|
|
|
fmt->coding_type = coding_FFmpeg;
|
|
|
|
fmt->is_at3p = 1;
|
|
|
|
break;
|
2017-12-27 00:43:52 +01:00
|
|
|
#else
|
|
|
|
goto fail;
|
2013-06-26 11:54:15 +02:00
|
|
|
#endif
|
2017-12-27 00:43:52 +01:00
|
|
|
}
|
2017-12-28 23:37:18 +01:00
|
|
|
|
2021-08-22 12:17:45 +02:00
|
|
|
#ifdef VGM_USE_ATRAC9
|
2019-03-02 16:16:02 +01:00
|
|
|
/* ATRAC9 GUID (0x47E142D2,36BA,4D8D,88,FC,61,65,4F,8C,83,6C) */
|
|
|
|
if (guid1 == 0x47E142D2 && guid2 == 0x36BA4D8D && guid3 == 0x88FC6165 && guid4 == 0x4F8C836C) {
|
2017-12-28 23:37:18 +01:00
|
|
|
fmt->coding_type = coding_ATRAC9;
|
2019-03-24 15:34:49 +01:00
|
|
|
fmt->is_at9 = 1;
|
2018-04-10 21:01:30 +02:00
|
|
|
break;
|
2017-12-28 23:37:18 +01:00
|
|
|
}
|
2021-08-22 12:17:45 +02:00
|
|
|
#endif
|
2017-12-28 23:37:18 +01:00
|
|
|
|
2018-04-10 21:01:30 +02:00
|
|
|
goto fail; /* unknown GUID */
|
2019-03-02 16:16:02 +01:00
|
|
|
}
|
2017-12-27 00:43:52 +01:00
|
|
|
|
2012-08-20 07:17:52 +02:00
|
|
|
default:
|
2021-08-26 19:39:58 +02:00
|
|
|
/* FFmpeg may play it */
|
2021-09-19 23:52:33 +02:00
|
|
|
//vgm_logi("RIFF: unknown codec 0x%04x (report)\n", fmt->format);
|
2012-08-20 07:17:52 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2019-03-02 16:16:02 +01:00
|
|
|
return 1;
|
2012-08-20 07:17:52 +02:00
|
|
|
|
|
|
|
fail:
|
2019-03-02 16:16:02 +01:00
|
|
|
return 0;
|
2012-08-20 07:17:52 +02:00
|
|
|
}
|
|
|
|
|
2024-03-31 16:09:36 +02:00
|
|
|
static bool is_ue4_msadpcm(STREAMFILE* sf, riff_fmt_chunk* fmt, int fact_sample_count, off_t start_offset, uint32_t data_size);
|
2020-06-30 23:20:36 +02:00
|
|
|
static size_t get_ue4_msadpcm_interleave(STREAMFILE* sf, riff_fmt_chunk* fmt, off_t start, size_t size);
|
2019-01-19 23:08:26 +01:00
|
|
|
|
|
|
|
|
2020-06-30 23:20:36 +02:00
|
|
|
VGMSTREAM* init_vgmstream_riff(STREAMFILE* sf) {
|
|
|
|
VGMSTREAM* vgmstream = NULL;
|
2017-12-27 00:43:52 +01:00
|
|
|
riff_fmt_chunk fmt = {0};
|
2008-07-06 20:05:04 +02:00
|
|
|
|
2017-12-27 00:43:52 +01:00
|
|
|
size_t file_size, riff_size, data_size = 0;
|
|
|
|
off_t start_offset = 0;
|
2012-08-20 07:17:52 +02:00
|
|
|
|
2018-02-17 12:30:14 +01:00
|
|
|
int fact_sample_count = 0;
|
|
|
|
int fact_sample_skip = 0;
|
2008-07-06 20:05:04 +02:00
|
|
|
|
|
|
|
int loop_flag = 0;
|
2018-02-23 23:30:55 +01:00
|
|
|
long loop_start_ms = -1, loop_end_ms = -1;
|
2018-03-03 19:07:59 +01:00
|
|
|
int32_t loop_start_wsmp = -1, loop_end_wsmp = -1;
|
|
|
|
int32_t loop_start_smpl = -1, loop_end_smpl = -1;
|
2018-09-21 13:31:56 +02:00
|
|
|
int32_t loop_start_cue = -1;
|
2020-03-01 12:22:50 +01:00
|
|
|
int32_t loop_start_nxbf = -1;
|
2008-07-06 20:05:04 +02:00
|
|
|
|
2017-04-22 10:18:47 +02:00
|
|
|
int FormatChunkFound = 0, DataChunkFound = 0, JunkFound = 0;
|
2008-07-06 20:05:04 +02:00
|
|
|
|
2022-12-31 17:31:20 +01:00
|
|
|
off_t mwv_pflt_offset = 0;
|
|
|
|
off_t mwv_ctrl_offset = 0;
|
2022-02-28 23:54:04 +01:00
|
|
|
int ignore_riff_size = 0;
|
2010-03-15 05:33:22 +01:00
|
|
|
|
2018-02-17 17:32:58 +01:00
|
|
|
|
2021-09-19 23:52:33 +02:00
|
|
|
/* checks*/
|
|
|
|
if (!is_id32be(0x00,sf,"RIFF"))
|
2024-02-04 15:25:53 +01:00
|
|
|
return NULL;
|
2021-09-19 23:52:33 +02:00
|
|
|
|
2022-12-31 17:21:56 +01:00
|
|
|
riff_size = read_u32le(0x04,sf);
|
|
|
|
|
|
|
|
if (!is_id32be(0x08,sf, "WAVE"))
|
2024-02-04 15:25:53 +01:00
|
|
|
return NULL;
|
2022-12-31 17:21:56 +01:00
|
|
|
|
|
|
|
file_size = get_streamfile_size(sf);
|
|
|
|
|
2018-08-25 12:20:55 +02:00
|
|
|
/* .lwav: to avoid hijacking .wav
|
|
|
|
* .xwav: fake for Xbox games (not needed anymore)
|
|
|
|
* .da: The Great Battle VI (PS1)
|
|
|
|
* .dax: Love Game's - Wai Wai Tennis (PS1)
|
|
|
|
* .cd: Exector (PS)
|
|
|
|
* .med: Psi Ops (PC)
|
|
|
|
* .snd: Layton Brothers (iOS/Android)
|
2018-03-28 22:58:37 +02:00
|
|
|
* .adx: Remember11 (PC) sfx
|
2018-05-27 17:32:15 +02:00
|
|
|
* .adp: Headhunter (DC)
|
2018-07-27 17:18:10 +02:00
|
|
|
* .xss: Spider-Man The Movie (Xbox)
|
2021-03-27 17:42:22 +01:00
|
|
|
* .xsew: Mega Man X Legacy Collection (PC)
|
2018-10-20 14:56:34 +02:00
|
|
|
* .adpcm: Angry Birds Transformers (Android)
|
2019-01-01 20:59:52 +01:00
|
|
|
* .adw: Dead Rising 2 (PC)
|
2019-01-26 16:14:50 +01:00
|
|
|
* .wd: Genma Onimusha (Xbox) voices
|
2019-01-26 16:34:25 +01:00
|
|
|
* (extensionless): Myst III (Xbox)
|
2019-01-27 23:40:40 +01:00
|
|
|
* .sbv: Spongebob Squarepants - The Movie (PC)
|
2019-03-24 15:34:49 +01:00
|
|
|
* .wvx: Godzilla - Destroy All Monsters Melee (Xbox)
|
2019-11-16 21:31:22 +01:00
|
|
|
* .str: Harry Potter and the Philosopher's Stone (Xbox)
|
2019-03-24 15:34:49 +01:00
|
|
|
* .at3: standard ATRAC3
|
2020-03-01 12:22:50 +01:00
|
|
|
* .rws: Climax ATRAC3 [Silent Hill Origins (PSP), Oblivion (PSP)]
|
2019-03-24 15:34:49 +01:00
|
|
|
* .aud: EA Replay ATRAC3
|
|
|
|
* .at9: standard ATRAC9
|
2021-12-31 16:20:52 +01:00
|
|
|
* .ckd: renamed ATRAC9 [Rayman Origins (Vita)]
|
2020-02-26 04:49:35 +01:00
|
|
|
* .saf: Whacked! (Xbox)
|
2020-07-18 19:24:32 +02:00
|
|
|
* .mwv: Level-5 games [Dragon Quest VIII (PS2), Rogue Galaxy (PS2)]
|
2020-11-22 19:01:17 +01:00
|
|
|
* .ima: Baja: Edge of Control (PS3/X360)
|
2021-10-21 22:44:04 +02:00
|
|
|
* .nsa: Studio Ring games that uses NScripter [Hajimete no Otetsudai (PC)]
|
2021-11-13 14:43:29 +01:00
|
|
|
* .pcm: Silent Hill Arcade (PC)
|
2022-02-28 23:57:51 +01:00
|
|
|
* .xvag: Uncharted Golden Abyss (Vita)[ATRAC9]
|
2022-06-26 17:03:42 +02:00
|
|
|
* .ogg/logg: Luftrausers (Vita)[ATRAC9]
|
2022-09-16 23:40:27 +02:00
|
|
|
* .p1d: Farming Simulator 15 (Vita)[ATRAC9]
|
2022-11-27 00:28:50 +01:00
|
|
|
* .xms: Ty the Tasmanian Tiger (Xbox)
|
2022-12-31 17:21:56 +01:00
|
|
|
* .mus: Burnout Legends/Dominator (PSP)
|
2023-03-19 22:50:51 +01:00
|
|
|
* .dat/ldat: RollerCoaster Tycoon 1/2 (PC)
|
2023-09-16 22:27:26 +02:00
|
|
|
* .wma/lwma: SRS: Street Racing Syndicate (Xbox), Fast and the Furious (Xbox)
|
2024-02-04 15:25:53 +01:00
|
|
|
* .caf: Topple (iOS)
|
2019-03-24 15:34:49 +01:00
|
|
|
*/
|
2024-02-04 15:25:53 +01:00
|
|
|
if (!check_extensions(sf, "wav,lwav,xwav,mwv,da,dax,cd,med,snd,adx,adp,xss,xsew,adpcm,adw,wd,,sbv,wvx,str,at3,rws,aud,at9,ckd,saf,ima,nsa,pcm,xvag,ogg,logg,p1d,xms,mus,dat,ldat,wma,lwma,caf")) {
|
|
|
|
return NULL;
|
2009-01-04 16:36:06 +01:00
|
|
|
}
|
2008-07-06 20:05:04 +02:00
|
|
|
|
2019-12-14 19:54:22 +01:00
|
|
|
/* some games have wonky sizes, selectively fix to catch bad rips and new mutations */
|
2020-06-30 23:32:55 +02:00
|
|
|
if (file_size != riff_size + 0x08) {
|
2021-08-22 12:17:45 +02:00
|
|
|
uint16_t codec = read_u16le(0x14,sf);
|
2020-06-30 23:32:55 +02:00
|
|
|
|
2021-09-19 23:52:33 +02:00
|
|
|
if ((codec & 0xFF00) == 0x6700 && riff_size + 0x08 + 0x01 == file_size)
|
|
|
|
riff_size += 0x01; /* [Shikkoku no Sharnoth (PC), Only One 2 (PC)] (Sony Sound Forge?) */
|
2020-06-06 16:11:24 +02:00
|
|
|
|
2020-06-30 23:32:55 +02:00
|
|
|
else if (codec == 0x0069 && riff_size == file_size)
|
2019-12-14 19:54:22 +01:00
|
|
|
riff_size -= 0x08; /* [Dynasty Warriors 3 (Xbox), BloodRayne (Xbox)] */
|
2020-06-06 16:11:24 +02:00
|
|
|
|
2020-06-30 23:32:55 +02:00
|
|
|
else if (codec == 0x0069 && riff_size + 0x04 == file_size)
|
2019-12-14 19:54:22 +01:00
|
|
|
riff_size -= 0x04; /* [Halo 2 (PC)] (possibly bad extractor? 'Gravemind Tool') */
|
2020-06-06 16:11:24 +02:00
|
|
|
|
2023-09-16 22:27:26 +02:00
|
|
|
else if (codec == 0x0069 && riff_size + 0x10 == file_size)
|
|
|
|
riff_size += 0x08; /* [Fast and the Furious (Xbox)] ("HASH" chunk + 4 byte hash) */
|
|
|
|
|
2020-06-30 23:32:55 +02:00
|
|
|
else if (codec == 0x0000 && riff_size + 0x04 == file_size)
|
2020-06-06 16:11:24 +02:00
|
|
|
riff_size -= 0x04; /* [Headhunter (DC), Bomber hehhe (DC)] */
|
|
|
|
|
2020-06-30 23:32:55 +02:00
|
|
|
else if (codec == 0x0000 && riff_size == file_size)
|
2020-06-06 16:11:24 +02:00
|
|
|
riff_size -= 0x08; /* [Rayman 2 (DC)] */
|
|
|
|
|
2020-08-12 17:40:20 +02:00
|
|
|
else if (codec == 0x0000 && riff_size + 0x08 + 0x02 == file_size)
|
2020-06-06 16:11:24 +02:00
|
|
|
riff_size -= 0x02; /* [Rayman 2 (DC)]-dcz */
|
|
|
|
|
2020-06-30 23:32:55 +02:00
|
|
|
else if (codec == 0x0300 && riff_size == file_size)
|
2019-12-14 19:54:22 +01:00
|
|
|
riff_size -= 0x08; /* [Chrono Ma:gia (Android)] */
|
2020-06-06 16:11:24 +02:00
|
|
|
|
2020-08-12 17:40:20 +02:00
|
|
|
else if (codec == 0xFFFE && riff_size + 0x08 + 0x18 == file_size)
|
|
|
|
riff_size += 0x18; /* [F1 2011 (Vita)] (adds a "pada" chunk but RIFF size wasn't updated) */
|
|
|
|
|
2022-12-31 17:31:20 +01:00
|
|
|
else if (codec == 0x0555) {
|
2021-08-22 12:17:45 +02:00
|
|
|
int channels = read_u16le(0x16, sf); /* [Dragon Quest VIII (PS2), Rogue Galaxy (PS2)] */
|
2020-07-30 18:22:12 +02:00
|
|
|
size_t file_size_fixed = riff_size + 0x08 + 0x04 * (channels - 1);
|
|
|
|
|
2021-08-22 12:17:45 +02:00
|
|
|
if (file_size_fixed <= file_size && file_size - file_size_fixed < 0x10) {
|
2020-07-30 18:22:12 +02:00
|
|
|
/* files inside HD6/DAT are also padded to 0x10 so need to fix file_size */
|
|
|
|
file_size = file_size_fixed;
|
|
|
|
riff_size = file_size - 0x08;
|
|
|
|
}
|
2020-07-19 17:06:27 +02:00
|
|
|
}
|
2020-07-18 19:24:32 +02:00
|
|
|
|
2020-06-30 23:20:36 +02:00
|
|
|
else if (riff_size >= file_size && read_32bitBE(0x24,sf) == 0x4E584246) /* "NXBF" */
|
2020-03-01 12:22:50 +01:00
|
|
|
riff_size = file_size - 0x08; /* [R:Racing Evolution (Xbox)] */
|
2020-06-21 00:35:09 +02:00
|
|
|
|
2020-06-30 23:32:55 +02:00
|
|
|
else if (codec == 0x0011 && (riff_size / 2 / 2 == read_32bitLE(0x30,sf))) /* riff_size = pcm_size (always stereo, has fact at 0x30) */
|
|
|
|
riff_size = file_size - 0x08; /* [Asphalt 6 (iOS)] (sfx/memory wavs have ok sizes?) */
|
2020-11-09 14:51:59 +01:00
|
|
|
|
|
|
|
else if (codec == 0xFFFE && riff_size + 0x08 + 0x30 == file_size)
|
|
|
|
riff_size += 0x30; /* [E.X. Troopers (PS3)] (adds "ver /eBIT/tIME/mrkr" empty chunks but RIFF size wasn't updated) */
|
2021-03-27 17:42:22 +01:00
|
|
|
|
2021-07-13 23:46:27 +02:00
|
|
|
else if (codec == 0xFFFE && riff_size + 0x08 + 0x38 == file_size)
|
|
|
|
riff_size += 0x38; /* [Sengoku Basara 4 (PS3)] (adds "ver /eBIT/tIME/mrkr" chunks but RIFF size wasn't updated) */
|
|
|
|
|
2021-03-27 17:42:22 +01:00
|
|
|
else if (codec == 0x0002 && riff_size + 0x08 + 0x1c == file_size)
|
|
|
|
riff_size += 0x1c; /* [Mega Man X Legacy Collection (PC)] (adds "ver /tIME/ver " chunks but RIFF size wasn't updated) */
|
2022-02-28 23:54:04 +01:00
|
|
|
|
|
|
|
else if (codec == 0x0001 && (
|
|
|
|
riff_size + 0x08 + 0x08 == file_size || riff_size + 0x08 + 0x09 == file_size ||
|
|
|
|
riff_size + 0x08 - 0x3E == file_size || riff_size + 0x08 - 0x02 == file_size))
|
|
|
|
ignore_riff_size = 1; /* [Cross Gate (PC)] (last info LIST chunk has wrong size) */
|
2022-06-19 19:36:44 +02:00
|
|
|
|
|
|
|
else if (codec == 0xFFFE && riff_size + 0x08 + 0x40 == file_size)
|
|
|
|
file_size -= 0x40; /* [Megami no Etsubo (PSP)] (has extra padding in all files) */
|
2023-12-30 17:04:29 +01:00
|
|
|
|
|
|
|
else if (codec == 0x0011 && file_size - riff_size - 0x08 <= 0x900 && is_id32be(riff_size + 0x08, sf, "cont"))
|
|
|
|
riff_size = file_size - 0x08; /* [Shin Megami Tensei: Imagine (PC)] (extra "cont" info 0x800/0x900 chunk) */
|
2019-12-14 19:54:22 +01:00
|
|
|
}
|
2018-03-28 22:58:37 +02:00
|
|
|
|
2017-12-27 00:43:52 +01:00
|
|
|
/* check for truncated RIFF */
|
2022-02-28 23:54:04 +01:00
|
|
|
if (file_size != riff_size + 0x08 && !ignore_riff_size) {
|
2021-08-26 19:39:58 +02:00
|
|
|
vgm_logi("RIFF: wrong expected size (report/re-rip?)\n");
|
2021-09-19 23:52:33 +02:00
|
|
|
VGM_LOG("riff: file_size = %x, riff_size+8 = %x\n", file_size, riff_size + 0x08); /* don't log to user */
|
2019-01-01 20:59:52 +01:00
|
|
|
goto fail;
|
2021-08-26 19:39:58 +02:00
|
|
|
}
|
2008-07-06 20:05:04 +02:00
|
|
|
|
|
|
|
/* read through chunks to verify format and find metadata */
|
|
|
|
{
|
2022-02-28 23:54:04 +01:00
|
|
|
uint32_t current_chunk = 0x0c; /* start with first chunk */
|
2008-07-06 20:05:04 +02:00
|
|
|
|
2020-07-19 17:06:27 +02:00
|
|
|
while (current_chunk < file_size) {
|
2022-02-28 23:54:04 +01:00
|
|
|
uint32_t chunk_id = read_u32be(current_chunk + 0x00,sf); /* FOURCC */
|
|
|
|
uint32_t chunk_size = read_u32le(current_chunk + 0x04,sf);
|
2008-07-06 20:05:04 +02:00
|
|
|
|
2022-02-28 23:54:04 +01:00
|
|
|
/* allow broken last chunk [Cross Gate (PC)] */
|
|
|
|
if (current_chunk + 0x08 + chunk_size > file_size) {
|
|
|
|
VGM_LOG("RIFF: broken chunk at %x + 0x08 + %x > %x\n", current_chunk, chunk_size, file_size);
|
|
|
|
break; /* truncated */
|
|
|
|
}
|
2008-07-06 20:05:04 +02:00
|
|
|
|
2019-03-02 16:16:02 +01:00
|
|
|
switch(chunk_id) {
|
2008-07-06 20:05:04 +02:00
|
|
|
case 0x666d7420: /* "fmt " */
|
2018-02-23 23:30:55 +01:00
|
|
|
if (FormatChunkFound) goto fail; /* only one per file */
|
2008-07-06 20:05:04 +02:00
|
|
|
FormatChunkFound = 1;
|
|
|
|
|
2022-12-31 17:31:20 +01:00
|
|
|
if (!read_fmt(0, sf, current_chunk, &fmt))
|
2012-08-20 07:17:52 +02:00
|
|
|
goto fail;
|
2018-03-28 22:58:37 +02:00
|
|
|
|
2020-06-06 16:11:24 +02:00
|
|
|
/* some Dreamcast/Naomi games again [Headhunter (DC), Bomber hehhe (DC), Rayman 2 (DC)] */
|
2018-03-28 22:58:37 +02:00
|
|
|
if (fmt.codec == 0x0000 && chunk_size == 0x12)
|
|
|
|
chunk_size += 0x02;
|
2008-07-06 20:05:04 +02:00
|
|
|
break;
|
2018-02-23 23:30:55 +01:00
|
|
|
|
|
|
|
case 0x64617461: /* "data" */
|
|
|
|
if (DataChunkFound) goto fail; /* only one per file */
|
2008-07-06 20:05:04 +02:00
|
|
|
DataChunkFound = 1;
|
|
|
|
|
2018-02-23 23:30:55 +01:00
|
|
|
start_offset = current_chunk + 0x08;
|
2008-07-06 20:05:04 +02:00
|
|
|
data_size = chunk_size;
|
|
|
|
break;
|
2018-02-23 23:30:55 +01:00
|
|
|
|
|
|
|
case 0x4C495354: /* "LIST" */
|
2020-06-30 23:20:36 +02:00
|
|
|
switch (read_32bitBE(current_chunk+0x08, sf)) {
|
2018-02-23 23:30:55 +01:00
|
|
|
case 0x6164746C: /* "adtl" */
|
2008-07-21 07:03:16 +02:00
|
|
|
/* yay, atdl is its own little world */
|
2022-02-28 23:54:04 +01:00
|
|
|
parse_adtl(current_chunk + 0x8, chunk_size,
|
2020-06-30 23:20:36 +02:00
|
|
|
sf,
|
2008-07-21 07:03:16 +02:00
|
|
|
&loop_start_ms,&loop_end_ms,&loop_flag);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2018-02-23 23:30:55 +01:00
|
|
|
|
|
|
|
case 0x736D706C: /* "smpl" (RIFFMIDISample + MIDILoop chunk) */
|
2018-10-07 02:24:37 +02:00
|
|
|
/* check loop count/loop info (most common) */
|
2018-02-23 23:30:55 +01:00
|
|
|
/* 0x00: manufacturer id, 0x04: product id, 0x08: sample period, 0x0c: unity node,
|
|
|
|
* 0x10: pitch fraction, 0x14: SMPTE format, 0x18: SMPTE offset, 0x1c: loop count, 0x20: sampler data */
|
2020-06-30 23:20:36 +02:00
|
|
|
if (read_32bitLE(current_chunk+0x08+0x1c, sf) == 1) { /* handle only one loop (could contain N MIDILoop) */
|
2018-02-23 23:30:55 +01:00
|
|
|
/* 0x24: cue point id, 0x28: type (0=forward, 1=alternating, 2=backward)
|
|
|
|
* 0x2c: start, 0x30: end, 0x34: fraction, 0x38: play count */
|
2020-06-30 23:20:36 +02:00
|
|
|
if (read_32bitLE(current_chunk+0x08+0x28, sf) == 0) { /* loop forward */
|
2008-10-08 02:09:11 +02:00
|
|
|
loop_flag = 1;
|
2020-06-30 23:20:36 +02:00
|
|
|
loop_start_smpl = read_32bitLE(current_chunk+0x08+0x2c, sf);
|
|
|
|
loop_end_smpl = read_32bitLE(current_chunk+0x08+0x30, sf) + 1; /* must add 1 as per spec (ok for standard WAV/AT3/AT9) */
|
2008-10-08 02:09:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2017-12-27 00:43:52 +01:00
|
|
|
|
2018-02-23 23:30:55 +01:00
|
|
|
case 0x77736D70: /* "wsmp" (RIFFDLSSample + DLSLoop chunk) */
|
|
|
|
/* check loop count/info (found in some Xbox games: Halo (non-looping), Dynasty Warriors 3, Crimson Sea) */
|
|
|
|
/* 0x00: size, 0x04: unity note, 0x06: fine tune, 0x08: gain, 0x10: loop count */
|
|
|
|
if (chunk_size >= 0x24
|
2020-06-30 23:20:36 +02:00
|
|
|
&& read_32bitLE(current_chunk+0x08+0x00, sf) == 0x14
|
|
|
|
&& read_32bitLE(current_chunk+0x08+0x10, sf) > 0
|
|
|
|
&& read_32bitLE(current_chunk+0x08+0x14, sf) == 0x10) {
|
2018-02-23 23:30:55 +01:00
|
|
|
/* 0x14: size, 0x18: loop type (0=forward, 1=release), 0x1c: loop start, 0x20: loop length */
|
2020-06-30 23:20:36 +02:00
|
|
|
if (read_32bitLE(current_chunk+0x08+0x18, sf) == 0) { /* loop forward */
|
2018-02-23 23:30:55 +01:00
|
|
|
loop_flag = 1;
|
2020-06-30 23:20:36 +02:00
|
|
|
loop_start_wsmp = read_32bitLE(current_chunk+0x08+0x1c, sf);
|
|
|
|
loop_end_wsmp = read_32bitLE(current_chunk+0x08+0x20, sf); /* must not add 1 as per spec */
|
2018-03-03 19:07:59 +01:00
|
|
|
loop_end_wsmp += loop_start_wsmp;
|
2018-02-23 23:30:55 +01:00
|
|
|
}
|
|
|
|
}
|
2009-01-04 16:36:06 +01:00
|
|
|
break;
|
2017-12-27 00:43:52 +01:00
|
|
|
|
2018-02-23 23:30:55 +01:00
|
|
|
case 0x66616374: /* "fact" */
|
2021-12-11 12:47:00 +01:00
|
|
|
if (chunk_size == 0x04) { /* standard (usually for ADPCM, MS recommends setting for non-PCM codecs but optional) */
|
2020-06-30 23:20:36 +02:00
|
|
|
fact_sample_count = read_32bitLE(current_chunk+0x08, sf);
|
2019-08-25 20:46:29 +02:00
|
|
|
}
|
2021-12-11 12:47:00 +01:00
|
|
|
else if (chunk_size == 0x10 && is_id32be(current_chunk+0x08+0x04, sf, "LyN ")) {
|
2018-04-07 11:37:44 +02:00
|
|
|
goto fail; /* parsed elsewhere */
|
2019-08-25 20:46:29 +02:00
|
|
|
}
|
|
|
|
else if ((fmt.is_at3 || fmt.is_at3p) && chunk_size == 0x08) { /* early AT3 (mainly PSP games) */
|
2020-06-30 23:20:36 +02:00
|
|
|
fact_sample_count = read_32bitLE(current_chunk+0x08, sf);
|
|
|
|
fact_sample_skip = read_32bitLE(current_chunk+0x0c, sf); /* base skip samples */
|
2019-08-25 20:46:29 +02:00
|
|
|
}
|
|
|
|
else if ((fmt.is_at3 || fmt.is_at3p) && chunk_size == 0x0c) { /* late AT3 (mainly PS3 games and few PSP games) */
|
2020-06-30 23:20:36 +02:00
|
|
|
fact_sample_count = read_32bitLE(current_chunk+0x08, sf);
|
2019-08-25 20:46:29 +02:00
|
|
|
/* 0x0c: base skip samples, ignored by decoder */
|
2020-06-30 23:20:36 +02:00
|
|
|
fact_sample_skip = read_32bitLE(current_chunk+0x10, sf); /* skip samples with extra 184 */
|
2019-08-25 20:46:29 +02:00
|
|
|
}
|
|
|
|
else if (fmt.is_at9 && chunk_size == 0x0c) {
|
2020-06-30 23:20:36 +02:00
|
|
|
fact_sample_count = read_32bitLE(current_chunk+0x08, sf);
|
2019-08-25 20:46:29 +02:00
|
|
|
/* 0x0c: base skip samples (same as next field) */
|
2020-06-30 23:20:36 +02:00
|
|
|
fact_sample_skip = read_32bitLE(current_chunk+0x10, sf);
|
2016-12-06 00:28:16 +01:00
|
|
|
}
|
2018-02-23 23:30:55 +01:00
|
|
|
break;
|
2016-12-06 00:28:16 +01:00
|
|
|
|
2021-12-11 12:47:00 +01:00
|
|
|
case 0x4C795345: /* "LySE" */
|
|
|
|
goto fail; /* parsed elsewhere */
|
|
|
|
|
2018-02-23 23:30:55 +01:00
|
|
|
case 0x70666c74: /* "pflt" (.mwv extension) */
|
|
|
|
mwv_pflt_offset = current_chunk; /* predictor filters */
|
2009-03-09 13:48:53 +01:00
|
|
|
break;
|
2019-03-02 16:16:02 +01:00
|
|
|
|
2018-02-23 23:30:55 +01:00
|
|
|
case 0x6374726c: /* "ctrl" (.mwv extension) */
|
2020-06-30 23:20:36 +02:00
|
|
|
loop_flag = read_32bitLE(current_chunk+0x08, sf);
|
2018-02-23 23:30:55 +01:00
|
|
|
mwv_ctrl_offset = current_chunk;
|
|
|
|
break;
|
|
|
|
|
2018-09-21 13:31:56 +02:00
|
|
|
case 0x63756520: /* "cue " (used in Source Engine for storing loop points) */
|
2021-05-02 16:59:59 +02:00
|
|
|
if (fmt.coding_type == coding_PCM8_U ||
|
|
|
|
fmt.coding_type == coding_PCM16LE ||
|
|
|
|
fmt.coding_type == coding_MSADPCM) {
|
2020-06-30 23:20:36 +02:00
|
|
|
uint32_t num_cues = read_32bitLE(current_chunk + 0x08, sf);
|
2018-09-21 13:31:56 +02:00
|
|
|
|
2020-01-03 21:16:22 +01:00
|
|
|
if (num_cues > 0) {
|
2021-05-02 16:59:59 +02:00
|
|
|
/* the second cue sets loop end point but it's not actually used by the engine */
|
2018-09-21 13:31:56 +02:00
|
|
|
loop_flag = 1;
|
2020-06-30 23:20:36 +02:00
|
|
|
loop_start_cue = read_32bitLE(current_chunk + 0x20, sf);
|
2018-09-21 13:31:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-03-08 19:37:29 +01:00
|
|
|
case 0x4E584246: /* "NXBF" (Namco NuSound v1) [R:Racing Evolution (Xbox)] */
|
|
|
|
/* very similar to NUS's NPSF, but not quite like Cstr */
|
|
|
|
/* 0x00: "NXBF" id */
|
|
|
|
/* 0x04: version? (0x00001000 = 1.00?) */
|
2020-03-01 12:22:50 +01:00
|
|
|
/* 0x08: data size */
|
|
|
|
/* 0x0c: channels */
|
|
|
|
/* 0x10: null */
|
2020-06-30 23:20:36 +02:00
|
|
|
loop_start_nxbf = read_32bitLE(current_chunk + 0x08 + 0x14, sf);
|
2020-03-01 12:22:50 +01:00
|
|
|
/* 0x18: sample rate */
|
2020-03-08 19:37:29 +01:00
|
|
|
/* 0x1c: volume? (0x3e8 = 1000 = max) */
|
2020-03-01 12:22:50 +01:00
|
|
|
/* 0x20: type/flags? */
|
2020-03-08 19:37:29 +01:00
|
|
|
/* 0x24: flag? */
|
2020-03-01 12:22:50 +01:00
|
|
|
/* 0x28: null */
|
|
|
|
/* 0x2c: null */
|
2020-03-08 19:37:29 +01:00
|
|
|
/* 0x30: always 0x40 */
|
2020-03-01 12:22:50 +01:00
|
|
|
loop_flag = (loop_start_nxbf >= 0);
|
|
|
|
break;
|
|
|
|
|
2018-02-23 23:30:55 +01:00
|
|
|
case 0x4A554E4B: /* "JUNK" */
|
2017-04-22 10:18:47 +02:00
|
|
|
JunkFound = 1;
|
|
|
|
break;
|
2018-02-23 23:30:55 +01:00
|
|
|
|
2021-12-31 16:20:52 +01:00
|
|
|
|
|
|
|
case 0x64737068: /* "dsph" */
|
|
|
|
case 0x63776176: /* "cwav" */
|
|
|
|
goto fail; /* parse elsewhere */
|
|
|
|
|
2008-07-06 20:05:04 +02:00
|
|
|
default:
|
|
|
|
/* ignorance is bliss */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-03-02 16:16:02 +01:00
|
|
|
/* chunks are even-sized with padding byte (for 16b reads) as per spec (normally
|
|
|
|
* pre-adjusted except for a few like Liar-soft's), at end may not have padding though
|
|
|
|
* (done *after* chunk parsing since size without padding is needed) */
|
|
|
|
if (chunk_size % 0x02 && current_chunk + 0x08 + chunk_size+0x01 <= file_size)
|
|
|
|
chunk_size += 0x01;
|
|
|
|
|
|
|
|
current_chunk += 0x08 + chunk_size;
|
2008-07-06 20:05:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!FormatChunkFound || !DataChunkFound) goto fail;
|
|
|
|
|
2018-02-23 23:30:55 +01:00
|
|
|
//todo improve detection using fmt sizes/values as Wwise's don't match the RIFF standard
|
2017-04-22 10:18:47 +02:00
|
|
|
/* 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") */
|
2017-07-01 22:44:00 +02:00
|
|
|
if (JunkFound
|
2020-06-30 23:20:36 +02:00
|
|
|
&& check_extensions(sf,"wav,lwav") /* for some .MED IMA */
|
2018-02-17 17:32:58 +01:00
|
|
|
&& (fmt.coding_type==coding_MSADPCM /*|| fmt.coding_type==coding_MS_IMA*/ || fmt.coding_type==coding_XBOX_IMA))
|
2017-10-28 01:34:32 +02:00
|
|
|
goto fail;
|
|
|
|
|
2018-04-06 20:49:49 +02:00
|
|
|
/* ignore Beyond Good & Evil HD PS3 evil reuse of PCM codec */
|
|
|
|
if (fmt.coding_type == coding_PCM16LE &&
|
2021-07-29 17:08:30 +02:00
|
|
|
read_u32be(start_offset+0x00, sf) == 0x4D534643 && /* "MSF\43" */
|
|
|
|
read_u32be(start_offset+0x34, sf) == 0xFFFFFFFF && /* always */
|
|
|
|
read_u32be(start_offset+0x38, sf) == 0xFFFFFFFF &&
|
|
|
|
read_u32be(start_offset+0x3c, sf) == 0xFFFFFFFF)
|
2018-04-06 20:49:49 +02:00
|
|
|
goto fail;
|
|
|
|
|
2022-05-01 20:35:11 +02:00
|
|
|
/* MSADPCM .ckd are parsed elsewhere, though they are valid so no big deal if parsed here (just that loops should be ignored) */
|
|
|
|
if (fmt.codec == 0x0002 && check_extensions(sf, "ckd"))
|
2021-12-31 16:20:52 +01:00
|
|
|
goto fail;
|
|
|
|
|
2019-03-24 15:34:49 +01:00
|
|
|
/* ignore Gitaroo Man Live! (PSP) multi-RIFF (to allow chunked TXTH) */
|
2020-06-30 23:20:36 +02:00
|
|
|
if (fmt.is_at3 && get_streamfile_size(sf) > 0x2800 && read_32bitBE(0x2800, sf) == 0x52494646) { /* "RIFF" */
|
2019-03-24 15:34:49 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
2017-04-22 10:18:47 +02:00
|
|
|
|
2018-01-21 01:47:02 +01:00
|
|
|
|
2017-12-27 00:43:52 +01:00
|
|
|
/* build the VGMSTREAM */
|
2021-08-22 12:17:45 +02:00
|
|
|
vgmstream = allocate_vgmstream(fmt.channels,loop_flag);
|
2017-12-27 00:43:52 +01:00
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
vgmstream->sample_rate = fmt.sample_rate;
|
2019-03-02 16:16:02 +01:00
|
|
|
vgmstream->channel_layout = fmt.channel_layout;
|
2017-12-27 00:43:52 +01:00
|
|
|
|
2019-09-29 18:25:24 +02:00
|
|
|
/* coding, layout, interleave */
|
|
|
|
vgmstream->coding_type = fmt.coding_type;
|
|
|
|
switch (fmt.coding_type) {
|
|
|
|
case coding_MS_IMA:
|
|
|
|
case coding_AICA:
|
|
|
|
case coding_XBOX_IMA:
|
|
|
|
case coding_IMA:
|
2019-12-14 19:54:22 +01:00
|
|
|
case coding_DVI_IMA:
|
2019-09-29 18:25:24 +02:00
|
|
|
#ifdef VGM_USE_FFMPEG
|
|
|
|
case coding_FFmpeg:
|
|
|
|
#endif
|
|
|
|
#ifdef VGM_USE_ATRAC9
|
|
|
|
case coding_ATRAC9:
|
2019-10-19 11:13:02 +02:00
|
|
|
#endif
|
|
|
|
#ifdef VGM_USE_VORBIS
|
|
|
|
case coding_OGG_VORBIS:
|
2019-09-29 18:25:24 +02:00
|
|
|
#endif
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
vgmstream->interleave_block_size = fmt.block_size;
|
|
|
|
break;
|
2022-01-08 21:00:13 +01:00
|
|
|
#ifdef VGM_USE_MPEG
|
|
|
|
case coding_MPEG_custom:
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
break;
|
|
|
|
#endif
|
2019-10-20 16:35:52 +02:00
|
|
|
case coding_MSADPCM:
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
vgmstream->frame_size = fmt.block_size;
|
|
|
|
break;
|
|
|
|
|
2019-09-29 18:25:24 +02:00
|
|
|
default:
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
vgmstream->interleave_block_size = fmt.interleave;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* samples, codec init (after setting coding to ensure proper close on failure) */
|
2012-08-20 07:17:52 +02:00
|
|
|
switch (fmt.coding_type) {
|
2023-08-18 07:20:22 +02:00
|
|
|
case coding_PCM32LE:
|
2021-11-12 18:45:18 +01:00
|
|
|
case coding_PCM24LE:
|
2008-07-06 20:05:04 +02:00
|
|
|
case coding_PCM16LE:
|
2019-09-14 12:42:08 +02:00
|
|
|
case coding_PCM8_U:
|
2023-08-18 06:44:37 +02:00
|
|
|
case coding_PCMFLOAT:
|
2021-11-12 18:45:18 +01:00
|
|
|
vgmstream->num_samples = pcm_bytes_to_samples(data_size, fmt.channels, fmt.bps);
|
2008-07-06 20:05:04 +02:00
|
|
|
break;
|
2018-02-17 17:32:58 +01:00
|
|
|
|
2009-01-04 16:36:06 +01:00
|
|
|
case coding_L5_555:
|
2021-08-22 12:17:45 +02:00
|
|
|
vgmstream->num_samples = data_size / 0x12 / fmt.channels * 32;
|
2017-12-27 00:43:52 +01:00
|
|
|
|
|
|
|
/* coefs */
|
2018-01-21 01:47:02 +01:00
|
|
|
{
|
2017-12-27 00:43:52 +01:00
|
|
|
int i, ch;
|
|
|
|
const int filter_order = 3;
|
2020-06-30 23:20:36 +02:00
|
|
|
int filter_count = read_32bitLE(mwv_pflt_offset+0x0c, sf);
|
2017-12-27 00:43:52 +01:00
|
|
|
if (filter_count > 0x20) goto fail;
|
|
|
|
|
2022-12-31 17:31:20 +01:00
|
|
|
if (!mwv_pflt_offset ||
|
2020-06-30 23:20:36 +02:00
|
|
|
read_32bitLE(mwv_pflt_offset+0x08, sf) != filter_order ||
|
|
|
|
read_32bitLE(mwv_pflt_offset+0x04, sf) < 8 + filter_count * 4 * filter_order)
|
2017-12-27 00:43:52 +01:00
|
|
|
goto fail;
|
|
|
|
|
2021-08-22 12:17:45 +02:00
|
|
|
for (ch = 0; ch < fmt.channels; ch++) {
|
2017-12-27 00:43:52 +01:00
|
|
|
for (i = 0; i < filter_count * filter_order; i++) {
|
2020-06-30 23:20:36 +02:00
|
|
|
int coef = read_32bitLE(mwv_pflt_offset+0x10+i*0x04, sf);
|
2017-12-27 00:43:52 +01:00
|
|
|
vgmstream->ch[ch].adpcm_coef_3by32[i] = coef;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-04 16:36:06 +01:00
|
|
|
break;
|
2018-02-17 17:32:58 +01:00
|
|
|
|
2011-12-14 01:04:03 +01:00
|
|
|
case coding_MSADPCM:
|
2021-08-22 12:17:45 +02:00
|
|
|
vgmstream->num_samples = msadpcm_bytes_to_samples(data_size, fmt.block_size, fmt.channels);
|
2018-02-24 22:32:13 +01:00
|
|
|
if (fact_sample_count && fact_sample_count < vgmstream->num_samples)
|
|
|
|
vgmstream->num_samples = fact_sample_count;
|
2011-12-14 01:04:03 +01:00
|
|
|
break;
|
2018-02-17 17:32:58 +01:00
|
|
|
|
2009-03-09 13:48:53 +01:00
|
|
|
case coding_MS_IMA:
|
2021-08-22 12:17:45 +02:00
|
|
|
vgmstream->num_samples = ms_ima_bytes_to_samples(data_size, fmt.block_size, fmt.channels);
|
2018-02-24 22:32:13 +01:00
|
|
|
if (fact_sample_count && fact_sample_count < vgmstream->num_samples)
|
|
|
|
vgmstream->num_samples = fact_sample_count;
|
2009-03-09 13:48:53 +01:00
|
|
|
break;
|
2018-02-17 17:32:58 +01:00
|
|
|
|
2019-09-21 19:15:01 +02:00
|
|
|
case coding_AICA:
|
|
|
|
case coding_AICA_int:
|
2021-08-22 12:17:45 +02:00
|
|
|
vgmstream->num_samples = yamaha_bytes_to_samples(data_size, fmt.channels);
|
2018-03-28 22:58:37 +02:00
|
|
|
break;
|
|
|
|
|
2018-02-17 12:30:14 +01:00
|
|
|
case coding_XBOX_IMA:
|
2021-08-22 12:17:45 +02:00
|
|
|
vgmstream->num_samples = xbox_ima_bytes_to_samples(data_size, fmt.channels);
|
2018-02-24 22:32:13 +01:00
|
|
|
if (fact_sample_count && fact_sample_count < vgmstream->num_samples)
|
|
|
|
vgmstream->num_samples = fact_sample_count; /* some (converted?) Xbox games have bigger fact_samples */
|
2018-02-17 12:30:14 +01:00
|
|
|
break;
|
2018-02-17 17:32:58 +01:00
|
|
|
|
2018-09-22 16:12:36 +02:00
|
|
|
case coding_IMA:
|
2019-12-14 19:54:22 +01:00
|
|
|
case coding_DVI_IMA:
|
2021-08-22 12:17:45 +02:00
|
|
|
vgmstream->num_samples = ima_bytes_to_samples(data_size, fmt.channels);
|
2018-09-22 16:12:36 +02:00
|
|
|
break;
|
|
|
|
|
2016-07-17 08:02:27 +02:00
|
|
|
#ifdef VGM_USE_FFMPEG
|
2017-12-27 00:43:52 +01:00
|
|
|
case coding_FFmpeg: {
|
2019-08-25 20:46:29 +02:00
|
|
|
if (!fmt.is_at3 && !fmt.is_at3p) goto fail;
|
2017-12-27 00:43:52 +01:00
|
|
|
|
2020-06-30 23:20:36 +02:00
|
|
|
vgmstream->codec_data = init_ffmpeg_atrac3_riff(sf, 0x00, NULL);
|
2019-08-25 20:46:29 +02:00
|
|
|
if (!vgmstream->codec_data) goto fail;
|
2017-05-20 18:00:27 +02:00
|
|
|
|
2019-08-25 20:46:29 +02:00
|
|
|
vgmstream->num_samples = fact_sample_count;
|
|
|
|
if (loop_flag) {
|
|
|
|
/* adjust RIFF loop/sample absolute values (with skip samples) */
|
|
|
|
loop_start_smpl -= fact_sample_skip;
|
|
|
|
loop_end_smpl -= fact_sample_skip;
|
2019-03-30 02:15:22 +01:00
|
|
|
|
2019-08-25 20:46:29 +02:00
|
|
|
/* happens with official tools when "fact" is not found */
|
|
|
|
if (vgmstream->num_samples == 0)
|
|
|
|
vgmstream->num_samples = loop_end_smpl;
|
2016-07-17 08:02:27 +02:00
|
|
|
}
|
2019-08-25 20:46:29 +02:00
|
|
|
|
2016-07-17 08:02:27 +02:00
|
|
|
break;
|
2017-12-27 00:43:52 +01:00
|
|
|
}
|
2016-07-17 08:02:27 +02:00
|
|
|
#endif
|
2017-12-28 23:37:18 +01:00
|
|
|
#ifdef VGM_USE_ATRAC9
|
|
|
|
case coding_ATRAC9: {
|
|
|
|
atrac9_config cfg = {0};
|
|
|
|
|
|
|
|
cfg.channels = vgmstream->channels;
|
2020-06-30 23:20:36 +02:00
|
|
|
cfg.config_data = read_32bitBE(fmt.offset+0x08+0x2c,sf);
|
2017-12-28 23:37:18 +01:00
|
|
|
cfg.encoder_delay = fact_sample_skip;
|
|
|
|
|
|
|
|
vgmstream->codec_data = init_atrac9(&cfg);
|
|
|
|
if (!vgmstream->codec_data) goto fail;
|
|
|
|
|
|
|
|
vgmstream->num_samples = fact_sample_count;
|
|
|
|
/* RIFF loop/sample values are absolute (with skip samples), adjust */
|
|
|
|
if (loop_flag) {
|
2018-03-03 19:07:59 +01:00
|
|
|
loop_start_smpl -= fact_sample_skip;
|
|
|
|
loop_end_smpl -= fact_sample_skip;
|
2017-12-28 23:37:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2013-06-26 11:54:15 +02:00
|
|
|
#endif
|
2019-10-19 11:13:02 +02:00
|
|
|
#ifdef VGM_USE_VORBIS
|
|
|
|
case coding_OGG_VORBIS: {
|
2021-09-19 23:52:33 +02:00
|
|
|
/* special handling of Liar-soft's buggy RIFF+Ogg made with Soundforge/vorbis.acm [Shikkoku no Sharnoth (PC)],
|
|
|
|
* and rarely other devs, not always buggy [Kirara Kirara NTR (PC), No One 2 (PC)] */
|
|
|
|
STREAMFILE* temp_sf = setup_riff_ogg_streamfile(sf, start_offset, data_size);
|
2019-10-19 11:13:02 +02:00
|
|
|
if (!temp_sf) goto fail;
|
|
|
|
|
|
|
|
vgmstream->codec_data = init_ogg_vorbis(temp_sf, 0x00, get_streamfile_size(temp_sf), NULL);
|
|
|
|
if (!vgmstream->codec_data) goto fail;
|
|
|
|
|
|
|
|
/* Soundforge includes fact_samples and should be equal to Ogg samples */
|
|
|
|
vgmstream->num_samples = fact_sample_count;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-01-08 21:00:13 +01:00
|
|
|
#ifdef VGM_USE_MPEG
|
|
|
|
case coding_MPEG_custom: {
|
|
|
|
mpeg_custom_config cfg = {0};
|
|
|
|
|
|
|
|
vgmstream->codec_data = init_mpeg_custom(sf, start_offset, &vgmstream->coding_type, fmt.channels, MPEG_STANDARD, &cfg);
|
|
|
|
if (!vgmstream->codec_data) goto fail;
|
|
|
|
|
|
|
|
/* should provide "fact" but it's optional (some game files don't include it) */
|
|
|
|
if (!fact_sample_count)
|
|
|
|
fact_sample_count = mpeg_get_samples(sf, start_offset, data_size);
|
|
|
|
vgmstream->num_samples = fact_sample_count;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2012-08-20 07:17:52 +02:00
|
|
|
default:
|
|
|
|
goto fail;
|
2008-07-06 20:05:04 +02:00
|
|
|
}
|
2010-03-15 05:33:22 +01:00
|
|
|
|
2019-10-20 01:25:42 +02:00
|
|
|
/* UE4 uses interleaved mono MSADPCM, try to autodetect without breaking normal MSADPCM */
|
2024-03-31 16:09:36 +02:00
|
|
|
if (fmt.coding_type == coding_MSADPCM && is_ue4_msadpcm(sf, &fmt, fact_sample_count, start_offset, data_size)) {
|
2019-10-20 01:25:42 +02:00
|
|
|
vgmstream->coding_type = coding_MSADPCM_int;
|
2021-06-20 18:10:34 +02:00
|
|
|
vgmstream->codec_config = 1; /* mark as UE4 MSADPCM */
|
2019-10-20 01:25:42 +02:00
|
|
|
vgmstream->frame_size = fmt.block_size;
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
2020-06-30 23:20:36 +02:00
|
|
|
vgmstream->interleave_block_size = get_ue4_msadpcm_interleave(sf, &fmt, start_offset, data_size);
|
2019-10-20 01:25:42 +02:00
|
|
|
if (fmt.size == 0x36)
|
2020-06-30 23:20:36 +02:00
|
|
|
vgmstream->num_samples = read_s32le(fmt.offset+0x08+0x32, sf);
|
2024-03-31 16:09:36 +02:00
|
|
|
else if (fmt.size == 0x32)
|
|
|
|
vgmstream->num_samples = msadpcm_bytes_to_samples(data_size / fmt.channels, fmt.block_size, 1);
|
2019-10-20 01:25:42 +02:00
|
|
|
}
|
|
|
|
|
2018-09-04 17:10:41 +02:00
|
|
|
/* Dynasty Warriors 5 (Xbox) 6ch interleaves stereo frames, probably not official */
|
|
|
|
if (vgmstream->coding_type == coding_XBOX_IMA && vgmstream->channels > 2) {
|
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
vgmstream->interleave_block_size = 0x24; /* block_size / channels */
|
|
|
|
if (vgmstream->channels > 2 && vgmstream->channels % 2 != 0)
|
|
|
|
goto fail; /* only 2ch+..+2ch layout is known */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-27 00:43:52 +01:00
|
|
|
/* meta, loops */
|
|
|
|
vgmstream->meta_type = meta_RIFF_WAVE;
|
2008-07-21 07:03:16 +02:00
|
|
|
if (loop_flag) {
|
2017-12-27 00:43:52 +01:00
|
|
|
if (loop_start_ms >= 0) {
|
|
|
|
vgmstream->loop_start_sample = (long long)loop_start_ms*fmt.sample_rate/1000;
|
|
|
|
vgmstream->loop_end_sample = (long long)loop_end_ms*fmt.sample_rate/1000;
|
2017-01-08 01:09:20 +01:00
|
|
|
vgmstream->meta_type = meta_RIFF_WAVE_labl;
|
2008-10-08 02:09:11 +02:00
|
|
|
}
|
2018-03-03 19:07:59 +01:00
|
|
|
else if (loop_start_smpl >= 0) {
|
|
|
|
vgmstream->loop_start_sample = loop_start_smpl;
|
|
|
|
vgmstream->loop_end_sample = loop_end_smpl;
|
2018-10-07 02:24:37 +02:00
|
|
|
/* end must add +1, but check in case of faulty tools */
|
|
|
|
if (vgmstream->loop_end_sample - 1 == vgmstream->num_samples)
|
|
|
|
vgmstream->loop_end_sample--;
|
|
|
|
|
2008-10-08 02:09:11 +02:00
|
|
|
vgmstream->meta_type = meta_RIFF_WAVE_smpl;
|
|
|
|
}
|
2018-03-03 19:07:59 +01:00
|
|
|
else if (loop_start_wsmp >= 0) {
|
|
|
|
vgmstream->loop_start_sample = loop_start_wsmp;
|
|
|
|
vgmstream->loop_end_sample = loop_end_wsmp;
|
2018-02-23 23:30:55 +01:00
|
|
|
vgmstream->meta_type = meta_RIFF_WAVE_wsmp;
|
|
|
|
}
|
2022-12-31 17:31:20 +01:00
|
|
|
else if (fmt.coding_type == coding_L5_555 && mwv_ctrl_offset) {
|
|
|
|
vgmstream->loop_start_sample = read_s32le(mwv_ctrl_offset + 0x0c, sf);
|
2017-12-27 00:43:52 +01:00
|
|
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
2022-12-31 17:31:20 +01:00
|
|
|
vgmstream->meta_type = meta_RIFF_WAVE_MWV;
|
2009-01-04 16:36:06 +01:00
|
|
|
}
|
2018-09-21 13:31:56 +02:00
|
|
|
else if (loop_start_cue != -1) {
|
|
|
|
vgmstream->loop_start_sample = loop_start_cue;
|
|
|
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
|
|
|
}
|
2020-03-01 12:22:50 +01:00
|
|
|
else if (loop_start_nxbf != -1) {
|
|
|
|
switch (fmt.coding_type) {
|
|
|
|
case coding_PCM16LE:
|
|
|
|
vgmstream->loop_start_sample = pcm_bytes_to_samples(loop_start_nxbf, vgmstream->channels, 16);
|
|
|
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
|
|
|
break;
|
2021-07-29 17:08:30 +02:00
|
|
|
default:
|
|
|
|
break;
|
2020-03-01 12:22:50 +01:00
|
|
|
}
|
|
|
|
}
|
2008-07-21 07:03:16 +02:00
|
|
|
}
|
2010-03-15 05:33:22 +01:00
|
|
|
|
2020-06-30 23:20:36 +02:00
|
|
|
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
|
2017-12-27 00:43:52 +01:00
|
|
|
goto fail;
|
2008-07-06 20:05:04 +02:00
|
|
|
|
2019-01-19 23:08:26 +01:00
|
|
|
return vgmstream;
|
2017-12-27 00:43:52 +01:00
|
|
|
|
2008-07-06 20:05:04 +02:00
|
|
|
fail:
|
2017-12-27 00:43:52 +01:00
|
|
|
close_vgmstream(vgmstream);
|
2008-07-06 20:05:04 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2009-05-25 22:59:50 +02:00
|
|
|
|
2024-03-31 16:09:36 +02:00
|
|
|
static bool is_ue4_msadpcm_blocks(STREAMFILE* sf, riff_fmt_chunk* fmt, uint32_t offset, uint32_t data_size) {
|
|
|
|
uint32_t max_offset = 10 * fmt->block_size; /* try N blocks */
|
|
|
|
if (max_offset > offset + data_size)
|
|
|
|
max_offset = offset + data_size;
|
|
|
|
|
|
|
|
/* UE4 encoder doesn't calculate optimal coefs and uses certain values every frame.
|
|
|
|
* Implicitly this should reject stereo frames (not used in UE4), that have scale/coefs in different positions. */
|
|
|
|
while (offset < max_offset) {
|
|
|
|
uint8_t coefs = read_u8(offset+0x00, sf);
|
|
|
|
uint16_t scale = read_u16le(offset+0x01, sf);
|
|
|
|
|
|
|
|
/* mono frames should only fill the lower bits (4b index) */
|
|
|
|
if (coefs > 0x07)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* size 0x36 always uses scale 0x00E6 and coefs 0x00 while size 0x32 usually does, except for early
|
|
|
|
* games where it may use more standard values [2013: Infected Wars (iPhone)] */
|
|
|
|
if (fmt->block_size == 0x200) {
|
|
|
|
if (scale == 0x00E6 && coefs != 0x00)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (scale > 0x4000) { /* observed max (high scales exists) */
|
|
|
|
VGM_LOG("RIFF: unexpected UE4 MSADPCM scale=%x\n", scale);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-01-19 23:08:26 +01:00
|
|
|
|
2024-03-31 16:09:36 +02:00
|
|
|
offset += fmt->block_size;
|
|
|
|
}
|
2019-01-19 23:08:26 +01:00
|
|
|
|
2024-03-31 16:09:36 +02:00
|
|
|
return true;
|
|
|
|
}
|
2019-01-19 23:08:26 +01:00
|
|
|
|
2024-03-31 16:09:36 +02:00
|
|
|
/* UE4 MSADPCM has a few minor quirks we can use to detect it */
|
|
|
|
static bool is_ue4_msadpcm(STREAMFILE* sf, riff_fmt_chunk* fmt, int fact_sample_count, off_t start, uint32_t data_size) {
|
2019-01-19 23:08:26 +01:00
|
|
|
|
2024-03-31 16:09:36 +02:00
|
|
|
/* UE4 allows >=2ch (sample rate may be anything), while mono files are just regular MSADPCM */
|
|
|
|
if (fmt->channels < 2)
|
|
|
|
return false;
|
2019-01-19 23:08:26 +01:00
|
|
|
|
2024-03-31 16:09:36 +02:00
|
|
|
/* UE4 encoder doesn't add "fact" while regular encoders usually do (but not always) */
|
|
|
|
if (fact_sample_count != 0)
|
|
|
|
return false;
|
2019-01-19 23:08:26 +01:00
|
|
|
|
2024-03-31 16:09:36 +02:00
|
|
|
/* later UE4 versions use fmt size 0x36 (unlike standard MSADPCM's 0x32), and only certain block sizes */
|
|
|
|
if (fmt->size == 0x36) {
|
|
|
|
if (!(fmt->block_size == 0x200))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (fmt->size == 0x32) {
|
|
|
|
/* other than 0x200 is rarely used [2013: Infected Wars (iPhone)] */
|
|
|
|
if (!(fmt->block_size == 0x200 || fmt->block_size == 0x9b || fmt->block_size == 0x69))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* could do it for fmt size 0x36 too but not important */
|
|
|
|
if (!is_ue4_msadpcm_blocks(sf, fmt, start, data_size))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
2019-01-19 23:08:26 +01:00
|
|
|
}
|
|
|
|
|
2024-03-31 16:09:36 +02:00
|
|
|
/* UE4's class is "ADPCM", assume it's the extension too (also safer since can't tell UE4 MSADPCM from .wav ADPCM in some cases) */
|
|
|
|
if (!check_extensions(sf, "adpcm"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2019-01-19 23:08:26 +01:00
|
|
|
}
|
|
|
|
|
2019-10-20 01:25:42 +02:00
|
|
|
/* for maximum annoyance later UE4 versions (~v4.2x?) interleave single frames instead of
|
2022-08-14 12:24:57 +02:00
|
|
|
* half interleave, but don't have flags to detect so we need some heuristics. Most later
|
2024-03-31 16:09:36 +02:00
|
|
|
* games with 0x36 chunk size use v2_interleave but notably Travis Strikes Again doesn't */
|
2020-06-30 23:20:36 +02:00
|
|
|
static size_t get_ue4_msadpcm_interleave(STREAMFILE* sf, riff_fmt_chunk* fmt, off_t start, size_t size) {
|
2021-08-22 12:17:45 +02:00
|
|
|
size_t v1_interleave = size / fmt->channels;
|
2019-10-20 01:25:42 +02:00
|
|
|
size_t v2_interleave = fmt->block_size;
|
2022-08-14 12:24:57 +02:00
|
|
|
uint8_t nibbles_half[0x20] = {0};
|
|
|
|
uint8_t nibbles_full[0x20] = {0};
|
|
|
|
int nibbles_size = sizeof(nibbles_full);
|
|
|
|
uint8_t empty[0x20] = {0};
|
|
|
|
int is_blank_half, is_blank_full;
|
2019-10-20 01:25:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* old versions */
|
|
|
|
if (fmt->size == 0x32)
|
|
|
|
return v1_interleave;
|
|
|
|
|
|
|
|
/* 6ch only observed in later versions [Fortnite (PC)], not padded */
|
2022-08-14 12:24:57 +02:00
|
|
|
if (fmt->channels > 2 || fmt->channels < 2)
|
2019-10-20 01:25:42 +02:00
|
|
|
return v2_interleave;
|
|
|
|
|
2022-08-14 12:24:57 +02:00
|
|
|
read_streamfile(nibbles_half, start + v1_interleave - nibbles_size, nibbles_size, sf);
|
|
|
|
is_blank_half = memcmp(nibbles_half, empty, nibbles_size) == 0;
|
|
|
|
|
|
|
|
read_streamfile(nibbles_full, start + size - nibbles_size, nibbles_size, sf);
|
|
|
|
is_blank_full = memcmp(nibbles_full, empty, nibbles_size) == 0;
|
2019-10-20 01:25:42 +02:00
|
|
|
|
|
|
|
/* last frame is almost always padded, so should at half interleave */
|
2024-03-31 16:09:36 +02:00
|
|
|
if (!is_blank_half && !is_blank_full)
|
2019-10-20 01:25:42 +02:00
|
|
|
return v1_interleave;
|
|
|
|
|
2024-03-31 16:09:36 +02:00
|
|
|
/* last frame is padded, and half interleave is not: should be regular interleave */
|
|
|
|
if (!is_blank_half && is_blank_full)
|
2022-08-14 12:24:57 +02:00
|
|
|
return v2_interleave;
|
2022-09-16 23:40:27 +02:00
|
|
|
|
2019-10-20 01:25:42 +02:00
|
|
|
/* last frame is silent-ish, so should at half interleave (TSA's SML_DarknessLoop_01, TSA_CAD_YAKATA)
|
|
|
|
* this doesn't work too well b/c num_samples at 0x36 uses all data, may need adjustment */
|
|
|
|
{
|
2022-08-14 12:24:57 +02:00
|
|
|
int empty_nibbles_full = 1, empty_nibbles_half = 1;
|
2019-10-20 01:25:42 +02:00
|
|
|
|
2024-03-31 16:09:36 +02:00
|
|
|
for (int i = 0; i < sizeof(nibbles_full); i++) {
|
2022-08-14 12:24:57 +02:00
|
|
|
uint8_t n1 = ((nibbles_full[i] >> 0) & 0x0f);
|
|
|
|
uint8_t n2 = ((nibbles_full[i] >> 4) & 0x0f);
|
2019-10-20 01:25:42 +02:00
|
|
|
if ((n1 != 0x0 && n1 != 0xf && n1 != 0x1) || (n2 != 0x0 && n2 != 0xf && n2 != 0x1)) {
|
2022-08-14 12:24:57 +02:00
|
|
|
empty_nibbles_full = 0;
|
2019-10-20 01:25:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-31 16:09:36 +02:00
|
|
|
for (int i = 0; i < sizeof(nibbles_half); i++) {
|
2022-08-14 12:24:57 +02:00
|
|
|
uint8_t n1 = ((nibbles_half[i] >> 0) & 0x0f);
|
|
|
|
uint8_t n2 = ((nibbles_half[i] >> 4) & 0x0f);
|
2019-10-20 01:25:42 +02:00
|
|
|
if ((n1 != 0x0 && n1 != 0xf && n1 != 0x1) || (n2 != 0x0 && n2 != 0xf && n2 != 0x1)) {
|
2022-08-14 12:24:57 +02:00
|
|
|
empty_nibbles_half = 0;
|
2019-10-20 01:25:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-31 16:09:36 +02:00
|
|
|
if (empty_nibbles_full && empty_nibbles_half)
|
2019-10-20 01:25:42 +02:00
|
|
|
return v1_interleave;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* other tests? */
|
|
|
|
|
|
|
|
return v2_interleave; /* favor newer games */
|
|
|
|
}
|
|
|
|
|
2020-06-14 15:50:50 +02:00
|
|
|
/* same but big endian, seen in the spec and in Kitchenette (PC) (possibly from Adobe Director) */
|
2020-06-30 23:20:36 +02:00
|
|
|
VGMSTREAM* init_vgmstream_rifx(STREAMFILE* sf) {
|
|
|
|
VGMSTREAM* vgmstream = NULL;
|
2017-12-27 00:43:52 +01:00
|
|
|
riff_fmt_chunk fmt = {0};
|
2012-08-20 07:17:52 +02:00
|
|
|
|
2017-12-27 00:43:52 +01:00
|
|
|
size_t file_size, riff_size, data_size = 0;
|
|
|
|
off_t start_offset = 0;
|
2009-05-25 22:59:50 +02:00
|
|
|
|
|
|
|
int loop_flag = 0;
|
|
|
|
off_t loop_start_offset = -1;
|
|
|
|
off_t loop_end_offset = -1;
|
|
|
|
|
2017-12-27 00:43:52 +01:00
|
|
|
int FormatChunkFound = 0, DataChunkFound = 0;
|
|
|
|
|
2009-05-25 22:59:50 +02:00
|
|
|
|
2021-09-19 23:52:33 +02:00
|
|
|
/* checks */
|
|
|
|
if (!is_id32be(0x00,sf, "RIFX"))
|
2009-05-25 22:59:50 +02:00
|
|
|
goto fail;
|
|
|
|
|
2021-09-19 23:52:33 +02:00
|
|
|
if (!check_extensions(sf, "wav,lwav"))
|
2009-05-25 22:59:50 +02:00
|
|
|
goto fail;
|
2021-09-19 23:52:33 +02:00
|
|
|
|
2021-07-13 23:46:27 +02:00
|
|
|
if (!is_id32be(0x08,sf, "WAVE"))
|
2009-05-25 22:59:50 +02:00
|
|
|
goto fail;
|
|
|
|
|
2021-07-13 23:46:27 +02:00
|
|
|
riff_size = read_u32be(0x04,sf);
|
2020-06-30 23:20:36 +02:00
|
|
|
file_size = get_streamfile_size(sf);
|
2009-05-25 22:59:50 +02:00
|
|
|
|
2017-12-27 00:43:52 +01:00
|
|
|
/* check for truncated RIFF */
|
2009-05-25 22:59:50 +02:00
|
|
|
if (file_size < riff_size+8) goto fail;
|
|
|
|
|
|
|
|
/* read through chunks to verify format and find metadata */
|
|
|
|
{
|
|
|
|
off_t current_chunk = 0xc; /* start with first chunk */
|
|
|
|
|
|
|
|
while (current_chunk < file_size && current_chunk < riff_size+8) {
|
2020-06-30 23:20:36 +02:00
|
|
|
uint32_t chunk_type = read_32bitBE(current_chunk,sf);
|
|
|
|
off_t chunk_size = read_32bitBE(current_chunk+4,sf);
|
2009-05-25 22:59:50 +02:00
|
|
|
|
|
|
|
if (current_chunk+8+chunk_size > file_size) goto fail;
|
|
|
|
|
|
|
|
switch(chunk_type) {
|
|
|
|
case 0x666d7420: /* "fmt " */
|
|
|
|
/* only one per file */
|
|
|
|
if (FormatChunkFound) goto fail;
|
|
|
|
FormatChunkFound = 1;
|
|
|
|
|
2022-12-31 17:31:20 +01:00
|
|
|
if (!read_fmt(1, sf, current_chunk, &fmt))
|
2012-08-20 07:17:52 +02:00
|
|
|
goto fail;
|
|
|
|
|
2009-05-25 22:59:50 +02:00
|
|
|
break;
|
|
|
|
case 0x64617461: /* data */
|
|
|
|
/* at most one per file */
|
|
|
|
if (DataChunkFound) goto fail;
|
|
|
|
DataChunkFound = 1;
|
|
|
|
|
|
|
|
start_offset = current_chunk + 8;
|
|
|
|
data_size = chunk_size;
|
|
|
|
break;
|
|
|
|
case 0x736D706C: /* smpl */
|
2017-12-27 00:43:52 +01:00
|
|
|
/* check loop count and loop info */
|
2020-06-30 23:20:36 +02:00
|
|
|
if (read_32bitBE(current_chunk+0x24, sf)==1) {
|
|
|
|
if (read_32bitBE(current_chunk+0x2c+4, sf)==0) {
|
2009-05-25 22:59:50 +02:00
|
|
|
loop_flag = 1;
|
2020-06-30 23:20:36 +02:00
|
|
|
loop_start_offset = read_32bitBE(current_chunk+0x2c+8, sf);
|
|
|
|
loop_end_offset = read_32bitBE(current_chunk+0x2c+0xc,sf) + 1;
|
2009-05-25 22:59:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* ignorance is bliss */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
current_chunk += 8+chunk_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!FormatChunkFound || !DataChunkFound) goto fail;
|
|
|
|
|
2017-04-22 10:18:47 +02:00
|
|
|
|
2017-12-27 00:43:52 +01:00
|
|
|
/* build the VGMSTREAM */
|
2021-08-22 12:17:45 +02:00
|
|
|
vgmstream = allocate_vgmstream(fmt.channels,loop_flag);
|
2017-12-27 00:43:52 +01:00
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
vgmstream->sample_rate = fmt.sample_rate;
|
|
|
|
|
|
|
|
/* init, samples */
|
2012-08-20 07:17:52 +02:00
|
|
|
switch (fmt.coding_type) {
|
2009-05-25 22:59:50 +02:00
|
|
|
case coding_PCM16BE:
|
2019-09-14 12:42:08 +02:00
|
|
|
case coding_PCM8_U:
|
2021-11-12 18:45:18 +01:00
|
|
|
vgmstream->num_samples = pcm_bytes_to_samples(data_size, vgmstream->channels, fmt.bps);
|
2012-08-20 07:17:52 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto fail;
|
2009-05-25 22:59:50 +02:00
|
|
|
}
|
|
|
|
|
2017-12-27 00:43:52 +01:00
|
|
|
/* coding, layout, interleave */
|
2012-08-20 07:17:52 +02:00
|
|
|
vgmstream->coding_type = fmt.coding_type;
|
|
|
|
switch (fmt.coding_type) {
|
|
|
|
default:
|
2017-12-27 00:43:52 +01:00
|
|
|
vgmstream->layout_type = layout_interleave;
|
|
|
|
vgmstream->interleave_block_size = fmt.interleave;
|
2012-08-20 07:17:52 +02:00
|
|
|
break;
|
|
|
|
}
|
2009-05-25 22:59:50 +02:00
|
|
|
|
2017-12-27 00:43:52 +01:00
|
|
|
/* meta, loops */
|
|
|
|
vgmstream->meta_type = meta_RIFX_WAVE;
|
2009-05-25 22:59:50 +02:00
|
|
|
if (loop_flag) {
|
2017-12-27 00:43:52 +01:00
|
|
|
if (loop_start_offset >= 0) {
|
2009-05-25 22:59:50 +02:00
|
|
|
vgmstream->loop_start_sample = loop_start_offset;
|
|
|
|
vgmstream->loop_end_sample = loop_end_offset;
|
2018-10-07 02:24:37 +02:00
|
|
|
/* end must add +1, but check in case of faulty tools */
|
|
|
|
if (vgmstream->loop_end_sample - 1 == vgmstream->num_samples)
|
|
|
|
vgmstream->loop_end_sample--;
|
|
|
|
|
2009-05-25 22:59:50 +02:00
|
|
|
vgmstream->meta_type = meta_RIFX_WAVE_smpl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-30 23:20:36 +02:00
|
|
|
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
|
2017-12-27 00:43:52 +01:00
|
|
|
goto fail;
|
2009-05-25 22:59:50 +02:00
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
2017-12-27 00:43:52 +01:00
|
|
|
close_vgmstream(vgmstream);
|
2009-05-25 22:59:50 +02:00
|
|
|
return NULL;
|
|
|
|
}
|