home/ atoms/ sc-time-pitch-granular

Granular time-pitch changing in SuperCollider decouples playback speed from pitch by varying grain rate and position

Time-pitch changing using granular synthesis reads segments (grains) of a buffer at a fixed pitch ratio but advances the playback position at a different rate. Setting pitchRatio=1 and posSpeed=0.25 plays at normal pitch but one-quarter speed. Setting pitchRatio=2 and posSpeed=1 transposes up an octave at normal speed. Grain overlap, grain duration, and random position jitter control artefact levels. In SC, this is implemented with GrainBuf driven by a position-advancing control proxy in ProxySpace, enabling real-time parameter changes without interrupting playback.

Examples

~timepitch = { |sndbuf, pitchRatio=1, grainRate=10, overlap=2, posSpeed=1| var grdur = overlap / grainRate; var pos = Phasor.ar(0, posSpeed * BufRateScale.kr(sndbuf) / BufSamples.kr(sndbuf)); GrainBuf.ar(2, Impulse.kr(grainRate), grdur, sndbuf, pitchRatio, pos) };

Assessment

Build a granular time-pitch patch that slows a spoken phrase to 50% speed without changing pitch. Tune overlap and jitter to minimise flanging artefacts. Then add real-time pitch transposition control.

“// figure 16.19 time-pitch changing p = ProxySpace.push(s.boot); b = Buffer.read(s, "sounds/a11wlk01-44_1.aiff");”
corpus · the-supercollider-book-official-code-examples-scbookcode-gpl · chunk 60