From 9ff2ce59449ade100a5976bb9de3f0b9b6f41665 Mon Sep 17 00:00:00 2001 From: bnnm Date: Thu, 27 Dec 2018 16:51:27 +0100 Subject: [PATCH] Add name_offset/name_size option for TXTH --- doc/TXTH.md | 16 ++++++++++++++-- src/meta/txth.c | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/doc/TXTH.md b/doc/TXTH.md index f78dcf00..666da2f7 100644 --- a/doc/TXTH.md +++ b/doc/TXTH.md @@ -190,11 +190,23 @@ body_file = (filename)|*.(extension)|null # Subsongs [OPTIONAL] # Sets the number of subsongs in the file, adjusting reads per subsong N: -# "value = @(offset) + subsong_offset*N". Mainly for bigfiles with consecutive -# headers per subsong, set subsong_offset to 0 when done as it affects any reads. +# "value = @(offset) + subsong_offset*N". (number) values aren't adjusted +# as they are seen as constants. +# Mainly for bigfiles with consecutive headers per subsong, set subsong_offset +# to 0 when done as it affects any reads. # The current subsong number is handled externally by plugins or TXTP. subsong_count = (number)|(offset)|(field) subsong_offset = (number)|(offset)|(field) + +# Names [OPTIONAL] +# Sets the name of the stream, most useful when used with subsongs. +# TXTH will read a string at name_offset, with name_size characters. +# name_size defaults to 0, which reads until null-terminator or a +# non-ascii character. +# name_offset can be a (number) value, but being an offset it's also +# adjusted by subsong_offset. +name_offset = (number)|(offset)|(field) +name_size = (number)|(offset)|(field) ``` ## Usages diff --git a/src/meta/txth.c b/src/meta/txth.c index 40165d5b..4dbb72a7 100644 --- a/src/meta/txth.c +++ b/src/meta/txth.c @@ -76,6 +76,10 @@ typedef struct { uint32_t subsong_count; uint32_t subsong_offset; + uint32_t name_offset_set; + uint32_t name_offset; + uint32_t name_size; + /* original STREAMFILE and its type (may be an unsupported "base" file or a .txth) */ STREAMFILE *streamFile; int streamfile_is_txth; @@ -194,6 +198,10 @@ VGMSTREAM * init_vgmstream_txth(STREAMFILE *streamFile) { vgmstream->loop_end_sample = txth.loop_end_sample; vgmstream->num_streams = txth.subsong_count; vgmstream->stream_size = txth.data_size; + if (txth.name_offset_set) { + size_t name_size = txth.name_size ? txth.name_size + 1 : STREAM_NAME_SIZE; + read_string(vgmstream->stream_name,name_size, txth.name_offset,txth.streamHead); + } /* codec specific (taken from GENH with minimal changes) */ switch (coding) { @@ -720,6 +728,16 @@ static int parse_keyval(STREAMFILE * streamFile_, txth_header * txth, const char else if (0==strcmp(key,"subsong_offset")) { if (!parse_num(txth->streamHead,txth,val, &txth->subsong_offset)) goto fail; } + else if (0==strcmp(key,"name_offset")) { + if (!parse_num(txth->streamHead,txth,val, &txth->name_offset)) goto fail; + txth->name_offset_set = 1; + /* special subsong adjustment */ + if (txth->subsong_offset) + txth->name_offset = txth->name_offset + txth->subsong_offset * (txth->target_subsong - 1); + } + else if (0==strcmp(key,"name_size")) { + if (!parse_num(txth->streamHead,txth,val, &txth->name_size)) goto fail; + } else if (0==strcmp(key,"header_file")) { if (txth->streamhead_opened) { close_streamfile(txth->streamHead);