I am trying to write audio files (.aif) from an msp external i am working on.
A file is written successfully, however, it does not open
in QT for example (stating end-of-file not found).
I am wondering where I am going wrong. Do I not have to write .aiff header information before writing my data or is this
handled by the sys API since I specify my file type as being ‘AIFF’.
Here is a snippet of my code:
// create file name to save .aif file as
char fileName = "doormouse";
short path = defvolume();
long type = ‘AIFF’;
long fileSizeBytes = sizeof(float) * wsf->tableSize;
// First: Create File
err = path_createsysfile(fileName, path, type, &fh);
fh = 0;
error("writesf~: error %d creating file", err);
// Second: Write File
err = sysfile_write(fh, &wsf->tableSize, wsf->table);
error("writesf~: error %d writing file", err);
// Third: Close File
sysfile_seteof(fh, fileSizeBytes); // state end-of-file
post("writesf~: wrote file %s sucessfully", fileName);
I’m pretty sure that creating the file as AIFF just tells the OS that the file should be treated as an AIFF file (regardless of whether the data is valid). Looking at your code you’ll have a RAW 32-bit floating point audio file.
You need to write the data into the file according to the AIFF spec. So yes you’d need to write header data and audio data as AIFF "chunks". You’d probably need to convert the floating point format to 8, 16, 24 or 32 bit signed ints too, I’m fairly sure AIFF doesn’t support float.
I found this which might be helpful:
Yah, Bourke’s AIFF tutorial is ver helpful.
I will relook at my code and try and write header data.
Thanks for the info.