I am trying to find an uncompressed audio file format that I can use to continuously record audio to (efficiently).
The audio file formats that I have come across so far require info to be continuously updated in the files header (header chunk), as the data is written to the file.
I am looking for an audio file format that allows me to just write basic audio format info to the header (ie: bits per sample, number of audio channels, etc…), and then just coontinuously append the sample data to the end of the file (without having to go back and update the header).
Having the disk file system continuously fo back to the start of the file to update the header causes serious perfomance issues.
The normal way a file (be it a txt, wav, aiff or whatever) is created and written to in a modern OS (Mac, Windows, Linux etc) is something like this:
A file header is created by the app (your DAW e.g) Bit depth, number of channels etc is written to the header. File length is set zero. The head is written to disk. The stream of the recorded performance is then continuosly written to a buffer (some kBytes or even Mbytes big) created by the app.
When filled enough the app writes this to the disk. Or rather, it’s handed over to the OS to save it to disk when it has nothing better to do. Then it’s handed over to the disk, where it’s stored in it’s cache memory (could be up to a GB big). When the disk has nothing better to do… it writes the bytes to the physical disk (if it’s a hard one) or to some free memory cells if its a ssd to be permanently saved. This is repeated during the length of the recording.
Back to your daw. When done recording (by pressing stop or whatever), the number of bytes saved so far is written to the file length variable of the file head, possibly together with some other items that might be nice to store in the head. The updated file head is then finally written to the disk.
So these “serious perfomance issues” just doesn’t exists…
That is not what’s happening with the wav file i/o library that I am currently using. It is updating the header on every block write operation.
I am open to using some different wav file output code, but I need something that is very lightweight, that is also written cross-platform, so it can compile on many different cpus/os.
Since audio is very low bandwidth, and because of what oxxyyd explained, I wouldn’t worry too much. It gets interesting if you want to record a very (VERY) high number of tracks at the same time, or if you want it to be robust if the computer crashes. In case of a crash, e.g. due to sudden power loss, you loose whatever is still stuck in the various super large caches, and you may end up with file system corruption too. So, what’s the use case?
You can simply come up with your own, dump the raw sample stream to disk with a few lines of basic C++ file i/o. Any audio software that is able to load raw files will work for opening it afterwards, as long as you remember the data type you used.
I’ve been using JUCE’s AudioFormatWriter / FileOutputStream to output 32-bit floats to .wav from processBlock. So it’s lossless or at least very close.