sorry, the correct word is probably sustain part, the post-attack-stable part of sound that you may be able to loop easily, for instance the quasi-steady state of a piano tone after the attack during the quasi-flat decay.
Something found in archives presents very clearly the problem, and a possible implementation :
Let's suppose this is the sample:
|-----SS-----LB-----LE------|
where:
SS= sample start (where we want the sample to start playing the first time)
LB= loop begin
LE= loop end
With appropriate calculations, the two phasors can be adjusted so that:
1) Phasor A reproduces the sample the first time from SS to LE in its first
cycle. In subsequent cycles it would do the same but it will be muted so we
don't mind.
2) Phasor B reproduces the loop region; its initial phase is calculated in
such a way that at the beginning, when it is muted, it will be producing
garbage, but when phasor A will reach point LB for the first time, phasor B
will also be on LB, so that, during ONE cycle of phasor B, the two phasors
will be reproducing *exactly* the same portion LB-LE synchronously.
So, at any moment of that cycle, we can (and we must) safely switch from the
output of phasor A to that of phasor B; we don't need to do a crossfade
because the two outputs are perfectly identical.
So, for detecting when to switch, we can use a [threshold~] on LB on the
output of phasor A, even if threshold is block quantized. No matter if the
actual switching occurs with a delay of almost one block, it will still be
safe to switch.
... which seems brilliant ! (sorry i do not remember this contribution's author)