Fix trailing samples not being cut when using pad end

This commit is contained in:
bnnm 2020-11-09 14:53:34 +01:00
parent 1770ca53b6
commit 1dbf99e994

View File

@ -404,13 +404,21 @@ static int render_fade(VGMSTREAM* vgmstream, sample_t* buf, int samples_done) {
}
}
static int render_pad_end(VGMSTREAM* vgmstream, sample_t* buf, int samples_to_do) {
static int render_pad_end(VGMSTREAM* vgmstream, sample_t* buf, int samples_done) {
play_state_t* ps = &vgmstream->pstate;
int channels = vgmstream->pstate.output_channels;
int start = 0;
/* since anything beyond pad end is silence no need to check ranges */
/* since anything beyond pad end is silence no need to check end */
if (ps->play_position < ps->pad_end_start) {
start = samples_done - (ps->play_position + samples_done - ps->pad_end_start);
}
else {
start = 0;
}
memset(buf, 0, samples_to_do * sizeof(sample_t) * channels);
return samples_to_do;
memset(buf + (start * channels), 0, (samples_done - start) * sizeof(sample_t) * channels);
return samples_done;
}
@ -445,7 +453,7 @@ int render_vgmstream(sample_t* buf, int32_t sample_count, VGMSTREAM* vgmstream)
tmpbuf += done * vgmstream->pstate.output_channels; /* as if mixed */
}
/* end padding (done before to avoid decoding if possible) */
/* end padding (done before to avoid decoding if possible, samples_to_do becomes 0) */
if (!vgmstream->config.play_forever /* && ps->pad_end_left */
&& ps->play_position + samples_done >= ps->pad_end_start) {
done = render_pad_end(vgmstream, tmpbuf, samples_to_do);
@ -462,10 +470,16 @@ int render_vgmstream(sample_t* buf, int32_t sample_count, VGMSTREAM* vgmstream)
samples_done += done;
/* simple fadeout */
if (!vgmstream->config.play_forever && ps->fade_left
&& ps->play_position + done >= ps->fade_start) {
render_fade(vgmstream, tmpbuf, done);
if (!vgmstream->config.play_forever) {
/* simple fadeout */
if (ps->fade_left && ps->play_position + done >= ps->fade_start) {
render_fade(vgmstream, tmpbuf, done);
}
/* silence leftover buf samples (rarely used when no fade is set) */
if (ps->play_position + done >= ps->pad_end_start) {
render_pad_end(vgmstream, tmpbuf, done);
}
}
tmpbuf += done * vgmstream->pstate.output_channels;