From 9d7a31e34c6706f278f4372fc61573b7666be394 Mon Sep 17 00:00:00 2001 From: Ted Moore Date: Mon, 30 May 2022 18:13:03 +0100 Subject: [PATCH 1/3] Stats RST and SC code --- doc/Stats.rst | 12 ++++-- example-code/sc/Stats.scd | 78 +++++++++++++++++++++++++++++++++------ 2 files changed, 75 insertions(+), 15 deletions(-) diff --git a/doc/Stats.rst b/doc/Stats.rst index 25869ee..581eeb3 100644 --- a/doc/Stats.rst +++ b/doc/Stats.rst @@ -1,17 +1,21 @@ -:digest: Rolling mean and standard deviation on list inputs +:digest: Rolling mean and standard deviation on control inputs :species: descriptor :sc-categories: Libraries>FluidDecomposition :sc-related: Guides/FluidCorpusManipulationToolkit :see-also: BufStats, Standardize -:description: Computes the rolling mean and sample standard deviation over a given window for multichannel list inputs. +:description: Computes the rolling mean and sample standard deviation over a given window for multichannel control inputs. :discussion: Each element of the list is dealt with in parallel. This is particularly suitable for multidimensional descriptors. -:output: The first outlet gives the [means], the second the [standard deviations], for each element of the original list. + +:output: The the [means] and [standard deviations] for each element of the original. :control size: The size of the history window to use. - + +.. only_in:: sc + + This is the number of previous control rate frames FluidStats will store and use to compute the statistics :message list: diff --git a/example-code/sc/Stats.scd b/example-code/sc/Stats.scd index f9e6ebe..b33856f 100644 --- a/example-code/sc/Stats.scd +++ b/example-code/sc/Stats.scd @@ -1,19 +1,75 @@ - +strong::Indexing into the output:: code:: + +~src = Buffer.read(s,FluidFilesPath("Tremblay-AaS-AcBassGuit-Melo-M.wav")); + ( -~gaussianNoise = { |a,b| - var mag = (-2 * a.abs.log).sqrt; - var f = 2 * pi * b.abs; - [mag * f.cos, mag * f.sin] -} +{ + var sig = PlayBuf.ar(1,~src,BufRateScale.ir(~src),loop:1); + var pitch = FluidPitch.kr(sig); // outputs 2 analyses: frequency and confidence + var stats = FluidStats.kr(pitch,10); + var means = stats[0]; // stats index 0 is an array of the means + var stddevs = stats[1]; // stats index 1 is an array of the stddevs + pitch.poll(label: "pitch analysis "); + stats.poll(label: "stats output "); + means.poll(label: "means "); + stddevs.poll(label:"stddevs "); + 0.poll(label:"-----------------------------------"); + sig; +}.play +) +:: +strong::Smoothing a signal:: +code:: +( +~src = Buffer.read(s,FluidFilesPath("Tremblay-AaS-AcBassGuit-Melo-M.wav")); +~cb = Bus.control(s,2); +) +( { - var src = ~gaussianNoise.value(WhiteNoise.kr,WhiteNoise.kr); - var stats = FluidStats.kr(src,20); - stats[0].poll(label:'means'); - stats[1].poll(label:'standard deviations'); -}.play + var sig = PlayBuf.ar(1,~src,BufRateScale.ir(~src),loop:1); + var pitch = FluidPitch.kr(sig); // outputs 2 analyses: frequency and confidence + var stats = FluidStats.kr(pitch,25); + var means = stats[0]; // stats index 0 is an array of the means + var stddevs = stats[1]; // stats index 1 is an array of the stddevs + Out.kr(~cb,[pitch[1],means[1]]); // write the confidence and the mean (smoothed) confidence to the bus + sig; +}.play; + +~cb.scope(zoom:0); ) + :: +strong::Standard Deviation:: +code:: + +~src = Buffer.read(s,FluidFilesPath("Tremblay-AaS-AcBassGuit-Melo-M.wav")); + +// Standard Deviation might provide some insight into moments of *change* +// because there will be a variety of different values in the history +// window being used to compute it +// (more variety in the data = higher standard deviation) +( +{ + var sig = PlayBuf.ar(1,~src,BufRateScale.ir(~src),loop:1); + var pitch = FluidPitch.kr(sig); // outputs 2 analyses: frequency and confidence + var stats = FluidStats.kr(pitch,25); + var stddevs = stats[1]; // stats index 1 is an array of the stddevs + SendReply.kr(Impulse.kr(30),"/stddevs",stddevs); + sig; +}.play; + +OSCdef(\stddevs,{ + arg msg; + var post = "stddev pitch : "; + {post = post ++ "*"} ! (msg[3] * 2).asInteger; + post = post ++ "\nstddev conf : "; + {post = post ++ "+"} ! (msg[4] * 200).asInteger; + post.postln; + "".postln; +},"/stddevs"); +) +:: \ No newline at end of file From bbca6afc3f63cc9a314554d9fdbd39c7206fdbf3 Mon Sep 17 00:00:00 2001 From: Ted Moore Date: Mon, 30 May 2022 18:57:52 +0100 Subject: [PATCH 2/3] stats rst and sc code --- doc/Stats.rst | 12 +++++++----- example-code/sc/Stats.scd | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/doc/Stats.rst b/doc/Stats.rst index 581eeb3..509157d 100644 --- a/doc/Stats.rst +++ b/doc/Stats.rst @@ -4,7 +4,13 @@ :sc-related: Guides/FluidCorpusManipulationToolkit :see-also: BufStats, Standardize :description: Computes the rolling mean and sample standard deviation over a given window for multichannel control inputs. -:discussion: Each element of the list is dealt with in parallel. This is particularly suitable for multidimensional descriptors. +:discussion: + + Each element of the list is dealt with in parallel. This is particularly suitable for multidimensional descriptors. + + .. only_in:: sc + + The parameter ``size`` is the number of previous control rate frames FluidStats will store and use to compute the statistics :output: The the [means] and [standard deviations] for each element of the original. @@ -13,10 +19,6 @@ The size of the history window to use. -.. only_in:: sc - - This is the number of previous control rate frames FluidStats will store and use to compute the statistics - :message list: The input list to be processed diff --git a/example-code/sc/Stats.scd b/example-code/sc/Stats.scd index b33856f..4680724 100644 --- a/example-code/sc/Stats.scd +++ b/example-code/sc/Stats.scd @@ -72,4 +72,29 @@ OSCdef(\stddevs,{ "".postln; },"/stddevs"); ) +:: +strong::Specifying "size" using seconds:: + +Because the parameter size is specified in control rate frames, one might want to be able to specify in seconds and convert to control rate frames before sending the value to the object. +code:: + +( +~synth = { + arg size_seconds = 1; + var sig = LFDNoise0.kr(20); + + // the number of control frames to store and use for + // statistics = the number of seconds you want / the + // duration of one control cycle + var size = size_seconds / ControlDur.ir; + + var stats = FluidStats.kr(sig,size); + var mean = stats[0][0]; + [sig,mean] +}.scope(zoom:0); +) + +~synth.set(\size_seconds,0.01); +~synth.set(\size_seconds,10); +~synth.set(\size_seconds,1); :: \ No newline at end of file From 2f8daa4b1f99f0feac326587aa89d78b5066b111 Mon Sep 17 00:00:00 2001 From: Ted Moore Date: Tue, 31 May 2022 15:56:31 +0100 Subject: [PATCH 3/3] feedback --- doc/Stats.rst | 2 +- example-code/sc/Stats.scd | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/Stats.rst b/doc/Stats.rst index 509157d..e1cc61e 100644 --- a/doc/Stats.rst +++ b/doc/Stats.rst @@ -12,7 +12,7 @@ The parameter ``size`` is the number of previous control rate frames FluidStats will store and use to compute the statistics -:output: The the [means] and [standard deviations] for each element of the original. +:output: The [means] and [standard deviations] for each element of the original. :control size: diff --git a/example-code/sc/Stats.scd b/example-code/sc/Stats.scd index 4680724..e38b539 100644 --- a/example-code/sc/Stats.scd +++ b/example-code/sc/Stats.scd @@ -72,6 +72,7 @@ OSCdef(\stddevs,{ "".postln; },"/stddevs"); ) + :: strong::Specifying "size" using seconds:: @@ -97,4 +98,5 @@ code:: ~synth.set(\size_seconds,0.01); ~synth.set(\size_seconds,10); ~synth.set(\size_seconds,1); + :: \ No newline at end of file