FluidStasndardize example update

nix
Gerard 6 years ago
parent ac3a524ffd
commit 64e3fc49b7

@ -37,6 +37,8 @@ METHOD:: fitTransform
Standardize a link::Classes/FluidDataSet:: into another link::Classes/FluidDataSet:: Standardize a link::Classes/FluidDataSet:: into another link::Classes/FluidDataSet::
ARGUMENT:: sourceDataset ARGUMENT:: sourceDataset
The link::Classes/FluidDataSet:: to standardize The link::Classes/FluidDataSet:: to standardize
ARGUMENT:: destDataset
The link::Classes/FluidDataSet:: to populate with standardized data
ARGUMENT:: action ARGUMENT:: action
A function to run when processing is complete A function to run when processing is complete
@ -60,64 +62,57 @@ s.boot;
~stand = FluidDataSet(s,\stand_help_standd); ~stand = FluidDataSet(s,\stand_help_standd);
~audio = Buffer.read(s,~audiofile); ~audio = Buffer.read(s,~audiofile);
~pitch_feature = Buffer.new(s); ~pitch_feature = Buffer.new(s);
~stats = Buffer.new(s); ~stats = Buffer.alloc(s, 7, 2);
~datapoint = Buffer.alloc(s,2);
~standardizer = FluidStandardize(s); ~standardizer = FluidStandardize(s);
) )
// Do a pitch analysis on the audio, which gives us pitch and pitch confidence (so a 2D datum)
// Load audio and run a pitch analysis, which gives us pitch and pitch confidence (so a 2D datum)
(
~audio = Buffer.read(s,~audiofile);
FluidBufPitch.process(s,~audio, features: ~pitch_feature);
)
// Divide the time series in to 10, and take the mean of each segment and add this as a point to // Divide the time series in to 10, and take the mean of each segment and add this as a point to
// the 'raw' FluidDataSet // the 'raw' FluidDataSet
( (
~raw.clear; {
~stand.clear; var trig = LocalIn.kr(1, 1);
FluidBufPitch.process(s,~audio,features:~pitch_feature,action:{ var buf = LocalBuf(2, 1);
"Pitch analysis.complete. Doing stats".postln; var count = PulseCount.kr(trig) - 1;
fork{
var chunkLen = (~pitch_feature.numFrames / 10).asInteger; var chunkLen = (~pitch_feature.numFrames / 10).asInteger;
10.do{ |i| var stats = FluidBufStats.kr(
s.sync; FluidBufStats.process(s,~pitch_feature,startFrame:i*chunkLen,numFrames:chunkLen,stats:~stats, action:{ source: ~pitch_feature, startFrame: count * chunkLen,
~stats.loadToFloatArray(action:{ |statsdata| numFrames: chunkLen, stats: ~stats, trig: trig
[statsdata[0],statsdata[1]].postln; );
~datapoint.setn(0,[statsdata[0],statsdata[1]]); var rd = BufRd.kr(2, ~stats, DC.kr(0), 0, 1);// pick only mean pitch and confidence
s.sync; var wr1 = BufWr.kr(rd[0], buf, DC.kr(0));
("Adding point" ++ i).postln; var wr2 = BufWr.kr(rd[1], buf, DC.kr(1));
~raw.addPoint(i,~datapoint); var dsWr = FluidDataSetWr.kr(\stand_help_raw, buf: buf, trig: Done.kr(stats));
}) LocalOut.kr( Done.kr(dsWr));
}); FreeSelf.kr(count - 9);
if(i == 9) {"Analysis done, dataset ready".postln} }.play;
}
}
});
) )
//Fit the FluidStandardizer to the raw data, and then apply the scaling out of place into
//our second FluidDataSet, so we can compare. // Standardize and load to language-side array
//Download the dataset contents into arrays for plotting
( (
~standardizer.fit(~raw);
~standardizer.transform(~raw,~stand);
~rawarray = Array.new(10); ~rawarray = Array.new(10);
~stdarray= Array.new(10); ~stdarray= Array.new(10);
fork{ ~standardizer.fitTransform(~raw,~stand, {
10.do{|i| ~raw.dump{|x| 10.do{|i|
~raw.getPoint(i,~datapoint,{ ~rawarray.add(x["data"][i.asString])
~datapoint.loadToFloatArray(action:{|a| ~rawarray.add(Array.newFrom(a))}) }};
}); ~stand.dump{|x| 10.do{|i|
s.sync; ~stdarray.add(x["data"][i.asString])
~stand.getPoint(i,~datapoint,{ }};
~datapoint.loadToFloatArray(action:{|a| ~stdarray.add(Array.newFrom(a))})
}); });
s.sync;
if(i==9){"Data downloaded".postln};
}
}
) )
//Plot side by side. Before standardization the two dimensions have radically different scales
//which can be unhelpful in many cases. Now they are zero-centered, and comparable
( (
~rawarray.flatten(1).unlace.plot("Unstandardized",Rect(0,0,400,400),minval:0,maxval:[5000,1]).plotMode=\bars; ~rawarray.flatten(1).unlace.plot("Unstandardized",Rect(0,0,400,400),minval:0,maxval:[5000,1]).plotMode=\bars;
~plot2 = ~stdarray.flatten(1).unlace.plot("Standardized",Rect(410,0,400,400)).plotMode=\bars; ~plot2 = ~stdarray.flatten(1).unlace.plot("Standardized",Rect(410,0,400,400)).plotMode=\bars;
) )
:: ::

Loading…
Cancel
Save