Merge pull request #869 from bnnm/mpc-aac

- Fix .mpc/mp+ total samples and encoder delay
- Fix .vxn encoder delay / gapless [Asphalt 9 (Android)]
- Fix EA SWVR .stream sample rate in some cases [Nascar Rumble (PS1)]
- Fix .wem with fully truncated PCM [Metal Gear Solid V (PC)]
- Fix some .aac encoder delay/sample issues
- Remove unneeded .hca subkeys (use .acb/awb)
This commit is contained in:
bnnm 2021-06-01 00:42:56 +02:00 committed by GitHub
commit 7cfa1f2960
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 4344 additions and 4267 deletions

View File

@ -570,6 +570,7 @@ STREAMFILE* ffmpeg_get_streamfile(ffmpeg_codec_data* data);
/* ffmpeg_decoder_utils.c (helper-things) */
ffmpeg_codec_data* init_ffmpeg_atrac3_raw(STREAMFILE* sf, off_t offset, size_t data_size, int sample_count, int channels, int sample_rate, int block_align, int encoder_delay);
ffmpeg_codec_data* init_ffmpeg_atrac3_riff(STREAMFILE* sf, off_t offset, int* out_samples);
ffmpeg_codec_data* init_ffmpeg_aac(STREAMFILE* sf, off_t offset, size_t size);
/* ffmpeg_decoder_custom_opus.c (helper-things) */
@ -655,6 +656,7 @@ size_t ac3_bytes_to_samples(size_t bytes, int full_block_align, int channels);
size_t aac_get_samples(STREAMFILE* sf, off_t start_offset, size_t bytes);
size_t mpeg_get_samples(STREAMFILE* sf, off_t start_offset, size_t bytes);
int32_t mpeg_get_samples_clean(STREAMFILE* sf, off_t start, size_t size, size_t* p_loop_start, size_t* p_loop_end, int is_vbr);
int mpc_get_samples(STREAMFILE* sf, off_t offset, int32_t* p_samples, int32_t* p_delay);
/* helper to pass a wrapped, clamped, fake extension-ed, SF to another meta */

View File

@ -1006,6 +1006,7 @@ size_t aac_get_samples(STREAMFILE* sf, off_t start_offset, size_t bytes) {
if (frame_size <= 0x08)
break;
//;VGM_LOG("AAC: %lx, %x\n", offset, frame_size);
frames++;
offset += frame_size;
}
@ -1013,6 +1014,82 @@ size_t aac_get_samples(STREAMFILE* sf, off_t start_offset, size_t bytes) {
return frames * samples_per_frame;
}
/* variable-sized var reader */
static int mpc_get_size(uint8_t* header, int header_size, int pos, int32_t* p_size) {
uint8_t tmp;
int32_t size = 0;
do {
if (pos >= header_size)
return pos;
tmp = header[pos];
size = (size << 7) | (tmp & 0x7F);
pos++;
}
while((tmp & 0x80));
*p_size = size;
return pos;
}
int mpc_get_samples(STREAMFILE* sf, off_t offset, int32_t* p_samples, int32_t* p_delay) {
uint8_t header[0x20];
int pos, size;
int32_t samples = 0, delay = 0;
if (read_streamfile(header, offset, sizeof(header), sf) != sizeof(header))
goto fail;;
if ((get_u32be(header) & 0xFFFFFF0F) == get_id32be("MP+\x07")) {
samples = get_u32le(header + 0x04) * 1152; /* total frames */
delay = 481; /* MPC_DECODER_SYNTH_DELAY */
samples -= delay;
/* in theory one header field can contain actual delay, not observed */
}
else if (get_u32be(header) == get_id32be("MPCK")) {
/* V8 header is made if mini chunks (16b type, 8b size including type+size):
* - SH: stream header
* - RG: replay gain
* - EI: encoder info
* - SO: seek?
* - ST: stream?
* - AP: audio part start */
if (get_u16be(header + 0x04) != 0x5348)
goto fail;
size = get_u8(header + 0x06);
if (0x04 + size > sizeof(header))
goto fail;
if (get_u8(header + 0x0b) != 0x08)
goto fail;
/* SH chunk: */
/* 0x00: CRC */
/* 0x04: header version (8) */
/* 0x05: samples (variable sized) */
/* 0xNN: "beginning silence" (variable sized) */
/* 0xNN: bitpacked channels/rate/etc */
pos = mpc_get_size(header, sizeof(header), 0x0C, &samples);
pos = mpc_get_size(header, sizeof(header), pos, &delay);
samples -= delay; /* original delay, not SYNTH_DELAY */
delay += 481; /* MPC_DECODER_SYNTH_DELAY */
/* SYNTH_DELAY seems to be forced, but official code isn't very clear (known samples set delay to 0 but need SYNTH DELAY) */
}
else {
goto fail;
}
if (p_samples) *p_samples = samples;
if (p_delay) *p_delay = delay;
return 1;
fail:
return 0;
}
/* ******************************************** */
/* CUSTOM STREAMFILES */
/* ******************************************** */

View File

@ -187,4 +187,24 @@ fail:
return NULL;
}
ffmpeg_codec_data* init_ffmpeg_aac(STREAMFILE* sf, off_t offset, size_t size) {
ffmpeg_codec_data* data = NULL;
data = init_ffmpeg_offset(sf, offset, size);
if (!data) goto fail;
/* seeks to 0 eats first frame for whatever reason */
ffmpeg_set_force_seek(data);
/* raw AAC doesn't set this, while some decoders like FAAD remove 1024,
* but should be handled in container as each encoder uses its own value
* (Apple: 2112, FAAD: probably 1024, etc) */
//ffmpeg_set_skip_samples(data, 1024);
return data;
fail:
free_ffmpeg(data);
return NULL;
}
#endif

View File

@ -4,43 +4,46 @@
/* SWVR - from EA games, demuxed from .av/trk/mis/etc [Future Cop L.A.P.D. (PS/PC), Freekstyle (PS2/GC), EA Sports Supercross (PS)] */
VGMSTREAM * init_vgmstream_ea_swvr(STREAMFILE *streamFile) {
VGMSTREAM* init_vgmstream_ea_swvr(STREAMFILE* sf) {
VGMSTREAM * vgmstream = NULL;
off_t start_offset;
int loop_flag = 0, channel_count, sample_rate, big_endian;
int loop_flag = 0, channels, sample_rate, big_endian;
coding_t coding;
uint32_t block_id;
int32_t (*read_32bit)(off_t,STREAMFILE*) = NULL;
int16_t (*read_16bit)(off_t,STREAMFILE*) = NULL;
int total_subsongs, target_subsong = streamFile->stream_index;
int total_subsongs, target_subsong = sf->stream_index;
/* checks */
/* .stream: common (found inside files)
* .str: shortened, probably unnecessary */
if (!check_extensions(streamFile,"stream,str"))
if (!check_extensions(sf,"stream,str"))
goto fail;
/* Files have no actual audio headers, so we inspect the first block for known values.
* Freekstyle uses multiblocks/subsongs (though some subsongs may be clones?) */
/* blocks ids are in machine endianness */
if (read_32bitBE(0x00,streamFile) == 0x52565753) { /* "RVWS" (PS1/PS2/PC) */
if (read_u32be(0x00,sf) == get_id32be("RVWS")) { /* PS1/PS2/PC */
big_endian = 0;
read_32bit = read_32bitLE;
read_16bit = read_16bitLE;
start_offset = read_32bit(0x04, streamFile);
start_offset = read_32bit(0x04, sf);
}
else if (read_32bitBE(0x00,streamFile) == 0x53575652) { /* "SWVR" (GC) */
else if (read_u32be(0x00,sf) == get_id32be("SWVR")) { /* GC */
big_endian = 1;
read_32bit = read_32bitBE;
read_16bit = read_16bitBE;
start_offset = read_32bit(0x04, streamFile);
start_offset = read_32bit(0x04, sf);
}
else if (read_32bitBE(0x00,streamFile) == 0x4D474156) { /* "MGAV", Freekstyle (PS2) raw movies */
else if (read_u32be(0x00,sf) == get_id32be("MGAV")) { /* Freekstyle (PS2) raw movies */
big_endian = 0;
read_32bit = read_32bitLE;
read_16bit = read_16bitLE;
start_offset = 0x00;
}
else if (read_32bitBE(0x00,streamFile) == 0x4453504D) { /* "DSPM", Freekstyle (GC) raw movies */
else if (read_u32be(0x00,sf) == get_id32be("DSPM")) { /* Freekstyle (GC) raw movies */
big_endian = 1;
read_32bit = read_32bitBE;
read_16bit = read_16bitBE;
@ -50,64 +53,81 @@ VGMSTREAM * init_vgmstream_ea_swvr(STREAMFILE *streamFile) {
goto fail;
}
if (read_32bit(start_offset+0x00, streamFile) == 0x50414444) /* "PADD" (Freekstyle) */
start_offset += read_32bit(start_offset+0x04, streamFile);
else if (read_32bit(start_offset+0x10, streamFile) == 0x53484452) /* "SHDR" (Future Cop PC) */
start_offset += read_32bit(start_offset+0x04, streamFile);
if (read_32bit(start_offset+0x00, sf) == get_id32be("PADD")) /* Freekstyle */
start_offset += read_32bit(start_offset+0x04, sf);
if (read_32bit(start_offset+0x00, streamFile) == 0x46494C4C) /* "FILL" (Freekstyle) */
start_offset += read_32bit(start_offset+0x04, streamFile);
if (read_32bit(start_offset+0x00, sf) == get_id32be("FILL")) /* Freekstyle */
start_offset += read_32bit(start_offset+0x04, sf);
total_subsongs = 1;
block_id = read_32bit(start_offset, streamFile);
block_id = read_32bit(start_offset, sf);
/* value after block id (usually at 0x38) is number of blocks of 0x6000 (results in file size, including FILLs) */
/* files are basically headerless so we inspect the first block
* Freekstyle uses multiblocks/subsongs (though some subsongs may be clones?) */
/* intended sample rate for PSX music (verified in emus) should be 14260, but is found in ELF as pitch value
* (ex. Nascar Rumble 0x052C in SLUS_010.68 at 0x000143BC): 0x052C * 44100 / 4096 ~= 14254.98046875hz
* Future Cop PSX pitch looks similar (comparing vs recordings). */
switch(block_id) {
case 0x5641474D: /* "VAGM" */
case 0x5641474D: /* "VAGM" (stereo music) */
coding = coding_PSX;
if (read_16bit(start_offset+0x1a, streamFile) == 0x0024) {
total_subsongs = read_32bit(start_offset+0x0c, streamFile)+1;
sample_rate = 22050;
if (read_16bit(start_offset+0x1a, sf) == 0x0024) {
total_subsongs = read_32bit(start_offset+0x0c, sf)+1;
sample_rate = 22050; /* Freekstyle (PS2) */
}
else {
sample_rate = 14008;
sample_rate = 1324 * 44100 / 4096; /* ~14254 [Future Cop (PS1), Nascar Rumble (PS1), EA Sports Motocross (PS1)] */
}
channel_count = 2;
channels = 2;
break;
case 0x56414742: /* "VAGB" */
case 0x56414742: /* "VAGB" (mono sfx/voices)*/
coding = coding_PSX;
if (read_16bit(start_offset+0x1a, streamFile) == 0x6400) {
sample_rate = 22050;
if (read_16bit(start_offset+0x1a, sf) == 0x6400) {
sample_rate = 22050; /* Freekstyle (PS2) */
}
else {
sample_rate = 14008;
/* approximate as pitches vary per file (ex. Nascar Rumble: engine=3779, heli=22050, commentary=11050) */
sample_rate = 1080 * 44100 / 4096; /* ~11627 [EA Sports Motocross (PS1)] */
}
channel_count = 1;
channels = 1;
break;
case 0x4453504D: /* "DSPM" */
case 0x4453504D: /* "DSPM" (stereo music) */
coding = coding_NGC_DSP;
total_subsongs = read_32bit(start_offset+0x0c, streamFile)+1;
sample_rate = 22050;
channel_count = 2;
total_subsongs = read_32bit(start_offset+0x0c, sf)+1;
sample_rate = 22050; /* Freekstyle (GC) */
channels = 2;
break;
case 0x44535042: /* "DSPB" */
case 0x44535042: /* "DSPB" (mono voices/sfx) */
coding = coding_NGC_DSP;
channel_count = 1;
sample_rate = 22050;
channels = 1;
sample_rate = 22050; /* Freekstyle (GC) */
break;
case 0x4D534943: /* "MSIC" */
case 0x4D534943: /* "MSIC" (stereo music) */
coding = coding_PCM8_U_int;
channel_count = 2;
sample_rate = 14008;
channels = 2;
sample_rate = 14291; /* assumed, by comparing vs PSX output [Future Cop (PC)] */
break;
case 0x53484F43: /* "SHOC" (a generic block but hopefully has PC sounds) */
if (read_32bit(start_offset+0x10, streamFile) == 0x53484F43) { /* SHDR */
coding = coding_PCM8_U_int; //todo there are other codecs
channel_count = 1;
sample_rate = 14008;
if (read_32bit(start_offset+0x10, sf) == get_id32be("SHDR")) { /* Future Cop (PC) */
/* there is a mini header? after SHDR
* 0x00: 5
* 0x04: "snds"
* 0x08: channels?
* 0x0c: data size without blocks/padding
* 0x10: null
* 0x14: null
* 0x18: null
* 0x1c: 1
* 0x20: 1
* 0x24: 0x4F430000 */
if (read_32bit(start_offset+0x18, sf) != get_id32be("snds"))
goto fail;
coding = coding_PCM8_U_int;
channels = 1;
sample_rate = 16000; /* assumed */
}
else {
//todo
/* The Lord of the Rings - The Return of the King (PC) uses IMA for sfx (in non-RVWS chunks)
* and some unknown codec for streams (mixed with strings and cutscene(?) commands) */
goto fail;
}
break;
@ -119,25 +139,25 @@ VGMSTREAM * init_vgmstream_ea_swvr(STREAMFILE *streamFile) {
if (target_subsong == 0) target_subsong = 1;
if (target_subsong < 0 || target_subsong > total_subsongs || total_subsongs < 1) goto fail;
loop_flag = 0;//(channel_count > 1); /* some Future Cop LAPD tracks repeat but other games have fadeouts */
loop_flag = 0;//(channels > 1); /* some Future Cop LAPD tracks repeat but other games have fadeouts */
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
vgmstream = allocate_vgmstream(channels, loop_flag);
if (!vgmstream) goto fail;
vgmstream->meta_type = meta_EA_SWVR;
vgmstream->sample_rate = sample_rate;
vgmstream->codec_endian = big_endian;
vgmstream->num_streams = total_subsongs;
vgmstream->stream_size = get_streamfile_size(streamFile) / total_subsongs; /* approx... */
vgmstream->stream_size = get_streamfile_size(sf) / total_subsongs; /* approx... */
vgmstream->coding_type = coding;
vgmstream->layout_type = layout_blocked_ea_swvr;
/* DSP coefs are loaded per block */
/* some files (voices etc) decode with pops but seems a mastering problem */
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
if (!vgmstream_open_stream(vgmstream,sf,start_offset))
goto fail;
/* calc num_samples manually */
@ -155,7 +175,7 @@ VGMSTREAM * init_vgmstream_ea_swvr(STREAMFILE *streamFile) {
}
vgmstream->num_samples += num_samples;
}
while (vgmstream->next_block_offset < get_streamfile_size(streamFile));
while (vgmstream->next_block_offset < get_streamfile_size(sf));
block_update(start_offset, vgmstream);
}

View File

@ -8,7 +8,7 @@ static int find_meta_loops(ffmpeg_codec_data* data, int32_t* p_loop_start, int32
/* parses any format supported by FFmpeg and not handled elsewhere:
* - MP3 (.mp3, .mus): Marc Ecko's Getting Up (PC)
* - MPC (.mpc): Moonshine Runners (PC), Asphalt 7 (PC)
* - MPC (.mpc, mp+): Moonshine Runners (PC), Asphalt 7 (PC)
* - FLAC (.flac): Warcraft 3 Reforged (PC), Call of Duty: Ghosts (PC)
* - DUCK (.wav): Sonic Jam (SAT), Virtua Fighter 2 (SAT)
* - ALAC/AAC (.caf): Chrono Trigger (iOS)
@ -24,7 +24,7 @@ VGMSTREAM* init_vgmstream_ffmpeg(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
ffmpeg_codec_data* data = NULL;
int loop_flag = 0;
int32_t loop_start = 0, loop_end = 0, num_samples = 0;
int32_t loop_start = 0, loop_end = 0, num_samples = 0, encoder_delay = 0;
int total_subsongs, target_subsong = sf->stream_index;
/* no checks */
@ -66,6 +66,11 @@ VGMSTREAM* init_vgmstream_ffmpeg(STREAMFILE* sf) {
/* hack for AAC files (will return 0 samples if not an actual file) */
if (!num_samples && check_extensions(sf, "aac,laac")) {
num_samples = aac_get_samples(sf, 0x00, get_streamfile_size(sf));
if (num_samples > 0) {
/* FFmpeg seeks to 0 eats first frame for whatever reason */
ffmpeg_set_force_seek(data);
}
}
#ifdef VGM_USE_MPEG
@ -76,10 +81,17 @@ VGMSTREAM* init_vgmstream_ffmpeg(STREAMFILE* sf) {
}
#endif
/* hack for MPC, that seeks/resets incorrectly due to seek table shenanigans */
if (read_u32be(0x00, sf) == 0x4D502B07 || /* "MP+\7" (Musepack V7) */
read_u32be(0x00, sf) == 0x4D50434B) { /* "MPCK" (Musepack V8) */
/* hack for MPC */
if (is_id32be(0x00, sf, "MP+\x07") || /* Musepack V7 */
is_id32be(0x00, sf, "MP+\x17") || /* Musepack V7 with flag (seen in FFmpeg) */
is_id32be(0x00, sf, "MPCK")) { /* Musepack V8 */
/* FFmpeg seeks/resets incorrectly due to MPC seek table shenanigans */
ffmpeg_set_force_seek(data);
/* FFmpeg gets this wrong as usual (specially V8 samples) */
mpc_get_samples(sf, 0x00, &num_samples, &encoder_delay);
ffmpeg_set_skip_samples(data, encoder_delay);
}
/* default but often inaccurate when calculated using bitrate (wrong for VBR) */
@ -91,7 +103,7 @@ VGMSTREAM* init_vgmstream_ffmpeg(STREAMFILE* sf) {
/* build VGMSTREAM */
vgmstream = allocate_vgmstream(data->channels, loop_flag);
if (!vgmstream) goto fail;
vgmstream->sample_rate = data->sampleRate;
vgmstream->meta_type = meta_FFMPEG;
vgmstream->coding_type = coding_FFmpeg;
@ -104,14 +116,13 @@ VGMSTREAM* init_vgmstream_ffmpeg(STREAMFILE* sf) {
vgmstream->channel_layout = ffmpeg_get_channel_layout(vgmstream->codec_data);
return vgmstream;
fail:
free_ffmpeg(data);
if (vgmstream) {
vgmstream->codec_data = NULL;
close_vgmstream(vgmstream);
}
return NULL;
}

View File

@ -11,7 +11,7 @@ typedef struct {
/**
* List of known keys, extracted from the game files (mostly found in 2ch.net).
* List of known keys, extracted from the game files (several found in 2ch.net, others from data analisys).
* CRI's tools expect an unsigned 64 bit number string, but keys are commonly found online in hex form.
* Keys only use 56 bits though, so the upper 8 bits can be ignored.
*
@ -401,6 +401,9 @@ static const hcakey_info hcakey_list[] = {
/* Mushoku Tensei: Game ni Nattemo Honki Dasu (Android) */
{12281329554827291428u}, // AA700C292CFCAB24
/* Dragalia Lost (iOS/Android) */
{2967411924141}, // 000002B2E7889CAD
/* D4DJ Groovy Mix (Android) [base files] */
{393410674916959300}, // 0575ACECA945A444
/* D4DJ Groovy Mix (Android) [music_* files, per-song later mixed with subkey] */
@ -627,9 +630,6 @@ static const hcakey_info hcakey_list[] = {
{0xb96786621e27daf3},
{0x1111d6c10e509824},
/* Dragalia Lost (iOS/Android) */
{2967411924141, subkeys_dgl, sizeof(subkeys_dgl) / sizeof(subkeys_dgl[0]) }, // 000002B2E7889CAD
};
#endif/*_HCA_KEYS_H_*/

File diff suppressed because it is too large Load Diff

View File

@ -42,15 +42,16 @@ VGMSTREAM* init_vgmstream_naac(STREAMFILE* sf) {
#ifdef VGM_USE_FFMPEG
{
vgmstream->codec_data = init_ffmpeg_offset(sf, start_offset, data_size);
vgmstream->codec_data = init_ffmpeg_aac(sf, start_offset, data_size);
if (!vgmstream->codec_data) goto fail;
vgmstream->coding_type = coding_FFmpeg;
vgmstream->layout_type = layout_none;
/* observed default, some files start without silence though seems correct when loop_start=0 */
ffmpeg_set_skip_samples(vgmstream->codec_data, 1024); /* raw AAC doesn't set this */
vgmstream->num_samples -= 1024; /* may end with 1024 of silence? */
vgmstream->num_samples -= 1024;
vgmstream->loop_end_sample -= 1024;
/* for some reason last frame is ignored/bugged in various decoders (gives EOF errors) */
}
#else
goto fail;

View File

@ -42,14 +42,14 @@ VGMSTREAM* init_vgmstream_strm_abylight(STREAMFILE* sf) {
#ifdef VGM_USE_FFMPEG
{
vgmstream->codec_data = init_ffmpeg_offset(sf, start_offset, data_size);
vgmstream->codec_data = init_ffmpeg_aac(sf, start_offset, data_size);
if (!vgmstream->codec_data) goto fail;
vgmstream->coding_type = coding_FFmpeg;
vgmstream->layout_type = layout_none;
/* apparently none, or maybe ~600 */
//ffmpeg_set_skip_samples(ffmpeg_data, 1024);
//vgmstream->num_samples -= 1024;
/* assumed, maybe a bit more */
ffmpeg_set_skip_samples(vgmstream->codec_data, 1024);
vgmstream->num_samples -= 1024;
}
#else
goto fail;

View File

@ -468,14 +468,18 @@ VGMSTREAM* init_vgmstream_txth(STREAMFILE* sf) {
case coding_FFmpeg: {
ffmpeg_codec_data *ffmpeg_data = NULL;
if (txth.codec == FFMPEG || txth.codec == AC3 || txth.codec == AAC) {
if (txth.codec == FFMPEG || txth.codec == AC3) {
/* default FFmpeg */
ffmpeg_data = init_ffmpeg_offset(txth.sf_body, txth.start_offset,txth.data_size);
if ( !ffmpeg_data ) goto fail;
ffmpeg_data = init_ffmpeg_offset(txth.sf_body, txth.start_offset, txth.data_size);
if (!ffmpeg_data) goto fail;
if (vgmstream->num_samples == 0)
vgmstream->num_samples = ffmpeg_data->totalSamples; /* sometimes works */
}
else if (txth.codec == AAC) {
ffmpeg_data = init_ffmpeg_aac(txth.sf_body, txth.start_offset, txth.data_size);
if (!ffmpeg_data) goto fail;
}
else {
/* fake header FFmpeg */
uint8_t buf[0x100];

View File

@ -1,10 +1,11 @@
#include "meta.h"
#include "../coding/coding.h"
/* VXN - from Gameloft mobile games */
VGMSTREAM* init_vgmstream_vxn(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
int loop_flag = 0, channel_count, codec, sample_rate, block_align, bits, num_samples;
int loop_flag = 0, channels, codec, sample_rate, block_align, bits, num_samples, encoder_delay;
off_t start_offset, stream_offset, chunk_offset, first_offset = 0x00;
size_t stream_size;
int total_subsongs, target_subsong = sf->stream_index;
@ -13,22 +14,32 @@ VGMSTREAM* init_vgmstream_vxn(STREAMFILE* sf) {
if (!check_extensions(sf,"vxn"))
goto fail;
if (read_u32be(0x00,sf) != 0x566F784E) /* "VoxN" */
if (!is_id32be(0x00,sf, "VoxN"))
goto fail;
/* 0x04: chunk size */
/* 0x08: ASCII version? ("0.0.1") */
if (read_u32le(0x10,sf) != get_streamfile_size(sf))
goto fail;
/* 0x14: first MPC data start */
/* header is RIFF-like with many custom chunks */
if (!find_chunk_le(sf, 0x41666D74,first_offset,0, &chunk_offset,NULL)) /* "Afmt" */
goto fail;
codec = read_u16le(chunk_offset+0x00, sf);
channel_count = read_u16le(chunk_offset+0x02, sf);
channels = read_u16le(chunk_offset+0x02, sf);
sample_rate = read_u32le(chunk_offset+0x04, sf);
block_align = read_u16le(chunk_offset+0x08, sf);
bits = read_16bitLE(chunk_offset+0x0a, sf);
bits = read_s16le(chunk_offset+0x0a, sf);
/* files are divided into segment subsongs, often a leadout and loop in that order
* (the "Plst" and "Rule" chunks may have order info) */
/* files are divided into segment subsongs, often a leadout and loop in that order,
* but may also have +15 [Asphalt 9]. Various chunks seem to define how they are used:
* - Rule: optional, not related to number of playlists
* - Plst: sets N playlists + some flags?
* - Stat: N entries (1 per playlist), start? + name (null-terminated, size 0x0C) + sample values?
* - Trsn: optional, transitions for playlists?
* - Grps: N entries (1 per playlist), 0x18 per entry, unknown
* - Gprs: playlist segments, 0x20 per entry, playlist id + segment + null + segment? + flags (0/1/-1)
*/
if (!find_chunk_le(sf, 0x5365676D,first_offset,0, &chunk_offset,NULL)) /* "Segm" */
goto fail;
total_subsongs = read_u32le(chunk_offset+0x00, sf);
@ -45,7 +56,7 @@ VGMSTREAM* init_vgmstream_vxn(STREAMFILE* sf) {
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
vgmstream = allocate_vgmstream(channels, loop_flag);
if (!vgmstream) goto fail;
vgmstream->sample_rate = sample_rate;
@ -85,16 +96,24 @@ VGMSTREAM* init_vgmstream_vxn(STREAMFILE* sf) {
break;
#ifdef VGM_USE_FFMPEG
case 0x0800: /* Musepack (ex. Asphalt Xtreme) */
case 0x0800: /* Musepack (ex. Asphalt Xtreme, Asphalt 9) */
if (bits != -1) goto fail;
vgmstream->codec_data = init_ffmpeg_offset(sf, start_offset,stream_size);
vgmstream->codec_data = init_ffmpeg_offset(sf, start_offset, stream_size);
if (!vgmstream->codec_data) goto fail;
vgmstream->coding_type = coding_FFmpeg;
vgmstream->layout_type = layout_none;
/* unlike standard .mpc, .vxn has no seek table so no need to fix */
//ffmpeg_set_force_seek(vgmstream->codec_data);
encoder_delay = 0;
mpc_get_samples(sf, start_offset, NULL, &encoder_delay);
/* num_samples matches MPC samples */
/* FFmpeg doesn't set encoder delay */
ffmpeg_set_skip_samples(vgmstream->codec_data, encoder_delay);
break;
#endif

View File

@ -109,6 +109,10 @@ VGMSTREAM* init_vgmstream_wwise(STREAMFILE* sf) {
}
vgmstream->num_samples = pcm_bytes_to_samples(ww.data_size, ww.channels, ww.bits_per_sample);
/* truncated .bnk RIFFs that only have header and no data is possible [Metal Gear Solid V (PC)] */
if (ww.truncated && !vgmstream->num_samples)
vgmstream->num_samples = 1; /* force something to avoid broken subsongs */
break;
case IMA: /* common */