From 6b4f54df92f6544c189aff38597d37ca511f2dd8 Mon Sep 17 00:00:00 2001 From: bnnm Date: Wed, 22 Aug 2018 21:04:16 +0200 Subject: [PATCH] Add TXTH "loop_flag = auto" to autodetect PS-ADPCM loop points --- src/meta/txth.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/meta/txth.c b/src/meta/txth.c index c0bff483..b8b02d72 100644 --- a/src/meta/txth.c +++ b/src/meta/txth.c @@ -57,6 +57,7 @@ typedef struct { uint32_t loop_flag; int loop_flag_set; + int loop_flag_auto; uint32_t coef_offset; uint32_t coef_spacing; @@ -132,6 +133,13 @@ VGMSTREAM * init_vgmstream_txth(STREAMFILE *streamFile) { goto fail; } + /* try to autodetect PS-ADPCM loop data */ + if (txth.loop_flag_auto && coding == coding_PSX) { + size_t data_size = get_streamfile_size(streamFile) - txth.start_offset; + txth.loop_flag = ps_find_loop_offsets(streamFile, txth.start_offset, data_size, txth.channels, txth.interleave, + (int32_t*)&txth.loop_start_sample, (int32_t*)&txth.loop_end_sample); + } + /* build the VGMSTREAM */ vgmstream = allocate_vgmstream(txth.channels,txth.loop_flag); @@ -583,8 +591,13 @@ static int parse_keyval(STREAMFILE * streamFile, STREAMFILE * streamText, txth_h txth->loop_adjust = get_bytes_to_samples(txth, txth->loop_adjust * (txth->interleave*txth->channels)); } else if (0==strcmp(key,"loop_flag")) { - if (!parse_num(streamFile,val, &txth->loop_flag)) goto fail; - txth->loop_flag_set = 1; + if (0==strcmp(val,"auto")) { + txth->loop_flag_auto = 1; + } + else { + if (!parse_num(streamFile,val, &txth->loop_flag)) goto fail; + txth->loop_flag_set = 1; + } } else if (0==strcmp(key,"coef_offset")) { if (!parse_num(streamFile,val, &txth->coef_offset)) goto fail; @@ -602,6 +615,9 @@ static int parse_keyval(STREAMFILE * streamFile, STREAMFILE * streamText, txth_h else if (0==strcmp(key,"coef_mode")) { if (!parse_num(streamFile,val, &txth->coef_mode)) goto fail; } + else if (0==strcmp(key,"psx_loops")) { + if (!parse_num(streamFile,val, &txth->coef_mode)) goto fail; + } else { VGM_LOG("TXTH: unknown key=%s, val=%s\n", key,val); goto fail;