home/ atoms/ sonic-pi-with-fx

with_fx wraps code in an audio effect that processes all sounds generated inside the block

with_fx :name do … end routes the audio of all play, sample, and synth calls inside the block through the named FX. Multiple FX can be chained by nesting blocks; audio flows outward from innermost to outermost. FX support opts for customisation (e.g., phase: for echo speed). Placing the loop inside a single with_fx block is far more CPU-efficient than wrapping a new FX around each iteration — the former creates one FX instance, the latter creates one per iteration.

Examples

with_fx :reverb do with_fx :echo, phase: 0.5 do play 50 sleep 0.5 play 62 end end

Assessment

Write a live_loop where the loop is inside with_fx :reverb. Rewrite it as with_fx inside the loop and explain the CPU cost difference.

“We put our loop _inside_ the `with_fx` block. This way we only create a single reverb for all notes played in our loop”
corpus · sonic-pi-built-in-tutorial · chunk 16