mirror of
https://github.com/ZDoom/fluidsynth.git
synced 2025-02-24 04:42:03 +00:00
another attempt to correctly mangle with invalid loops
This commit is contained in:
parent
47eb2ef9ac
commit
f2eb657905
1 changed files with 19 additions and 7 deletions
|
@ -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,12 +3195,18 @@ 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)
|
||||
{
|
||||
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) */
|
||||
if(inv_start)
|
||||
sam->loopstart = sam->start + 1;
|
||||
|
||||
if(inv_end)
|
||||
sam->loopend = sam->end - 1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue