From 872475bfc302c40e3353bc423e2c7d85a1fa0bc5 Mon Sep 17 00:00:00 2001 From: bnnm Date: Wed, 9 Dec 2020 21:19:24 +0100 Subject: [PATCH] Add .awc with Vorbis in sfx mode [Red Dead Redemption 2 (PC)] --- src/coding/coding.h | 4 + src/coding/vorbis_custom_decoder.c | 2 + src/coding/vorbis_custom_decoder.h | 12 +- src/coding/vorbis_custom_utils_awc.c | 86 +++++++++++++ src/libvgmstream.vcproj | 4 + src/libvgmstream.vcxproj | 1 + src/libvgmstream.vcxproj.filters | 3 + src/meta/awc.c | 176 +++++++++++++++++---------- 8 files changed, 221 insertions(+), 67 deletions(-) create mode 100644 src/coding/vorbis_custom_utils_awc.c diff --git a/src/coding/coding.h b/src/coding/coding.h index 9545218b..c5fee09e 100644 --- a/src/coding/coding.h +++ b/src/coding/coding.h @@ -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; diff --git a/src/coding/vorbis_custom_decoder.c b/src/coding/vorbis_custom_decoder.c index 4b887a46..4dbcd825 100644 --- a/src/coding/vorbis_custom_decoder.c +++ b/src/coding/vorbis_custom_decoder.c @@ -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) { diff --git a/src/coding/vorbis_custom_decoder.h b/src/coding/vorbis_custom_decoder.h index 8080800d..b3fa05ae 100644 --- a/src/coding/vorbis_custom_decoder.h +++ b/src/coding/vorbis_custom_decoder.h @@ -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_ */ diff --git a/src/coding/vorbis_custom_utils_awc.c b/src/coding/vorbis_custom_utils_awc.c new file mode 100644 index 00000000..b87793aa --- /dev/null +++ b/src/coding/vorbis_custom_utils_awc.c @@ -0,0 +1,86 @@ +#include "vorbis_custom_decoder.h" + +#ifdef VGM_USE_VORBIS +#include + + +/* **************************************************************************** */ +/* 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 diff --git a/src/libvgmstream.vcproj b/src/libvgmstream.vcproj index 12520ad9..4b704d5e 100644 --- a/src/libvgmstream.vcproj +++ b/src/libvgmstream.vcproj @@ -2310,6 +2310,10 @@ RelativePath=".\coding\vorbis_custom_decoder.c" > + + diff --git a/src/libvgmstream.vcxproj b/src/libvgmstream.vcxproj index 892c94f3..a3ac3b05 100644 --- a/src/libvgmstream.vcxproj +++ b/src/libvgmstream.vcxproj @@ -631,6 +631,7 @@ + diff --git a/src/libvgmstream.vcxproj.filters b/src/libvgmstream.vcxproj.filters index 8dda843c..c042dfc1 100644 --- a/src/libvgmstream.vcxproj.filters +++ b/src/libvgmstream.vcxproj.filters @@ -1378,6 +1378,9 @@ coding\Source Files + + coding\Source Files + coding\Source Files diff --git a/src/meta/awc.c b/src/meta/awc.c index 58355352..9d57e856 100644 --- a/src/meta/awc.c +++ b/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; + } }