From c1be03b8dbc29e2e3c2370603eb98e0f1e128f9c Mon Sep 17 00:00:00 2001 From: Owen Green Date: Fri, 5 Jun 2020 19:01:05 +0100 Subject: [PATCH] Add FluidBufFlatten help --- .../HelpSource/Classes/FluidBufFlatten.schelp | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 release-packaging/HelpSource/Classes/FluidBufFlatten.schelp diff --git a/release-packaging/HelpSource/Classes/FluidBufFlatten.schelp b/release-packaging/HelpSource/Classes/FluidBufFlatten.schelp new file mode 100644 index 0000000..a70f609 --- /dev/null +++ b/release-packaging/HelpSource/Classes/FluidBufFlatten.schelp @@ -0,0 +1,91 @@ +TITLE:: FluidBufFlatten +summary:: Flatten a multichannel buffer on the server +categories:: FluidCorpusManipulation +related:: Classes/Buffer + +DESCRIPTION:: +Flatten a multichannel link::Classes/Buffer:: to a single channel. This can be useful for constructing n-dimensional data points for use with link::Classes/FluidDataSet:: + +The code::axis:: determines how the flattening is arranged. The default value, 1, flattens channel-wise, such that (if we imagine channels are rows, time positions are columns): + +table:: + ## a 1 || a 2 || a 3 + ## b 1 || b 2 || b 3 + ## c 1 || c 2 || c 3 +:: + +becomes + +table:: +## a 1 || b 1 || c 1 || a 2 || b 2 || c 2 || a 3 || b 3 || c 3 +:: + +whereas with code::axis = 0:: we get + +table:: + ## a 1 || a 2 || a 3 || b 1 || b 2 || b 3 || c 1 || c 2 || c 3 +:: + + +CLASSMETHODS:: + +private::new1 + +METHOD:: process, processBlocking + +Run the process on the given sever, and perfrom code::action:: when done + +ARGUMENT:: server +The link::Classes/Server:: on which to run + +ARGUMENT:: source +The link::Classes/Buffer:: to flatten + +ARGUMENT:: destination +The link::Classes/Buffer:: to write the flattened data to + +ARGUMENT:: axis +Whether to group points channel-wise or frame-wise + +ARGUMENT:: action +Runs when processing is complete + +METHOD:: kr +Run as a control rate link::Classes/UGen:: + +ARGUMENT:: source +The link::Classes/Buffer:: to flatten + +ARGUMENT:: destination +The link::Classes/Buffer:: to write the flattened data to + +ARGUMENT:: axis +Whether to group points channel-wise or frame-wise + +ARGUMENT:: trig +Trigger signal to defer / retrigger processing + +EXAMPLES:: + +code:: +//FluidBufPitch is useful to illustrate the effect of this, because the pitch and confidence values are easily distinguishable + +( +~path = File.realpath(FluidLoadFolder.class.filenameSymbol).dirname +/+ "../AudioFiles"; +~randomsoundfile = SoundFile.collect(~path +/+ '*').choose; +b = Buffer.read(s,~randomsoundfile.path,action:{"Sound Loaded".postln}); +~pitchdata = Buffer.new; +~flatdata = Buffer.new; +) + +//Pitch analysis, writes pitches as frequecnies to chan 0, confidences [0-1] to chan 1 +FluidBufPitch.process(s,b,numFrames:512 * 10,numChans:1,features:~pitchdata,action:{"Pitch Analysis Done".postln}); + +// Flatten and print the flat buffer. We expect to see larger numbers (20-2000) interleaved with smaller (0-1) +FluidBufFlatten.process(s,~pitchdata,~flatdata,action:{ + ~flatdata.loadToFloatArray(action:{ |a| + a.postln; + }) +}) + +:: \ No newline at end of file