Blame doc/FAQ.html

Packit 4aff17
Packit 4aff17
<HTML>
Packit 4aff17
Packit 4aff17
<HEAD>
Packit 4aff17
	<TITLE>
Packit 4aff17
	libsndfile : Frequently Asked Questions.
Packit 4aff17
	</TITLE>
Packit 4aff17
	<META NAME="Author"      CONTENT="Erik de Castro Lopo (erikd AT mega-nerd DOT com)">
Packit 4aff17
	<META NAME="Description" CONTENT="The libsndfile FAQ.">
Packit 4aff17
	<META NAME="Keywords"    CONTENT="WAV AIFF AU libsndfile sound audio dsp Linux">
Packit 4aff17
	<LINK REL="stylesheet" HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
Packit 4aff17
	<LINK REL="stylesheet" HREF="print.css" TYPE="text/css" MEDIA="print">
Packit 4aff17
</HEAD>
Packit 4aff17
Packit 4aff17
<BODY>
Packit 4aff17
Packit 4aff17

libsndfile : Frequently Asked Questions.

Packit 4aff17

Packit 4aff17
Q1 : Do you plan to support XYZ codec in libsndfile?
Packit 4aff17
Q2 : In version 0 the SF_INFO struct had a pcmbitwidth field
Packit 4aff17
		but version 1 does not. Why?
Packit 4aff17
Q3 : Compiling is really slow on MacOS X. Why?
Packit 4aff17
Q4 : When trying to compile libsndfile on Solaris I get a "bad
Packit 4aff17
		substitution" error during linking. What can I do to fix this?
Packit 4aff17
Q5 : Why doesn't libsndfile do interleaving/de-interleaving?
Packit 4aff17
Q6 : What's the best format for storing temporary files?
Packit 4aff17
Q7 : On Linux/Unix/MacOS X, what's the best way of detecting the
Packit 4aff17
	presence of libsndfile?
Packit 4aff17
Q8 : I have libsndfile installed and now I want to use it. I
Packit 4aff17
	just want a simple Makefile! What do I do?
Packit 4aff17
Q9 : How about adding the ability to write/read sound files to/from
Packit 4aff17
	memory buffers?
Packit 4aff17
Q10 : Reading a 16 bit PCM file as normalised floats and then
Packit 4aff17
	writing them back changes some sample values. Why?
Packit 4aff17
Q11 : I'm having problems with u-law encoded WAV files generated by
Packit 4aff17
	libsndfile in Winamp. Why?
Packit 4aff17
Q12 : I'm looking at sf_read*. What are items? What are frames?
Packit 4aff17
Q13 : Why can't libsndfile open this Sound Designer II (SD2)
Packit 4aff17
	file?
Packit 4aff17
Q14 : I'd like to statically link libsndfile to my closed source
Packit 4aff17
	application. Can I buy a license so that this is possible?
Packit 4aff17
Q15 : My program is crashing during a call to a function in libsndfile.
Packit 4aff17
	Is this a bug in libsndfile?
Packit 4aff17
Q16 : Will you accept a fix for compiling libsndfile with compiler X?
Packit 4aff17
	
Packit 4aff17
Q17 : Can libsndfile read/write files from/to UNIX pipes?
Packit 4aff17
	
Packit 4aff17
Q18 : Is it possible to build a Universal Binary on Mac OS X?
Packit 4aff17
	
Packit 4aff17
Q19 : I have project files for Visual Studio / XCode / Whatever. Why
Packit 4aff17
	don't you distribute them with libsndfile?
Packit 4aff17
	
Packit 4aff17
Q20 : Why doesn't libsndfile support MP3? Lots of other Open Source
Packit 4aff17
	projects support it!
Packit 4aff17
	
Packit 4aff17
Q21 : How do I use libsndfile in a closed source or commercial program
Packit 4aff17
	and comply with the license?
Packit 4aff17
	
Packit 4aff17
Q22 : What versions of windows does libsndfile work on?
Packit 4aff17
	
Packit 4aff17
Q23 : I'm cross compiling libsndfile for another platform. How can I
Packit 4aff17
	run the test suite?
Packit 4aff17
	
Packit 4aff17

Packit 4aff17
Packit 4aff17
Packit 4aff17
Packit 4aff17


Q1 : Do you plan to support XYZ codec in libsndfile?

Packit 4aff17

Packit 4aff17
If source code for XYZ codec is available under a suitable license (LGPL, BSD,
Packit 4aff17
MIT etc) then yes, I'd like to add it.
Packit 4aff17

Packit 4aff17

Packit 4aff17
If suitable documentation is available on how to decode and encode the format
Packit 4aff17
then maybe, depending on how much work is involved.
Packit 4aff17

Packit 4aff17

Packit 4aff17
If XYZ is some proprietary codec where no source code or documentation is
Packit 4aff17
available then no.
Packit 4aff17

Packit 4aff17

Packit 4aff17
So if you want support for XYZ codec, first find existing source code or
Packit 4aff17
documentation.
Packit 4aff17
If you can't find either then the answer is no.
Packit 4aff17

Packit 4aff17
Packit 4aff17
Packit 4aff17


Q2 : In version 0 the SF_INFO struct had a pcmbitwidth field

Packit 4aff17
		but version 1 does not. Why?
Packit 4aff17

Packit 4aff17
	This was dropped for a number of reasons:
Packit 4aff17

Packit 4aff17
    Packit 4aff17
    	
  • pcmbitwidth makes little sense on compressed or floating point formats
  • Packit 4aff17
    	
  • with the new API you really don't need to know it
  • Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    As documented
    Packit 4aff17
        here
    Packit 4aff17
    there is now a well defined behaviour which ensures that no matter what the
    Packit 4aff17
    bit width of the source file, the scaling always does something sensible.
    Packit 4aff17
    This makes it safe to read 8, 16, 24 and 32 bit PCM files using sf_read_short()
    Packit 4aff17
    and always have the optimal behaviour.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17


    Q3 : Compiling is really slow on MacOS X. Why?

    Packit 4aff17

    Packit 4aff17
    When you configure and compile libsndfile, it uses the /bin/sh shell for a number
    Packit 4aff17
    of tasks (ie configure script and libtool).
    Packit 4aff17
    Older versions of OS X (10.2?) shipped a really crappy Bourne shell as /bin/sh
    Packit 4aff17
    which resulted in really slow compiles.
    Packit 4aff17
    Newer version of OS X ship GNU Bash as /bin/sh and this answer doesn't apply in that
    Packit 4aff17
    case.
    Packit 4aff17

    Packit 4aff17

    Packit 4aff17
    To fix this I suggest that you install the GNU Bash shell, rename /bin/sh to
    Packit 4aff17
    /bin/sh.old and make a symlink from /bin/sh to the bash shell.
    Packit 4aff17
    Bash is designed to behave as a Bourne shell when is is called as /bin/sh.
    Packit 4aff17

    Packit 4aff17

    Packit 4aff17
    When I did this on my iBook running MacOS X, compile times dropped from 13 minutes
    Packit 4aff17
    to 3 minutes.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17


    Q4 : When trying to compile libsndfile on Solaris I get a "bad

    Packit 4aff17
    		substitution" error on linking. Why?
    Packit 4aff17

    Packit 4aff17
    It seems that the Solaris Bourne shell disagrees with GNU libtool.
    Packit 4aff17

    Packit 4aff17

    Packit 4aff17
    To fix this I suggest that you install the GNU Bash shell, rename /bin/sh to
    Packit 4aff17
    /bin/sh.old and make a symlink from /bin/sh to the bash shell.
    Packit 4aff17
    Bash is designed to behave as a Bourne shell when is is called as /bin/sh.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17


    Q5 : Why doesn't libsndfile do interleaving/de-interleaving?

    Packit 4aff17

    Packit 4aff17
    This problem is bigger than it may seem at first.
    Packit 4aff17

    Packit 4aff17

    Packit 4aff17
    For a stereo file, it is a pretty safe bet that a simple interleaving/de-interleaving
    Packit 4aff17
    could satisfy most users.
    Packit 4aff17
    However, for files with more than 2 channels this is unlikely to be the case.
    Packit 4aff17
    If the user has a 4 channel file and want to play that file on a stereo output
    Packit 4aff17
    sound card they either want the first 2 channels or they want some mixed combination
    Packit 4aff17
    of the 4 channels.
    Packit 4aff17

    Packit 4aff17

    Packit 4aff17
    When you add more channels, the combinations grow exponentially and it becomes
    Packit 4aff17
    increasingly difficult to cover even a sensible subset of the possible combinations.
    Packit 4aff17
    On top of that, coding any one style of interleaver/de-interleaver is trivial, while
    Packit 4aff17
    coding one that can cover all combinations is far from trivial.
    Packit 4aff17
    This means that this feature will not be added any time soon.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17


    Q6 : What's the best format for storing temporary files?

    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    When you want to store temporary data there are a number of requirements;
    Packit 4aff17

    Packit 4aff17
      Packit 4aff17
      	
    • A simple, easy to parse header.
    • Packit 4aff17
      	
    • The format must provide the fastest possible read and write rates (ie
    • Packit 4aff17
      		avoid conversions and encoding/decoding).
      Packit 4aff17
      	
    • The file format must be reasonably common and playable by most players.
    • Packit 4aff17
      	
    • Able to store data in either endian-ness.
    • Packit 4aff17
      Packit 4aff17

      Packit 4aff17
      The format which best meets these requirements is AU, which allows data to be
      Packit 4aff17
      stored in any one of short, int, float and double (among others) formats.
      Packit 4aff17

      Packit 4aff17

      Packit 4aff17
      For instance, if an application uses float data internally, its temporary files
      Packit 4aff17
      should use a format of (SF_ENDIAN_CPU | SF_FORMAT_AU | SF_FORMAT_FLOAT) which
      Packit 4aff17
      will store big endian float data in big endian CPUs and little endian float data
      Packit 4aff17
      on little endian CPUs.
      Packit 4aff17
      Reading and writing this format will not require any conversions or byte swapping
      Packit 4aff17
      regardless of the host CPU.
      Packit 4aff17

      Packit 4aff17
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17


      Q7 : On Linux/Unix/MaxOS X, what's the best way of detecting the presence

      Packit 4aff17
      	of libsndfile using autoconf?
      Packit 4aff17
      Packit 4aff17

      Packit 4aff17
      libsndfile uses the pkg-config (man pkg-config) method of registering itself with the
      Packit 4aff17
      host system.
      Packit 4aff17
      The best way of detecting its presence is using something like this in configure.ac
      Packit 4aff17
      (or configure.in):
      Packit 4aff17

      Packit 4aff17
      Packit 4aff17
              PKG_CHECK_MODULES(SNDFILE, sndfile >= 1.0.2, ac_cv_sndfile=1, ac_cv_sndfile=0)
      Packit 4aff17
      Packit 4aff17
              AC_DEFINE_UNQUOTED([HAVE_SNDFILE],${ac_cv_sndfile},
      Packit 4aff17
      			[Set to 1 if you have libsndfile.])
      Packit 4aff17
      Packit 4aff17
              AC_SUBST(SNDFILE_CFLAGS)
      Packit 4aff17
              AC_SUBST(SNDFILE_LIBS)
      Packit 4aff17
      Packit 4aff17

      Packit 4aff17
      This will automatically set the SNDFILE_CFLAGS and SNDFILE_LIBS
      Packit 4aff17
      variables which can be used in Makefile.am like this:
      Packit 4aff17

      Packit 4aff17
      Packit 4aff17
              SNDFILE_CFLAGS = @SNDFILE_CFLAGS@
      Packit 4aff17
              SNDFILE_LIBS = @SNDFILE_LIBS@
      Packit 4aff17
      Packit 4aff17

      Packit 4aff17
      If you install libsndfile from source, you will probably need to set the
      Packit 4aff17
      PKG_CONFIG_PATH environment variable as suggested at the end of the
      Packit 4aff17
      libsndfile configure process. For instance on my system I get this:
      Packit 4aff17

      Packit 4aff17
      Packit 4aff17
              -=-=-=-=-=-=-=-=-=-= Configuration Complete =-=-=-=-=-=-=-=-=-=-
      Packit 4aff17
      Packit 4aff17
                Configuration summary :
      Packit 4aff17
      Packit 4aff17
                  Version : ..................... 1.0.5
      Packit 4aff17
                  Experimental code : ........... no
      Packit 4aff17
      Packit 4aff17
                Tools :
      Packit 4aff17
      Packit 4aff17
                  Compiler is GCC : ............. yes
      Packit 4aff17
                  GCC major version : ........... 3
      Packit 4aff17
      Packit 4aff17
                Installation directories :
      Packit 4aff17
      Packit 4aff17
                  Library directory : ........... /usr/local/lib
      Packit 4aff17
                  Program directory : ........... /usr/local/bin
      Packit 4aff17
                  Pkgconfig directory : ......... /usr/local/lib/pkgconfig
      Packit 4aff17
      Packit 4aff17
              Compiling some other packages against libsndfile may require
      Packit 4aff17
              the addition of "/usr/local/lib/pkgconfig" to the
      Packit 4aff17
              PKG_CONFIG_PATH environment variable.
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17


      Q8 : I have libsndfile installed and now I want to use it. I just want

      Packit 4aff17
      		a simple Makefile! What do I do?
      Packit 4aff17
      Packit 4aff17

      Packit 4aff17
      The pkg-config program makes finding the correct compiler flag values and
      Packit 4aff17
      library location far easier.
      Packit 4aff17
      During the installation of libsndfile, a file named sndfile.pc is installed
      Packit 4aff17
      in the directory ${libdir}/pkgconfig (ie if libsndfile is installed in
      Packit 4aff17
      /usr/local/lib, sndfile.pc will be installed in
      Packit 4aff17
      /usr/local/lib/pkgconfig/).
      Packit 4aff17

      Packit 4aff17

      Packit 4aff17
      In order for pkg-config to find sndfile.pc it may be necessary to point the
      Packit 4aff17
      environment variable PKG_CONFIG_PATH in the right direction.
      Packit 4aff17

      Packit 4aff17
      Packit 4aff17
              export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17

      Packit 4aff17
      Then, to compile a C file into an object file, the command would be:
      Packit 4aff17

      Packit 4aff17
      Packit 4aff17
              gcc `pkg-config --cflags sndfile` -c somefile.c
      Packit 4aff17
      Packit 4aff17

      Packit 4aff17
      and to link a number of objects into an executable that links against libsndfile,
      Packit 4aff17
      the command would be:
      Packit 4aff17

      Packit 4aff17
      Packit 4aff17
              gcc `pkg-config --libs sndfile` obj1.o obj2.o -o program
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17


      Q9 : How about adding the ability to write/read sound files to/from

      Packit 4aff17
      	memory buffers?
      Packit 4aff17
      Packit 4aff17

      Packit 4aff17
      This has been added for version 1.0.13.
      Packit 4aff17

      Packit 4aff17
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17


      Q10 : Reading a 16 bit PCM file as normalised floats and then

      Packit 4aff17
      	writing them back changes some sample values. Why?
      Packit 4aff17
      Packit 4aff17

      Packit 4aff17
      This is caused by the fact that the conversion from 16 bit short to float is
      Packit 4aff17
      done by dividing by 32768 (0x8000 in hexadecimal) while the conversion from
      Packit 4aff17
      float to 16 bit short is done by multiplying by 32767 (0x7FFF in hex).
      Packit 4aff17
      So for instance, a value in a 16 bit PCM file of 20000 gets read as a floating
      Packit 4aff17
      point number of 0.6103515625 (20000.0 / 0x8000).
      Packit 4aff17
      Converting that back to a 16 bit short results in a value of 19999.3896484375
      Packit 4aff17
      (0.6103515625 * 0x7FFF) which then gets rounded down to 19999.
      Packit 4aff17

      Packit 4aff17

      Packit 4aff17
      You will notice that for this particular case, the error is 1 in 20000 or
      Packit 4aff17
      0.005%.
      Packit 4aff17
      Interestingly, for values of less than 16369, dividing by 0x8000 followed
      Packit 4aff17
      by multiplying by 0x7FFF and then rounding the result, gives back the
      Packit 4aff17
      original value.
      Packit 4aff17
      It turns out that as long as the host operating system supplies the 1999 ISO
      Packit 4aff17
      C Standard functions lrintf and lrint (or a replacement has
      Packit 4aff17
      been supplied) then the maximum possible error is 1 in 16369 or about 0.006%.
      Packit 4aff17

      Packit 4aff17

      Packit 4aff17
      Regardless of the size of the error, the reason why this is done is rather
      Packit 4aff17
      subtle.
      Packit 4aff17

      Packit 4aff17

      Packit 4aff17
      In a file containing 16 bit PCM samples, the values are restricted to the range
      Packit 4aff17
      [-32768, 32767] while we want floating point values in the range [-1.0, 1.0].
      Packit 4aff17
      The only way to do this conversion is to do a floating point division by a value
      Packit 4aff17
      of 0x8000.
      Packit 4aff17
      Converting the other way, the only way to ensure that floating point values in
      Packit 4aff17
      the range [-1.0, 1.0] are within the valid range allowed by a 16 bit short is
      Packit 4aff17
      to multiply by 0x7FFF.
      Packit 4aff17

      Packit 4aff17

      Packit 4aff17
      Some people would say that this is a severe short-coming of libsndfile.
      Packit 4aff17
      I would counter that anybody who is constantly converting back and forth
      Packit 4aff17
      between 16 bit shorts and normalised floats is going to suffer other losses
      Packit 4aff17
      in audio quality that they should also be concerned about.
      Packit 4aff17

      Packit 4aff17

      Packit 4aff17
      Since this problem only occurs when converting between integer data on disk and
      Packit 4aff17
      normalized floats in the application, it can be avoided by using something
      Packit 4aff17
      other than normalized floats in the application.
      Packit 4aff17
      Alternatives to normalized floats are the short and int data
      Packit 4aff17
      types (ie using sf_read_short or sf_read_int) or using un-normalized floats
      Packit 4aff17
      (see
      Packit 4aff17
      	
      Packit 4aff17
      	SFC_SET_NORM_FLOAT).
      Packit 4aff17

      Packit 4aff17

      Packit 4aff17
      Another way to deal with this problem is to consider 16 bit short data as a
      Packit 4aff17
      final destination format only, not as an intermediate storage format.
      Packit 4aff17
      All intermediate data (ie which is going to be processed further) should be
      Packit 4aff17
      stored in floating point format which is supported by all of the most common
      Packit 4aff17
      file formats.
      Packit 4aff17
      If floating point files are considered too large (2 times the size of a 16 bit
      Packit 4aff17
      PCM file), it would also be possible to use 24 bit PCM as an intermediate
      Packit 4aff17
      storage format (and which is also supported by most common file types).
      Packit 4aff17

      Packit 4aff17
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17


      Q11 : I'm having problems with u-law encoded WAV files generated by

      Packit 4aff17
      	libsndfile in Winamp. Why?
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17

      Packit 4aff17
      This is actually a Winamp problem.
      Packit 4aff17
      The official Microsoft spec suggests that the 'fmt ' chunk should be 18 bytes.
      Packit 4aff17
      Unfortunately at least one of Microsoft's own applications (Sound Recorder on
      Packit 4aff17
      Win98 I believe) did not accept 18 bytes 'fmt ' chunks.
      Packit 4aff17

      Packit 4aff17

      Packit 4aff17
      Michael Lee did some experimenting and found that:
      Packit 4aff17

      Packit 4aff17
      Packit 4aff17
          I have checked that Windows Media Player 9, QuickTime Player 6.4,
      Packit 4aff17
          RealOne Player 2.0 and GoldWave 5.06 can all play u-law files with
      Packit 4aff17
          16-byte or 18-byte 'fmt ' chunk. Only Winamp (2.91) and foobar2000
      Packit 4aff17
          are unable to play u-law files with 16-byte 'fmt ' chunk.
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17

      Packit 4aff17
      Even this is a very small sampling of all the players out there.
      Packit 4aff17
      For that reason it is probably not a good idea to change this now because there
      Packit 4aff17
      is the risk of breaking something that currently works.
      Packit 4aff17

      Packit 4aff17
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17


      Q12 : I'm looking at sf_read*. What are items? What are frames?

      Packit 4aff17
      Packit 4aff17
      Packit 4aff17

      Packit 4aff17
      An <tt>item</tt> is a single sample of the data type you are reading; ie a
      Packit 4aff17
      single <tt>short</tt> value for <tt>sf_read_short</tt> or a single <tt>float</tt>
      Packit 4aff17
      for <tt>sf_read_float</tt>.
      Packit 4aff17

      Packit 4aff17
      Packit 4aff17

      Packit 4aff17
      For a sound file with only one channel, a frame is the same as a item (ie a
      Packit 4aff17
      single sample) while for multi channel sound files, a single frame contains a
      Packit 4aff17
      single item for each channel.
      Packit 4aff17

      Packit 4aff17
      Packit 4aff17

      Packit 4aff17
      Here are two simple, correct examples, both of which are assumed to be working
      Packit 4aff17
      on a stereo file, first using items:
      Packit 4aff17

      Packit 4aff17
      Packit 4aff17
      Packit 4aff17
              #define CHANNELS 2
      Packit 4aff17
              short data [CHANNELS * 100] ;
      Packit 4aff17
              sf_count items_read = sf_read_short (file, data, 200) ;
      Packit 4aff17
              assert (items_read == 200) ;
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17

      Packit 4aff17
      and now reading the exact same amount of data using frames:
      Packit 4aff17

      Packit 4aff17
      Packit 4aff17
      Packit 4aff17
              #define CHANNELS 2
      Packit 4aff17
              short data [CHANNELS * 100] ;
      Packit 4aff17
              sf_count frames_read = sf_readf_short (file, data, 100) ;
      Packit 4aff17
              assert (frames_read == 100) ;
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17


      Q13 : Why can't libsndfile open this Sound Designer II (SD2) file?

      Packit 4aff17
      Packit 4aff17
      Packit 4aff17

      Packit 4aff17
      This is somewhat complicated.
      Packit 4aff17
      First some background.
      Packit 4aff17

      Packit 4aff17
      Packit 4aff17

      Packit 4aff17
      SD2 files are native to the Apple Macintosh platform and use features of
      Packit 4aff17
      the Mac filesystem (file resource forks) to store the file's sample rate,
      Packit 4aff17
      number of channels, sample width and more.
      Packit 4aff17
      When you look at a file and its resource fork on Mac OS X it looks like
      Packit 4aff17
      this:
      Packit 4aff17

      Packit 4aff17
      Packit 4aff17
      Packit 4aff17
              -rw-r--r--  1 erikd erikd   46512 Oct 18 22:57 file.sd2
      Packit 4aff17
              -rw-r--r--  1 erikd erikd     538 Oct 18 22:57 file.sd2/rsrc
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17

      Packit 4aff17
      Notice how the file itself looks like a directory containing a single file
      Packit 4aff17
      named rsrc.
      Packit 4aff17
      When libsndfile is compiled for MacOS X, it should open (for write and read)
      Packit 4aff17
      SD2 file with resource forks like this without any problems.
      Packit 4aff17
      It will also handle files with the resource fork in a separate file as
      Packit 4aff17
      described below.
      Packit 4aff17

      Packit 4aff17
      Packit 4aff17

      Packit 4aff17
      When SD2 files are moved to other platforms, the resource fork of the file
      Packit 4aff17
      can sometimes be dropped altogether.
      Packit 4aff17
      All that remains is the raw audio data and no information about the number
      Packit 4aff17
      of channels, sample rate or bit width which makes it a little difficult for
      Packit 4aff17
      libsndfile to open the file.
      Packit 4aff17

      Packit 4aff17
      Packit 4aff17

      Packit 4aff17
      However, it is possible to safely move an SD2 file to a Linux or Windows
      Packit 4aff17
      machine.
      Packit 4aff17
      For instance, when an SD2 file is copied from inside MacOS X to a windows
      Packit 4aff17
      shared directory or a Samba share (ie Linux), MacOS X is clever enough to
      Packit 4aff17
      store the resource fork of the file in a separate hidden file in the
      Packit 4aff17
      same directory like this:
      Packit 4aff17

      Packit 4aff17
      Packit 4aff17
              -rw-r--r--  1 erikd erikd     538 Oct 18 22:57 ._file.sd2
      Packit 4aff17
              -rw-r--r--  1 erikd erikd   46512 Oct 18 22:57 file.sd2
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17

      Packit 4aff17
      Regardless of what platform it is running on, when libsndfile is asked to
      Packit 4aff17
      open a file named "foo" and it can't recognize the file type from
      Packit 4aff17
      the data in the file, it will attempt to open the resource fork and if
      Packit 4aff17
      that fails, it then tries to open a file named "._foo" to see if
      Packit 4aff17
      the file has a valid resource fork.
      Packit 4aff17
      This is the same regardless of whether the file is being opened for read
      Packit 4aff17
      or write.
      Packit 4aff17

      Packit 4aff17
      Packit 4aff17

      Packit 4aff17
      In short, libsndfile should open SD2 files with a valid resource fork on
      Packit 4aff17
      all of the platforms that libsndfile supports.
      Packit 4aff17
      If a file has lost its resource fork, the only option is the open the file
      Packit 4aff17
      using the SF_FORMAT_RAW option and guessing its sample rate, channel count
      Packit 4aff17
      and bit width.
      Packit 4aff17

      Packit 4aff17
      Packit 4aff17

      Packit 4aff17
      Occasionally, when SD2 files are moved to other systems, the file is
      Packit 4aff17
      	BinHexed
      Packit 4aff17
      which wraps the resource fork and the data fork together.
      Packit 4aff17
      For these files, it would be possible to write a BinHex parser but
      Packit 4aff17
      there is not a lot to gain considering how rare these BinHexed SD2
      Packit 4aff17
      files are.
      Packit 4aff17

      Packit 4aff17
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17


      Q14 : I'd like to statically link libsndfile to my closed source

      Packit 4aff17
      	application. Can I buy a license so that this is possible?
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17

      Packit 4aff17
      Unfortunately no.
      Packit 4aff17
      libsndfile contains code written by other people who have agreed that their
      Packit 4aff17
      code be used under the GNU LGPL but no more.
      Packit 4aff17
      Even if they were to agree, there would be significant difficulties in
      Packit 4aff17
      dividing up the payments fairly.
      Packit 4aff17

      Packit 4aff17
      Packit 4aff17

      Packit 4aff17
      The only way you can legally use libsndfile as a statically linked
      Packit 4aff17
      library is if your application is released under the GNU GPL or LGPL.
      Packit 4aff17

      Packit 4aff17
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17


      Q15 : My program is crashing during a call to a function in libsndfile.

      Packit 4aff17
      	Is this a bug in libsndfile?
      Packit 4aff17
      Packit 4aff17
      Packit 4aff17

      Packit 4aff17
      libsndfile is being used by large numbers of people all over the world
      Packit 4aff17
      without any problems like this. That means that it is much more likely
      Packit 4aff17
      that your code has a bug than libsndfile. However, it is still possible
      Packit 4aff17
      that there is a bug in libsndfile.
      Packit 4aff17

      Packit 4aff17

      Packit 4aff17
      To figure out whether it is your code or libsndfile you should do the
      Packit 4aff17
      following:
      Packit 4aff17

      Packit 4aff17
      	
        Packit 4aff17
        	
      • Make sure you are compiling your code with warnings switched on and
      • Packit 4aff17
        		that you fix as many warnings as possible.
        Packit 4aff17
        		With the GNU compiler (gcc) I would recommend at least
        Packit 4aff17
        		-W -Wall -Werror which will force you to fix all warnings
        Packit 4aff17
        		before you can run the code.
        Packit 4aff17
        	
      • Try using a memory debugger.
      • Packit 4aff17
        		Valgrind on x86 Linux is excellent.
        Packit 4aff17
        		Purify also
        Packit 4aff17
        		has a good reputation.
        Packit 4aff17
        	
      • If the code is clean after the above two steps and you still get
      • Packit 4aff17
        		a crash in libsndfile, then send me a small snippet of code (no
        Packit 4aff17
        		more than 30-40 lines) which includes the call to sf_open() and
        Packit 4aff17
        		also shows how all variables passed to/returned from sf_open()
        Packit 4aff17
        		are defined.
        Packit 4aff17
        	
        Packit 4aff17
        Packit 4aff17
        Packit 4aff17
        Packit 4aff17


        Q16 : Will you accept a fix for compiling libsndfile with compiler X?

        Packit 4aff17
        Packit 4aff17
        Packit 4aff17

        Packit 4aff17
        If compiler X is a C++ compiler then no.
        Packit 4aff17
        C and C++ are different enough to make writing code that compiles as valid C
        Packit 4aff17
        and valid C++ too difficult.
        Packit 4aff17
        I would rather spend my time fixing bugs and adding features.
        Packit 4aff17

        Packit 4aff17
        Packit 4aff17

        Packit 4aff17
        If compiler X is a C compiler then I will do what I can as long as that does
        Packit 4aff17
        not hamper the correctness, portability and maintainability of the existing
        Packit 4aff17
        code.
        Packit 4aff17
        It should be noted however that libsndfile uses features specified by the 1999
        Packit 4aff17
        ISO C Standard.
        Packit 4aff17
        This can make compiling libsndfile with some older compilers difficult.
        Packit 4aff17

        Packit 4aff17
        Packit 4aff17
        Packit 4aff17
        Packit 4aff17


        Q17 : Can libsndfile read/write files from/to UNIX pipes?

        Packit 4aff17
        Packit 4aff17
        Packit 4aff17

        Packit 4aff17
        Yes, libsndfile can read files from pipes.
        Packit 4aff17
        Unfortunately, the write case is much more complicated.
        Packit 4aff17

        Packit 4aff17
        Packit 4aff17

        Packit 4aff17
        File formats like AIFF and WAV have information at the start of the file (the
        Packit 4aff17
        file header) which states the length of the file, the number of sample frames
        Packit 4aff17
        etc.
        Packit 4aff17
        This information must be filled in correctly when the file header is written,
        Packit 4aff17
        but this information is not reliably known until the file is closed.
        Packit 4aff17
        This means that libsndfile cannot write AIFF, WAV and many other file types
        Packit 4aff17
        to a pipe.
        Packit 4aff17

        Packit 4aff17
        Packit 4aff17

        Packit 4aff17
        However, there is at least one file format (AU) which is specifically designed
        Packit 4aff17
        to be written to a pipe.
        Packit 4aff17
        Like AIFF and WAV, AU has a header with a sample frames field, but it is
        Packit 4aff17
        specifically allowable to set that frames field to 0x7FFFFFFF if the file
        Packit 4aff17
        length is not known when the header is written.
        Packit 4aff17
        The AU file format can also hold data in many of the standard formats (ie
        Packit 4aff17
        SF_FORMAT_PCM_16, SF_FORMAT_PCM_24, SF_FORMAT_FLOAT etc) as well as allowing
        Packit 4aff17
        data in both big and little endian format.
        Packit 4aff17

        Packit 4aff17
        Packit 4aff17

        Packit 4aff17
        See also FAQ Q6.
        Packit 4aff17

        Packit 4aff17
        Packit 4aff17
        Packit 4aff17
        Packit 4aff17


        Q18 : Is it possible to build a Universal Binary on Mac OS X?

        Packit 4aff17
        Packit 4aff17
        Packit 4aff17

        Packit 4aff17
        Yes, but you must do two separate configure/build/test runs; one on PowerPC
        Packit 4aff17
        and one on Intel.
        Packit 4aff17
        It is then possible to merge the binaries into a single universal binary using
        Packit 4aff17
        one of the programs in the Apple tool chain.
        Packit 4aff17

        Packit 4aff17
        Packit 4aff17

        Packit 4aff17
        It is not possible to build a working universal binary via a single
        Packit 4aff17
        compile/build run on a single CPU.
        Packit 4aff17

        Packit 4aff17
        Packit 4aff17

        Packit 4aff17
        The problem is that the libsndfile build process detects features of the CPU its
        Packit 4aff17
        being built for during the configure process and when building a universal binary,
        Packit 4aff17
        configure is only run once and that data is then used for both CPUs.
        Packit 4aff17
        That configure data will be wrong for one of those CPUs.
        Packit 4aff17
        You will still be able to compile libsndfile, and the test suite will pass on
        Packit 4aff17
        the machine you compiled it on.
        Packit 4aff17
        However, if you take the universal binary test suite programs compiled on one
        Packit 4aff17
        CPU and run them on the other, the test suite will fail.
        Packit 4aff17

        Packit 4aff17
        Packit 4aff17

        Packit 4aff17
        Part of the problem is that the CPU endian-ness is detected at configure time.
        Packit 4aff17
        Yes, I know the Apple compiler defines one of the macros __LITTLE_ENDIAN__
        Packit 4aff17
        and __BIG_ENDIAN__, but those macros are not part of the 1999 ISO C Standard
        Packit 4aff17
        and they are not portable.
        Packit 4aff17

        Packit 4aff17
        Packit 4aff17

        Packit 4aff17
        Endian issues are not the only reason why the cross compiled binary will fail.
        Packit 4aff17
        The configure script also detects other CPU specific idiosyncrasies to provide
        Packit 4aff17
        more optimized code.
        Packit 4aff17

        Packit 4aff17
        Packit 4aff17

        Packit 4aff17
        Finally, the real show stopper problem with universal binaries is the problem
        Packit 4aff17
        with the test suite.
        Packit 4aff17
        libsndfile contains a huge, comprehensive test suite.
        Packit 4aff17
        When you compile a universal binary and run the test suite, you only test the
        Packit 4aff17
        native compile.
        Packit 4aff17
        The cross compiled binary (the one with the much higher chance of having
        Packit 4aff17
        problems) cannot be tested.
        Packit 4aff17

        Packit 4aff17
        Packit 4aff17

        Packit 4aff17
        Now, if you have read this far you're probably thinking there must be a way
        Packit 4aff17
        to fix this and there probably is.
        Packit 4aff17
        The problem is that its a hell of a lot of work and would require significant
        Packit 4aff17
        changes to the configure process, the internal code and the test suite.
        Packit 4aff17
        In addition, these changes must not break compilation on any of the platforms
        Packit 4aff17
        libsndfile is currently working on.
        Packit 4aff17

        Packit 4aff17
        Packit 4aff17
        Packit 4aff17
        Packit 4aff17
        Packit 4aff17


        Q19 : I have project files for Visual Studio / XCode / Whatever. Why

        Packit 4aff17
        	don't you distribute them with libsndfile?
        Packit 4aff17
        Packit 4aff17
        Packit 4aff17

        Packit 4aff17
        There's a very good reason for this.
        Packit 4aff17
        I will only distribute things that I actually have an ability to test and
        Packit 4aff17
        maintain.
        Packit 4aff17
        Project files for a bunch of different compilers and Integrated Development
        Packit 4aff17
        Environments are simply too difficult to maintain.
        Packit 4aff17

        Packit 4aff17
        Packit 4aff17

        Packit 4aff17
        The problem is that every time I add a new file to libsndfile or rename an
        Packit 4aff17
        existing file I would have to modify all the project files and then test that
        Packit 4aff17
        libsndfile still built with all the different compilers.
        Packit 4aff17

        Packit 4aff17
        Packit 4aff17

        Packit 4aff17
        Maintaining these project files is also rather difficult if I don't have access
        Packit 4aff17
        to the required compiler/IDE.
        Packit 4aff17
        If I just edit the project files without testing them I will almost certainly
        Packit 4aff17
        get it wrong.
        Packit 4aff17
        If I release a version of libsndfile with broken project files, I'll get a bunch
        Packit 4aff17
        of emails from people complaining about it not building and have no way of
        Packit 4aff17
        fixing or even testing it.
        Packit 4aff17

        Packit 4aff17
        Packit 4aff17

        Packit 4aff17
        I currently release sources that I personally test on Win32, Linux and
        Packit 4aff17
        MacOS X (PowerPC) using the compiler I trust (GNU GCC).
        Packit 4aff17
        Supporting one compiler on three (actually much more because GCC is available
        Packit 4aff17
        almost everywhere) platforms is doable without too much pain.
        Packit 4aff17
        I also release binaries for Win32 with instructions on how to use those
        Packit 4aff17
        binaries with Visual Studio.
        Packit 4aff17
        As a guy who is mainly interested in Linux, I'm not to keen to jump through
        Packit 4aff17
        a bunch of hoops to support compilers and operating systems I don't use.
        Packit 4aff17

        Packit 4aff17
        Packit 4aff17

        Packit 4aff17
        So, I hear you want to volunteer to maintain the project files for Some Crappy
        Packit 4aff17
        Compiler 2007?
        Packit 4aff17
        Well sorry, that won't work either.
        Packit 4aff17
        I have had numerous people over the years offer to maintaining the project
        Packit 4aff17
        files for Microsoft's Visual Studio.
        Packit 4aff17
        Every single time that happened, they maintained it for a release or two and
        Packit 4aff17
        then disappeared off the face of the earth.
        Packit 4aff17
        Hence, I'm not willing to enter into an arrangement like that again.
        Packit 4aff17

        Packit 4aff17
        Packit 4aff17
        Packit 4aff17
        Packit 4aff17


        Q20 : Why doesn't libsndfile support MP3? Lots of other Open Source

        Packit 4aff17
        	projects support it!
        Packit 4aff17
        Packit 4aff17
        Packit 4aff17

        Packit 4aff17
        MP3 is not supported for one very good reason; doing so requires the payment
        Packit 4aff17
        of licensing fees.
        Packit 4aff17
        As can be seen from
        Packit 4aff17
        	
        Packit 4aff17
        	mp3licensing.com
        Packit 4aff17
        the required royalty payments are not cheap.
        Packit 4aff17

        Packit 4aff17
        Packit 4aff17

        Packit 4aff17
        Yes, I know other libraries ignore the licensing requirements, but their legal
        Packit 4aff17
        status is extremely dubious.
        Packit 4aff17
        At any time, the body selling the licenses could go after the authors of those
        Packit 4aff17
        libraries.
        Packit 4aff17
        Some of those authors may be students and hence wouldn't be worth pursuing.
        Packit 4aff17

        Packit 4aff17
        Packit 4aff17

        Packit 4aff17
        However, libsndfile is released under the name of a company, Mega Nerd Pty Ltd;
        Packit 4aff17
        a company which has income from from libsamplerate licensing, libsndfile based
        Packit 4aff17
        consulting income and other unrelated consulting income.
        Packit 4aff17
        Adding MP3 support to libsndfile could place that income under legal threat.
        Packit 4aff17

        Packit 4aff17
        Packit 4aff17

        Packit 4aff17
        Fortunately, Ogg Vorbis exists as an alternative to MP3.
        Packit 4aff17
        Support for Ogg Vorbis was added to libsndfile (mostly due to the efforts of
        Packit 4aff17
        John ffitch of the Csound project) in version 1.0.18.
        Packit 4aff17

        Packit 4aff17
        Packit 4aff17
        Packit 4aff17
        Packit 4aff17
        Packit 4aff17


        Q21 : How do I use libsndfile in a closed source or commercial program

        Packit 4aff17
        	and comply with the license?
        Packit 4aff17
        Packit 4aff17
        Packit 4aff17

        Packit 4aff17
        Here is a checklist of things you need to do to make sure your use of libsndfile
        Packit 4aff17
        in a closed source or commercial project complies with the license libsndfile is
        Packit 4aff17
        released under, the GNU Lesser General Public License (LGPL):
        Packit 4aff17

        Packit 4aff17
        Packit 4aff17
          Packit 4aff17
        • Make sure you are linking to libsndfile as a shared library (Linux and Unix
        • Packit 4aff17
          	systems), Dynamic Link Library (Microsoft Windows) or dynlib (Mac OS X).
          Packit 4aff17
          	If you are using some other operating system that doesn't allow dynamically
          Packit 4aff17
          	linked libraries, you will not be able to use libsndfile unless you release
          Packit 4aff17
          	the source code to your program.
          Packit 4aff17
        • In the licensing documentation for your program, add a statement that your
        • Packit 4aff17
          	software depends on libsndfile and that libsndfile is released under the GNU
          Packit 4aff17
          	Lesser General Public License, either
          Packit 4aff17
          		version 2.1
          Packit 4aff17
          	or optionally
          Packit 4aff17
          		version 3.
          Packit 4aff17
        • Include the text for both versions of the license, possibly as separate
        • Packit 4aff17
          	files named libsndfile_lgpl_v2_1.txt and libsndfile_lgpl_v3.txt.
          Packit 4aff17
          Packit 4aff17
          Packit 4aff17
          Packit 4aff17
          Packit 4aff17


          Q22 : What versions of Windows does libsndfile work on?

          Packit 4aff17
          Packit 4aff17
          Packit 4aff17

          Packit 4aff17
          Currently the precompiled windows binaries are thoroughly tested on Windows XP.
          Packit 4aff17
          As such, they should also work on Win2k and Windows Vista.
          Packit 4aff17
          They may also work on earlier versions of Windows.
          Packit 4aff17

          Packit 4aff17
          Packit 4aff17

          Packit 4aff17
          Since version 0.1.18 I have also been releasing precompiled binaries for Win64,
          Packit 4aff17
          the 64 bit version of Windows.
          Packit 4aff17
          These binaries have received much less testing than the  32 bit versions, but
          Packit 4aff17
          should work as expected.
          Packit 4aff17
          I'd be very interested in receiving feedback  on these binaries.
          Packit 4aff17

          Packit 4aff17
          Packit 4aff17
          Packit 4aff17
          Packit 4aff17


          Q23 : I'm cross compiling libsndfile for another platform. How can I

          Packit 4aff17
          	run the test suite?
          Packit 4aff17
          Packit 4aff17
          Packit 4aff17

          Packit 4aff17

          Packit 4aff17
          Packit 4aff17

          Packit 4aff17
          Since version 1.0.21 the top level Makefile has an extra make target,
          Packit 4aff17
          'test-tarball'.
          Packit 4aff17
          Building this target creates a tarball called called:
          Packit 4aff17

          Packit 4aff17
          Packit 4aff17
          <center><tt>
          Packit 4aff17
          libsndfile-testsuite-${host_triplet}-${version}.tar.gz
          Packit 4aff17
          </tt></center>
          Packit 4aff17
          Packit 4aff17

          Packit 4aff17
          in the top level directory.
          Packit 4aff17
          This tarball can then be copied to the target platform.
          Packit 4aff17
          Once untarred and test script <tt>test_wrapper.sh</tt> can be run from
          Packit 4aff17
          the top level of the extracted tarball.
          Packit 4aff17

          Packit 4aff17
          Packit 4aff17
          Packit 4aff17

          Packit 4aff17

          Packit 4aff17
          	The libsndfile home page is here :
          Packit 4aff17
          		
          Packit 4aff17
          			http://www.mega-nerd.com/libsndfile/.
          Packit 4aff17

          Packit 4aff17
          Version : 1.0.28
          Packit 4aff17

          Packit 4aff17
          Packit 4aff17
          </BODY>
          Packit 4aff17
          </HTML>