Plot a function faster?

Well, and plot is actually not designed for a visualisation of 120 seconds. The artifacts won’t give you something meaningful. However, if you have the data in the language you can inspect parts.
Therefore we can build in an action function into the fast plot, it would pass the array, then you can plot parts. Moreover you can inspect the audio file in the SC recordings directory with an external editor.

/ helper synthDef to indicate storage of temporary SynthDef of passed function

(
SynthDef(\finishedStore, {
	SendReply.ar(Impulse.ar(0), '/finishedStore');
	Line.ar(dur: 0.001, doneAction: 2);
	Silent.ar
}).store
)


(
~plotNRT = { |function, duration = 1, numChannels = 1, action|
	var soundFile, array;
	var synthDef = function.asSynthDef;
	var dateString = Date.getDate.stamp;
	var renderString = "render_" ++ dateString;
	var soundFileName = Platform.recordingsDir +/+ renderString ++ ".aiff";
	var options = ServerOptions().numOutputBusChannels = numChannels;
	var oscFunc = OSCFunc({ |msg|
		// produces score and renders aiff
		Score.recordNRT(
			[
				[0.0, [\s_new, synthDef.name, 1000, 0, 0]],
				[duration, [\c_set, 0, 0]]
			],
			("~/" ++ renderString ++ ".osc").standardizePath,
			soundFileName,
			options: options,
			duration: duration,
			// after rendering is finished we can plot
			action: {
				soundFile = SoundFile.new;
				soundFile.openRead(soundFileName);
				{
					array = FloatArray.newClear(soundFile.numFrames);
					soundFile.readData(array);
					function.notNil.if { action.(array) };
					array.plot;
					soundFile.close;
				}.defer

			}
		);
	}, '/finishedStore').oneShot;
	// triggers synth finishedStore which triggers OSCFunc
	synthDef.store(completionMsg: [\s_new, \finishedStore, -1]);
}
)


// plot 120 seconds
// audio file stored in SC recordings directory

~plotNRT.({ LFDNoise3.ar(150) }, 120, action: { |x| a = x })

a.size
-> 5292032

a[(400000..420000)].plot
1 Like