1b815c7f3Sopenharmony_ci---
2b815c7f3Sopenharmony_cilayout: default
3b815c7f3Sopenharmony_cititle: libsndfile : Frequently Asked Questions.
4b815c7f3Sopenharmony_ci---
5b815c7f3Sopenharmony_ci
6b815c7f3Sopenharmony_ci# libsndfile : Frequently Asked Questions
7b815c7f3Sopenharmony_ci
8b815c7f3Sopenharmony_ci1. [Do you plan to support XYZ codec in libsndfile?](#Q001)
9b815c7f3Sopenharmony_ci2. [In version 0 the SF\_INFO struct had a pcmbitwidth field but version 1 does not. Why?](#Q002)
10b815c7f3Sopenharmony_ci3. [Compiling is really slow on MacOS X. Why?](#Q003)
11b815c7f3Sopenharmony_ci4. [When trying to compile libsndfile on Solaris I get a "bad substitution" error during linking. What can I do to fix this?](#Q004)
12b815c7f3Sopenharmony_ci5. [Why doesn't libsndfile do interleaving/de-interleaving?](#Q005)
13b815c7f3Sopenharmony_ci6. [What's the best format for storing temporary files?](#Q006)
14b815c7f3Sopenharmony_ci7. [On Linux/Unix/MacOS X, what's the best way of detecting the presence of libsndfile?](#Q007)
15b815c7f3Sopenharmony_ci8. [I have libsndfile installed and now I want to use it. I just want a simple Makefile\! What do I do?](#Q008)
16b815c7f3Sopenharmony_ci9. [How about adding the ability to write/read sound files to/from memory buffers?](#Q009)
17b815c7f3Sopenharmony_ci10. [Reading a 16 bit PCM file as normalised floats and then writing them back changes some sample values. Why?](#Q010)
18b815c7f3Sopenharmony_ci11. [I'm having problems with u-law encoded WAV files generated by libsndfile in Winamp. Why?](#Q011)
19b815c7f3Sopenharmony_ci12. [I'm looking at sf\_read\*. What are items? What are frames?](#Q012)
20b815c7f3Sopenharmony_ci13. [Why can't libsndfile open this Sound Designer II (SD2) file?](#Q013)
21b815c7f3Sopenharmony_ci14. [I'd like to statically link libsndfile to my closed source application. Can I buy a license so that this is possible?](#Q014)
22b815c7f3Sopenharmony_ci15. [My program is crashing during a call to a function in libsndfile. Is this a bug in libsndfile?](#Q015)
23b815c7f3Sopenharmony_ci16. [Will you accept a fix for compiling libsndfile with compiler X?](#Q016)
24b815c7f3Sopenharmony_ci17. [Can libsndfile read/write files from/to UNIX pipes?](#Q017)
25b815c7f3Sopenharmony_ci18. [Is it possible to build a Universal Binary on Mac OS X?](#Q018)
26b815c7f3Sopenharmony_ci19. [I have project files for Visual Studio / XCode / Whatever. Why don't you distribute them with libsndfile?](#Q019)
27b815c7f3Sopenharmony_ci20. [Why doesn't libsndfile support MP3?](#Q020)
28b815c7f3Sopenharmony_ci21. [How do I use libsndfile in a closed source or commercial program and comply with the license?](#Q021)
29b815c7f3Sopenharmony_ci22. [What versions of windows does libsndfile work on?](#Q022)
30b815c7f3Sopenharmony_ci23. [I'm cross compiling libsndfile for another platform. How can I run the test suite?](#Q023)
31b815c7f3Sopenharmony_ci
32b815c7f3Sopenharmony_ci-----
33b815c7f3Sopenharmony_ci
34b815c7f3Sopenharmony_ci## Q1 : Do you plan to support XYZ codec in libsndfile? {#Q001}
35b815c7f3Sopenharmony_ci
36b815c7f3Sopenharmony_ciIf source code for XYZ codec is available under a suitable license (LGPL, BSD,
37b815c7f3Sopenharmony_ciMIT etc) then yes, I'd like to add it.
38b815c7f3Sopenharmony_ci
39b815c7f3Sopenharmony_ciIf suitable documentation is available on how to decode and encode the format
40b815c7f3Sopenharmony_cithen maybe, depending on how much work is involved.
41b815c7f3Sopenharmony_ci
42b815c7f3Sopenharmony_ciIf XYZ is some proprietary codec where no source code or documentation is
43b815c7f3Sopenharmony_ciavailable then no.
44b815c7f3Sopenharmony_ci
45b815c7f3Sopenharmony_ciSo if you want support for XYZ codec, first find existing source code or
46b815c7f3Sopenharmony_cidocumentation. If you can't find either then the answer is no.
47b815c7f3Sopenharmony_ci
48b815c7f3Sopenharmony_ci## Q2 : In version 0 the SF\_INFO struct had a pcmbitwidth field but version 1 does not. Why? {#Q002}
49b815c7f3Sopenharmony_ci
50b815c7f3Sopenharmony_ciThis was dropped for a number of reasons:
51b815c7f3Sopenharmony_ci
52b815c7f3Sopenharmony_ci- pcmbitwidth makes little sense on compressed or floating point formats
53b815c7f3Sopenharmony_ci- with the new API you really don't need to know it
54b815c7f3Sopenharmony_ci
55b815c7f3Sopenharmony_ciAs documented [here](api.md#note-1) there is now a well defined behaviour which
56b815c7f3Sopenharmony_ciensures that no matter what the bit width of the source file, the scaling always
57b815c7f3Sopenharmony_cidoes something sensible. This makes it safe to read 8, 16, 24 and 32 bit PCM
58b815c7f3Sopenharmony_cifiles using `sf_read_short()` and always have the optimal behaviour.
59b815c7f3Sopenharmony_ci
60b815c7f3Sopenharmony_ci## Q3 : Compiling is really slow on MacOS X. Why? {#Q003}
61b815c7f3Sopenharmony_ci
62b815c7f3Sopenharmony_ciWhen you configure and compile libsndfile, it uses the /bin/sh shell for a
63b815c7f3Sopenharmony_cinumber of tasks (ie configure script and libtool). Older versions of OS X
64b815c7f3Sopenharmony_ci(10.2?) shipped a really crappy Bourne shell as /bin/sh which resulted in
65b815c7f3Sopenharmony_ci**really** slow compiles. Newer version of OS X ship GNU Bash as /bin/sh and
66b815c7f3Sopenharmony_cithis answer doesn't apply in that case.
67b815c7f3Sopenharmony_ci
68b815c7f3Sopenharmony_ciTo fix this I suggest that you install the GNU Bash shell, rename /bin/sh to
69b815c7f3Sopenharmony_ci/bin/sh.old and make a symlink from /bin/sh to the bash shell. Bash is designed
70b815c7f3Sopenharmony_cito behave as a Bourne shell when it is called as /bin/sh.
71b815c7f3Sopenharmony_ci
72b815c7f3Sopenharmony_ciWhen I did this on my iBook running MacOS X, compile times dropped from 13
73b815c7f3Sopenharmony_ciminutes to 3 minutes.
74b815c7f3Sopenharmony_ci
75b815c7f3Sopenharmony_ci## Q4 : When trying to compile libsndfile on Solaris I get a "bad substitution" error on linking. Why? {#Q004}
76b815c7f3Sopenharmony_ci
77b815c7f3Sopenharmony_ciIt seems that the Solaris Bourne shell disagrees with GNU libtool.
78b815c7f3Sopenharmony_ci
79b815c7f3Sopenharmony_ciTo fix this I suggest that you install the GNU Bash shell, rename /bin/sh to
80b815c7f3Sopenharmony_ci/bin/sh.old and make a symlink from /bin/sh to the bash shell. Bash is designed
81b815c7f3Sopenharmony_cito behave as a Bourne shell when it is called as /bin/sh.
82b815c7f3Sopenharmony_ci
83b815c7f3Sopenharmony_ci## Q5 : Why doesn't libsndfile do interleaving/de-interleaving? {#Q005}
84b815c7f3Sopenharmony_ci
85b815c7f3Sopenharmony_ciThis problem is bigger than it may seem at first.
86b815c7f3Sopenharmony_ci
87b815c7f3Sopenharmony_ciFor a stereo file, it is a pretty safe bet that a simple interleaving/
88b815c7f3Sopenharmony_cide-interleaving could satisfy most users. However, for files with more than 2
89b815c7f3Sopenharmony_cichannels this is unlikely to be the case. If the user has a 4 channel file and
90b815c7f3Sopenharmony_ciwant to play that file on a stereo output sound card they either want the first
91b815c7f3Sopenharmony_ci2 channels or they want some mixed combination of the 4 channels.
92b815c7f3Sopenharmony_ci
93b815c7f3Sopenharmony_ciWhen you add more channels, the combinations grow exponentially and it becomes
94b815c7f3Sopenharmony_ciincreasingly difficult to cover even a sensible subset of the possible
95b815c7f3Sopenharmony_cicombinations. On top of that, coding any one style of interleaver/de-interleaver
96b815c7f3Sopenharmony_ciis trivial, while coding one that can cover all combinations is far from
97b815c7f3Sopenharmony_citrivial. This means that this feature will not be added any time soon.
98b815c7f3Sopenharmony_ci
99b815c7f3Sopenharmony_ci## Q6 : What's the best format for storing temporary files? {#Q006}
100b815c7f3Sopenharmony_ci
101b815c7f3Sopenharmony_ciWhen you want to store temporary data there are a number of requirements:
102b815c7f3Sopenharmony_ci
103b815c7f3Sopenharmony_ci- A simple, easy to parse header.
104b815c7f3Sopenharmony_ci- The format must provide the fastest possible read and write rates (ie avoid
105b815c7f3Sopenharmony_ci  conversions and encoding/decoding).
106b815c7f3Sopenharmony_ci- The file format must be reasonably common and playable by most players.
107b815c7f3Sopenharmony_ci- Able to store data in either endian-ness.
108b815c7f3Sopenharmony_ci
109b815c7f3Sopenharmony_ciThe format which best meets these requirements is AU, which allows data to be
110b815c7f3Sopenharmony_cistored in any one of short, int, float and double (among others) formats.
111b815c7f3Sopenharmony_ci
112b815c7f3Sopenharmony_ciFor instance, if an application uses float data internally, its temporary files
113b815c7f3Sopenharmony_cishould use a format of (SF_ENDIAN_CPU | SF_FORMAT_AU | SF_FORMAT_FLOAT) which
114b815c7f3Sopenharmony_ciwill store big endian float data in big endian CPUs and little endian float data
115b815c7f3Sopenharmony_cion little endian CPUs. Reading and writing this format will not require any
116b815c7f3Sopenharmony_ciconversions or byte swapping regardless of the host CPU.
117b815c7f3Sopenharmony_ci
118b815c7f3Sopenharmony_ci## Q7 : On Linux/Unix/MaxOS X, what's the best way of detecting the presence of libsndfile using autoconf? {#Q007}
119b815c7f3Sopenharmony_ci
120b815c7f3Sopenharmony_cilibsndfile uses the pkg-config (man pkg-config) method of registering itself
121b815c7f3Sopenharmony_ciwith the host system. The best way of detecting its presence is using something
122b815c7f3Sopenharmony_cilike this in configure.ac (or configure.in):
123b815c7f3Sopenharmony_ci
124b815c7f3Sopenharmony_ci    PKG_CHECK_MODULES(SNDFILE, sndfile >= 1.0.2, ac_cv_sndfile=1, ac_cv_sndfile=0)
125b815c7f3Sopenharmony_ci
126b815c7f3Sopenharmony_ci    AC_DEFINE_UNQUOTED([HAVE_SNDFILE],${ac_cv_sndfile},
127b815c7f3Sopenharmony_ci        [Set to 1 if you have libsndfile.])
128b815c7f3Sopenharmony_ci
129b815c7f3Sopenharmony_ci    AC_SUBST(SNDFILE_CFLAGS)
130b815c7f3Sopenharmony_ci    AC_SUBST(SNDFILE_LIBS)
131b815c7f3Sopenharmony_ci
132b815c7f3Sopenharmony_ciThis will automatically set the **SNDFILE_CFLAGS** and **SNDFILE_LIBS**
133b815c7f3Sopenharmony_civariables which can be used in Makefile.am like this:
134b815c7f3Sopenharmony_ci
135b815c7f3Sopenharmony_ci    SNDFILE_CFLAGS = @SNDFILE_CFLAGS@
136b815c7f3Sopenharmony_ci    SNDFILE_LIBS = @SNDFILE_LIBS@
137b815c7f3Sopenharmony_ci
138b815c7f3Sopenharmony_ciIf you install libsndfile from source, you will probably need to set the
139b815c7f3Sopenharmony_ci**PKG_CONFIG_PATH** environment variable as suggested at the end of the
140b815c7f3Sopenharmony_cilibsndfile configure process. For instance on my system I get this:
141b815c7f3Sopenharmony_ci
142b815c7f3Sopenharmony_ci    -=-=-=-=-=-=-=-=-=-= Configuration Complete =-=-=-=-=-=-=-=-=-=-
143b815c7f3Sopenharmony_ci
144b815c7f3Sopenharmony_ci        Configuration summary :
145b815c7f3Sopenharmony_ci
146b815c7f3Sopenharmony_ci        Version : ..................... 1.0.5
147b815c7f3Sopenharmony_ci        Experimental code : ........... no
148b815c7f3Sopenharmony_ci
149b815c7f3Sopenharmony_ci        Tools :
150b815c7f3Sopenharmony_ci
151b815c7f3Sopenharmony_ci        Compiler is GCC : ............. yes
152b815c7f3Sopenharmony_ci        GCC major version : ........... 3
153b815c7f3Sopenharmony_ci
154b815c7f3Sopenharmony_ci        Installation directories :
155b815c7f3Sopenharmony_ci
156b815c7f3Sopenharmony_ci        Library directory : ........... /usr/local/lib
157b815c7f3Sopenharmony_ci        Program directory : ........... /usr/local/bin
158b815c7f3Sopenharmony_ci        Pkgconfig directory : ......... /usr/local/lib/pkgconfig
159b815c7f3Sopenharmony_ci
160b815c7f3Sopenharmony_ci    Compiling some other packages against libsndfile may require
161b815c7f3Sopenharmony_ci    the addition of "/usr/local/lib/pkgconfig" to the
162b815c7f3Sopenharmony_ci    PKG_CONFIG_PATH environment variable.
163b815c7f3Sopenharmony_ci
164b815c7f3Sopenharmony_ci## Q8 : I have libsndfile installed and now I want to use it. I just want a simple Makefile\! What do I do? {#Q008}
165b815c7f3Sopenharmony_ci
166b815c7f3Sopenharmony_ciThe **pkg-config** program makes finding the correct compiler flag values and
167b815c7f3Sopenharmony_cilibrary location far easier. During the installation of libsndfile, a file named
168b815c7f3Sopenharmony_ci**sndfile.pc** is installed in the directory **${libdir}/pkgconfig** (ie if
169b815c7f3Sopenharmony_cilibsndfile is installed in **/usr/local/lib**, **sndfile.pc** will be installed
170b815c7f3Sopenharmony_ciin **/usr/local/lib/pkgconfig/**).
171b815c7f3Sopenharmony_ci
172b815c7f3Sopenharmony_ciIn order for pkg-config to find sndfile.pc it may be necessary to point the
173b815c7f3Sopenharmony_cienvironment variable **PKG_CONFIG_PATH** in the right direction.
174b815c7f3Sopenharmony_ci
175b815c7f3Sopenharmony_ci    export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
176b815c7f3Sopenharmony_ci
177b815c7f3Sopenharmony_ciThen, to compile a C file into an object file, the command would be:
178b815c7f3Sopenharmony_ci
179b815c7f3Sopenharmony_ci    gcc `pkg-config --cflags sndfile` -c somefile.c
180b815c7f3Sopenharmony_ci
181b815c7f3Sopenharmony_ciand to link a number of objects into an executable that links against
182b815c7f3Sopenharmony_cilibsndfile, the command would be:
183b815c7f3Sopenharmony_ci
184b815c7f3Sopenharmony_ci    gcc `pkg-config --libs sndfile` obj1.o obj2.o -o program
185b815c7f3Sopenharmony_ci
186b815c7f3Sopenharmony_ci## Q9 : How about adding the ability to write/read sound files to/from memory buffers? {#Q009}
187b815c7f3Sopenharmony_ci
188b815c7f3Sopenharmony_ciThis has been [added](api.md#open_virtual) for version 1.0.12.
189b815c7f3Sopenharmony_ci
190b815c7f3Sopenharmony_ci## Q10 : Reading a 16 bit PCM file as normalised floats and then writing them back changes some sample values. Why? {#Q010}
191b815c7f3Sopenharmony_ci
192b815c7f3Sopenharmony_ciThis is caused by the fact that the conversion from 16 bit short to float is
193b815c7f3Sopenharmony_cidone by dividing by 32768 (0x8000 in hexadecimal) while the conversion from
194b815c7f3Sopenharmony_cifloat to 16 bit short is done by multiplying by 32767 (0x7FFF in hex). So for
195b815c7f3Sopenharmony_ciinstance, a value in a 16 bit PCM file of 20000 gets read as a floating point
196b815c7f3Sopenharmony_cinumber of 0.6103515625 (20000.0 / 0x8000). Converting that back to a 16 bit
197b815c7f3Sopenharmony_cishort results in a value of 19999.3896484375 (0.6103515625 \* 0x7FFF) which then
198b815c7f3Sopenharmony_cigets rounded down to 19999.
199b815c7f3Sopenharmony_ci
200b815c7f3Sopenharmony_ciYou will notice that for this particular case, the error is 1 in 20000 or
201b815c7f3Sopenharmony_ci0.005%. Interestingly, for values of less than 16369, dividing by 0x8000
202b815c7f3Sopenharmony_cifollowed by multiplying by 0x7FFF and then rounding the result, gives back the
203b815c7f3Sopenharmony_cioriginal value. It turns out that as long as the host operating system supplies
204b815c7f3Sopenharmony_cithe 1999 ISO C Standard functions **lrintf** and **lrint** (or a replacement has
205b815c7f3Sopenharmony_cibeen supplied) then the maximum possible error is 1 in 16369 or about 0.006%.
206b815c7f3Sopenharmony_ci
207b815c7f3Sopenharmony_ciRegardless of the size of the error, the reason why this is done is rather
208b815c7f3Sopenharmony_cisubtle.
209b815c7f3Sopenharmony_ci
210b815c7f3Sopenharmony_ciIn a file containing 16 bit PCM samples, the values are restricted to the range
211b815c7f3Sopenharmony_ci[-32768, 32767] while we want floating point values in the range [-1.0, 1.0].
212b815c7f3Sopenharmony_ciThe only way to do this conversion is to do a floating point division by a value
213b815c7f3Sopenharmony_ciof 0x8000. Converting the other way, the only way to ensure that floating point
214b815c7f3Sopenharmony_civalues in the range [-1.0, 1.0] are within the valid range allowed by a 16 bit
215b815c7f3Sopenharmony_cishort is to multiply by 0x7FFF.
216b815c7f3Sopenharmony_ci
217b815c7f3Sopenharmony_ciSome people would say that this is a severe short-coming of libsndfile. I would
218b815c7f3Sopenharmony_cicounter that anybody who is constantly converting back and forth between 16 bit
219b815c7f3Sopenharmony_cishorts and normalised floats is going to suffer other losses in audio quality
220b815c7f3Sopenharmony_cithat they should also be concerned about.
221b815c7f3Sopenharmony_ci
222b815c7f3Sopenharmony_ciSince this problem only occurs when converting between integer data on disk and
223b815c7f3Sopenharmony_cinormalized floats in the application, it can be avoided by using something other
224b815c7f3Sopenharmony_cithan normalized floats in the application. Alternatives to normalized floats are
225b815c7f3Sopenharmony_cithe **short** and **int** data types (ie using sf_read_short or sf_read_int) or
226b815c7f3Sopenharmony_ciusing un-normalized floats (see
227b815c7f3Sopenharmony_ci[SFC_SET_NORM_FLOAT](command.html#sfc_set_norm_float)).
228b815c7f3Sopenharmony_ci
229b815c7f3Sopenharmony_ciAnother way to deal with this problem is to consider 16 bit short data as a
230b815c7f3Sopenharmony_cifinal destination format only, not as an intermediate storage format. All
231b815c7f3Sopenharmony_ciintermediate data (ie which is going to be processed further) should be stored
232b815c7f3Sopenharmony_ciin floating point format which is supported by all of the most common file
233b815c7f3Sopenharmony_ciformats. If floating point files are considered too large (2 times the size of a
234b815c7f3Sopenharmony_ci16 bit PCM file), it would also be possible to use 24 bit PCM as an intermediate
235b815c7f3Sopenharmony_cistorage format (and which is also supported by most common file types).
236b815c7f3Sopenharmony_ci
237b815c7f3Sopenharmony_ci## Q11 : I'm having problems with u-law encoded WAV files generated by libsndfile in Winamp. Why? {#Q011}
238b815c7f3Sopenharmony_ci
239b815c7f3Sopenharmony_ciThis is actually a Winamp problem. The official Microsoft spec suggests that the
240b815c7f3Sopenharmony_ci'fmt ' chunk should be 18 bytes. Unfortunately at least one of Microsoft's own
241b815c7f3Sopenharmony_ciapplications (Sound Recorder on Win98 I believe) did not accept 18 bytes 'fmt '
242b815c7f3Sopenharmony_cichunks.
243b815c7f3Sopenharmony_ci
244b815c7f3Sopenharmony_ciMichael Lee did some experimenting and found that:
245b815c7f3Sopenharmony_ci
246b815c7f3Sopenharmony_ci> I have checked that Windows Media Player 9, QuickTime Player 6.4, RealOne
247b815c7f3Sopenharmony_ci> Player 2.0 and GoldWave 5.06 can all play u-law files with 16-byte or 18-byte
248b815c7f3Sopenharmony_ci> 'fmt ' chunk. Only Winamp (2.91) and foobar2000 are unable to play u-law files
249b815c7f3Sopenharmony_ci> with 16-byte 'fmt ' chunk.
250b815c7f3Sopenharmony_ci
251b815c7f3Sopenharmony_ciEven this is a very small sampling of all the players out there. For that reason
252b815c7f3Sopenharmony_ciit is probably not a good idea to change this now because there is the risk of
253b815c7f3Sopenharmony_cibreaking something that currently works.
254b815c7f3Sopenharmony_ci
255b815c7f3Sopenharmony_ci## Q12 : I'm looking at sf_read*. What are items? What are frames? {#Q012}
256b815c7f3Sopenharmony_ci
257b815c7f3Sopenharmony_ciAn `item` is a single sample of the data type you are reading; ie a single
258b815c7f3Sopenharmony_ci`short` value for `sf_read_short` or a single `float` for `sf_read_float`.
259b815c7f3Sopenharmony_ci
260b815c7f3Sopenharmony_ciFor a sound file with only one channel, a frame is the same as a item (ie a
261b815c7f3Sopenharmony_cisingle sample) while for multi channel sound files, a single frame contains a
262b815c7f3Sopenharmony_cisingle item for each channel.
263b815c7f3Sopenharmony_ci
264b815c7f3Sopenharmony_ciHere are two simple, correct examples, both of which are assumed to be working
265b815c7f3Sopenharmony_cion a stereo file, first using items:
266b815c7f3Sopenharmony_ci
267b815c7f3Sopenharmony_ci```c
268b815c7f3Sopenharmony_ci#define CHANNELS 2
269b815c7f3Sopenharmony_cishort data [CHANNELS * 100] ;
270b815c7f3Sopenharmony_cisf_count items_read = sf_read_short (file, data, 200) ;
271b815c7f3Sopenharmony_ciassert (items_read == 200) ;
272b815c7f3Sopenharmony_ci```
273b815c7f3Sopenharmony_ci
274b815c7f3Sopenharmony_ciand now reading the exact same amount of data using frames:
275b815c7f3Sopenharmony_ci
276b815c7f3Sopenharmony_ci```c
277b815c7f3Sopenharmony_ci#define CHANNELS 2
278b815c7f3Sopenharmony_cishort data [CHANNELS * 100] ;
279b815c7f3Sopenharmony_cisf_count frames_read = sf_readf_short (file, data, 100) ;
280b815c7f3Sopenharmony_ciassert (frames_read == 100) ;
281b815c7f3Sopenharmony_ci```
282b815c7f3Sopenharmony_ci
283b815c7f3Sopenharmony_ci## Q13 : Why can't libsndfile open this Sound Designer II (SD2) file? {#Q013}
284b815c7f3Sopenharmony_ci
285b815c7f3Sopenharmony_ciThis is somewhat complicated. First some background.
286b815c7f3Sopenharmony_ci
287b815c7f3Sopenharmony_ciSD2 files are native to the Apple Macintosh platform and use features of the Mac
288b815c7f3Sopenharmony_cifilesystem (file resource forks) to store the file's sample rate, number of
289b815c7f3Sopenharmony_cichannels, sample width and more. When you look at a file and its resource fork
290b815c7f3Sopenharmony_cion Mac OS X it looks like this:
291b815c7f3Sopenharmony_ci
292b815c7f3Sopenharmony_ci    -rw-r--r--  1 erikd erikd   46512 Oct 18 22:57 file.sd2
293b815c7f3Sopenharmony_ci    -rw-r--r--  1 erikd erikd     538 Oct 18 22:57 file.sd2/rsrc
294b815c7f3Sopenharmony_ci
295b815c7f3Sopenharmony_ciNotice how the file itself looks like a directory containing a single file named
296b815c7f3Sopenharmony_ci**rsrc**. When libsndfile is compiled for MacOS X, it should open (for write and
297b815c7f3Sopenharmony_ciread) SD2 file with resource forks like this without any problems. It will also
298b815c7f3Sopenharmony_cihandle files with the resource fork in a separate file as described below.
299b815c7f3Sopenharmony_ci
300b815c7f3Sopenharmony_ciWhen SD2 files are moved to other platforms, the resource fork of the file can
301b815c7f3Sopenharmony_cisometimes be dropped altogether. All that remains is the raw audio data and no
302b815c7f3Sopenharmony_ciinformation about the number of channels, sample rate or bit width which makes
303b815c7f3Sopenharmony_ciit a little difficult for libsndfile to open the file.
304b815c7f3Sopenharmony_ci
305b815c7f3Sopenharmony_ciHowever, it is possible to safely move an SD2 file to a Linux or Windows
306b815c7f3Sopenharmony_cimachine. For instance, when an SD2 file is copied from inside MacOS X to a
307b815c7f3Sopenharmony_ciwindows shared directory or a Samba share (ie Linux), MacOS X is clever enough
308b815c7f3Sopenharmony_cito store the resource fork of the file in a separate hidden file in the same
309b815c7f3Sopenharmony_cidirectory like this:
310b815c7f3Sopenharmony_ci
311b815c7f3Sopenharmony_ci    -rw-r--r--  1 erikd erikd     538 Oct 18 22:57 ._file.sd2
312b815c7f3Sopenharmony_ci    -rw-r--r--  1 erikd erikd   46512 Oct 18 22:57 file.sd2
313b815c7f3Sopenharmony_ci
314b815c7f3Sopenharmony_ciRegardless of what platform it is running on, when libsndfile is asked to open a
315b815c7f3Sopenharmony_cifile named **"foo"** and it can't recognize the file type from the data in the
316b815c7f3Sopenharmony_cifile, it will attempt to open the resource fork and if that fails, it then tries
317b815c7f3Sopenharmony_cito open a file named **"._foo"** to see if the file has a valid resource fork.
318b815c7f3Sopenharmony_ciThis is the same regardless of whether the file is being opened for read or
319b815c7f3Sopenharmony_ciwrite.
320b815c7f3Sopenharmony_ci
321b815c7f3Sopenharmony_ciIn short, libsndfile should open SD2 files with a valid resource fork on all of
322b815c7f3Sopenharmony_cithe platforms that libsndfile supports. If a file has lost its resource fork,
323b815c7f3Sopenharmony_cithe only option is the open the file using the SF_FORMAT_RAW option and guessing
324b815c7f3Sopenharmony_ciits sample rate, channel count and bit width.
325b815c7f3Sopenharmony_ci
326b815c7f3Sopenharmony_ciOccasionally, when SD2 files are moved to other systems, the file is
327b815c7f3Sopenharmony_ci[BinHexed](http://www.macdisk.com/binhexen.php3) which wraps the resource fork
328b815c7f3Sopenharmony_ciand the data fork together. For these files, it would be possible to write a
329b815c7f3Sopenharmony_ciBinHex parser but there is not a lot to gain considering how rare these BinHexed
330b815c7f3Sopenharmony_ciSD2 files are.
331b815c7f3Sopenharmony_ci
332b815c7f3Sopenharmony_ci## Q14 : I'd like to statically link libsndfile to my closed source application. Can I buy a license so that this is possible? {#Q014}
333b815c7f3Sopenharmony_ci
334b815c7f3Sopenharmony_ciUnfortunately no. libsndfile contains code written by other people who have
335b815c7f3Sopenharmony_ciagreed that their code be used under the GNU LGPL but no more. Even if they were
336b815c7f3Sopenharmony_cito agree, there would be significant difficulties in dividing up the payments
337b815c7f3Sopenharmony_cifairly.
338b815c7f3Sopenharmony_ci
339b815c7f3Sopenharmony_ciThe **only** way you can legally use libsndfile as a statically linked library
340b815c7f3Sopenharmony_ciis if your application is released under the GNU GPL or LGPL.
341b815c7f3Sopenharmony_ci
342b815c7f3Sopenharmony_ci## Q15 : My program is crashing during a call to a function in libsndfile. Is this a bug in libsndfile? {#Q015}
343b815c7f3Sopenharmony_ci
344b815c7f3Sopenharmony_cilibsndfile is being used by large numbers of people all over the world without
345b815c7f3Sopenharmony_ciany problems like this. That means that it is much more likely that your code
346b815c7f3Sopenharmony_cihas a bug than libsndfile. However, it is still possible that there is a bug in
347b815c7f3Sopenharmony_cilibsndfile.
348b815c7f3Sopenharmony_ci
349b815c7f3Sopenharmony_ciTo figure out whether it is your code or libsndfile you should do the following:
350b815c7f3Sopenharmony_ci
351b815c7f3Sopenharmony_ci- Make sure you are compiling your code with warnings switched on and that you
352b815c7f3Sopenharmony_ci  fix as many warnings as possible. With the GNU compiler (gcc) I would
353b815c7f3Sopenharmony_ci  recommend at least **-W -Wall -Werror** which will force you to fix all
354b815c7f3Sopenharmony_ci  warnings before you can run the code.
355b815c7f3Sopenharmony_ci- Try using a memory debugger. [Valgrind](http://valgrind.kde.org/) on x86 Linux
356b815c7f3Sopenharmony_ci  is excellent. [Purify](http://www.ibm.com/software/awdtools/purify/) also has
357b815c7f3Sopenharmony_ci  a good reputation.
358b815c7f3Sopenharmony_ci- If the code is clean after the above two steps and you still get a crash in
359b815c7f3Sopenharmony_ci  libsndfile, then send me a small snippet of code (no more than 30-40 lines)
360b815c7f3Sopenharmony_ci  which includes the call to sf_open() and also shows how all variables passed
361b815c7f3Sopenharmony_ci  to/returned from sf_open() are defined.
362b815c7f3Sopenharmony_ci
363b815c7f3Sopenharmony_ci## Q16 : Will you accept a fix for compiling libsndfile with compiler X? {#Q016}
364b815c7f3Sopenharmony_ci
365b815c7f3Sopenharmony_ciIf compiler X is a C++ compiler then no. C and C++ are different enough to make
366b815c7f3Sopenharmony_ciwriting code that compiles as valid C and valid C++ too difficult. I would
367b815c7f3Sopenharmony_cirather spend my time fixing bugs and adding features.
368b815c7f3Sopenharmony_ci
369b815c7f3Sopenharmony_ciIf compiler X is a C compiler then I will do what I can as long as that does not
370b815c7f3Sopenharmony_cihamper the correctness, portability and maintainability of the existing code. It
371b815c7f3Sopenharmony_cishould be noted however that libsndfile uses features specified by the 1999 ISO
372b815c7f3Sopenharmony_ciC Standard. This can make compiling libsndfile with some older compilers
373b815c7f3Sopenharmony_cidifficult.
374b815c7f3Sopenharmony_ci
375b815c7f3Sopenharmony_ci## Q17 : Can libsndfile read/write files from/to UNIX pipes? {#Q017}
376b815c7f3Sopenharmony_ci
377b815c7f3Sopenharmony_ciYes, libsndfile can read files from pipes. Unfortunately, the write case is much
378b815c7f3Sopenharmony_cimore complicated.
379b815c7f3Sopenharmony_ci
380b815c7f3Sopenharmony_ciFile formats like AIFF and WAV have information at the start of the file (the
381b815c7f3Sopenharmony_cifile header) which states the length of the file, the number of sample frames
382b815c7f3Sopenharmony_cietc. This information must be filled in correctly when the file header is
383b815c7f3Sopenharmony_ciwritten, but this information is not reliably known until the file is closed.
384b815c7f3Sopenharmony_ciThis means that libsndfile cannot write AIFF, WAV and many other file types to a
385b815c7f3Sopenharmony_cipipe.
386b815c7f3Sopenharmony_ci
387b815c7f3Sopenharmony_ciHowever, there is at least one file format (AU) which is specifically designed
388b815c7f3Sopenharmony_cito be written to a pipe. Like AIFF and WAV, AU has a header with a sample frames
389b815c7f3Sopenharmony_cifield, but it is specifically allowable to set that frames field to 0x7FFFFFFF
390b815c7f3Sopenharmony_ciif the file length is not known when the header is written. The AU file format
391b815c7f3Sopenharmony_cican also hold data in many of the standard formats (ie SF_FORMAT_PCM_16,
392b815c7f3Sopenharmony_ciSF_FORMAT_PCM_24, SF_FORMAT_FLOAT etc) as well as allowing data in both big and
393b815c7f3Sopenharmony_cilittle endian format.
394b815c7f3Sopenharmony_ci
395b815c7f3Sopenharmony_ciSee also [FAQ Q6](#Q006).
396b815c7f3Sopenharmony_ci
397b815c7f3Sopenharmony_ci## Q18 : Is it possible to build a Universal Binary on Mac OS X? {#Q018}
398b815c7f3Sopenharmony_ci
399b815c7f3Sopenharmony_ciYes, but you must do two separate configure/build/test runs; one on PowerPC and
400b815c7f3Sopenharmony_cione on Intel. It is then possible to merge the binaries into a single universal
401b815c7f3Sopenharmony_cibinary using one of the programs in the Apple tool chain.
402b815c7f3Sopenharmony_ci
403b815c7f3Sopenharmony_ciIt is **not** possible to build a working universal binary via a single
404b815c7f3Sopenharmony_cicompile/build run on a single CPU.
405b815c7f3Sopenharmony_ci
406b815c7f3Sopenharmony_ciThe problem is that the libsndfile build process detects features of the CPU its
407b815c7f3Sopenharmony_cibeing built for during the configure process and when building a universal
408b815c7f3Sopenharmony_cibinary, configure is only run once and that data is then used for both CPUs.
409b815c7f3Sopenharmony_ciThat configure data will be wrong for one of those CPUs. You will still be able
410b815c7f3Sopenharmony_cito compile libsndfile, and the test suite will pass on the machine you compiled
411b815c7f3Sopenharmony_ciit on. However, if you take the universal binary test suite programs compiled on
412b815c7f3Sopenharmony_cione CPU and run them on the other, the test suite will fail.
413b815c7f3Sopenharmony_ci
414b815c7f3Sopenharmony_ciPart of the problem is that the CPU endian-ness is detected at configure time.
415b815c7f3Sopenharmony_ciYes, I know the Apple compiler defines one of the macros \_\_LITTLE\_ENDIAN\_\_
416b815c7f3Sopenharmony_ciand \_\_BIG\_ENDIAN\_\_, but those macros are not part of the 1999 ISO C
417b815c7f3Sopenharmony_ciStandard and they are not portable.
418b815c7f3Sopenharmony_ci
419b815c7f3Sopenharmony_ciEndian issues are not the only reason why the cross compiled binary will fail.
420b815c7f3Sopenharmony_ciThe configure script also detects other CPU specific idiosyncrasies to provide
421b815c7f3Sopenharmony_cimore optimized code.
422b815c7f3Sopenharmony_ci
423b815c7f3Sopenharmony_ciFinally, the real show stopper problem with universal binaries is the problem
424b815c7f3Sopenharmony_ciwith the test suite. libsndfile contains a huge, comprehensive test suite. When
425b815c7f3Sopenharmony_ciyou compile a universal binary and run the test suite, you only test the native
426b815c7f3Sopenharmony_cicompile. The cross compiled binary (the one with the much higher chance of
427b815c7f3Sopenharmony_cihaving problems) cannot be tested.
428b815c7f3Sopenharmony_ci
429b815c7f3Sopenharmony_ciNow, if you have read this far you're probably thinking there must be a way to
430b815c7f3Sopenharmony_cifix this and there probably is. The problem is that its a hell of a lot of work
431b815c7f3Sopenharmony_ciand would require significant changes to the configure process, the internal
432b815c7f3Sopenharmony_cicode and the test suite. In addition, these changes must not break compilation
433b815c7f3Sopenharmony_cion any of the platforms libsndfile is currently working on.
434b815c7f3Sopenharmony_ci
435b815c7f3Sopenharmony_ci## Q19 : I have project files for Visual Studio / XCode / Whatever. Why don't you distribute them with libsndfile? {#Q019}
436b815c7f3Sopenharmony_ci
437b815c7f3Sopenharmony_ciUse CMake project.
438b815c7f3Sopenharmony_ci
439b815c7f3Sopenharmony_ci## Q20 : Why doesn't libsndfile support MP3? {#Q020}
440b815c7f3Sopenharmony_ci
441b815c7f3Sopenharmony_ci~~In the past, MP3 was not supported because the technology behind MP3 was
442b815c7f3Sopenharmony_cipatented. Those patents have now expired and there is an
443b815c7f3Sopenharmony_ci[open ticket](https://github.com/libsndfile/libsndfile/issues/258) to implement
444b815c7f3Sopenharmony_ciMP3 support.~~
445b815c7f3Sopenharmony_ci
446b815c7f3Sopenharmony_ci**Update :** Starting from version 1.1.0 libsndfile supports MP3 format.
447b815c7f3Sopenharmony_ci
448b815c7f3Sopenharmony_ci## Q21 : How do I use libsndfile in a closed source or commercial program and comply with the license? {#Q021}
449b815c7f3Sopenharmony_ci
450b815c7f3Sopenharmony_ciHere is a checklist of things you need to do to make sure your use of libsndfile
451b815c7f3Sopenharmony_ciin a closed source or commercial project complies with the license libsndfile is
452b815c7f3Sopenharmony_cireleased under, the GNU Lesser General Public License (LGPL):
453b815c7f3Sopenharmony_ci
454b815c7f3Sopenharmony_ci- Make sure you are linking to libsndfile as a shared library (Linux and Unix
455b815c7f3Sopenharmony_ci  systems), Dynamic Link Library (Microsoft Windows) or dynlib (Mac OS X). If
456b815c7f3Sopenharmony_ci  you are using some other operating system that doesn't allow dynamically
457b815c7f3Sopenharmony_ci  linked libraries, you will not be able to use libsndfile unless you release
458b815c7f3Sopenharmony_ci  the source code to your program.
459b815c7f3Sopenharmony_ci- In the licensing documentation for your program, add a statement that your
460b815c7f3Sopenharmony_ci  software depends on libsndfile and that libsndfile is released under the GNU
461b815c7f3Sopenharmony_ci  Lesser General Public License, either
462b815c7f3Sopenharmony_ci  [version 2.1](http://www.gnu.org/licenses/lgpl-2.1.txt) or optionally
463b815c7f3Sopenharmony_ci  [version 3](http://www.gnu.org/licenses/lgpl.txt).
464b815c7f3Sopenharmony_ci- Include the text for both versions of the license, possibly as separate files
465b815c7f3Sopenharmony_ci  named libsndfile_lgpl_v2_1.txt and libsndfile_lgpl_v3.txt.
466b815c7f3Sopenharmony_ci
467b815c7f3Sopenharmony_ci## Q22 : What versions of Windows does libsndfile work on? {#Q022}
468b815c7f3Sopenharmony_ci
469b815c7f3Sopenharmony_ciNew versions of libsndfile binary releases require Wiindows Vista. If you need
470b815c7f3Sopenharmony_ciWindows XP support, you can build DLL from sources, we don't use specific WinXP
471b815c7f3Sopenharmony_cifeatures.
472b815c7f3Sopenharmony_ci
473b815c7f3Sopenharmony_ci## Q23 : I'm cross compiling libsndfile for another platform. How can I run the test suite? {#Q023}
474b815c7f3Sopenharmony_ci
475b815c7f3Sopenharmony_ciSince version 1.0.21 the top level Makefile has an extra make target,
476b815c7f3Sopenharmony_ci'test-tarball'. Building this target creates a tarball called called:
477b815c7f3Sopenharmony_ci
478b815c7f3Sopenharmony_ci    ` libsndfile-testsuite-${host_triplet}-${version}.tar.gz`
479b815c7f3Sopenharmony_ci
480b815c7f3Sopenharmony_ciin the top level directory. This tarball can then be copied to the target
481b815c7f3Sopenharmony_ciplatform. Once untarred and test script `test_wrapper.sh` can be run from the
482b815c7f3Sopenharmony_citop level of the extracted tarball.
483