Jump to content

sc:Synthdef for sampler

Recommended Posts



I have a synthdef for a sampler that plays from a buffer based on the list of all files in a folder. It's working fine in SuperCollider:


SynthDef(\play, {
    var sig, buf, e;
    e = PathName.new("/directory_path/*").files.scramble.copyFromStart(20);
    buf = \buf.ir(0);
    sig = PlayBuf.ar(1!2, buf, BufRateScale.ir(buf) * \rate.ir(1), doneAction: 2);
    sig = sig * \amp.ir(0.5);
    Out.ar(\out.ir(0), sig);

Synth(\play, [buf: b, rate: 0.midiratio]);


I'm not sure how to build this in OM's sc:synthdef as the examples seem to be focused on oscillator-based sound sources.


My first attempt at an OpusModus sc:synthdef sampler (based on the above example) is:

(sc:defsynth sampler ((freq 200) (dur 2.0))
   (let* (e = PathName.new("/directory_path/*").files.scramble.copyFromStart(20))
         (buf = \buf.ir(0))
         (sig = PlayBuf.ar(1!2, buf, BufRateScale.ir(buf) * \rate.ir(1), doneAction: 2))
         (sig = sig * \amp.ir(0.5))
    (sc:out.ar 0 out)))


Which evaluates with a bug. I'm sure there are syntax problems but I'm also wondering if there are conceptual switches I could make to understand synthbuilding in OM rather than supercollider.





Link to comment
Share on other sites

Here's an example of sampler design:


(sc:defsynth stf-sampler1 ((buffer 0) (rate 1) (start 0) (amp 0.5) (out 0))
  (let (
        (sig (sc:play-buf.ar 2 buffer (* rate (sc:buf-rate-scale.ir buffer))
                          :start-pos (* start (sc:buf-frames.ir buffer))
                          :act :free)))
    (sc:out.ar out (* amp sig))))

(defparameter sample1 (sc:buffer-read "/Users/stephaneboussuge/Samples/tibetan-singing-bowl.wav" :bufnum 0))

;(sc:synth :stf-sampler1)
;(sc:synth :stf-sampler1 :rate 0.5)
;(sc:synth :stf-sampler1 :rate 2)


Hope it helps.





Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

Terms of Use Privacy Policy