I would be very interested to learn from others how they use the sapf language, especially which functions they add to the tool belt (prelude file) and use regularly.
I’ll start with one of mine: a freeverb-based reverberation unit. It supports both mono and stereo input signals, and outputs in stereo.
\in roomSize damping wet
"(in roomSize damping wet --> outL outR) stereo reverberator based on the Freeverb algorithm.
Runs individual input channels through L and R stereo reverb core.
in: mono or stereo input signal.
roomSize: 0 to 1, controls the decay time of the reverb tail.
damping: 0 to 1, controls the high-frequency damping. Higher values mean more damping.
wet: 0 to 1, controls the wet/dry mix (0=dry, 1=wet)."
[
in type 'VList ==
\[ in un2 ] ;; If stereo, unpack and leave L then R on the stack.
\[ in aa ] ;; If mono, duplicate it to leave M then M on the stack.
if
= inR = inL ;; Assign the two values now on the stack to L and R.
100m = maxDelay ;; A safe max delay time in seconds.
44100.0 = ref_sr
23 ref_sr / = stereoSpread ;; A common value for Freeverb stereo spread
;; Delay times from the original Freeverb in samples, converted to seconds, based on reference sample rate
;; Create slightly different delay times for Left and Right channels
[1116 1188 1277 1356 1422 1491 1557 1617] ref_sr / = combDelaysL
combDelaysL stereoSpread + = combDelaysR
[225 556 441 341] ref_sr / = apDelaysL
apDelaysL stereoSpread + = apDelaysR
;; Map 0-1 parameters to actual values
roomSize 0.1 5.0 unilinc = decayTime
damping 0 1 15k 500 linexp = lpfreq
1 wet - = dryMix
;; Process Left and Right channels through separate parallel comb filter banks.
combDelaysL @ \d [ inL d maxDelay decayTime lpfreq lpcombc ] ! +/ = summedCombsL
combDelaysR @ \d [ inR d maxDelay decayTime lpfreq lpcombc ] ! +/ = summedCombsR
;; Process each channel through its own series of all-pass diffusers.
summedCombsL
apDelaysL 0 at maxDelay 0.5 alpasl
apDelaysL 1 at maxDelay 0.5 alpasl
apDelaysL 2 at maxDelay 0.5 alpasl
apDelaysL 3 at maxDelay 0.5 alpasl
= wetSignalL
summedCombsR
apDelaysR 0 at maxDelay 0.5 alpasl
apDelaysR 1 at maxDelay 0.5 alpasl
apDelaysR 2 at maxDelay 0.5 alpasl
apDelaysR 3 at maxDelay 0.5 alpasl
= wetSignalR
;; Final stereo output.
inL dryMix * wetSignalL wet * + = outL
inR dryMix * wetSignalR wet * + = outR
[outL outR]
] = freeverbs