How do I wrap a sample in an envelope in Overtone?

40 Views Asked by At

Some samples I use from Freesound.org have a slight click at the end, e.g.:

repl> (use 'overtone.live)
nil
repl> (def stick (freesound 82280))
#'repl/stick
repl> (stick)

So I'm trying to wrap this sample in an envelope, however all I get is silence. I suspect there's something wrong with my use of buf-rd...

(definst stick1
  [amp 0.7]
  (let [env     (env-gen (perc) :action FREE)
        phase   (phasor:ar :start 0 :end 1 :rate 1)
        index   (* phase (buf-frames stick))
        snd     (buf-rd 1 stick index)]
    (* amp env snd)))

(stick1)
1

There are 1 best solutions below

0
On

play-buf is the correct function to encorporate a sample in an envelope. perc is used to set an attack of 0.01 seconds, and a release of 1 second before silence, thus killing the click.

(def stick (freesound 82280))

(definst stick1
  [amp 0.7]
  (let [env     (env-gen (perc 0.01 1) :action FREE)
        snd     (play-buf 1 stick)]
    (* amp env snd)))

(stick1)