This may be obvious to everyone else already. It certainly is so in retrospect, but it took me a while to twig it, so I thought I'd mention it here.
I've been playing a bit with loscil to generate sounds from samples, both musical notes, and 'found' sounds. The loscil opcode has the option of setting sustain-loop start and end points, but as I started with non-musical sounds I was having difficulty figuring out suitable settings for these.
Then Bruce McCosar posted his experiments using the University of Iowa instrument samples, and so I immediately grabbed a couple too -- an A3 soprano Sax, and an A4 Violin.
As I wanted to add sustain to these, I initially wondered whether I had any hope of finding suitable values. Then it dawned on me -- one cycle of a 440 Hz standard-pitch A is just about 100 frames of a 44100 Hz sampled file! So a good starting loop length is some multiple of that.
Starting with the Sax sample (which is actually 220 Hz fundamental), I chose an arbitrary start point and an end point 200 frames later, and it worked perfectly! It was somewhat improved further by increasing to 800 frames, and didn't seem to be bothered (in this case) by the slight error incurred.
Moving on to the violin, I had a bit more trouble. For a start, the pitch of the sample is nothing like a standard 440 A! By trying to match by ear to an adjusted tone, it's somewhere around 430 Hz (maybe). As I expected, trying a 100 sample loop on that sounded really bad.
Using 'sox', I adjusted it by a few cents to where I thought it should be, and after a couple of attempts got a 100-sample loop to be reasonable. With the current 'best adjusted' sample, that short loop actually works better than one with more cycles, but with a slightly sharp one, for instance, I found that 499 samples sounded best.
If multiple cycles are preferred, one need to remember the slight error: 440 Hz is actually 100.222...
samples, so 5 cycles should probably be 501 samples, and so on. Experimentation is obviously going to be necessary, but having a starting point is a great help.
The start point isn't really critical, as long as you're getting just about an exact number of cycles
-- and as long as the instrument is constant tone! If it has vibrato or other major time variation things won't be so simple. (Better to add vibrato afterward if you can, anyway.) Pitches other than A may not fit so neatly into a given number of samples either: Standard C for instance (261.6 Hz) comes out to 168.578 samples, which means quite a discontinuity at the loop point.
Hope that makes sense and might be useful. I should probably post some of my experiments as Bruce is doing.