another attempt to correctly mangle with invalid loops

This commit is contained in:
Tom M 2017-08-04 11:18:56 +02:00 committed by GitHub
parent 47eb2ef9ac
commit f2eb657905

View file

@ -3160,12 +3160,19 @@ fixup_sample (SFData * sf)
fluid_list_t *p;
SFSample *sam;
int invalid_loops=FALSE;
int inv_start;
int inv_end;
p = sf->sample;
while (p)
{
sam = (SFSample *) (p->data);
// The SoundFont 2.4 spec defines the loop start index as the first sample point of the loop
inv_start = (sam->loopstart < sam->start) || (sam->loopstart >= sam->loopend);
// while loop end is the first point AFTER the last sample of the loop.
inv_end = (sam->loopend > sam->end+1) || (sam->loopstart >= sam->loopend);
/* if sample is not a ROM sample and end is over the sample data chunk
or sam start is greater than 4 less than the end (at least 4 samples) */
if ((!(sam->sampletype & FLUID_SAMPLETYPE_ROM)
@ -3179,8 +3186,7 @@ fixup_sample (SFData * sf)
return (OK);
}
else if (sam->loopend > sam->end || sam->loopstart >= sam->loopend
|| sam->loopstart < sam->start)
else if (inv_start || inv_end)
{ /* loop is fowled?? (cluck cluck :) */
FLUID_LOG (FLUID_DBG, _("Sample '%s' has invalid loop,"
" extending loop to full sample"), sam->name);
@ -3189,13 +3195,19 @@ fixup_sample (SFData * sf)
/* can pad loop by 8 samples and ensure at least 4 for loop (2*8+4) */
if ((sam->end - sam->start) >= 20)
{
sam->loopstart = sam->start + 8;
sam->loopend = sam->end - 8;
if(inv_start)
sam->loopstart = sam->start + 8;
if(inv_end)
sam->loopend = sam->end - 8;
}
else
{ /* loop is fowled, sample is tiny (can't pad 8 samples) */
sam->loopstart = sam->start + 1;
sam->loopend = sam->end - 1;
if(inv_start)
sam->loopstart = sam->start + 1;
if(inv_end)
sam->loopend = sam->end - 1;
}
}