Git init
[external/libsndfile.git] / doc / FAQ.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2 <HTML>
3
4 <HEAD>
5         <TITLE>
6         libsndfile : Frequently Asked Questions.
7         </TITLE>
8         <META NAME="Author"      CONTENT="Erik de Castro Lopo (erikd AT mega-nerd DOT com)">
9         <META NAME="Description" CONTENT="The libsndfile FAQ.">
10         <META NAME="Keywords"    CONTENT="WAV AIFF AU libsndfile sound audio dsp Linux">
11         <LINK REL="stylesheet" HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
12         <LINK REL="stylesheet" HREF="print.css" TYPE="text/css" MEDIA="print">
13 </HEAD>
14
15 <BODY>
16
17 <H1><B>libsndfile : Frequently Asked Questions.</B></H1>
18 <P>
19 <A HREF="#Q001">Q1 : Do you plan to support XYZ codec in libsndfile?</A><BR>
20 <A HREF="#Q002">Q2 : In version 0 the SF_INFO struct had a pcmbitwidth field
21                 but version 1 does not. Why?</A><BR>
22 <A HREF="#Q003">Q3 : Compiling is really slow on MacOS X. Why?</A><BR>
23 <A HREF="#Q004">Q4 : When trying to compile libsndfile on Solaris I get a "bad
24                 substitution" error during linking. What can I do to fix this?</A><BR>
25 <A HREF="#Q005">Q5 : Why doesn't libsndfile do interleaving/de-interleaving?</A><BR>
26 <A HREF="#Q006">Q6 : What's the best format for storing temporary files?</A><BR>
27 <A HREF="#Q007">Q7 : On Linux/Unix/MacOS X, what's the best way of detecting the
28         presence of libsndfile?</A><BR>
29 <A HREF="#Q008">Q8 : But I just want a simple Makefile! What do I do?</A><BR>
30 <A HREF="#Q009">Q9 : How about adding the ability to write/read sound files to/from
31         memory buffers?</A><BR>
32 <A HREF="#Q010">Q10 : Reading a 16 bit PCM file as normalised floats and then
33         writing them back changes some sample values. Why?</A><BR>
34 <A HREF="#Q011">Q11 : I'm having problems with u-law encoded WAV files generated by
35         libsndfile in Winamp. Why?</A><BR>
36 <A HREF="#Q012">Q12 : I'm looking at sf_read*. What are items? What are frames?</A><BR>
37 <A HREF="#Q013">Q13 : Why can't libsndfile open this Sound Designer II (SD2)
38         file?</A><BR>
39 <A HREF="#Q014">Q14 : I'd like to statically link libsndfile to my closed source
40         application. Can I buy a license so that this is possible?</A><BR>
41 <A HREF="#Q015">Q15 : My program is crashing during a call to a function in libsndfile.
42         Is this a bug in libsndfile?</A><BR>
43 <A HREF="#Q016">Q16 : Will you accept a fix for compiling libsndfile with compiler X?
44         </A><BR>
45 <A HREF="#Q017">Q17 : Can libsndfile read/write files from/to UNIX pipes?
46         </A><BR>
47 <A HREF="#Q018">Q18 : Is it possible to build a Universal Binary on Mac OS X?
48         </A><BR>
49 <A HREF="#Q019">Q19 : I have project files for Visual Studio / XCode / Whatever. Why
50         don't you distribute them with libsndfile?
51         </A><BR>
52 <A HREF="#Q020">Q20 : Why doesn't libsndfile support MP3? Lots of other Open Source
53         projects support it!
54         </A><BR>
55 <A HREF="#Q021">Q21 : How do I use libsndfile in a closed source or commercial program
56         and comply with the license?
57         </A><BR>
58 <A HREF="#Q022">Q22 : What versions of windows does libsndfile work on?
59         </A><BR>
60 <A HREF="#Q023">Q23 : I'm cross compiling libsndfile for another platform. How can I
61         run the test suite?
62         </A><BR>
63 <HR>
64
65 <!-- ========================================================================= -->
66 <A NAME="Q001"></A>
67 <H2><BR><B>Q1 : Do you plan to support XYZ codec in libsndfile?</B></H2>
68 <P>
69 If source code for XYZ codec is available under a suitable license (LGPL, BSD,
70 MIT etc) then yes, I'd like to add it.
71 </P>
72 <P>
73 If suitable documentation is available on how to decode and encode the format
74 then maybe, depending on how much work is involved.
75 </P>
76 <P>
77 If XYZ is some proprietary codec where no source code or documentation is
78 available then no.
79 </P>
80 <P>
81 So if you want support for XYZ codec, first find existing source code or
82 documentation.
83 If you can't find either then the answer is no.
84 </P>
85 <!-- ========================================================================= -->
86 <A NAME="Q002"></A>
87 <H2><BR><B>Q2 : In version 0 the SF_INFO struct had a pcmbitwidth field
88                 but version 1 does not. Why?</B></H2>
89 <P>
90         This was dropped for a number of reasons:
91 </P>
92 <UL>
93         <LI> pcmbitwidth makes little sense on compressed or floating point formats
94         <LI> with the new API you really don't need to know it
95 </UL>
96 <P>
97 As documented
98     <A HREF="http://www.mega-nerd.com/libsndfile/api.html#note1">here</A>
99 there is now a well defined behaviour which ensures that no matter what the
100 bit width of the source file, the scaling always does something sensible.
101 This makes it safe to read 8, 16, 24 and 32 bit PCM files using sf_read_short()
102 and always have the optimal behaviour.
103 </P>
104
105 <!-- ========================================================================= -->
106 <A NAME="Q003"></A>
107 <H2><BR><B>Q3 : Compiling is really slow on MacOS X. Why?</B></H2>
108 <P>
109 When you configure and compile libsndfile, it uses the /bin/sh shell for a number
110 of tasks (ie configure script and libtool).
111 Older versions of OS X (10.2?) shipped a really crappy Bourne shell as /bin/sh
112 which resulted in <b>really</b> slow compiles.
113 Newer version of OS X ship GNU Bash as /bin/sh and this answer doesn't apply in that
114 case.
115 </P>
116 <P>
117 To fix this I suggest that you install the GNU Bash shell, rename /bin/sh to
118 /bin/sh.old and make a symlink from /bin/sh to the bash shell.
119 Bash is designed to behave as a Bourne shell when is is called as /bin/sh.
120 </P>
121 <P>
122 When I did this on my iBook running MacOS X, compile times dropped from 13 minutes
123 to 3 minutes.
124 </P>
125
126 <!-- ========================================================================= -->
127 <A NAME="Q004"></A>
128 <H2><BR><B>Q4 : When trying to compile libsndfile on Solaris I get a "bad
129                 substitution" error on linking. Why?</B></H2>
130 <P>
131 It seems that the Solaris Bourne shell disagrees with GNU libtool.
132 </P>
133 <P>
134 To fix this I suggest that you install the GNU Bash shell, rename /bin/sh to
135 /bin/sh.old and make a symlink from /bin/sh to the bash shell.
136 Bash is designed to behave as a Bourne shell when is is called as /bin/sh.
137 </P>
138
139 <!-- ========================================================================= -->
140 <A NAME="Q005"></A>
141 <H2><BR><B>Q5 : Why doesn't libsndfile do interleaving/de-interleaving?</B></H2>
142 <P>
143 This problem is bigger than it may seem at first.
144 </P>
145 <P>
146 For a stereo file, it is a pretty safe bet that a simple interleaving/de-interleaving
147 could satisfy most users.
148 However, for files with more than 2 channels this is unlikely to be the case.
149 If the user has a 4 channel file and want to play that file on a stereo output
150 sound card they either want the first 2 channels or they want some mixed combination
151 of the 4 channels.
152 </P>
153 <P>
154 When you add more channels, the combinations grow exponentially and it becomes
155 increasingly difficult to cover even a sensible subset of the possible combinations.
156 On top of that, coding any one style of interleaver/de-interleaver is trivial, while
157 coding one that can cover all combinations is far from trivial.
158 This means that this feature will not be added any time soon.
159 </P>
160
161 <!-- ========================================================================= -->
162 <A NAME="Q006"></A>
163 <H2><BR><B>Q6 : What's the best format for storing temporary files?</B></H2>
164
165 <P>
166 When you want to store temporary data there are a number of requirements;
167 </P>
168 <UL>
169         <LI> A simple, easy to parse header.
170         <LI> The format must provide the fastest possible read and write rates (ie
171                 avoid conversions and encoding/decoding).
172         <LI> The file format must be reasonably common and playable by most players.
173         <LI> Able to store data in either endian-ness.
174 </UL>
175 <P>
176 The format which best meets these requirements is AU, which allows data to be
177 stored in any one of short, int, float and double (among others) formats.
178 </P>
179 <P>
180 For instance, if an application uses float data internally, its temporary files
181 should use a format of (SF_ENDIAN_CPU | SF_FORMAT_AU | SF_FORMAT_FLOAT) which
182 will store big endian float data in big endian CPUs and little endian float data
183 on little endian CPUs.
184 Reading and writing this format will not require any conversions or byte swapping
185 regardless of the host CPU.
186 </P>
187
188 <!-- ========================================================================= -->
189
190 <A NAME="Q007"></A>
191 <H2><BR><B>Q7 : On Linux/Unix/MaxOS X, what's the best way of detecting the presence
192         of libsndfile using autoconf?</B></H2>
193
194 <P>
195 libsndfile uses the pkg-config (man pkg-config) method of registering itself with the
196 host system.
197 The best way of detecting its presence is using something like this in configure.ac
198 (or configure.in):
199 </P>
200 <PRE>
201         PKG_CHECK_MODULES(SNDFILE, sndfile >= 1.0.2, ac_cv_sndfile=1, ac_cv_sndfile=0)
202
203         AC_DEFINE_UNQUOTED([HAVE_SNDFILE],${ac_cv_sndfile},
204                         [Set to 1 if you have libsndfile.])
205
206         AC_SUBST(SNDFILE_CFLAGS)
207         AC_SUBST(SNDFILE_LIBS)
208 </PRE>
209 <P>
210 This will automatically set the <B>SNDFILE_CFLAGS</B> and <B>SNDFILE_LIBS</B>
211 variables which can be used in Makefile.am like this:
212 </P>
213 <PRE>
214         SNDFILE_CFLAGS = @SNDFILE_CFLAGS@
215         SNDFILE_LIBS = @SNDFILE_LIBS@
216 </PRE>
217 <P>
218 If you install libsndfile from source, you will probably need to set the
219 <B>PKG_CONFIG_PATH</B> environment variable as suggested at the end of the
220 libsndfile configure process. For instance on my system I get this:
221 </P>
222 <PRE>
223         -=-=-=-=-=-=-=-=-=-= Configuration Complete =-=-=-=-=-=-=-=-=-=-
224
225           Configuration summary :
226
227             Version : ..................... 1.0.5
228             Experimental code : ........... no
229
230           Tools :
231
232             Compiler is GCC : ............. yes
233             GCC major version : ........... 3
234
235           Installation directories :
236
237             Library directory : ........... /usr/local/lib
238             Program directory : ........... /usr/local/bin
239             Pkgconfig directory : ......... /usr/local/lib/pkgconfig
240
241         Compiling some other packages against libsndfile may require
242         the addition of "/usr/local/lib/pkgconfig" to the
243         PKG_CONFIG_PATH environment variable.
244 </PRE>
245
246 <!-- ========================================================================= -->
247
248 <A NAME="Q008"></A>
249 <H2><BR><B>Q8 : But I just want a simple Makefile! What do I do?</B></H2>
250
251 <P>
252 The <B>pkg-config</B> program makes finding the correct compiler flag values and
253 library location far easier.
254 During the installation of libsndfile, a file named <B>sndfile.pc</B> is installed
255 in the directory <B>${libdir}/pkgconfig</B> (ie if libsndfile is installed in
256 <B>/usr/local/lib</B>, <B>sndfile.pc</B> will be installed in
257 <B>/usr/local/lib/pkgconfig/</B>).
258 </P>
259 <P>
260 In order for pkg-config to find sndfile.pc it may be necessary to point the
261 environment variable <B>PKG_CONFIG_PATH</B> in the right direction.
262 </P>
263 <PRE>
264         export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
265 </PRE>
266
267 <P>
268 Then, to compile a C file into an object file, the command would be:
269 </P>
270 <PRE>
271         gcc `pkg-config --cflags sndfile` -c somefile.c
272 </PRE>
273 <P>
274 and to link a number of objects into an executable that links against libsndfile,
275 the command would be:
276 </P>
277 <PRE>
278         gcc `pkg-config --libs sndfile` obj1.o obj2.o -o program
279 </PRE>
280
281 <!-- ========================================================================= -->
282
283 <A NAME="Q009"></A>
284 <H2><BR><B>Q9 : How about adding the ability to write/read sound files to/from
285         memory buffers?</B></H2>
286
287 <P>
288 This has been added for version 1.0.13.
289 </P>
290
291 <!-- ========================================================================= -->
292
293 <A NAME="Q010"></A>
294 <H2><BR><B>Q10 : Reading a 16 bit PCM file as normalised floats and then
295         writing them back changes some sample values. Why?</B></H2>
296
297 <P>
298 This is caused by the fact that the conversion from 16 bit short to float is
299 done by dividing by 32768 (0x8000 in hexadecimal) while the conversion from
300 float to 16 bit short is done by multiplying by 32767 (0x7FFF in hex).
301 So for instance, a value in a 16 bit PCM file of 20000 gets read as a floating
302 point number of 0.6103515625 (20000.0 / 0x8000).
303 Converting that back to a 16 bit short results in a value of 19999.3896484375
304 (0.6103515625 * 0x7FFF) which then gets rounded down to 19999.
305 </P>
306 <P>
307 You will notice that for this particular case, the error is 1 in 20000 or
308 0.005%.
309 Interestingly, for values of less than 16369, dividing by 0x8000 followed
310 by multiplying by 0x7FFF and then rounding the result, gives back the
311 original value.
312 It turns out that as long as the host operating system supplies the 1999 ISO
313 C Standard functions <B>lrintf</B> and <B>lrint</B> (or a replacement has
314 been supplied) then the maximum possible error is 1 in 16369 or about 0.006%.
315 </P>
316 <P>
317 Regardless of the size of the error, the reason why this is done is rather
318 subtle.
319 </P>
320 <P>
321 In a file containing 16 bit PCM samples, the values are restricted to the range
322 [-32768, 32767] while we want floating point values in the range [-1.0, 1.0].
323 The only way to do this conversion is to do a floating point division by a value
324 of 0x8000.
325 Converting the other way, the only way to ensure that floating point values in
326 the range [-1.0, 1.0] are within the valid range allowed by a 16 bit short is
327 to multiply by 0x7FFF.
328 </P>
329 <P>
330 Some people would say that this is a severe short-coming of libsndfile.
331 I would counter that anybody who is constantly converting back and forth
332 between 16 bit shorts and normalised floats is going to suffer other losses
333 in audio quality that they should also be concerned about.
334 </P>
335 <P>
336 Since this problem only occurs when converting between integer data on disk and
337 normalized floats in the application, it can be avoided by using something
338 other than normalized floats in the application.
339 Alternatives to normalized floats are the <b>short</b> and <b>int</b> data
340 types (ie using sf_read_short or sf_read_int) or using un-normalized floats
341 (see
342         <a href="http://www.mega-nerd.com/libsndfile/command.html#SFC_SET_NORM_FLOAT">
343         SFC_SET_NORM_FLOAT</a>).
344 </P>
345 <P>
346 Another way to deal with this problem is to consider 16 bit short data as a
347 final destination format only, not as an intermediate storage format.
348 All intermediate data (ie which is going to be processed further) should be
349 stored in floating point format which is supported by all of the most common
350 file formats.
351 If floating point files are considered too large (2 times the size of a 16 bit
352 PCM file), it would also be possible to use 24 bit PCM as an intermediate
353 storage format (and which is also supported by most common file types).
354 </P>
355
356 <!-- ========================================================================= -->
357
358 <A NAME="Q011"></A>
359 <H2><BR><B>Q11 : I'm having problems with u-law encoded WAV files generated by
360         libsndfile in Winamp. Why?
361 </B></H2>
362
363 <P>
364 This is actually a Winamp problem.
365 The official Microsoft spec suggests that the 'fmt ' chunk should be 18 bytes.
366 Unfortunately at least one of Microsoft's own applications (Sound Recorder on
367 Win98 I believe) did not accept 18 bytes 'fmt ' chunks.
368 </P>
369 <P>
370 Michael Lee did some experimenting and found that:
371 </P>
372 <PRE>
373     I have checked that Windows Media Player 9, QuickTime Player 6.4,
374     RealOne Player 2.0 and GoldWave 5.06 can all play u-law files with
375     16-byte or 18-byte 'fmt ' chunk. Only Winamp (2.91) and foobar2000
376     are unable to play u-law files with 16-byte 'fmt ' chunk.
377 </PRE>
378
379 <P>
380 Even this is a very small sampling of all the players out there.
381 For that reason it is probably not a good idea to change this now because there
382 is the risk of breaking something that currently works.
383 </P>
384
385 <!-- ========================================================================= -->
386
387 <A NAME="Q012"></A>
388 <H2><BR><B>Q12 : I'm looking at sf_read*. What are items? What are frames?
389 </B></H2>
390
391 <P>
392 For a sound file with only one channel, a frame is the same as a item.
393 </P>
394 <P>
395 For multi channel sound files, a single frame contains a single item for
396 each channel.
397 </P>
398
399 <!-- ========================================================================= -->
400
401 <A NAME="Q013"></A>
402 <H2><BR><B>Q13 : Why can't libsndfile open this Sound Designer II (SD2) file?
403 </B></H2>
404
405 <P>
406 This is somewhat complicated.
407 First some background.
408 </P>
409
410 <P>
411 SD2 files are native to the Apple Macintosh platform and use features of
412 the Mac filesystem (file resource forks) to store the file's sample rate,
413 number of channels, sample width and more.
414 When you look at a file and its resource fork on Mac OS X it looks like
415 this:
416 </P>
417
418 <PRE>
419         -rw-r--r--  1 erikd erikd   46512 Oct 18 22:57 file.sd2
420         -rw-r--r--  1 erikd erikd     538 Oct 18 22:57 file.sd2/rsrc
421 </PRE>
422
423 <P>
424 Notice how the file itself looks like a directory containing a single file
425 named <B>rsrc</B>.
426 When libsndfile is compiled for MacOS X, it should open (for write and read)
427 SD2 file with resource forks like this without any problems.
428 It will also handle files with the resource fork in a separate file as
429 described below.
430 </P>
431
432 <P>
433 When SD2 files are moved to other platforms, the resource fork of the file
434 can sometimes be dropped altogether.
435 All that remains is the raw audio data and no information about the number
436 of channels, sample rate or bit width which makes it a little difficult for
437 libsndfile to open the file.
438 </P>
439
440 <P>
441 However, it is possible to safely move an SD2 file to a Linux or Windows
442 machine.
443 For instance, when an SD2 file is copied from inside MacOS X to a windows
444 shared directory or a Samba share (ie Linux), MacOS X is clever enough to
445 store the resource fork of the file in a separate hidden file in the
446 same directory like this:
447 </P>
448 <PRE>
449         -rw-r--r--  1 erikd erikd     538 Oct 18 22:57 ._file.sd2
450         -rw-r--r--  1 erikd erikd   46512 Oct 18 22:57 file.sd2
451 </PRE>
452
453 <P>
454 Regardless of what platform it is running on, when libsndfile is asked to
455 open a file named <B>"foo"</B> and it can't recognize the file type from
456 the data in the file, it will attempt to open the resource fork and if
457 that fails, it then tries to open a file named <B>"._foo"</B> to see if
458 the file has a valid resource fork.
459 This is the same regardless of whether the file is being opened for read
460 or write.
461 </P>
462
463 <P>
464 In short, libsndfile should open SD2 files with a valid resource fork on
465 all of the platforms that libsndfile supports.
466 If a file has lost its resource fork, the only option is the open the file
467 using the SF_FORMAT_RAW option and guessing its sample rate, channel count
468 and bit width.
469 </P>
470
471 <P>
472 Occasionally, when SD2 files are moved to other systems, the file is
473         <A HREF="http://www.macdisk.com/binhexen.php3">BinHexed</A>
474 which wraps the resource fork and the data fork together.
475 For these files, it would be possible to write a BinHex parser but
476 there is not a lot to gain considering how rare these BinHexed SD2
477 files are.
478 </P>
479
480 <!-- ========================================================================= -->
481 <A NAME="Q014"></A>
482 <H2><BR><B>Q14 : I'd like to statically link libsndfile to my closed source
483         application. Can I buy a license so that this is possible?
484 </B></H2>
485
486 <P>
487 Unfortunately no.
488 libsndfile contains code written by other people who have agreed that their
489 code be used under the GNU LGPL but no more.
490 Even if they were to agree, there would be significant difficulties in
491 dividing up the payments fairly.
492 </P>
493
494 <P>
495 The <B>only</B> way you can legally use libsndfile as a statically linked
496 library is if your application is released under the GNU GPL or LGPL.
497 </P>
498
499 <!-- ========================================================================= -->
500 <A NAME="Q015"></A>
501 <H2><BR><B>Q15 : My program is crashing during a call to a function in libsndfile.
502         Is this a bug in libsndfile?
503 </B></H2>
504
505 <P>
506 libsndfile is being used by large numbers of people all over the world
507 without any problems like this. That means that it is much more likely
508 that your code has a bug than libsndfile. However, it is still possible
509 that there is a bug in libsndfile.
510 </P>
511 <P>
512 To figure out whether it is your code or libsndfile you should do the
513 following:
514 </P>
515         <UL>
516         <LI>Make sure you are compiling your code with warnings switched on and
517                 that you fix as many warnings as possible.
518                 With the GNU compiler (gcc) I would recommend at least
519                 <B>-W -Wall -Werror</B> which will force you to fix all warnings
520                 before you can run the code.
521         <LI>Try using a memory debugger.
522                 <A HREF="http://valgrind.kde.org/">Valgrind</A> on x86 Linux is excellent.
523                 <A HREF="http://www.ibm.com/software/awdtools/purify/">Purify</A> also
524                 has a good reputation.
525         <LI>If the code is clean after the above two steps and you still get
526                 a crash in libsndfile, then send me a small snippet of code (no
527                 more than 30-40 lines) which includes the call to sf_open() and
528                 also shows how all variables passed to/returned from sf_open()
529                 are defined.
530         </UL>
531
532 <!-- ========================================================================= -->
533 <A NAME="Q016"></A>
534 <H2><BR><B>Q16 : Will you accept a fix for compiling libsndfile with compiler X?
535 </B></H2>
536
537 <P>
538 If compiler X is a C++ compiler then no.
539 C and C++ are different enough to make writing code that compiles as valid C
540 and valid C++ too difficult.
541 I would rather spend my time fixing bugs and adding features.
542 </P>
543
544 <P>
545 If compiler X is a C compiler then I will do what I can as long as that does
546 not hamper the correctness, portability and maintainability of the existing
547 code.
548 It should be noted however that libsndfile uses features specified by the 1999
549 ISO C Standard.
550 This can make compiling libsndfile with some older compilers difficult.
551 </P>
552
553 <!-- ========================================================================= -->
554 <A NAME="Q017"></A>
555 <H2><BR><B>Q17 : Can libsndfile read/write files from/to UNIX pipes?
556 </B></H2>
557
558 <P>
559 Yes, libsndfile can read files from pipes.
560 Unfortunately, the write case is much more complicated.
561 </P>
562
563 <P>
564 File formats like AIFF and WAV have information at the start of the file (the
565 file header) which states the length of the file, the number of sample frames
566 etc.
567 This information must be filled in correctly when the file header is written,
568 but this information is not reliably known until the file is closed.
569 This means that libsndfile cannot write AIFF, WAV and many other file types
570 to a pipe.
571 </P>
572
573 <P>
574 However, there is at least one file format (AU) which is specifically designed
575 to be written to a pipe.
576 Like AIFF and WAV, AU has a header with a sample frames field, but it is
577 specifically allowable to set that frames field to 0x7FFFFFFF if the file
578 length is not known when the header is written.
579 The AU file format can also hold data in many of the standard formats (ie
580 SF_FORMAT_PCM_16, SF_FORMAT_PCM_24, SF_FORMAT_FLOAT etc) as well as allowing
581 data in both big and little endian format.
582 </P>
583
584 <P>
585 See also <A HREF="#Q006">FAQ Q6</A>.
586 </P>
587
588 <!-- ========================================================================= -->
589 <A NAME="Q018"></A>
590 <H2><BR><B>Q18 : Is it possible to build a Universal Binary on Mac OS X?
591 </B></H2>
592
593 <P>
594 Yes, but you must do two separate configure/build/test runs; one on PowerPC
595 and one on Intel.
596 It is then possible to merge the binaries into a single universal binary using
597 one of the programs in the Apple tool chain.
598 </P>
599
600 <P>
601 It is <b>not</b> possible to build a working universal binary via a single
602 compile/build run on a single CPU.
603 </P>
604
605 <P>
606 The problem is that the libsndfile build process detects features of the CPU its
607 being built for during the configure process and when building a universal binary,
608 configure is only run once and that data is then used for both CPUs.
609 That configure data will be wrong for one of those CPUs.
610 You will still be able to compile libsndfile, and the test suite will pass on
611 the machine you compiled it on.
612 However, if you take the universal binary test suite programs compiled on one
613 CPU and run them on the other, the test suite will fail.
614 </P>
615
616 <P>
617 Part of the problem is the the CPU endian-ness is detected at configure time.
618 Yes, I know the Apple compiler defines one of the macros __LITTLE_ENDIAN__
619 and __BIG_ENDIAN__, but those macros are not part of the 1999 ISO C Standard
620 and they are not portable.
621 </P>
622
623 <P>
624 Endian issues are not the only reason why the cross compiled binary will fail.
625 The configure script also detects other CPU specific idiosyncrasies to provide
626 more optimized code.
627 </P>
628
629 <P>
630 Finally, the real show stopper problem with universal binaries is the problem
631 with the test suite.
632 libsndfile contains a huge, comprehensive test suite.
633 When you compile a universal binary and run the test suite, you only test the
634 native compile.
635 The cross compiled binary (the one with the much higher chance of having
636 problems) cannot be tested.
637 </P>
638
639 <P>
640 Now, if you have read this far you're probably thinking there must be a way
641 to fix this and there probably is.
642 The problem is that its a hell of a lot of work and would require significant
643 changes to the configure process, the internal code and the test suite.
644 In addition, these changes must not break compilation on any of the platforms
645 libsndfile is currently working on.
646 </p>
647
648
649 <!-- ========================================================================= -->
650 <A NAME="Q019"></A>
651 <H2><BR><B>Q19 : I have project files for Visual Studio / XCode / Whatever. Why
652         don't you distribute them with libsndfile?
653 </B></H2>
654
655 <P>
656 There's a very good reason for this.
657 I will only distribute things that I actually have an ability to test and
658 maintain.
659 Project files for a bunch of different compilers and Integrated Development
660 Environments are simply too difficult to maintain.
661 </P>
662
663 <P>
664 The problem is that every time I add a new file to libsndfile or rename an
665 existing file I would have to modify all the project files and then test that
666 libsndfile still built with all the different compilers.
667 </P>
668
669 <P>
670 Maintaining these project files is also rather difficult if I don't have access
671 to the required compiler/IDE.
672 If I just edit the project files without testing them I will almost certainly
673 get it wrong.
674 If I release a version of libsndfile with broken project files, I'll get a bunch
675 of emails from people complaining about it not building and have no way of
676 fixing or even testing it.
677 </P>
678
679 <P>
680 I currently release sources that I personally test on Win32, Linux and
681 MacOS X (PowerPC) using the compiler I trust (GNU GCC).
682 Supporting one compiler on three (actually much more because GCC is available
683 almost everywhere) platforms is doable without too much pain.
684 I also release binaries for Win32 with instructions on how to use those
685 binaries with Visual Studio.
686 As a guy who is mainly interested in Linux, I'm not to keen to jump through
687 a bunch of hoops to support compilers and operating systems I don't use.
688 </P>
689
690 <P>
691 So, I hear you want to volunteer to maintain the project files for Some Crappy
692 Compiler 2007?
693 Well sorry, that won't work either.
694 I have had numerous people over the years offer to maintaining the project
695 files for Microsoft's Visual Studio.
696 Every single time that happened, they maintained it for a release or two and
697 then disappeared off the face of the earth.
698 Hence, I'm not willing to enter into an arrangement like that again.
699 </P>
700
701 <!-- ========================================================================= -->
702 <A NAME="Q020"></A>
703 <H2><BR><B>Q20 : Why doesn't libsndfile support MP3? Lots of other Open Source
704         projects support it!
705 </B></H2>
706
707 <P>
708 MP3 is not supported for one very good reason; doing so requires the payment
709 of licensing fees.
710 As can be seen from
711         <a href="http://www.mp3licensing.com/royalty/software.html">
712         mp3licensing.com</a>
713 the required royalty payments are not cheap.
714 </P>
715
716 <p>
717 Yes, I know other libraries ignore the licensing requirements, but their legal
718 status is extremely dubious.
719 At any time, the body selling the licenses could go after the authors of those
720 libraries.
721 Some of those authors may be students and hence wouldn't be worth pursuing.
722 </P>
723
724 <p>
725 However, libsndfile is released under the name of a company, Mega Nerd Pty Ltd;
726 a company which has income from from libsamplerate licensing, libsndfile based
727 consulting income and other unrelated consulting income.
728 Adding MP3 support to libsndfile could place that income would be under legal
729 threat.
730 </p>
731
732 <p>
733 Fortunately, Ogg Vorbis exists as an alternative to MP3.
734 Support for Ogg Vorbis was added to libsndfile (mostly due to the efforts of
735 John ffitch of the Csound project) in version 1.0.18.
736 </p>
737
738
739 <!-- ========================================================================= -->
740 <A NAME="Q021"></A>
741 <H2><BR><B>Q21 : How do I use libsndfile in a closed source or commercial program
742         and comply with the license?
743 </B></H2>
744
745 <p>
746 Here is a checklist of things you need to do to make sure your use of libsndfile
747 in a closed source or commercial project complies with the license libsndfile is
748 released under, the GNU Lesser General Public License (LGPL):
749 </p>
750
751 <ul>
752 <li>Make sure you are linking to libsndfile as a shared library (Linux and Unix
753         systems), Dynamic Link Library (Microsoft Windows) or dynlib (Mac OS X).
754         If you are using some other operating system that doesn't allow dynamically
755         linked libraries, you will not be able to use libsndfile unless you release
756         the source code to your program.
757 <li>In the licensing documentation for your program, add a statement that your
758         software depends on libsndfile and that libsndfile is released under the GNU
759         Lesser General Public License, either
760                 <a href="http://www.gnu.org/licenses/lgpl-2.1.txt">version 2.1</a>
761         or optionally
762                 <a href="http://www.gnu.org/licenses/lgpl.txt">version 3</a>.
763 <li>Include the text for both versions of the license, possibly as separate
764         files named libsndfile_lgpl_v2_1.txt and libsndfile_lgpl_v3.txt.
765 </ul>
766
767 <!-- ========================================================================= -->
768 <A NAME="Q022"></A>
769 <H2><BR><B>Q22 : What versions of Windows does libsndfile work on?
770 </B></H2>
771
772 <p>
773 Currently the precompiled windows binaries are thoroughly tested on Windows XP.
774 As such, they should also work on Win2k and Windows Vista.
775 They may also work on earlier versions of Windows.
776 </p>
777
778 <p>
779 Since version 0.1.18 I have also been releasing precompiled binaries for Win64,
780 the 64 bit version of Windows.
781 These binaries have received much less testing than the  32 bit versions, but
782 should work as expected.
783 I'd be very interested in receiving feedback  on these binaries.
784 </p>
785
786 <!-- ========================================================================= -->
787 <A NAME="Q023"></A>
788 <H2><BR><B>Q23 : I'm cross compiling libsndfile for another platform. How can I
789         run the test suite?
790 </B></H2>
791
792 <p>
793 </p>
794
795 <p>
796 Since version 1.0.21 the top level Makefile has an extra make target,
797 'test-tarball'.
798 Building this target creates a tarball called called:
799 </p>
800
801 <center><tt>
802 libsndfile-testsuite-${host_triplet}-${version}.tar.gz
803 </tt></center>
804
805 <p>
806 in the top level directory.
807 This tarball can then be copied to the target platform.
808 Once untarred and test script <tt>test_wrapper.sh</tt> can be run from
809 the top level of the extracted tarball.
810 </p>
811
812 <!-- ========================================================================= -->
813 <HR>
814 <P>
815         The libsndfile home page is here :
816                 <A HREF="http://www.mega-nerd.com/libsndfile/">
817                         http://www.mega-nerd.com/libsndfile/</A>.
818 <BR>
819 Version : 1.0.21
820 </P>
821
822 </BODY>
823 </HTML>