Difference between revisions of "SuperCollider Cookbook"
From CCRMA Wiki
Line 1: | Line 1: | ||
'''SuperCollider Cookbook by Bruno''' | '''SuperCollider Cookbook by Bruno''' | ||
− | ==Play a sound file== | + | ==Play a sound file, vary speed, reverse== |
− | + | '''create a buffer''' | |
<pre> | <pre> | ||
~mysound = Buffer.read(s, "path/to/sound/file.wav"); | ~mysound = Buffer.read(s, "path/to/sound/file.wav"); | ||
</pre> | </pre> | ||
− | + | '''simple play''' | |
<pre>{PlayBuf.ar(1, ~mysound)}.play; // number of channels and buffer</pre> | <pre>{PlayBuf.ar(1, ~mysound)}.play; // number of channels and buffer</pre> | ||
− | + | '''get sound file info''' | |
<pre>[~mysound.bufnum, ~mysound.numChannels, ~mysound.path, ~mysound.numFrames];</pre> | <pre>[~mysound.bufnum, ~mysound.numChannels, ~mysound.path, ~mysound.numFrames];</pre> | ||
− | + | '''varying speed''' | |
<pre>{PlayBuf.ar(1, ~mysound, 2, loop: 1)}.play; // play 2x faster | <pre>{PlayBuf.ar(1, ~mysound, 2, loop: 1)}.play; // play 2x faster | ||
{PlayBuf.ar(1, ~mysound, 0.5, loop: 1)}.play; // play at half the speed | {PlayBuf.ar(1, ~mysound, 0.5, loop: 1)}.play; // play at half the speed | ||
{PlayBuf.ar(1, ~mysound, Line.kr(0.5, 2, 10), loop: 1)}.play; // playback speed goes from 0.5 to 2 in 10 seconds</pre> | {PlayBuf.ar(1, ~mysound, Line.kr(0.5, 2, 10), loop: 1)}.play; // playback speed goes from 0.5 to 2 in 10 seconds</pre> | ||
− | + | '''changing direction''' | |
<pre>{PlayBuf.ar(1, ~mysound, -1, loop: 1)}.play; // reverse sound | <pre>{PlayBuf.ar(1, ~mysound, -1, loop: 1)}.play; // reverse sound | ||
{PlayBuf.ar(1, ~mysound, -0.5, loop: 1)}.play; // play at half the speed AND reversed</pre> | {PlayBuf.ar(1, ~mysound, -0.5, loop: 1)}.play; // play at half the speed AND reversed</pre> |
Revision as of 17:15, 8 June 2011
SuperCollider Cookbook by Bruno
Contents
Play a sound file, vary speed, reverse
create a buffer
~mysound = Buffer.read(s, "path/to/sound/file.wav");
simple play
{PlayBuf.ar(1, ~mysound)}.play; // number of channels and buffer
get sound file info
[~mysound.bufnum, ~mysound.numChannels, ~mysound.path, ~mysound.numFrames];
varying speed
{PlayBuf.ar(1, ~mysound, 2, loop: 1)}.play; // play 2x faster {PlayBuf.ar(1, ~mysound, 0.5, loop: 1)}.play; // play at half the speed {PlayBuf.ar(1, ~mysound, Line.kr(0.5, 2, 10), loop: 1)}.play; // playback speed goes from 0.5 to 2 in 10 seconds
changing direction
{PlayBuf.ar(1, ~mysound, -1, loop: 1)}.play; // reverse sound {PlayBuf.ar(1, ~mysound, -0.5, loop: 1)}.play; // play at half the speed AND reversed
Play a MIDI file
Do this and that.
List Operations
scramble
reverse
find nth
Looping
While
( i = 0; while ( { i < 5 }, { i = i + 1; "boing".postln }); )
For
for (3, 7, { arg i; i.postln }); // prints values 3 through 7
ForBy
forBy (0, 8, 2, { arg i; i.postln }); // prints values 0 through 8 by 2's
Do
[ "first", "second", "third", 444) ].do({ arg item, i; [i, item].postln; }); 5.do({ arg item; item.postln }); // iterates from zero to four "you".do({ arg item; item.postln }); // a String is a collection of characters 'they'.do({ arg item; item.postln }); // a Symbol is a singular item (8..20).do({ arg item; item.postln }); // iterates from eight to twenty (8,10..20).do({ arg item; item.postln }); // iterates from eight to twenty, with stepsize two