There are quicker ways to do it (e.g. check out the "play" function), but here's how to do it with lots of configurability:
{-# LANGUAGE DataKinds, ExtendedDefaultRules #-}
import Vivid
foo = sd (0 :: I "buf") $ do
let buf = V::V "buf"
s <- playBuf (buf_ buf, rate_ $ bufRateScale buf ~* 3, doneAction_ 2)
out 0 [s,s]
main = do
buf <- newBufferFromFile "the_letter.flac"
synth foo (b2i buf :: I "buf")
A couple notes:
- For fun we play it at 3x speed.
- "doneAction_ 2" means when the buffer is done playing the Synth frees itself.
- "bufRateScale" converts from the samplerate of the file to the samplerate of the sc server.
- We can make a Buffer from lots of file formats, but notably not mp3. This is the SC server's limitation, as it can't use the patented mp3 decoder. ".wav" works, as does .flac, .ogg, and others.
Tom
I'm imagining asking a synth to play some sample from a collection. Is it possible?
--
Jeff Brown | Jeffrey Benjamin Brown
_______________________________________________