I’ve studied the WavWriter class but I can’t get anything working to simply make a copy of a wav file on the SD card to the SD card. The SD card works for writing wave files to it and I’ve even got them being loaded from the SD card to SDRAM. Theoretically I think the Copy() function would open the source wav file and the destination and then read a chunk from the source to then write to the destination until the full file was written. Like this which I adapted from an ostensibly working source:
FRESULT CopyFile(const char* src, const char* dst) {
FIL srcFile, dstFile;
FRESULT res;
UINT br, bw;
BYTE buffer[512];
res = f_open(&srcFile, src, FA_READ);
if(res != FR_OK) {
return res;
}
res = f_open(&dstFile, dst, FA_WRITE | FA_CREATE_ALWAYS);
if(res != FR_OK) {
f_close(&srcFile);
return res;
}
bool ok = true;
for(;;) {
res = f_read(&srcFile, buffer, sizeof(buffer), &br);
if(res != FR_OK) {
ok = false;
break;
}
if(br == 0) break; // EOF
res = f_write(&dstFile, buffer, br, &bw);
if(res != FR_OK || bw < br) {
ok = false;
break;
}
}
ok &= (f_size(&srcFile) == f_size(&dstFile));
f_close(&srcFile);
f_close(&dstFile);
return ok ? FR_OK : FR_DISK_ERR;
}
But I’m getting an error when I try to read. The program halts for about 8 seconds and I’m left with an empty wav file where the copy should be. I’m wondering if having a loop without the sanctimonious streaming per main loop update in WavWriter is too much for this function i.e. a blocking loop. But I’m just sort of in the weeds, out of my league, and maybe someone else has a better idea or actually has a working wav copying function.