Q1 : On Linux, sf_open returns weird info about files. Why?
Q2 : In version 0 the SF_INFO struct had a pcmbitwidth field
but version 1 does not. Why?
Q3 : Compiling is really slow on MacOSX. Why?
Q4 : When trying to compile libsndfile on Solaris I get a "bad
substitution" error during linking. What can I do to fix this?
Q5 : Why doesn't libsndfile do interleaving/de-interleaving?
Q6 : What's the best format for storing temporary files?
Q7 : On Linux/Unix/MaxOSX, what's the best way of detecting the
presence of libsndfile?
Q8 : How about adding the ability to write/read sound files to/from
memory buffers?
This simple call to sf_open :
file = sf_open (filename, SFM_READ, &sfinfo) ; printf ("srate : %d\n", sfinfo.samplerate) ; printf ("frames : %d\n", sfinfo.frames) ; printf ("channels : %d\n", sfinfo.channels) ; printf ("format : %d\n", sfinfo.format) ; printf ("sections : %d\n", sfinfo.sections); printf ("seekable : %d\n", sfinfo.seekable) ;
returns this weird info:
srate : 0 frames : 1445760 channels : 44100 format : 2 sections : 65538 seekable : 1
This is only a problem on Linux and other 32 bit OSes (possibly 32 bit Solaris) which require special compiler command line options to allow access to files greater than 2 Gig in size. These instructions should show you a way around this problem.
This was dropped for a number of reasons:
As documented here there is now a well defined behaviour which ensures that no matter what the bit width of the source file, the scaling always does something sensible. This makes it safe to read 8, 16, 24 and 32 bit PCM files using sf_read_short() and always have the optimal behaviour.
When you configure and compile libsndfile, it uses the Bourne shell for a number of tasks (ie configure script and libtool). However, Apple has decided to ship their system with a really crappy Bourne shell.
To fix this I suggest that you install the GNU Bash shell, rename /bin/sh to /bin/sh.old and make a softlink from /bin/sh to the bash shell. Bash is designed to behave as a Bourne shell when is is called as /bin/sh.
When I did this on my iBook running MacOSX, compile times dropped from 13 mintes to 3 minutes.
It seems that the Solaris Bourne shell disagrees with GNU libtool.
To fix this I suggest that you install the GNU Bash shell, rename /bin/sh to /bin/sh.old and make a softlink from /bin/sh to the bash shell. Bash is designed to behave as a Bourne shell when is is called as /bin/sh.
This problem is bigger than it may seem at first.
For a stereo file, it a pretty safe bet that a simple interleaving/de-interleaving could satisfy most users. However, for file with more than 2 channels this is unlikely to be the case. If the user has a 4 channel file and want to play that file on a stereo output sound card they either want the fitst two channels or they want some mixed combination of the 4 channels.
When you add more channels, the combinations grow exponentially and it becomes increasingly difficult to cover even a sensible subset of the possible combinations. On top of that, coding any one style of interleaver/de-interleaver is trivial, while coding one that can cover all combinations is far from trivial. This means that this feature will not be added any time soon.
When you want to store temporary data there are a number of requirements;
The format which best means these requirements is AU, which allows data to be stored in any one of short, int, float and double (among others).
For instance, if an application uses float data internally, it temporary files should use a format of (SF_ENDIAN_CPU | SF_FORMAT_AU | SF_FORMAT_FLOAT) which will store big endian float data in big endian CPUs and little float endian data on little endian CPUs. Reading and writing this format will not require any conversions or byte swapping regardless of the host CPU.
libsndfile uses the pkg-config (man pkg-config) method of registering itself with the host system. The best way of detecting its presence is using something like this in configure.ac (or configure.in):
PKG_CHECK_MODULES(SNDFILE, sndfile >= 1.0.2, ac_cv_sndfile=1, ac_cv_sndfile=0) AC_DEFINE_UNQUOTED([HAVE_SNDFILE],${ac_cv_sndfile}, [Set to 1 if you have libsndfile.]) AC_SUBST(SNDFILE_CFLAGS) AC_SUBST(SNDFILE_LIBS)
This will automatically set the SNDFILE_CFLAGS and SNDFILE_LIBS variables which can be used in Makefile.am like this:
SNDFILE_CFLAGS = @SNDFILE_CFLAGS@ SNDFILE_LIBS = @SNDFILE_LIBS@
If you install libsndfile from source, you will probably need to set the PKG_CONFIG_PATH environment variableas suggested at the end of the libsndfile configure process. For instance on my system I get this:
-=-=-=-=-=-=-=-=-=-= Configuration Complete =-=-=-=-=-=-=-=-=-=- Configuration summary : Version : ..................... 1.0.5 Experimental code : ........... no Tools : Compiler is GCC : ............. yes GCC major version : ........... 2 ** This compiler version allows applications to write ** to static strings within the library. ** Compile with GCC version 3.X to avoid this problem. Installation directories : Library directory : ........... /usr/local/lib Program directory : ........... /usr/local/bin Pkgconfig directory : ......... /usr/local/lib/pkgconfig Compiling some other packages against libsndfile may require the addition of "/usr/local/lib/pkgconfig" to the PKG_CONFIG_PATH environment variable.
I have a had a number of requests like this over the last 18 months. As yet, no-one has been able to justify why this is a good idea and why this cannot be done a different way.
One example of different way is temproary files stored on a temporary file systems (ie tmpfs on both Linux and Solaris). These require not changes to libsndfile, no extra code in libsndfile, achieve exactly what is required and work now.
The libsndfile home page is here :
http://www.zip.com.au/~erikd/libsndfile/.
Version : 1.0.5