From af2bb05fdb9f6436a263de3d50abc73b743d89b8 Mon Sep 17 00:00:00 2001 From: bnnm Date: Sun, 22 Aug 2021 12:22:19 +0200 Subject: [PATCH] blocked: add sample count util --- src/layout/blocked.c | 38 +++++++++++++++++++++++++++++++++++++- src/layout/layout.h | 1 + 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/layout/blocked.c b/src/layout/blocked.c index c28c4fe0..14b4e335 100644 --- a/src/layout/blocked.c +++ b/src/layout/blocked.c @@ -1,6 +1,7 @@ #include "layout.h" #include "../vgmstream.h" #include "../decode.h" +#include "../coding/coding.h" /* Decodes samples for blocked streams. @@ -90,7 +91,7 @@ void render_vgmstream_blocked(sample_t* buffer, int32_t sample_count, VGMSTREAM* } /* helper functions to parse new block */ -void block_update(off_t block_offset, VGMSTREAM * vgmstream) { +void block_update(off_t block_offset, VGMSTREAM* vgmstream) { switch (vgmstream->layout_type) { case layout_blocked_ast: block_update_ast(block_offset,vgmstream); @@ -216,3 +217,38 @@ void block_update(off_t block_offset, VGMSTREAM * vgmstream) { break; } } + +void blocked_count_samples(VGMSTREAM* vgmstream, STREAMFILE* sf, off_t offset) { + int block_samples; + off_t max_offset = get_streamfile_size(sf); + + vgmstream->next_block_offset = offset; + do { + block_update(vgmstream->next_block_offset, vgmstream); + + if (vgmstream->current_block_samples < 0 || vgmstream->current_block_size == 0xFFFFFFFF) + break; + + if (vgmstream->current_block_samples) { + block_samples = vgmstream->current_block_samples; + } + else { + switch(vgmstream->coding_type) { + case coding_PCM16_int: block_samples = pcm16_bytes_to_samples(vgmstream->current_block_size, 1); break; + case coding_PCM8_int: + case coding_PCM8_U_int: block_samples = pcm8_bytes_to_samples(vgmstream->current_block_size, 1); break; + case coding_XBOX_IMA: block_samples = xbox_ima_bytes_to_samples(vgmstream->current_block_size, 1); break; + case coding_NGC_DSP: block_samples = dsp_bytes_to_samples(vgmstream->current_block_size, 1); break; + case coding_PSX: block_samples = ps_bytes_to_samples(vgmstream->current_block_size,1); break; + default: + VGM_LOG("BLOCKED: missing codec\n"); + return; + } + } + + vgmstream->num_samples += block_samples; + } + while (vgmstream->next_block_offset < max_offset); + + block_update(offset, vgmstream); /* reset */ +} diff --git a/src/layout/layout.h b/src/layout/layout.h index 0a1ae872..79dc63b5 100644 --- a/src/layout/layout.h +++ b/src/layout/layout.h @@ -7,6 +7,7 @@ /* blocked layouts */ void render_vgmstream_blocked(sample_t* buffer, int32_t sample_count, VGMSTREAM* vgmstream); void block_update(off_t block_offset, VGMSTREAM* vgmstream); +void blocked_count_samples(VGMSTREAM* vgmstream, STREAMFILE* sf, off_t offset); void block_update_ast(off_t block_ofset, VGMSTREAM* vgmstream); void block_update_mxch(off_t block_ofset, VGMSTREAM* vgmstream);