From 439665b69f3753abaf72a963176f00b8153551f5 Mon Sep 17 00:00:00 2001 From: bnnm Date: Sun, 8 Sep 2024 21:07:48 +0200 Subject: [PATCH] doc --- doc/TXTH.md | 4 +++- src/coding/ffmpeg_decoder.c | 16 +++++++++++++--- src/layout/layered.c | 2 +- src/meta/bik.c | 15 +++++++++------ 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/doc/TXTH.md b/doc/TXTH.md index dc5ecc6f..6935931f 100644 --- a/doc/TXTH.md +++ b/doc/TXTH.md @@ -303,11 +303,13 @@ id_check = (value) ``` #### NUMBER OF CHANNELS [REQUIRED] +How many audio channels the file has, typically 2 (stereo). ``` channels = (value) ``` -#### MUSIC FREQUENCY [REQUIRED] +#### AUDIO FREQUENCY [REQUIRED] +Number of samples per second, typically 48000/44100/32000/24000/22050/11025. ``` sample_rate = (value) ``` diff --git a/src/coding/ffmpeg_decoder.c b/src/coding/ffmpeg_decoder.c index ddfcad7c..32ee25d7 100644 --- a/src/coding/ffmpeg_decoder.c +++ b/src/coding/ffmpeg_decoder.c @@ -432,11 +432,16 @@ fail: /* FFmpeg internals (roughly) for reference: * + * // metadata info first extracted * AVFormatContext // base info extracted from input file * AVStream // substreams * AVCodecParameters // codec id, channels, format, ... * - * AVCodecContext // sample rate and general info + * // codec info passed to 'decode' functions + * AVCodecContext // codec's sample rate, priv data and general info + * AVPacket // encoded data (1 or N frames) passed to decoder + * AVFrame // decoded data (audio samples + channels + etc) received from decoder + * // (bufs are internally managed) * * - open avformat to get all possible format info (needs file or custom IO) * - open avcodec based on target stream + codec info from avformat @@ -444,8 +449,13 @@ fail: * - read next frame into packet via avformat * - decode packet via avcodec * - handle samples -*/ - + * + * In FFmpeg, each "avformat" defines an struct with format info/config and read_probe (detection) + read_header + * (setup format/codec params) + read_packet (demux single frame) functions. Meanwhile "avcodec" defines an struct + * with config and decode_init/close (setup, may use first block's data to init itself or some extradata from + * avformat) + decode_frame (loads AVFrame from AVPacket) + decode_flush (reset state). + * Codec/demuxer contexts aren't alloc'd manually and instead they declare priv data size. + */ static int init_ffmpeg_config(ffmpeg_codec_data* data, int target_subsong, int reset) { int errcode = 0; diff --git a/src/layout/layered.c b/src/layout/layered.c index caca579a..8af5f0a8 100644 --- a/src/layout/layered.c +++ b/src/layout/layered.c @@ -35,7 +35,7 @@ void render_vgmstream_layered(sbuf_t* sdst, VGMSTREAM* vgmstream) { samples_to_do = sdst->samples - sdst->filled; if (samples_to_do <= 0) { /* when decoding more than num_samples */ - VGM_LOG_ONCE("LAYERED: wrong samples_to_do\n"); + VGM_LOG_ONCE("LAYERED: wrong %i samples_to_do (%i filled vs %i samples)\n", samples_to_do, sdst->filled, sdst->samples); goto decode_fail; } diff --git a/src/meta/bik.c b/src/meta/bik.c index 0a1f94ce..1c181f91 100644 --- a/src/meta/bik.c +++ b/src/meta/bik.c @@ -6,16 +6,13 @@ static bool bink_get_info(STREAMFILE* sf, int target_subsong, int* p_total_subso /* BINK 1/2 - RAD Game Tools movies (audio/video format) */ VGMSTREAM* init_vgmstream_bik(STREAMFILE* sf) { - VGMSTREAM * vgmstream = NULL; - int channels = 0, loop_flag = 0, sample_rate = 0, num_samples = 0; - int total_subsongs = 0, target_subsong = sf->stream_index; - size_t stream_size; + VGMSTREAM* vgmstream = NULL; /* checks */ /* bink1/2 header, followed by version-char (audio is the same) */ if ((read_u32be(0x00,sf) & 0xffffff00) != get_id32be("BIK\0") && (read_u32be(0x00,sf) & 0xffffff00) != get_id32be("KB2\0")) - goto fail; + return NULL; /* .bik/bk2: standard * .bik2: older? @@ -25,7 +22,13 @@ VGMSTREAM* init_vgmstream_bik(STREAMFILE* sf) { * .vid: Etrange Libellules games [Alice in Wonderland (PC)] * .bika: fake extension for demuxed audio */ if (!check_extensions(sf,"bik,bk2,bik2,ps3,xmv,xen,vid,bika")) - goto fail; + return NULL; + + /* this typically handles regular or demuxed videos, but .bik with a 4x4 video made for audio do exist [Viva PiƱata (DS)] */ + + int channels = 0, loop_flag = 0, sample_rate = 0, num_samples = 0; + int total_subsongs = 0, target_subsong = sf->stream_index; + size_t stream_size; /* find target stream info and samples */ if (!bink_get_info(sf, target_subsong, &total_subsongs, &stream_size, &channels, &sample_rate, &num_samples))