Let me know if this is what you’re going for. See the code below (sorry, I Ted-ified a few spots!). I’m guessing that you want each of the frames in all of these buffers to end up as a datapoint in your FluidDataSet
?
Notice that when you add a label to the localLabelSet ( localLabelSet.addLabel(count, identifier);
) the identifier
in the label set is actually the frame index and the “label
” is the identifier that you want to end up in the FluidDataSet.
When FluidDataSet.fromBuffer
uses the FluidLabelSet
it looks at the FluidLabelSet
identifiers as buffer indices and assigned the label from the FluidLabelSet
to that buffer index when it gets added.
Let me know if you have any questions!
Cheers,
T
(
~labels = [
"BodyHits",
"BowingOnBody",
"ColLegnoArco",
"ColLegnoBounces",
"ColLegnoOnG",
"FrictionSeparated",
"HarmOnBridgeBb",
"PizzBehindBridge",
"PizzGliss",
"PizzOnA",
"PizzOnD",
"PizzOnG",
"PizzOnE",
"ScratchySeparated",
"TailPieceLowerSeparated",
"TailPieceOnStringsSeparated",
"TrillD-Eb-Separated", // there's a typo in the folder, the sub folder only has one "l"
"TrillA-Bb-Separated",
"TrillG-Ab-Separated",
"TrillE-F-Separated"];
// store buffers in a dictionary
~allAudioBuffers = Dictionary.new();
// may need a little more buffers
s.options.numBuffers_(16384);
s.boot;
)
// 1. Run this code and choose "ViolinSoundsSegmented" folder
(
~loadAudioToBuffers = {
FileDialog.new( okFunc: { arg pathArray;
var path;
path = pathArray.at(0);
path.postln;
Buffer.freeAll;
~labels.do({
arg label;
// read audio file into audio buffer
~allAudioBuffers.put(
label, (path +/+ label +/+ "*").pathMatch.collect({
|file| Buffer.read(s, file);
}));
});
},fileMode: 0);
};
~loadAudioToBuffers.value;
)
// 2. Analyze sounds and store the descriptors in a dataset
(
// create empty buffers for each audio file
~allFeatureBuffers = Dictionary.new();
~allAudioBuffers.keysValuesDo({
arg label, arrayOfBuffers;
// create an empty array for this label
~allFeatureBuffers.put(label, []);
// append empty buffers
arrayOfBuffers.do({
arg buf, idx;
~allFeatureBuffers[label] = ~allFeatureBuffers[label].add(Buffer.new(s));
});
});
)
// peek at feature buffers for PizzOnD
~allAudioBuffers["PizzOnD"];
~allFeatureBuffers["PizzOnD"];
(
// fill feature buffers with MFCCs!
Routine({
~allAudioBuffers.keysValuesDo({
arg label, arrayOfBuffers;
arrayOfBuffers.do({
arg audioBuf, bufIdx;
var featureBuf;
t = Main.elapsedTime;
featureBuf = ~allFeatureBuffers[label].at(bufIdx);
FluidBufMFCC.process(
s,
audioBuf,
windowSize: 2048,
hopSize: 2048,
numCoeffs: 13,
startCoeff: 1,
features: featureBuf,
).wait;
(Main.elapsedTime - t).postln;
});
})
}).play;
)
~allAudioBuffers.size
~allFeatureBuffers["PizzOnD"].size
// look at the feature buffers now that they have been filled
~allFeatureBuffers["PizzOnD"][0].numFrames // these are the timesteps
~allFeatureBuffers["PizzOnD"][0].numChannels // these are the features (each channel is one MFCC), e.g. numCoeffs
// what should we have here:
(
~allFeatureBuffers.keysValuesDo{
arg k, v;
var nframes = v.collect{arg buf; buf.numFrames}.sum;
// k.postln;
// v.postln;
"%\t\t\t\t\ttotal n frames: %".format(k,nframes).postln;
};
"\ntotal frames that should end up in the dataset: ".post;
~allFeatureBuffers.collect{
arg bufarr;
bufarr.collect{arg buf; buf.numFrames}.sum;
}.sum.postln;
)
// fill up the dataset!
(
~dummyBuffer = Buffer.alloc(s, 13, 1);
~dummyBuffer.loadCollection(Array.fill(13, { rrand(0,1) }));
~dataset = FluidDataSet.new(s);
~dataset.addPoint(\dummy, ~dummyBuffer);
~dataset2 = FluidDataSet.new(s);
Routine({
~allFeatureBuffers.keysValuesDo({
arg label, arrayOfBuffers;
arrayOfBuffers.do({
arg buffer, bufIdx;
var localLabelSet;
// buffer.postln;
// make one label for each datapoint
localLabelSet = FluidLabelSet(s);
buffer.numFrames.do({
arg count;
// a unique identifier for this datapoint
var identifier = "%_buf-%_frame-%".format(label,bufIdx,count);
// "identifier: %".format(identifier).postln;
localLabelSet.addLabel(count, identifier); // if label is unique the dataset ends up being complete
});
// localLabelSet.print;
~dataset2.fromBuffer(buffer,0,localLabelSet);
~dataset.merge(~dataset2, 0);
// localLabelSet.free;
});
});
~dataset.deletePoint(\dummy);
"data set made".postln;
~dataset.print;
}).play;
)