Forums > Dev

sysfile_write: .aiff

April 30, 2006 | 3:53 am

Hello all,

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[256] = "doormouse";
short path = defvolume();
long type = ‘AIFF’;
t_filehandle fh;
long fileSizeBytes = sizeof(float) * wsf->tableSize;
short err;

// First: Create File
err = path_createsysfile(fileName, path, type, &fh);
if(err) {
fh = 0;
error("writesf~: error %d creating file", err);
return;
}

// Second: Write File
err = sysfile_write(fh, &wsf->tableSize, wsf->table);
if(err) {
error("writesf~: error %d writing file", err);
return;
}

// Third: Close File
sysfile_seteof(fh, fileSizeBytes); // state end-of-file
sysfile_close(fh);
post("writesf~: wrote file %s sucessfully", fileName);

Thanks,


April 30, 2006 | 7:41 am

Hello,

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:

http://astronomy.swin.edu.au/~pbourke/dataformats/aiff/

Regards,
M


May 1, 2006 | 2:42 am

Hey Martin,

Yah, Bourke’s AIFF tutorial is ver helpful.

I will relook at my code and try and write header data.

Thanks for the info.


Viewing 3 posts - 1 through 3 (of 3 total)