// title: Buffer Plotter // author: Dindoléon // description: // This is a setup that allows you to plot a Synth() output, using a buffer. See https://scsynth.org/t/what-is-the-best-way-to-plot-a-synth/5160 . // code: s.boot; ( var bufferSize = s.sampleRate * 1; // Buffer size is fixed. s.sampleRate * seconds makes sense. if( ~plotterIn == nil, { ~plotterIn = Bus.audio( s, 2 ) } ); // Declare a global channel for the plotter input, stereo if( ~plotterBuffer != nil, { ~plotterBuffer.free } ); // Reset the buffer if existant ~plotterBuffer = Buffer.alloc( s, bufferSize, 2 ); // Create our buffer, stereo SynthDef( \toBuffer, { // A simple routing synth | bufNum | var in = In.ar( ~plotterIn, 2 ); // Takes an input RecordBuf.ar( in, bufNum, loop: 0, doneAction: 2 ); // And outputs it in our buffer } ).add; ) ( // Demo Synth SynthDef( \demoSynth, { | out = 0, freq = 220 | var snd = SinOsc.ar( freq!2 ); snd = snd * EnvGen.kr( Env.perc( 0.1, 0.9 ), doneAction: 2 ); Out.ar( out, snd ); } ).add ) ( Synth( \toBuffer, [ \bufNum, ~plotterBuffer ] ); // Trigger the buffer synth Synth( \demoSynth, [ \out, ~plotterIn, \freq, 110 ] ); // Then our favorite synth ) // You will need to wait the bufferSize length before plotting it ! ~plotterBuffer.plot // Finally print the result if( ~plotterBuffer != nil, { ~plotterBuffer.free } ); // Free the buffer if existant