Skip to content

Commit

Permalink
Updated VGMStream to r1951-100-g73ef7c6c
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Snowhill <[email protected]>
  • Loading branch information
kode54 committed Nov 24, 2024
1 parent de43b1b commit aa491fe
Show file tree
Hide file tree
Showing 12 changed files with 1,592 additions and 1,388 deletions.
4 changes: 4 additions & 0 deletions Frameworks/vgmstream/libvgmstream.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@
835C883722CC17BE001B4B3F /* ogg_vorbis_streamfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 835C883522CC17BE001B4B3F /* ogg_vorbis_streamfile.h */; };
835DF7032C79ABB50008814A /* sbuf.c in Sources */ = {isa = PBXBuildFile; fileRef = 835DF7022C79ABB50008814A /* sbuf.c */; };
835DF7052C79AED70008814A /* play_state.c in Sources */ = {isa = PBXBuildFile; fileRef = 835DF7042C79AED70008814A /* play_state.c */; };
836581A62CF3E53600E26C58 /* sdd.c in Sources */ = {isa = PBXBuildFile; fileRef = 836581A52CF3E53600E26C58 /* sdd.c */; };
836C052B23F62F1A00FA07C7 /* libatrac9.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 835FC6C623F62AEF006960FA /* libatrac9.framework */; };
836C052C23F62F3100FA07C7 /* libatrac9.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 835FC6C623F62AEF006960FA /* libatrac9.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
836DF622298F83F400CD0580 /* cri_keys.h in Headers */ = {isa = PBXBuildFile; fileRef = 836DF61F298F83F400CD0580 /* cri_keys.h */; };
Expand Down Expand Up @@ -1370,6 +1371,7 @@
835DF7022C79ABB50008814A /* sbuf.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sbuf.c; sourceTree = "<group>"; };
835DF7042C79AED70008814A /* play_state.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = play_state.c; sourceTree = "<group>"; };
835FC6C123F62AEE006960FA /* libatrac9.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = libatrac9.xcodeproj; path = ../libatrac9/libatrac9.xcodeproj; sourceTree = "<group>"; };
836581A52CF3E53600E26C58 /* sdd.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = sdd.c; sourceTree = "<group>"; };
836DF61F298F83F400CD0580 /* cri_keys.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cri_keys.h; sourceTree = "<group>"; };
836DF620298F83F400CD0580 /* bitstream_msb.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bitstream_msb.h; sourceTree = "<group>"; };
836DF621298F83F400CD0580 /* cri_keys.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cri_keys.c; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2520,6 +2522,7 @@
8399335E2591E8C0001855AF /* sbk.c */,
8349A8F51FE6257D00E26435 /* scd_pcm.c */,
836F6EEE18BDC2190095E648 /* sd9.c */,
836581A52CF3E53600E26C58 /* sdd.c */,
834FE0E6215C79EC000A5D3D /* sdf.c */,
83A8BAE225667AA7000F5F3F /* sdrh.c */,
836F6EEF18BDC2190095E648 /* sdt.c */,
Expand Down Expand Up @@ -3209,6 +3212,7 @@
83FBB17D2A4FF87200CD0580 /* sf_utils.c in Sources */,
8349A91F1FE6258200E26435 /* naac.c in Sources */,
834F7DD22C7093EA003AC386 /* ice_decoder.c in Sources */,
836581A62CF3E53600E26C58 /* sdd.c in Sources */,
83AFABBE23795202002F3947 /* isb.c in Sources */,
836F6FD218BDC2190095E648 /* ps2_bmdx.c in Sources */,
836F703C18BDC2190095E648 /* bns.c in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions Frameworks/vgmstream/vgmstream/src/formats.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ static const char* extension_list[] = {
"scd",
"sch",
"sd9",
"sdd",
"sdl",
"sdp", //txth/reserved [Metal Gear Arcade (AC)]
"sdf",
Expand Down Expand Up @@ -1446,6 +1447,7 @@ static const meta_info meta_info_list[] = {
{meta_EA_SBK, "Electronic Arts SBK header"},
{meta_DSP_ASURA, "Rebellion DSP header"},
{meta_ONGAKUKAN_RIFF_ADP, "Ongakukan RIFF WAVE header"},
{meta_SDD, "Doki Denki DSBH header"},
};

void get_vgmstream_coding_description(VGMSTREAM* vgmstream, char* out, size_t out_size) {
Expand Down
69 changes: 65 additions & 4 deletions Frameworks/vgmstream/vgmstream/src/meta/awc.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ VGMSTREAM* init_vgmstream_awc(STREAMFILE* sf) {
#endif

#ifdef VGM_USE_ATRAC9
case 0x0F: { /* ATRAC9 (PC) [Red Dead Redemption (PS4)] */
case 0x0F: { /* ATRAC9 (PS4) [Red Dead Redemption (PS4)] */
if (awc.is_streamed) {
vgmstream->layout_data = build_layered_awc(sf_body, &awc);
if (!vgmstream->layout_data) goto fail;
Expand Down Expand Up @@ -205,6 +205,50 @@ VGMSTREAM* init_vgmstream_awc(STREAMFILE* sf) {
}
break;

#ifdef VGM_USE_ATRAC9
case 0x0D: { /* OPUS (PC) [Red Dead Redemption (PC)] */
if (awc.is_streamed) {
vgmstream->layout_data = build_layered_awc(sf_body, &awc);
if (!vgmstream->layout_data) goto fail;
vgmstream->layout_type = layout_layered;
vgmstream->coding_type = coding_FFmpeg;
}
else {
VGM_LOG("AWC: unknown non-streamed Opus mode\n");
goto fail;
}
break;
}
#endif

case 0x11: { /* RIFF-MSADPCM (PC) [Red Dead Redemption (PC)] */
if (awc.is_streamed) {
VGM_LOG("AWC: unknown streamed mode for codec 0x%02x\n", awc.codec);
goto fail;
}
else {
VGMSTREAM* temp_vs = NULL;
STREAMFILE* temp_sf = NULL;

temp_sf = setup_subfile_streamfile(sf_body, awc.stream_offset, awc.stream_size, "wav");
if (!temp_sf) goto fail;

temp_vs = init_vgmstream_riff(temp_sf);
close_streamfile(temp_sf);
if (!temp_vs) goto fail;

temp_vs->num_streams = vgmstream->num_streams;
temp_vs->stream_size = vgmstream->stream_size;
temp_vs->meta_type = vgmstream->meta_type;
strcpy(temp_vs->stream_name, vgmstream->stream_name);

close_vgmstream(vgmstream);
//vgmstream = temp_vs;
return temp_vs;
}
break;
}

case 0xFF:
vgmstream->coding_type = coding_SILENCE;
snprintf(vgmstream->stream_name, STREAM_NAME_SIZE, "[%s]", "midi");
Expand Down Expand Up @@ -617,6 +661,24 @@ static VGMSTREAM* build_blocks_vgmstream(STREAMFILE* sf, awc_header* awc, int ch
break;
}
#endif
#ifdef VGM_USE_FFMPEG
case 0x0D: {
opus_config cfg = {0};

/* read from first block (all blocks have it but same thing), see awc_streamfile.h */
uint32_t frame_size_offset = awc->stream_offset + 0x10 * awc->channels + 0x70 * channel + 0x04;

cfg.frame_size = read_u16le(frame_size_offset, sf); // always 0x50?
cfg.channels = 1;

vgmstream->codec_data = init_ffmpeg_fixed_opus(temp_sf, substream_offset, substream_size, &cfg);
if (!vgmstream->codec_data) goto fail;
vgmstream->coding_type = coding_FFmpeg;
vgmstream->layout_type = layout_none;

break;
}
#endif
#ifdef VGM_USE_ATRAC9
case 0x0F: {
atrac9_config cfg = {0};
Expand Down Expand Up @@ -669,9 +731,8 @@ static VGMSTREAM* build_blocks_vgmstream(STREAMFILE* sf, awc_header* awc, int ch
// independently.
//
// This can be simulated by making one decoder per block (segmented, but opens too many SFs and can't skip
// samples correctly), or with a custom STREAMFILE that skips repeated block (works ok-ish but not all codecs).
// samples correctly), or with a custom STREAMFILE that skips repeated block (works ok-ish).
static layered_layout_data* build_layered_awc(STREAMFILE* sf, awc_header* awc) {
int i;
layered_layout_data* data = NULL;


Expand All @@ -680,7 +741,7 @@ static layered_layout_data* build_layered_awc(STREAMFILE* sf, awc_header* awc) {
if (!data) goto fail;

/* open each layer subfile */
for (i = 0; i < awc->channels; i++) {
for (int i = 0; i < awc->channels; i++) {
data->layers[i] = build_blocks_vgmstream(sf, awc, i);
if (!data->layers[i]) goto fail;
}
Expand Down
7 changes: 5 additions & 2 deletions Frameworks/vgmstream/vgmstream/src/meta/awc_streamfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ typedef struct {
* 0x00: "D11A"
* 0x04: frame size
* 0x06: frame samples
* 0x08: flags? (0x0103=AT9, 0x0104=DSP)
* 0x08: flags? (0x0101=OPUS, 0x0103=AT9, 0x0104=DSP)
* 0x0a: sample rate
* 0x0c: ATRAC9 config (repeated but same for all blocks) or "D11E" (DSP)
* 0x0c: ATRAC9 config (repeated but same for all blocks) or "D11E" (OPUS/DSP)
* 0x10-0x70: padding with 0x77 (ATRAC3) or standard DSP header for original full file (DSP)
* - padding up to data start, depending on codec (DSP/ATRAC9: none, others: aligned to 0x800)
*/
Expand Down Expand Up @@ -91,6 +91,7 @@ static bool read_awc_block(STREAMFILE* sf, awc_block_info_t* bi) {
extra_entry_size = 0x00;
header_padding = 0x800;
break;
case 0x0D: /* OPUS */
case 0x0F: /* ATRAC9 */
channel_entry_size = 0x10;
seek_entry_size = 0x00;
Expand Down Expand Up @@ -136,6 +137,7 @@ static bool read_awc_block(STREAMFILE* sf, awc_block_info_t* bi) {
bi->blk[ch].chunk_size = align_size_to_block(bi->blk[ch].channel_size, 0x10);
//bi->blk[ch].channel_size = (pre-loaded);
break;
case 0x0D: /* OPUS */
case 0x0F: /* ATRAC9 */
bi->blk[ch].frame_size = read_u16(offset + 0x04, sf);
bi->blk[ch].chunk_size = bi->blk[ch].entries * bi->blk[ch].frame_size;
Expand Down Expand Up @@ -217,6 +219,7 @@ static uint32_t get_block_repeated_size(STREAMFILE* sf, awc_block_info_t* bi, in
return skip_size; /* skip_size fills frame size */
}

case 0x0D: /* OPUS */
case 0x0F: /* ATRAC9 */
default:
VGM_LOG("AWC: found channel skip in codec %x\n", bi->codec); /* not seen */
Expand Down
Loading

0 comments on commit aa491fe

Please sign in to comment.