SNEX - reading external files
-
What is the best way to get a text file into SNEX?
I have a BIG dataset that I need to feed into a snex node for some physical modelling.
50 x 50 array (there are 50 chunks of data, and each one of those chunks contains 50 numbers).My first guess is maybe external data?
I thought it was worth making a post just in case there is a better way!
I really don't want to have to punch it in like thisThank you
-
@griffinboy From interface you could create an array of audio buffers that contain the data, so in the end it's a matrix of NxN
From this I write a real audioFile, but I think it should stay internal to get passed to the externalData object of a SNEX node, I just don't know how...
So I think the procedure is to take the reference of an audioFile slot from the SNEX node into the interface script, xrite the array of buffers into it, then read it from the SNEX ExternalData. But all my attempts failed...
There's a externalData example in the Snippet Browser you could check.
const var ScriptFX1 = Synth.getAudioSampleProcessor("Script FX1"); const var dataSetFile = FileSystem.getFolder(FileSystem.Downloads).getChildFile("dataSet.txt"); const var dataSetAudioFile = FileSystem.getFolder(FileSystem.Downloads).getChildFile("dataSet.wav"); // Maybe a lead to what should be done next to pass to the externalData? //const var refAudioFile = Engine.createAndRegisterAudioFile(0); //const var audioFile = ScriptFX1.getAudioFile(0); // the array of buffers that'll hold the data reg dataAsBufferArray = importDataFile(dataSetFile); inline function importDataFile(df) { if (!df.isFile()) return {}; local asText = df.loadAsString(); local buffer = Buffer.create(); local temp = asText.split("\n"); // split each line for (line in temp) line = line.split("\t"); // if TAB has been used, otherwise -> split(" ") for spaces local arrayOfBuffers = []; // now we have all strings in a 2D array, we need to parse them for (i=0; i<temp.length; i++) { local newBuffer = Buffer.create(temp.length); for (j=0; j<temp[i].length; j++) newBuffer[j] = parseFloat(temp[i][j]); arrayOfBuffers.push(newBuffer); } // here I write to a real file but I think it should stay internal...; // ... just couldn't get it to work with the externalData thing so I choose a real file in the waiting dataSetAudioFile.writeAudioFile(arrayOfBuffers, 44100.0, 16); return arrayOfBuffers; }
If your matrix is always square (50x50) you can also simply write only one buffer as opposed to an array. This might be easier to handle later in the externalData SNEX object. But if you are at this point, it's already looking good!
ExternalData data; void setExternalData(const ExternalData& ed, int index) { data = ed; ed.referBlockTo(sample[0], 0); }
-
@ustk
mmm.
Really interesting thank you.I'll try this method out!
I could always format the data and paste it directly into a snex array
But I'm trying not to do that becuase that would box me in a bit. I'd have to edit the data instead of just editing the text file.I might make a feature request for an easier way.
Most people probably don't care about this functionality, but it's very useful for physical modelling / analog emulation. -
@griffinboy Well, I care about this too
This is definitely doable already, it is just a matter of taking the right path...
I don't think SNEX is made for direct communication with the outside world anyway, so to me ExternalData is the way, until the master of the castle pops in at least... @Christoph-Hart ?