Skip to content

Buffers and audio files

Eric Clack edited this page Jan 8, 2019 · 11 revisions

Playing samples

Most of the time you'll want to load a sample and return a function that can be used to trigger the sample. This can be done with (sample <path>).

(def flute (sample "/home/rosejn/studio/samples/flutes/flutey-echo-intro-blast.wav"))

(flute)

Loading a sample into a buffer

You can load a wav file into an audio buffer using (load-sample <path>):

(def flute-buf (load-sample "/home/rosejn/studio/samples/flutes/flutey-echo-intro-blast.wav"))

Buffers are in-memory storage spots for audio files, and they can be either read from disk or generated by synths. You can view the contents of an audio buffer using the (scope :buf <buffer>) function:

(scope :buf flute-buf)

(N.B. see this Google groups discussion on potential troubles (e.g. crashing your JVM!) using scope)

Playing a sample from a buffer

If you want to load a sample and use it as a signal-generator in a more complex synth, then use play-buf for example:

(def sample-buf (load-sample "36.wav"))
(defsynth reverb-on-left []
  (let [dry (play-buf 1 sample-buf)
	wet (free-verb dry 1)]
    (out 0 [wet dry])))

(reverb-on-left)

Samples/buffers can be passed to the synth at the time its played:

(def sample-buf (load-sample "36.wav"))
(defsynth sample-player [buf] (out 0 (play-buf 1 buf)))

(sample-player sample-buf)

Loading Samples from Freesound

The website http://www.freesound.org/ has a large variety of sounds available. Overtone will download and cache files locally. For example:

(def snare (freesound 26903))
(snare)

Freesound samples people have found useful

Searching for sound files can sometimes be a bit difficult to find exactly what you want. Here are some files that people have used in example code from a google search in October of 2012. Consider adding useful sounds here for others.

id name id name id name id name
406 click 436 ride 777 kick 802 close-hat
2086 kick2 8323 powerwords 9088 jetbike 13254 cymbal
16309 open-snare 16568 two-cows 25649 subby 26657 open-hat
26903 snare 30628 steam-whistles 33637 boom 44293 sleigh-bells
48310 clap 50623 water-drops 80187 witch-cackle 80401 explosion
87731 snap 132676 clap2