dataset example now with a language side flattener to gain 25x speed

nix
Pierre Alexandre Tremblay 6 years ago
parent 9f7b2ba865
commit f8fe8be9a1

@ -12,13 +12,13 @@ s.reboot;
if(s.hasBooted.not){"Warning: server not running".postln}; if(s.hasBooted.not){"Warning: server not running".postln};
//STEP 1: Get some files //STEP 1: Get some files
(
Buffer.freeAll; Buffer.freeAll;
(
FileDialog.new(fileMode:2,okFunc:{|x| ~path = x[0]; FileDialog.new(fileMode:2,okFunc:{|x| ~path = x[0];
~audioBuffers = SoundFile.collectIntoBuffers(~path+/+'*',s); ~audioBuffers = SoundFile.collectIntoBuffers(~path+/+'*',s);
~lookup = Dictionary(n:~audioBuffers.size); ~lookup = Dictionary(n:~audioBuffers.size);
~audioBuffers.do{|b| ~lookup.add(b.path->b)}; ~audioBuffers.do{|b| ~lookup.add(b.path->b)};
}); });
) )
//STEP 2: Make a FluidDataSet //STEP 2: Make a FluidDataSet
@ -27,29 +27,61 @@ FileDialog.new(fileMode:2,okFunc:{|x| ~path = x[0];
//STEP 3A: EITHER populate the dataset like so (and cry about how long the data point assembly takes) //STEP 3A: EITHER populate the dataset like so (and cry about how long the data point assembly takes)
( (
Routine{ Routine{
~audioBuffers.do{|b| var tmpMFCCs = Buffer.new(s);
var tmpMFCCs = Buffer.new(s); var tmpStats = Buffer.new(s);
var tmpStats = Buffer.new(s); var tmpFlat = Buffer.alloc(s,12 * 4 * 2, 1);
var tmpFlat = Buffer.new(s,12 * 4 * 2, 1); s.sync;
s.sync; ~audioBuffers.do{|b|
("Analyzing" + b.path).postln; ("Analyzing" + b.path).postln;
FluidBufMFCC.process(s,b,features: tmpMFCCs); FluidBufMFCC.process(s,b,features: tmpMFCCs);
FluidBufStats.process(s,source:tmpMFCCs, stats: tmpStats,numDerivs:1); FluidBufStats.process(s,source:tmpMFCCs, stats: tmpStats,numDerivs:1);
"stats".postln; "stats".postln;
12.do{|i| 12.do{|i|
//This takes ages becayse of server syncing :-( //This takes ages becayse of server syncing :-(
FluidBufCompose.process(s,tmpStats,0,2, i+1,1, destination: tmpFlat, destStartFrame: (i*8)); FluidBufCompose.process(s,tmpStats,0,2, i+1,1, destination: tmpFlat, destStartFrame: (i*8));
FluidBufCompose.process(s,tmpStats,4,1, i+1,1, destination: tmpFlat, destStartFrame: (i*8) + 2); FluidBufCompose.process(s,tmpStats,4,1, i+1,1, destination: tmpFlat, destStartFrame: (i*8) + 2);
FluidBufCompose.process(s,tmpStats,6,1, i+1,1, destination:tmpFlat, destStartFrame: (i*8) + 3); FluidBufCompose.process(s,tmpStats,6,3, i+1,1, destination:tmpFlat, destStartFrame: (i*8) + 3);
FluidBufCompose.process(s,tmpStats,0,2, i+1,1, destination: tmpFlat, destStartFrame: (i*8) + 4); FluidBufCompose.process(s,tmpStats,11,1, i+1,1, destination: tmpFlat, destStartFrame: (i*8) + 6);
FluidBufCompose.process(s,tmpStats,4,1, i+1,1, destination: tmpFlat, destStartFrame: (i*8) + 6); FluidBufCompose.process(s,tmpStats,13,1, i+1,1, destination:tmpFlat, destStartFrame: (i*8) + 7);
FluidBufCompose.process(s,tmpStats,6,1, i+1,1, destination:tmpFlat, destStartFrame: (i*8) + 7); };
}; ~dataset.addPoint(b.path,tmpFlat);
~dataset.addPoint(b.path,tmpFlat); };
tmpFlat.free; s.sync;
tmpStats.free; "Done".postln;
tmpMFCCs.free; tmpFlat.free;
}; tmpStats.free;
tmpMFCCs.free;
}.play
)
//STEP 3B: OR populate the dataset with the flattening happening in langage side (much faster for now)
(
Routine{
var tmpMFCCs = Buffer.new(s);
var tmpStats = Buffer.new(s);
var langStats;
var langFlat;
var tmpFlat = Buffer.alloc(s,12 * 4 * 2, 1);
s.sync;
~audioBuffers.do{|b|
("Analyzing" + b.path).postln;
FluidBufMFCC.process(s,b,features: tmpMFCCs);
FluidBufStats.process(s,source:tmpMFCCs, stats: tmpStats,numDerivs:1);
tmpStats.getn(0,182,{|y| langStats = y;});
s.sync;
"stats".postln;
langFlat = Array.new();
//taking the mean, std, min and max, and the mean, std, min and max of the first derivative, of each MFCCs except coeff 0 to dismiss amplitude)
[0,1,4,6,7,8,11,13].do({|i| var j,k; j =((i*13)+1); k = j + 11;langFlat = langFlat ++ langStats[j..k]});
tmpFlat.setn(0,langFlat);
s.sync;
~dataset.addPoint(b.path,tmpFlat);
};
s.sync;
"Done".postln;
tmpStats.free;
tmpMFCCs.free;
tmpFlat.free;
}.play }.play
) )
@ -68,7 +100,7 @@ FileDialog.new(fileMode: 0, acceptMode: 1, okFunc:{|x| var file = x[0];
}); });
) )
//STEP 3B: OR load in one you rolled earlier //STEP 3C: OR load in one you rolled earlier
FileDialog.new(fileMode: 0, acceptMode: 0, okFunc:{|x| ~dataset.read(x[0])}); FileDialog.new(fileMode: 0, acceptMode: 0, okFunc:{|x| ~dataset.read(x[0])});
//peek //peek
@ -79,6 +111,7 @@ c = Buffer.new(s)
//FluidKDTree //FluidKDTree
~kdtree = FluidKDTree.new(s) ~kdtree = FluidKDTree.new(s)
~kdtree.fit(~dataset,action:{"fit".postln}) ~kdtree.fit(~dataset,action:{"fit".postln})
//match //match
~kdtree.kNearest(c,5,{|x| ~matches = x;}) ~kdtree.kNearest(c,5,{|x| ~matches = x;})
~kdtree.kNearestDist(c,5,{|x| x.postln}) ~kdtree.kNearestDist(c,5,{|x| x.postln})
@ -94,13 +127,13 @@ c = Buffer.new(s)
~kMeans.predict(~dataset,~labels, {|x| x.postln}) ~kMeans.predict(~dataset,~labels, {|x| x.postln})
~labels.getLabel(~audioBuffers[2].path,action:{|c| c.postln}) ~labels.getLabel(~audioBuffers[2].path,action:{|c| c.postln})
Routine{ Routine{
~labels.size({|x|x.do {|i| ~labels.size({|x|x.do {|i|
forkIfNeeded{ forkIfNeeded{
~audioBuffers[i].path.postln; ~audioBuffers[i].path.postln;
~labels.getLabel(~audioBuffers[i].path,action:{|c| c.postln}); ~labels.getLabel(~audioBuffers[i].path,action:{|c| c.postln});
s.sync; s.sync;
} }
} }
}); });
}.play }.play
~labels.write(~path+/+"labels.json") ~labels.write(~path+/+"labels.json")
Loading…
Cancel
Save