Playing Samples in SuperCollider

The Buffer class manages samples in SuperCollider. There are many ways to use samples, based on these buffers. The following example loads a WAV file (find it in the download) and creates a looping node. When running, the playback speed can be changed:

s.boot;

// get and enter the absolute path to a sample
~sample_path = "/some/directory/sala_formanten.wav";

~buffer  = Buffer.read(s,~sample_path);

(
~sampler = {

      |rate= 0.1|

      var out = LoopBuf.ar(1,~buffer.bufnum, BufRateScale.kr(~buffer.bufnum) * rate, 1, 0,0,~buffer.numFrames);

      Out.ar(0, out);

}.play;

)

// set the play rate manually
~sampler.set(\rate,-0.1);

Exercise