Fix missing end samples in Wwise Vorbis

This commit is contained in:
bnnm 2022-07-14 23:08:09 +02:00
parent f7ccb96b2f
commit 23474dc27c
3 changed files with 11 additions and 8 deletions

View File

@ -409,6 +409,7 @@ typedef struct {
uint32_t setup_id; /* external setup */
int big_endian; /* flag */
uint32_t stream_end; /* optional, to avoid overreading into next subsong or chunk */
/* Wwise Vorbis config */
wwise_setup_t setup_type;

View File

@ -65,6 +65,9 @@ vorbis_custom_codec_data* init_vorbis_custom(STREAMFILE* sf, off_t start_offset,
/* write output */
config->data_start_offset = data->config.data_start_offset;
if (!data->config.stream_end) {
data->config.stream_end = get_streamfile_size(sf);
}
return data;
@ -78,19 +81,11 @@ fail:
void decode_vorbis_custom(VGMSTREAM* vgmstream, sample_t* outbuf, int32_t samples_to_do, int channels) {
VGMSTREAMCHANNEL *stream = &vgmstream->ch[0];
vorbis_custom_codec_data* data = vgmstream->codec_data;
size_t stream_size = get_streamfile_size(stream->streamfile);
//data->op.packet = data->buffer;/* implicit from init */
int samples_done = 0;
while (samples_done < samples_to_do) {
/* extra EOF check for edge cases */
if (stream->offset >= stream_size) {
memset(outbuf + samples_done * channels, 0, (samples_to_do - samples_done) * sizeof(sample) * channels);
break;
}
if (data->samples_full) { /* read more samples */
int samples_to_get;
float **pcm;
@ -123,6 +118,12 @@ void decode_vorbis_custom(VGMSTREAM* vgmstream, sample_t* outbuf, int32_t sample
else { /* read more data */
int ok, rc;
/* extra EOF check */
if (stream->offset >= data->config.stream_end) {
/* may need to drain samples? (not a thing in vorbis due to packet types?) */
goto decode_fail;
}
/* not actually needed, but feels nicer */
data->op.granulepos += samples_to_do; /* can be changed next if desired */
data->op.packetno++;

View File

@ -477,6 +477,7 @@ VGMSTREAM* init_vgmstream_fsb5(STREAMFILE* sf) {
cfg.channels = fsb5.channels;
cfg.sample_rate = fsb5.sample_rate;
cfg.setup_id = read_u32le(fsb5.extradata_offset,sf);
cfg.stream_end = fsb5.stream_offset + fsb5.stream_size;
vgmstream->codec_data = init_vorbis_custom(sb, fsb5.stream_offset, VORBIS_FSB, &cfg);
if (!vgmstream->codec_data) goto fail;