I want to write audio data to stdout, preferably using libsndfile. When I output WAV to /dev/stdout I manage to write the header, but then I get an error
Error : could not open file : /dev/stdout
System error : Illegal seek.
I assume this is related to http://www.mega-nerd.com/libsndfile/FAQ.html#Q017, some file formats cannot be written without seeks. However, when I try to output SF_FORMAT_AU | SF_FORMAT_PCM_16 instead, I still get the same Illegal seek error.
Are there any audio file formats that can be written completely without seeking?
I’m using Linux.
EDIT: It might be obvious, but RAW format works (without seeking). Unfortunately I need a format that has meta information like sample rate.
You should finish reading that FAQ… the link you give us has all the answers.
So use AU instead of WAV.
Also make sure that you open the SNDFILE object with
sf_open_fd, and notsf_open_virtual(orsf_open):If you use
sf_open_fd, then libsndfile will usefstatto determine whether the file descriptor is a pipe or a regular file. If you usesf_open_virtualorsf_open, it will assume that the file is seekable. This appears to be a flaw in libsndfile, but you should be usingsf_open_fdanyway.Footnote: Don’t open
/dev/stdoutto get standard output; it is already open and there is no need to open it again. Use file descriptorSTDOUT_FILENO.