thanks again. hmm again over my head for the moment. have to read up on that singleton pattern. yeah it sounds complex because i am not a programmer really
so i would put all my loading data code and other common stuff into the header file. and create a class where i put in all the static pointers i need and it would only be called once when i create multiple instances? sounds great. phuuh.
i looked at the patch.cpp and i can see all the classes there. so basically something like this should work for my header file?
;class lpc_common{
public:
static uint8_t *lpc_data;
static uint16_t *onset_data;
static uint32_t *word_idx;
static uint8_t wordcount = 0;
void dataInit () {
FIL lpcfile, onsetfile;
uint32_t lpcfile_len, onsetfile_len;
FRESULT err;
UINT bytes_read;
err = f_open(&lpcfile, "0:/lpcdata.sns", FA_READ | FA_OPEN_EXISTING);
if(err != FR_OK) {
LogTextMessage("Unable to open lpcdata, is the file on the sdcard?");
return;
}
lpcfile_len = f_size(&lpcfile);
lpc_data = (uint8_t *)sdram_malloc(lpcfile_len);
// Load lpcdata into sdram
int remaining_bytes = lpcfile_len;
int offset = 0;
while (remaining_bytes > 0) {
if (remaining_bytes > sizeof(fbuff)) {
err = f_read(&lpcfile, fbuff, sizeof(fbuff), &bytes_read);
if (bytes_read == 0)
break;
memcpy((char*)(&lpc_data[0]) + offset,(char *)fbuff,bytes_read);
remaining_bytes -= bytes_read;
offset += bytes_read;
} else {
err = f_read(&lpcfile, fbuff, remaining_bytes, &bytes_read);
memcpy((char*)(&lpc_data[0]) + offset,(char *)fbuff,bytes_read);
remaining_bytes = 0;
}
}
if (err != FR_OK) {
LogTextMessage("Failed reading lpcdata file, aborting...\n");
return;
}
err = f_close(&lpcfile);
if (err != FR_OK) {
LogTextMessage("Failed closing lpcdata file, aborting...\n");
return;
}
//load onsets into sdram
err = f_open(&onsetfile, "0:/onsets.sns", FA_READ | FA_OPEN_EXISTING);
if(err != FR_OK) {
LogTextMessage("Unable to open onsets, is the file on the sdcard?");
return;
}
onsetfile_len = f_size(&onsetfile);
//16bit only needs half the size because f_size reports 8bits(bytes) not 16bit
onset_data = (uint16_t *)sdram_malloc(onsetfile_len/2);
//16bit uses two slots, equals length reported by f_size, since we are writing one byte at a time
remaining_bytes = onsetfile_len;
offset = 0;
while (remaining_bytes > 0) {
if (remaining_bytes > sizeof(fbuff)) {
err = f_read(&onsetfile, fbuff, sizeof(fbuff), &bytes_read);
if (bytes_read == 0)
break;
memcpy((char*)(&onset_data[0]) + offset,(char *)fbuff,bytes_read);
remaining_bytes -= bytes_read;
offset += bytes_read;
} else {
err = f_read(&onsetfile, fbuff, remaining_bytes, &bytes_read);
memcpy((char*)(&onset_data[0]) + offset,(char *)fbuff,bytes_read);
remaining_bytes = 0;
}
}
if (err != FR_OK) {
LogTextMessage("Failed reading onset file, aborting...\n");
return;
}
err = f_close(&onsetfile);
if (err != FR_OK) {
LogTextMessage("Failed closing onset file, aborting...\n");
return;
}
//calculate word indexes from wordlengths and put into sdram
word_idx = (uint32_t*)sdram_malloc(onsetfile_len/2);
int i;
for(i=0;i<sizeof(word_idx);i++){
if (i == 0) word_idx[0] = 0;
else {
word_idx[i] = onset_data[i-1] + word_idx[i - 1];
}
}
wordcount = sizeof(word_idx);
}
}
and i can then access the pointers via lpc_common.lpc_data and the file loading via lpc_comon.dataInit()
?
probably not, but maybe something in that direction?
thanks for your time and support, really appreciated.