home/ atoms/ sc-granular-ugens

SuperCollider's GrainSin, GrainFM, and GrainBuf UGens generate individual grains at a specified density

SC provides dedicated grain UGens: GrainSin generates sine-wave grains, GrainFM generates FM grains, and GrainBuf reads grains from a buffer (enabling granular time-stretching and pitch-shifting of recorded audio). All take a trigger signal, grain duration, and per-grain parameters. Density (grains per second) is controlled by the trigger rate. GrainBuf’s rate and position arguments allow scrubbing through a sample at arbitrary speed and direction. Custom envelope shapes can be stored in buffers and passed as envbuf. Using ProxySpace, each parameter can be a live-rewriteable control proxy.

Examples

~grain = { GrainBuf.ar(2, Impulse.kr(20), 0.05, wavebuf, ~rate.kr, ~filepos.kr, 2, WhiteNoise.kr) * 0.2 }; ~filepos = { MouseX.kr + LFNoise0.kr(100, 0.03) };

Assessment

Build a GrainBuf patch that freezes a sample at a mouse-controlled position with controllable grain duration. Compare the sound at 10 vs 100 grains/second. Swap in a custom percussive envelope buffer.

“~grain = { arg envbuf = -1, density = 10, graindur=0.1, amp=0.2; var pan, env, freqdev; var trig = Impulse.kr(density); pan = MouseX.kr(-1, 1);”
corpus · the-supercollider-book-official-code-examples-scbookcode-gpl · chunk 57