So I’m trying to cache a dataset to disk as it doesn’t change and I often need to restart the SuperCollider server&interpreter.
Not too sure what the correct approach is, I couldn’t find any documentation,
but essentially I using the toBuffer
method, making a buffer and a label set, writing both to file then reloading them. I’ve tried different file formats, doesn’t seem to make a difference.
This works for small data sets but not for large and I do not know why…
first a small example that shows a working small dataset.
— you will need to set ~pwd
to a directory —
FluidDataSet.version = Fluid Corpus Manipulation Toolkit: version 1.0.0+sha.3fd541f.core.sha.f86443a
Manjaro linux - all built from source.
~initalDataSet = FluidDataSet(s);
b = Buffer.loadCollection(s, [1,0.23], 1)
~initalDataSet.addPoint("first", b)
b.setn(0, [-0.3, 4.4])
~initalDataSet.addPoint("second", b)
~initalDataSet.dump{|d| d["data"].keysValuesDo{|k,v| [k,v].postln}}
//[ second, [ -0.30000001192093, 4.4000000953674 ] ]
//[ first, [ 1.0, 0.23000000417233 ] ]
~toBufB = Buffer(s)
~toBufL = FluidLabelSet(s)
~initalDataSet.toBuffer(~toBufB, 0, ~toBufL)
~fromBufDataSet = FluidDataSet(s)
~fromBufDataSet.fromBuffer(~toBufB, 0, ~toBufL)
~fromBufDataSet.dump{|d| d["data"].keysValuesDo{|k,v| [k,v].postln}}
//[ second, [ -0.30000001192093, 4.4000000953674 ] ]
//[ first, [ 1.0, 0.23000000417233 ] ]
~toBufB.write(~pwd+/+"test/b.wav", headerFormat: "WAV", sampleFormat: "float")
~toBufL.write(~pwd+/+"test/dl.json")
~loadedB = Buffer.read(s, ~pwd+/+"test/b.wav")
~loadedL = FluidLabelSet(s);
~loadedL.read(~pwd+/+"test/dl.json")
~loadedD = FluidDataSet(s);
~loadedD.fromBuffer(~loadedB, 0, ~loadedL)
~loadedD.dump{|d| d["data"].keysValuesDo{|k,v| [k,v].postln}}
//[ second, [ -0.30000001192093, 4.4000000953674 ] ]
//[ first, [ 1.0, 0.23000000417233 ] ]
// woo it works !!!!
Now exactly the same example but with a larger dataset that does not work…
// make large data set
~initalDataSet = FluidDataSet(s);
b = Buffer.loadCollection(s, [1, 0.23], 1)
r = Routine({
1000.do{|n|
b.set(0, {1.0.rand}.());
b.set(1, {1.0.rand}.());
Server.default.sync;
~initalDataSet.addPoint(n.asString, b);
};
"done".postln;
})
r.play
~initalDataSet.dump{|d| d["data"].["504"].postln}
// [ 0.89565253257751, 0.23000000417233 ]
~toBufB = Buffer(s)
~toBufL = FluidLabelSet(s)
~initalDataSet.toBuffer(~toBufB, 0, ~toBufL)
~fromBufDataSet = FluidDataSet(s)
~fromBufDataSet.fromBuffer(~toBufB, 0, ~toBufL)
~fromBufDataSet.dump{|d| d["data"].["504"].postln}
//[ 0.89565253257751, 0.23000000417233 ]
// right so writing to a buffer and reading works fine
~toBufB.write(~pwd+/+"test/b.wav", headerFormat: "WAV", sampleFormat: "float")
~toBufL.write(~pwd+/+"test/dl.json")
~loadedB = Buffer.read(s, ~pwd+/+"test/b.wav")
~loadedL = FluidLabelSet(s);
~loadedL.read(~pwd+/+"test/dl.json")
~loadedD = FluidDataSet(s);
~loadedD.fromBuffer(~loadedB, 0, ~loadedL)
~loadedD.dump{|d| d["data"].["504"].postln}
// [ 0.225949883461, 0.23000000417233 ]
// ehh???!?!?
Any ideas? Or is there a better way to do this?