libADLMIDI and libOPNMIDI: Fixed an infinite loop caused the stuck

Recently I've got the report from @drfrag666 that at LZDoom some banks
do cause the dead freeze and that is probably because of the merge
problems. However, after my research, I found the bug at me: in a very
special case, a zero delay value may appear that will cause the stuck.
This commit is contained in:
Wohlstand 2020-10-16 11:44:03 +03:00 committed by Christoph Oelckers
parent a175de1531
commit eac26c3aca
2 changed files with 8 additions and 0 deletions

View file

@ -1311,6 +1311,8 @@ ADLMIDI_EXPORT int adl_playFormat(ADL_MIDIPlayer *device, int sampleCount,
while(left > 0)
{
{//...
if(setup.delay <= 0.0)
setup.delay = double(left / 2) / double(setup.PCM_RATE);
const double eat_delay = setup.delay < setup.maxdelay ? setup.delay : setup.maxdelay;
if(hasSkipped)
{
@ -1419,6 +1421,8 @@ ADLMIDI_EXPORT int adl_generateFormat(struct ADL_MIDIPlayer *device, int sampleC
while(left > 0)
{
{//...
if(delay <= 0.0)
delay = double(left / 2) / double(setup.PCM_RATE);
const double eat_delay = delay < setup.maxdelay ? delay : setup.maxdelay;
delay -= eat_delay;
setup.carry += double(setup.PCM_RATE) * eat_delay;

View file

@ -1044,6 +1044,8 @@ OPNMIDI_EXPORT int opn2_playFormat(OPN2_MIDIPlayer *device, int sampleCount,
while(left > 0)
{
{//
if(setup.delay <= 0.0)
setup.delay = double(left / 2) / double(setup.PCM_RATE);
const double eat_delay = setup.delay < setup.maxdelay ? setup.delay : setup.maxdelay;
if(hasSkipped)
{
@ -1139,6 +1141,8 @@ OPNMIDI_EXPORT int opn2_generateFormat(struct OPN2_MIDIPlayer *device, int sampl
while(left > 0)
{
{//
if(delay <= 0.0)
delay = double(left / 2) / double(setup.PCM_RATE);
const double eat_delay = delay < setup.maxdelay ? delay : setup.maxdelay;
delay -= eat_delay;
setup.carry += double(setup.PCM_RATE) * eat_delay;