mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-11-28 16:30:54 +01:00
commit
eb837c3fd6
@ -344,6 +344,7 @@ typedef enum {
|
||||
VORBIS_OGL, /* Shin'en OGL: custom packet headers */
|
||||
VORBIS_SK, /* Silicon Knights AUD: "OggS" replaced by "SK" */
|
||||
VORBIS_VID1, /* Neversoft VID1: custom packet blocks/headers */
|
||||
VORBIS_AWC, /* Rockstar AWC: custom packet blocks/headers */
|
||||
} vorbis_custom_t;
|
||||
|
||||
/* config for Wwise Vorbis (3 types for flexibility though not all combinations exist) */
|
||||
@ -366,6 +367,9 @@ typedef struct {
|
||||
wwise_header_t header_type;
|
||||
wwise_packet_t packet_type;
|
||||
|
||||
/* AWC config */
|
||||
off_t header_offset;
|
||||
|
||||
/* output (kinda ugly here but to simplify) */
|
||||
off_t data_start_offset;
|
||||
|
||||
|
@ -51,6 +51,7 @@ vorbis_custom_codec_data* init_vorbis_custom(STREAMFILE* sf, off_t start_offset,
|
||||
case VORBIS_OGL: ok = vorbis_custom_setup_init_ogl(sf, start_offset, data); break;
|
||||
case VORBIS_SK: ok = vorbis_custom_setup_init_sk(sf, start_offset, data); break;
|
||||
case VORBIS_VID1: ok = vorbis_custom_setup_init_vid1(sf, start_offset, data); break;
|
||||
case VORBIS_AWC: ok = vorbis_custom_setup_init_awc(sf, start_offset, data); break;
|
||||
default: goto fail;
|
||||
}
|
||||
if(!ok) goto fail;
|
||||
@ -134,6 +135,7 @@ void decode_vorbis_custom(VGMSTREAM* vgmstream, sample_t* outbuf, int32_t sample
|
||||
case VORBIS_OGL: ok = vorbis_custom_parse_packet_ogl(stream, data); break;
|
||||
case VORBIS_SK: ok = vorbis_custom_parse_packet_sk(stream, data); break;
|
||||
case VORBIS_VID1: ok = vorbis_custom_parse_packet_vid1(stream, data); break;
|
||||
case VORBIS_AWC: ok = vorbis_custom_parse_packet_awc(stream, data); break;
|
||||
default: goto decode_fail;
|
||||
}
|
||||
if(!ok) {
|
||||
|
@ -43,12 +43,14 @@ int vorbis_custom_setup_init_wwise(STREAMFILE* sf, off_t start_offset, vorbis_cu
|
||||
int vorbis_custom_setup_init_ogl(STREAMFILE* sf, off_t start_offset, vorbis_custom_codec_data* data);
|
||||
int vorbis_custom_setup_init_sk(STREAMFILE* sf, off_t start_offset, vorbis_custom_codec_data* data);
|
||||
int vorbis_custom_setup_init_vid1(STREAMFILE* sf, off_t start_offset, vorbis_custom_codec_data* data);
|
||||
int vorbis_custom_setup_init_awc(STREAMFILE* sf, off_t start_offset, vorbis_custom_codec_data* data);
|
||||
|
||||
int vorbis_custom_parse_packet_fsb(VGMSTREAMCHANNEL *stream, vorbis_custom_codec_data* data);
|
||||
int vorbis_custom_parse_packet_wwise(VGMSTREAMCHANNEL *stream, vorbis_custom_codec_data* data);
|
||||
int vorbis_custom_parse_packet_ogl(VGMSTREAMCHANNEL *stream, vorbis_custom_codec_data* data);
|
||||
int vorbis_custom_parse_packet_sk(VGMSTREAMCHANNEL *stream, vorbis_custom_codec_data* data);
|
||||
int vorbis_custom_parse_packet_vid1(VGMSTREAMCHANNEL *stream, vorbis_custom_codec_data* data);
|
||||
int vorbis_custom_parse_packet_fsb(VGMSTREAMCHANNEL* stream, vorbis_custom_codec_data* data);
|
||||
int vorbis_custom_parse_packet_wwise(VGMSTREAMCHANNEL* stream, vorbis_custom_codec_data* data);
|
||||
int vorbis_custom_parse_packet_ogl(VGMSTREAMCHANNEL* stream, vorbis_custom_codec_data* data);
|
||||
int vorbis_custom_parse_packet_sk(VGMSTREAMCHANNEL* stream, vorbis_custom_codec_data* data);
|
||||
int vorbis_custom_parse_packet_vid1(VGMSTREAMCHANNEL* stream, vorbis_custom_codec_data* data);
|
||||
int vorbis_custom_parse_packet_awc(VGMSTREAMCHANNEL* stream, vorbis_custom_codec_data* data);
|
||||
#endif/* VGM_USE_VORBIS */
|
||||
|
||||
#endif/*_VORBIS_CUSTOM_DECODER_H_ */
|
||||
|
86
src/coding/vorbis_custom_utils_awc.c
Normal file
86
src/coding/vorbis_custom_utils_awc.c
Normal file
@ -0,0 +1,86 @@
|
||||
#include "vorbis_custom_decoder.h"
|
||||
|
||||
#ifdef VGM_USE_VORBIS
|
||||
#include <vorbis/codec.h>
|
||||
|
||||
|
||||
/* **************************************************************************** */
|
||||
/* EXTERNAL API */
|
||||
/* **************************************************************************** */
|
||||
|
||||
/**
|
||||
* AWC removes the Ogg layer and uses 32b frame sizes for headers and 16b frame sizes for data
|
||||
*/
|
||||
int vorbis_custom_setup_init_awc(STREAMFILE* sf, off_t start_offset, vorbis_custom_codec_data* data) {
|
||||
off_t offset = data->config.header_offset;
|
||||
size_t packet_size;
|
||||
|
||||
/* read 3 packets with triad (id/comment/setup), each with an AWC header */
|
||||
|
||||
/* normal identificacion packet */
|
||||
packet_size = read_u32le(offset, sf);
|
||||
if (packet_size > data->buffer_size) goto fail;
|
||||
data->op.bytes = read_streamfile(data->buffer, offset + 0x04, packet_size, sf);
|
||||
if (vorbis_synthesis_headerin(&data->vi, &data->vc, &data->op) != 0)
|
||||
goto fail;
|
||||
offset += 0x04 + packet_size;
|
||||
|
||||
/* normal comment packet */
|
||||
packet_size = read_u32le(offset, sf);
|
||||
if (packet_size > data->buffer_size) goto fail;
|
||||
data->op.bytes = read_streamfile(data->buffer, offset + 0x04, packet_size, sf);
|
||||
if (vorbis_synthesis_headerin(&data->vi, &data->vc, &data->op) !=0)
|
||||
goto fail;
|
||||
offset += 0x04 + packet_size;
|
||||
|
||||
/* normal setup packet */
|
||||
packet_size = read_u32le(offset, sf);
|
||||
if (packet_size > data->buffer_size) goto fail;
|
||||
data->op.bytes = read_streamfile(data->buffer, offset + 0x04, packet_size, sf);
|
||||
if (vorbis_synthesis_headerin(&data->vi, &data->vc, &data->op) != 0)
|
||||
goto fail;
|
||||
offset += 0x04 + packet_size;
|
||||
|
||||
/* data starts separate */
|
||||
data->config.data_start_offset = start_offset;
|
||||
|
||||
return 1;
|
||||
|
||||
fail:
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* as AWC was coded by wackos, frames are forced to fit 0x800 chunks and rest is padded, in both sfx and music/blocked modes
|
||||
* (ex. read frame until 0x7A0 + next frame is size 0x140 > pads 0x60 and last goes to next chunk) */
|
||||
static inline off_t find_padding_awc(off_t offset, vorbis_custom_codec_data* data) {
|
||||
offset = offset - data->config.data_start_offset;
|
||||
|
||||
return 0x800 - (offset % 0x800);
|
||||
}
|
||||
|
||||
int vorbis_custom_parse_packet_awc(VGMSTREAMCHANNEL* stream, vorbis_custom_codec_data* data) {
|
||||
size_t bytes;
|
||||
|
||||
/* get next packet size from the AWC 16b header, except between chunks */
|
||||
data->op.bytes = read_u16le(stream->offset, stream->streamfile);
|
||||
if (data->op.bytes == 0) { // || (stream->offset - start & 0x800) < 0x01 //todo could pad near block end?
|
||||
stream->offset += find_padding_awc(stream->offset, data);
|
||||
data->op.bytes = read_u16le(stream->offset, stream->streamfile);
|
||||
}
|
||||
|
||||
stream->offset += 0x02;
|
||||
if (data->op.bytes == 0 || data->op.bytes == 0xFFFF || data->op.bytes > data->buffer_size)
|
||||
goto fail; /* EOF or end padding */
|
||||
|
||||
/* read raw block */
|
||||
bytes = read_streamfile(data->buffer, stream->offset, data->op.bytes, stream->streamfile);
|
||||
stream->offset += data->op.bytes;
|
||||
if (bytes != data->op.bytes) goto fail; /* wrong packet? */
|
||||
|
||||
return 1;
|
||||
|
||||
fail:
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
@ -103,7 +103,7 @@ static const char* extension_list[] = {
|
||||
"bgw",
|
||||
"bh2pcm",
|
||||
"bik",
|
||||
"bika",
|
||||
"bika", //fake extension for .bik (to be removed)
|
||||
"bik2",
|
||||
//"bin", //common
|
||||
"bk2",
|
||||
|
@ -2310,6 +2310,10 @@
|
||||
RelativePath=".\coding\vorbis_custom_decoder.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\coding\vorbis_custom_utils_awc.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\coding\vorbis_custom_utils_fsb.c"
|
||||
>
|
||||
|
@ -631,6 +631,7 @@
|
||||
<ClCompile Include="coding\ubi_adpcm_decoder.c" />
|
||||
<ClCompile Include="coding\vadpcm_decoder.c" />
|
||||
<ClCompile Include="coding\vorbis_custom_decoder.c" />
|
||||
<ClCompile Include="coding\vorbis_custom_utils_awc.c" />
|
||||
<ClCompile Include="coding\vorbis_custom_utils_fsb.c" />
|
||||
<ClCompile Include="coding\vorbis_custom_utils_ogl.c" />
|
||||
<ClCompile Include="coding\vorbis_custom_utils_sk.c" />
|
||||
|
@ -1378,6 +1378,9 @@
|
||||
<ClCompile Include="coding\vorbis_custom_decoder.c">
|
||||
<Filter>coding\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="coding\vorbis_custom_utils_awc.c">
|
||||
<Filter>coding\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="coding\vorbis_custom_utils_fsb.c">
|
||||
<Filter>coding\Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
176
src/meta/awc.c
176
src/meta/awc.c
@ -10,7 +10,7 @@ typedef struct {
|
||||
|
||||
int total_subsongs;
|
||||
|
||||
int channel_count;
|
||||
int channels;
|
||||
int sample_rate;
|
||||
int codec;
|
||||
int num_samples;
|
||||
@ -19,27 +19,28 @@ typedef struct {
|
||||
|
||||
off_t stream_offset;
|
||||
size_t stream_size;
|
||||
off_t vorbis_offset;
|
||||
|
||||
} awc_header;
|
||||
|
||||
static int parse_awc_header(STREAMFILE* streamFile, awc_header* awc);
|
||||
static int parse_awc_header(STREAMFILE* sf, awc_header* awc);
|
||||
|
||||
|
||||
/* AWC - from RAGE (Rockstar Advanced Game Engine) audio [Red Dead Redemption, Max Payne 3, GTA5 (multi)] */
|
||||
VGMSTREAM * init_vgmstream_awc(STREAMFILE *streamFile) {
|
||||
VGMSTREAM * vgmstream = NULL;
|
||||
VGMSTREAM* init_vgmstream_awc(STREAMFILE* sf) {
|
||||
VGMSTREAM* vgmstream = NULL;
|
||||
awc_header awc = {0};
|
||||
|
||||
|
||||
/* checks */
|
||||
if (!check_extensions(streamFile,"awc"))
|
||||
if (!check_extensions(sf,"awc"))
|
||||
goto fail;
|
||||
if (!parse_awc_header(streamFile, &awc))
|
||||
if (!parse_awc_header(sf, &awc))
|
||||
goto fail;
|
||||
|
||||
|
||||
/* build the VGMSTREAM */
|
||||
vgmstream = allocate_vgmstream(awc.channel_count, 0);
|
||||
vgmstream = allocate_vgmstream(awc.channels, 0);
|
||||
if (!vgmstream) goto fail;
|
||||
|
||||
vgmstream->sample_rate = awc.sample_rate;
|
||||
@ -77,15 +78,15 @@ VGMSTREAM * init_vgmstream_awc(STREAMFILE *streamFile) {
|
||||
layered_layout_data * data = NULL;
|
||||
|
||||
/* init layout */
|
||||
data = init_layout_layered(awc.channel_count);
|
||||
data = init_layout_layered(awc.channels);
|
||||
if (!data) goto fail;
|
||||
vgmstream->layout_data = data;
|
||||
vgmstream->layout_type = layout_layered;
|
||||
vgmstream->coding_type = coding_FFmpeg;
|
||||
|
||||
/* open each layer subfile */
|
||||
for (i = 0; i < awc.channel_count; i++) {
|
||||
STREAMFILE* temp_streamFile;
|
||||
for (i = 0; i < awc.channels; i++) {
|
||||
STREAMFILE* temp_sf = NULL;
|
||||
int layer_channels = 1;
|
||||
|
||||
/* build the layer VGMSTREAM */
|
||||
@ -99,20 +100,20 @@ VGMSTREAM * init_vgmstream_awc(STREAMFILE *streamFile) {
|
||||
data->layers[i]->num_samples = awc.num_samples;
|
||||
|
||||
/* setup custom IO streamfile, pass to FFmpeg and hope it's fooled */
|
||||
temp_streamFile = setup_awc_xma_streamfile(streamFile, awc.stream_offset, awc.stream_size, awc.block_chunk, awc.channel_count, i);
|
||||
if (!temp_streamFile) goto fail;
|
||||
temp_sf = setup_awc_xma_streamfile(sf, awc.stream_offset, awc.stream_size, awc.block_chunk, awc.channels, i);
|
||||
if (!temp_sf) goto fail;
|
||||
|
||||
substream_offset = 0; /* where FFmpeg thinks data starts, which our custom streamFile will clamp */
|
||||
substream_size = get_streamfile_size(temp_streamFile); /* data of one XMA substream without blocks */
|
||||
substream_offset = 0; /* where FFmpeg thinks data starts, which our custom sf will clamp */
|
||||
substream_size = get_streamfile_size(temp_sf); /* data of one XMA substream without blocks */
|
||||
block_size = 0x8000; /* no idea */
|
||||
block_count = substream_size / block_size; /* not accurate but not needed */
|
||||
|
||||
bytes = ffmpeg_make_riff_xma2(buf, 0x100, awc.num_samples, substream_size, layer_channels, awc.sample_rate, block_count, block_size);
|
||||
data->layers[i]->codec_data = init_ffmpeg_header_offset(temp_streamFile, buf,bytes, substream_offset,substream_size);
|
||||
data->layers[i]->codec_data = init_ffmpeg_header_offset(temp_sf, buf,bytes, substream_offset,substream_size);
|
||||
|
||||
xma_fix_raw_samples(data->layers[i], temp_streamFile, substream_offset,substream_size, 0, 0,0); /* samples are ok? */
|
||||
xma_fix_raw_samples(data->layers[i], temp_sf, substream_offset,substream_size, 0, 0,0); /* samples are ok? */
|
||||
|
||||
close_streamfile(temp_streamFile);
|
||||
close_streamfile(temp_sf);
|
||||
if (!data->layers[i]->codec_data) goto fail;
|
||||
}
|
||||
|
||||
@ -125,13 +126,13 @@ VGMSTREAM * init_vgmstream_awc(STREAMFILE *streamFile) {
|
||||
block_size = 0x8000; /* no idea */
|
||||
block_count = awc.stream_size / block_size; /* not accurate but not needed */
|
||||
|
||||
bytes = ffmpeg_make_riff_xma2(buf, 0x100, awc.num_samples, awc.stream_size, awc.channel_count, awc.sample_rate, block_count, block_size);
|
||||
vgmstream->codec_data = init_ffmpeg_header_offset(streamFile, buf,bytes, awc.stream_offset,awc.stream_size);
|
||||
bytes = ffmpeg_make_riff_xma2(buf, 0x100, awc.num_samples, awc.stream_size, awc.channels, awc.sample_rate, block_count, block_size);
|
||||
vgmstream->codec_data = init_ffmpeg_header_offset(sf, buf,bytes, awc.stream_offset,awc.stream_size);
|
||||
if (!vgmstream->codec_data) goto fail;
|
||||
vgmstream->coding_type = coding_FFmpeg;
|
||||
vgmstream->layout_type = layout_none;
|
||||
|
||||
xma_fix_raw_samples(vgmstream, streamFile, awc.stream_offset,awc.stream_size, 0, 0,0); /* samples are ok? */
|
||||
xma_fix_raw_samples(vgmstream, sf, awc.stream_offset,awc.stream_size, 0, 0,0); /* samples are ok? */
|
||||
}
|
||||
|
||||
break;
|
||||
@ -146,21 +147,37 @@ VGMSTREAM * init_vgmstream_awc(STREAMFILE *streamFile) {
|
||||
cfg.chunk_size = awc.block_chunk;
|
||||
cfg.big_endian = awc.big_endian;
|
||||
|
||||
vgmstream->codec_data = init_mpeg_custom(streamFile, awc.stream_offset, &vgmstream->coding_type, vgmstream->channels, MPEG_AWC, &cfg);
|
||||
vgmstream->codec_data = init_mpeg_custom(sf, awc.stream_offset, &vgmstream->coding_type, vgmstream->channels, MPEG_AWC, &cfg);
|
||||
if (!vgmstream->codec_data) goto fail;
|
||||
vgmstream->layout_type = layout_none;
|
||||
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#ifdef VGM_USE_MPEG
|
||||
case 0x08: { /* Vorbis (PC) [Red Dead Redemption 2 (PC)] */
|
||||
vorbis_custom_config cfg = {0};
|
||||
|
||||
if (awc.is_music) goto fail; /* needs blocks */
|
||||
|
||||
cfg.channels = awc.channels;
|
||||
cfg.sample_rate = awc.sample_rate;
|
||||
cfg.header_offset = awc.vorbis_offset;
|
||||
|
||||
vgmstream->codec_data = init_vorbis_custom(sf, awc.stream_offset, VORBIS_AWC, &cfg);
|
||||
if (!vgmstream->codec_data) goto fail;
|
||||
vgmstream->layout_type = layout_none;
|
||||
vgmstream->coding_type = coding_VORBIS_custom;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
VGM_LOG("AWC: unknown codec 0x%02x\n", awc.codec);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
||||
if (!vgmstream_open_stream(vgmstream,streamFile,awc.stream_offset))
|
||||
if (!vgmstream_open_stream(vgmstream, sf, awc.stream_offset))
|
||||
goto fail;
|
||||
return vgmstream;
|
||||
|
||||
@ -172,36 +189,36 @@ fail:
|
||||
|
||||
/* Parse Rockstar's AWC header (much info from LibertyV: https://github.com/koolkdev/libertyv).
|
||||
* Made of entries for N streams, each with a number of tags pointing to chunks (header, data, events, etc). */
|
||||
static int parse_awc_header(STREAMFILE* streamFile, awc_header* awc) {
|
||||
int64_t (*read_64bit)(off_t,STREAMFILE*) = NULL;
|
||||
int32_t (*read_32bit)(off_t,STREAMFILE*) = NULL;
|
||||
int16_t (*read_16bit)(off_t,STREAMFILE*) = NULL;
|
||||
static int parse_awc_header(STREAMFILE* sf, awc_header* awc) {
|
||||
uint64_t (*read_u64)(off_t,STREAMFILE*) = NULL;
|
||||
uint32_t (*read_u32)(off_t,STREAMFILE*) = NULL;
|
||||
uint16_t (*read_u16)(off_t,STREAMFILE*) = NULL;
|
||||
int i, ch, entries;
|
||||
uint32_t flags, info_header, tag_count = 0, tags_skip = 0;
|
||||
off_t off;
|
||||
int target_subsong = streamFile->stream_index;
|
||||
int target_subsong = sf->stream_index;
|
||||
|
||||
|
||||
/* check header */
|
||||
if (read_32bitBE(0x00,streamFile) != 0x41444154 && /* "ADAT" (LE) */
|
||||
read_32bitBE(0x00,streamFile) != 0x54414441) /* "TADA" (BE) */
|
||||
if (read_u32be(0x00,sf) != 0x41444154 && /* "ADAT" (LE) */
|
||||
read_u32be(0x00,sf) != 0x54414441) /* "TADA" (BE) */
|
||||
goto fail;
|
||||
|
||||
awc->big_endian = read_32bitBE(0x00,streamFile) == 0x54414441;
|
||||
awc->big_endian = read_u32be(0x00,sf) == 0x54414441;
|
||||
if (awc->big_endian) {
|
||||
read_64bit = read_64bitBE;
|
||||
read_32bit = read_32bitBE;
|
||||
read_16bit = read_16bitBE;
|
||||
read_u64 = read_u64be;
|
||||
read_u32 = read_u32be;
|
||||
read_u16 = read_u16be;
|
||||
} else {
|
||||
read_64bit = read_64bitLE;
|
||||
read_32bit = read_32bitLE;
|
||||
read_16bit = read_16bitLE;
|
||||
read_u64 = read_u64le;
|
||||
read_u32 = read_u32le;
|
||||
read_u16 = read_u16le;
|
||||
}
|
||||
|
||||
|
||||
flags = read_32bit(0x04,streamFile);
|
||||
entries = read_32bit(0x08,streamFile);
|
||||
//header_size = read_32bit(0x0c,streamFile); /* after to stream id/tags, not including chunks */
|
||||
flags = read_u32(0x04,sf);
|
||||
entries = read_u32(0x08,sf);
|
||||
//header_size = read_u32(0x0c,sf); /* after to stream id/tags, not including chunks */
|
||||
|
||||
off = 0x10;
|
||||
|
||||
@ -227,7 +244,7 @@ static int parse_awc_header(STREAMFILE* streamFile, awc_header* awc) {
|
||||
/* Music when the first id is 0 (base/fake entry with info for all channels), sfx pack otherwise.
|
||||
* sfx = N single streams, music = N-1 interleaved mono channels (even for MP3/XMA).
|
||||
* Music seems layered (N-1/2 stereo pairs), maybe set with events? */
|
||||
awc->is_music = (read_32bit(off + 0x00,streamFile) & 0x1FFFFFFF) == 0x00000000;
|
||||
awc->is_music = (read_u32(off + 0x00,sf) & 0x1FFFFFFF) == 0x00000000;
|
||||
if (awc->is_music) { /* all streams except id 0 is a channel */
|
||||
awc->total_subsongs = 1;
|
||||
target_subsong = 1; /* we only need id 0, though channels may have its own tags/chunks */
|
||||
@ -241,7 +258,7 @@ static int parse_awc_header(STREAMFILE* streamFile, awc_header* awc) {
|
||||
|
||||
/* get stream base info */
|
||||
for (i = 0; i < entries; i++) {
|
||||
info_header = read_32bit(off + 0x04*i, streamFile);
|
||||
info_header = read_u32(off + 0x04*i, sf);
|
||||
tag_count = (info_header >> 29) & 0x7; /* 3b */
|
||||
//id = (info_header >> 0) & 0x1FFFFFFF; /* 29b */
|
||||
if (target_subsong-1 == i)
|
||||
@ -258,10 +275,11 @@ static int parse_awc_header(STREAMFILE* streamFile, awc_header* awc) {
|
||||
size_t size;
|
||||
off_t offset;
|
||||
|
||||
tag_header = (uint64_t)read_64bit(off + 0x08*i,streamFile);
|
||||
tag_header = read_u64(off + 0x08*i,sf);
|
||||
tag = (uint8_t)((tag_header >> 56) & 0xFF); /* 8b */
|
||||
size = (size_t)((tag_header >> 28) & 0x0FFFFFFF); /* 28b */
|
||||
offset = (off_t)((tag_header >> 0) & 0x0FFFFFFF); /* 28b */
|
||||
//;VGM_LOG("AWC: tag%i/%i at %lx: t=%x, o=%lx, s=%x\n", i, tag_count, off + 0x08*i, tag, offset, size);
|
||||
|
||||
/* Tags are apparently part of a hash derived from a word ("data", "format", etc).
|
||||
* If music + 1ch, the header and data chunks can repeat for no reason (sometimes not even pointed). */
|
||||
@ -278,28 +296,30 @@ static int parse_awc_header(STREAMFILE* streamFile, awc_header* awc) {
|
||||
}
|
||||
|
||||
/* 0x00(32): unknown (some count?) */
|
||||
awc->block_chunk = read_32bit(offset + 0x04,streamFile);
|
||||
awc->channel_count = read_32bit(offset + 0x08,streamFile);
|
||||
awc->block_chunk = read_u32(offset + 0x04,sf);
|
||||
awc->channels = read_u32(offset + 0x08,sf);
|
||||
|
||||
if (awc->channel_count != entries - 1) { /* not counting id-0 */
|
||||
if (awc->channels != entries - 1) { /* not counting id-0 */
|
||||
VGM_LOG("AWC: number of music channels doesn't match entries\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
for (ch = 0; ch < awc->channel_count; ch++) {
|
||||
for (ch = 0; ch < awc->channels; ch++) {
|
||||
int num_samples, sample_rate, codec;
|
||||
/* 0x00(32): stream id (not always in the header entries order) */
|
||||
/* 0x08(16): headroom?, 0x0d(8): round size?, 0x0e(16): unknown (zero?) */
|
||||
num_samples = read_32bit(offset + 0x0c + 0x10*ch + 0x04,streamFile);
|
||||
sample_rate = (uint16_t)read_16bit(offset + 0x0c + 0x10*ch + 0x0a,streamFile);
|
||||
codec = read_8bit(offset + 0x0c + 0x10*ch + 0x0c, streamFile);
|
||||
/* 0x00): stream id (not always in the header entries order) */
|
||||
num_samples = read_u32(offset + 0x0c + 0x10*ch + 0x04,sf);
|
||||
/* 0x08: headroom */
|
||||
sample_rate = read_u16(offset + 0x0c + 0x10*ch + 0x0a,sf);
|
||||
codec = read_u8(offset + 0x0c + 0x10*ch + 0x0c,sf);
|
||||
/* 0x0d(8): round size? */
|
||||
/* 0x0e: unknown (zero/-1) */
|
||||
|
||||
/* validate channels differences */
|
||||
if ((awc->num_samples && !(awc->num_samples >= num_samples - 10 && awc->num_samples <= num_samples + 10)) ||
|
||||
(awc->sample_rate && awc->sample_rate != sample_rate)) {
|
||||
VGM_LOG("AWC: found header diffs in channel %i, ns=%i vs %i, sr=%i vs %i\n",
|
||||
ch, awc->num_samples, num_samples, awc->sample_rate, sample_rate);
|
||||
/* sometimes (often cutscenes in Max Payne 3 and RDR DLC) channels have bif sample diffs,
|
||||
/* sometimes (often cutscenes in Max Payne 3 and RDR DLC) channels have sample diffs,
|
||||
* probably one stream is simply silent after its samples end */
|
||||
}
|
||||
|
||||
@ -313,6 +333,12 @@ static int parse_awc_header(STREAMFILE* streamFile, awc_header* awc) {
|
||||
awc->sample_rate = sample_rate;
|
||||
awc->codec = codec;
|
||||
}
|
||||
|
||||
if (awc->codec == 0x08) {
|
||||
/* one vorbis header per channel, pasted together */
|
||||
awc->vorbis_offset = offset + size;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 0xFA: /* sfx header */
|
||||
@ -320,16 +346,39 @@ static int parse_awc_header(STREAMFILE* streamFile, awc_header* awc) {
|
||||
VGM_LOG("AWC: sfx header found in music\n");
|
||||
goto fail;
|
||||
}
|
||||
/* 0x04(32): -1?, 0x0a(16x4): unknown x4, 0x12: null? */
|
||||
awc->num_samples = read_32bit(offset + 0x00,streamFile);
|
||||
awc->sample_rate = (uint16_t)read_16bit(offset + 0x08,streamFile);
|
||||
awc->codec = read_8bit(offset + 0x13, streamFile);
|
||||
awc->channel_count = 1;
|
||||
|
||||
awc->num_samples = read_u32(offset + 0x00,sf);
|
||||
/* 0x04: -1? */
|
||||
awc->sample_rate = read_u16(offset + 0x08,sf);
|
||||
/* 0x0a: unknown x4 */
|
||||
/* 0x12: null? */
|
||||
awc->codec = read_u8(offset + 0x13, sf);
|
||||
awc->channels = 1;
|
||||
break;
|
||||
|
||||
case 0x76: /* sfx header for vorbis */
|
||||
if (awc->is_music) {
|
||||
VGM_LOG("AWC: sfx header found in music\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
awc->num_samples = read_u32(offset + 0x00,sf);
|
||||
/* 0x04: -1? */
|
||||
awc->sample_rate = read_u16(offset + 0x08,sf);
|
||||
/* 0x0a: granule start? (negative) */
|
||||
/* 0x0c: granule max? */
|
||||
/* 0x10: unknown */
|
||||
awc->codec = read_u8(offset + 0x1c, sf); /* 16b? */
|
||||
/* 0x1e: vorbis header size */
|
||||
awc->channels = 1;
|
||||
|
||||
awc->vorbis_offset = offset + 0x20;
|
||||
break;
|
||||
|
||||
case 0xA3: /* block-to-sample table (32b x number of blocks w/ num_samples at the start of each block) */
|
||||
case 0xBD: /* events (32bx4): type_hash, params_hash, timestamp_ms, flags */
|
||||
default: /* 0x5C=animation/RSC?, 0x68=midi?, 0x36/0x2B/0x5A/0xD9=? */
|
||||
case 0x5C: /* animation/RSC config? */
|
||||
default: /* 0x68=midi?, 0x36=hash thing?, 0x2B=sizes, 0x5A/0xD9=? */
|
||||
//VGM_LOG("AWC: ignoring unknown tag 0x%02x\n", tag);
|
||||
break;
|
||||
}
|
||||
@ -340,11 +389,14 @@ static int parse_awc_header(STREAMFILE* streamFile, awc_header* awc) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* If music, data is divided into blocks of block_chunk size with padding.
|
||||
/* In music mode, data is divided into blocks of block_chunk size with padding.
|
||||
* Each block has a header/seek table and interleaved data for all channels */
|
||||
if (awc->is_music && read_32bit(awc->stream_offset, streamFile) != 0) {
|
||||
VGM_LOG("AWC: music found, but block doesn't start with seek table at %x\n", (uint32_t)awc->stream_offset);
|
||||
goto fail;
|
||||
{
|
||||
int32_t seek_start = read_u32(awc->stream_offset, sf); /* -1 in later (RDR2) versions */
|
||||
if (awc->is_music && !(seek_start == 0 || seek_start == -1)) {
|
||||
VGM_LOG("AWC: music found, but block doesn't start with seek table at %x\n", (uint32_t)awc->stream_offset);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -382,6 +382,9 @@ static const hcakey_info hcakey_list[] = {
|
||||
/* Readyyy! (Android) */
|
||||
{1234567890987654321}, // 112210F4B16C1CB1
|
||||
|
||||
/* HoneyWorks Premium Live (Android) */
|
||||
{20200401000000}, // 0000125F45B9D640
|
||||
|
||||
/* Dragalia Lost (iOS/Android) */
|
||||
{2967411924141, subkeys_dgl, sizeof(subkeys_dgl) / sizeof(subkeys_dgl[0]) }, // 000002B2E7889CAD
|
||||
|
||||
|
@ -1,51 +1,56 @@
|
||||
#include "meta.h"
|
||||
#include "../coding/coding.h"
|
||||
|
||||
|
||||
/* .NAAC - from Namco 3DS games (Ace Combat - Assault Horizon Legacy, Taiko no Tatsujin Don to Katsu no Jikuu Daibouken) */
|
||||
VGMSTREAM* init_vgmstream_naac(STREAMFILE* sf) {
|
||||
VGMSTREAM* vgmstream = NULL;
|
||||
off_t start_offset;
|
||||
int loop_flag, channel_count;
|
||||
int loop_flag, channels;
|
||||
size_t data_size;
|
||||
|
||||
/* check extension */
|
||||
if ( !check_extensions(sf,"naac") )
|
||||
|
||||
/* checks */
|
||||
if (!check_extensions(sf,"naac"))
|
||||
goto fail;
|
||||
|
||||
/* check header */
|
||||
if (read_32bitBE(0x00,sf) != 0x41414320) /* "AAC " */
|
||||
if (read_u32be(0x00,sf) != 0x41414320) /* "AAC " */
|
||||
goto fail;
|
||||
if (read_32bitLE(0x04,sf) != 0x01) /* version? */
|
||||
if (read_u32le(0x04,sf) != 0x01) /* version? */
|
||||
goto fail;
|
||||
|
||||
start_offset = 0x1000;
|
||||
loop_flag = (read_32bitLE(0x18,sf) != 0);
|
||||
channel_count = read_32bitLE(0x08,sf);
|
||||
loop_flag = (read_s32le(0x18,sf) != 0);
|
||||
channels = read_s32le(0x08,sf);
|
||||
|
||||
/* build the VGMSTREAM */
|
||||
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
||||
vgmstream = allocate_vgmstream(channels, loop_flag);
|
||||
if (!vgmstream) goto fail;
|
||||
|
||||
vgmstream->sample_rate = read_32bitLE(0x0c,sf);
|
||||
vgmstream->num_samples = read_32bitLE(0x10,sf); /* without skip_samples */
|
||||
vgmstream->loop_start_sample = read_32bitLE(0x14,sf); /* with skip_samples */
|
||||
vgmstream->loop_end_sample = read_32bitLE(0x18,sf);
|
||||
/* 0x1c: loop start offset, 0x20: loop end offset (within data) */
|
||||
data_size = read_32bitLE(0x24,sf);
|
||||
/* 0x28: unknown; 0x2c: table start offset?; 0x30: seek table (always 0xFD0, padded) */
|
||||
vgmstream->sample_rate = read_s32le(0x0c,sf);
|
||||
vgmstream->num_samples = read_s32le(0x10,sf); /* without skip_samples */
|
||||
vgmstream->loop_start_sample = read_s32le(0x14,sf); /* with skip_samples */
|
||||
vgmstream->loop_end_sample = read_s32le(0x18,sf) + 1; /* without skip_samples */
|
||||
/* 0x1c: loop start offset */
|
||||
/* 0x20: loop end offset (within data) */
|
||||
data_size = read_u32le(0x24,sf);
|
||||
/* 0x28: unknown */
|
||||
/* 0x2c: table start offset? */
|
||||
/* 0x30: seek table (always 0xFD0, padded) */
|
||||
|
||||
vgmstream->meta_type = meta_NAAC;
|
||||
|
||||
#ifdef VGM_USE_FFMPEG
|
||||
{
|
||||
vgmstream->codec_data = init_ffmpeg_offset(sf, start_offset,data_size);
|
||||
vgmstream->codec_data = init_ffmpeg_offset(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;
|
||||
vgmstream->num_samples -= 1024; /* may end with 1024 of silence? */
|
||||
vgmstream->loop_end_sample -= 1024;
|
||||
}
|
||||
#else
|
||||
goto fail;
|
||||
|
@ -1888,8 +1888,13 @@ static txtp_header* parse_txtp(STREAMFILE* sf) {
|
||||
|
||||
/* skip BOM if needed */
|
||||
if (file_size > 0 &&
|
||||
((uint16_t)read_16bitLE(0x00, sf) == 0xFFFE || (uint16_t)read_16bitLE(0x00, sf) == 0xFEFF))
|
||||
(read_u16le(0x00, sf) == 0xFFFE || read_u16le(0x00, sf) == 0xFEFF)) {
|
||||
txt_offset = 0x02;
|
||||
}
|
||||
else if ((read_u32be(0x00, sf) & 0xFFFFFF00) == 0xEFBBBF00) {
|
||||
txt_offset = 0x03;
|
||||
}
|
||||
|
||||
|
||||
/* read and parse lines */
|
||||
while (txt_offset < file_size) {
|
||||
|
Loading…
Reference in New Issue
Block a user