I have some sf2 soundfonts that loop fine normally, but using TinySoundFont come to an abrupt end rather than looping.
Can you think of any reason this would happen? I assume something this basic should have been tried and tested. Modifying tsf_voice_ender as follows keeps the sound looping, but not sure this is the correct way to go about things?
if (tmpSourceSamplePosition >= tmpSampleEndDbl || v->ampenv.segment == TSF_SEGMENT_DONE)
{
if (isLooping) tmpSourceSamplePosition -= (tmpLoopEnd - tmpLoopStart + 1.0); // Added line
else {
tsf_voice_kill(v);
return;
}
}
Also in the following function the highlighted line is problematic as it forces the play position to jump abruptly to the end of the loop.
static void tsf_voice_end(tsf* f, struct tsf_voice* v)
{
// if maxVoiceNum is set, assume that voice rendering and note queuing are on separate threads
// so to minimize the chance that voice rendering would advance the segment at the same time
// we just do it twice here and hope that it sticks
int repeats = (f->maxVoiceNum ? 2 : 1);
while (repeats--)
{
tsf_voice_envelope_nextsegment(&v->ampenv, TSF_SEGMENT_SUSTAIN, f->outSampleRate);
tsf_voice_envelope_nextsegment(&v->modenv, TSF_SEGMENT_SUSTAIN, f->outSampleRate);
if (v->region->loop_mode == TSF_LOOPMODE_SUSTAIN)
{
// Continue playing, but stop looping.
v->loopEnd = v->loopStart; < ---- PROBLEMATIC LINE
}
}
}
Paul
I have some sf2 soundfonts that loop fine normally, but using TinySoundFont come to an abrupt end rather than looping.
Can you think of any reason this would happen? I assume something this basic should have been tried and tested. Modifying tsf_voice_ender as follows keeps the sound looping, but not sure this is the correct way to go about things?
if (tmpSourceSamplePosition >= tmpSampleEndDbl || v->ampenv.segment == TSF_SEGMENT_DONE)
{
if (isLooping) tmpSourceSamplePosition -= (tmpLoopEnd - tmpLoopStart + 1.0); // Added line
else {
tsf_voice_kill(v);
return;
}
}
Also in the following function the highlighted line is problematic as it forces the play position to jump abruptly to the end of the loop.
static void tsf_voice_end(tsf* f, struct tsf_voice* v)
{
// if maxVoiceNum is set, assume that voice rendering and note queuing are on separate threads
// so to minimize the chance that voice rendering would advance the segment at the same time
// we just do it twice here and hope that it sticks
int repeats = (f->maxVoiceNum ? 2 : 1);
while (repeats--)
{
tsf_voice_envelope_nextsegment(&v->ampenv, TSF_SEGMENT_SUSTAIN, f->outSampleRate);
tsf_voice_envelope_nextsegment(&v->modenv, TSF_SEGMENT_SUSTAIN, f->outSampleRate);
if (v->region->loop_mode == TSF_LOOPMODE_SUSTAIN)
{
// Continue playing, but stop looping.
v->loopEnd = v->loopStart; < ---- PROBLEMATIC LINE
}
}
}
Paul