blocked: add sample count util

This commit is contained in:
bnnm 2021-08-22 12:22:19 +02:00
parent f9ef1f2d89
commit af2bb05fdb
2 changed files with 38 additions and 1 deletions

View File

@ -1,6 +1,7 @@
#include "layout.h" #include "layout.h"
#include "../vgmstream.h" #include "../vgmstream.h"
#include "../decode.h" #include "../decode.h"
#include "../coding/coding.h"
/* Decodes samples for blocked streams. /* Decodes samples for blocked streams.
@ -216,3 +217,38 @@ void block_update(off_t block_offset, VGMSTREAM * vgmstream) {
break; 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 */
}

View File

@ -7,6 +7,7 @@
/* blocked layouts */ /* blocked layouts */
void render_vgmstream_blocked(sample_t* buffer, int32_t sample_count, VGMSTREAM* vgmstream); void render_vgmstream_blocked(sample_t* buffer, int32_t sample_count, VGMSTREAM* vgmstream);
void block_update(off_t block_offset, 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_ast(off_t block_ofset, VGMSTREAM* vgmstream);
void block_update_mxch(off_t block_ofset, VGMSTREAM* vgmstream); void block_update_mxch(off_t block_ofset, VGMSTREAM* vgmstream);