[chuck-users] SndBuf use of .loop and .interp (herman asked)

Perry Cook prc at cs.princeton.edu
Thu Feb 27 14:51:24 EST 2020

.interp doesn’t do what you think it does.  It just specifies the
type of internal interpolation for smoothing of playback (only 
applicable for non 1.0 rates).

SndBuf .loop just tells it to start over at the beginning
when it reaches the end (or end after reaching the beginning):

SndBuf s => dac;
"special:dope" => s.read; // load homer
s.length() => now;  // play him
second => now;     // wait a bit
1 => s.loop;            // loop homer now
2*second => now; // for 2 seconds
-1 => s.rate;          // then play him backward 
2*second => now; // for two more

If you need to loop a specific piece of a sound in SndBuf, 
you should either:  edit that in a sound editor and save/ it as a new file.
Figure out the exact sample points within the wave that
should be your start and end loop points.  Then use .pos
and => now to loop it.  You don’t even need .loop mode 
for that, because it will keep playing as long as the start
is within the buffer boundaries.

If you want smooth looping without pops at the edges, 
you could maybe use an ADSR to smooth the beginning 
and end.  Not sure of your application here, but SndBuf
is not a flexible sample playback UGen that knows about
loops like a SoundFont player would.


> From: herman verbaeten <hverb54 at hotmail.com>
> Hi,
> In my attempt to loop-play 1 portion of the soundbuffer for a certain periode time(2000 milliseconds in my example) i get a kind of clicking when the geginning of the sample pos is different from the ending..
> Maybe .loop and .interp of SndBuf is a solution here. Anyone who knows how to use them?
> Kind regards,
> Herman
> me.sourceDir() + "aeiou.wav" => string filename;
> if( me.args() ) me.arg(0) => filename;
> SndBuf buf => dac;
> filename => buf.read;
> fun void looper()
> {
> while(true)
> {
> 1500::samp => now;
> 50000 => buf.pos;
> }}
> spork ~ looper();
> 2000::ms => now;
> -------------- next part --------------

More information about the chuck-users mailing list