lokki
i used this code back in the days to load 16 samples into tables on startup of a heavy program. i can simply adapt this to load only one file.
my preset-table has a format of integers between 0 and 127 (midi messages). can i still get the data from a text file via the getSamples function? or is this only working with wav files? note that i cannot try this right now, since my bela is in my atelier. or is there a similar function to getSamples to read data from a text file. either way, i don't mind what format the preset file will be in since i will only save and recall it from within heavy. so it can also be a pseudo wav file if that is the easiest solution.
char fileName[12];
char tableName[14];
char lengthName[14];
for (int k = 0; k < 16; k++) {
sprintf(fileName, "sample%d.wav", k);
sprintf(tableName, "sample-table%d", k);
sprintf(lengthName, "samplelength%d", k);
int sampleLen = getNumFrames(fileName);
hv_uint32_t tableHash = hv_stringToHash(tableName);
hv_table_setLength(gHeavyContext, tableHash, sampleLen); // resize the table
float * table = hv_table_getBuffer(gHeavyContext, tableHash); // once resized, get a pointer to the array
int channel = 0; // take the first channel of the file
int startFrame = 0; // start from the beginning
int lastFrame = sampleLen; // until the end of the file
getSamples(fileName, table, channel, startFrame, lastFrame);
//optional bonus: send a message to a `[receive myTableLengthReceiver]` in Heavy with the new table length
hv_sendFloatToReceiver(gHeavyContext, hv_stringToHash(lengthName), sampleLen);
}