blob: ce0164a23e61003795c770158b5da2dd2cf36364 [file] [log] [blame]
Alexandre Lision7c6f4a62013-09-05 13:27:01 -04001<!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>
69If source code for XYZ codec is available under a suitable license (LGPL, BSD,
70MIT etc) then yes, I'd like to add it.
71</P>
72<P>
73If suitable documentation is available on how to decode and encode the format
74then maybe, depending on how much work is involved.
75</P>
76<P>
77If XYZ is some proprietary codec where no source code or documentation is
78available then no.
79</P>
80<P>
81So if you want support for XYZ codec, first find existing source code or
82documentation.
83If 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>
97As documented
98 <A HREF="http://www.mega-nerd.com/libsndfile/api.html#note1">here</A>
99there is now a well defined behaviour which ensures that no matter what the
100bit width of the source file, the scaling always does something sensible.
101This makes it safe to read 8, 16, 24 and 32 bit PCM files using sf_read_short()
102and 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>
109When you configure and compile libsndfile, it uses the /bin/sh shell for a number
110of tasks (ie configure script and libtool).
111Older versions of OS X (10.2?) shipped a really crappy Bourne shell as /bin/sh
112which resulted in <b>really</b> slow compiles.
113Newer version of OS X ship GNU Bash as /bin/sh and this answer doesn't apply in that
114case.
115</P>
116<P>
117To 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.
119Bash is designed to behave as a Bourne shell when is is called as /bin/sh.
120</P>
121<P>
122When I did this on my iBook running MacOS X, compile times dropped from 13 minutes
123to 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>
131It seems that the Solaris Bourne shell disagrees with GNU libtool.
132</P>
133<P>
134To 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.
136Bash 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>
143This problem is bigger than it may seem at first.
144</P>
145<P>
146For a stereo file, it is a pretty safe bet that a simple interleaving/de-interleaving
147could satisfy most users.
148However, for files with more than 2 channels this is unlikely to be the case.
149If the user has a 4 channel file and want to play that file on a stereo output
150sound card they either want the first 2 channels or they want some mixed combination
151of the 4 channels.
152</P>
153<P>
154When you add more channels, the combinations grow exponentially and it becomes
155increasingly difficult to cover even a sensible subset of the possible combinations.
156On top of that, coding any one style of interleaver/de-interleaver is trivial, while
157coding one that can cover all combinations is far from trivial.
158This 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>
166When 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>
176The format which best meets these requirements is AU, which allows data to be
177stored in any one of short, int, float and double (among others) formats.
178</P>
179<P>
180For instance, if an application uses float data internally, its temporary files
181should use a format of (SF_ENDIAN_CPU | SF_FORMAT_AU | SF_FORMAT_FLOAT) which
182will store big endian float data in big endian CPUs and little endian float data
183on little endian CPUs.
184Reading and writing this format will not require any conversions or byte swapping
185regardless 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>
195libsndfile uses the pkg-config (man pkg-config) method of registering itself with the
196host system.
197The 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>
210This will automatically set the <B>SNDFILE_CFLAGS</B> and <B>SNDFILE_LIBS</B>
211variables 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>
218If 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
220libsndfile 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>
252The <B>pkg-config</B> program makes finding the correct compiler flag values and
253library location far easier.
254During the installation of libsndfile, a file named <B>sndfile.pc</B> is installed
255in 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>
260In order for pkg-config to find sndfile.pc it may be necessary to point the
261environment 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>
268Then, 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>
274and to link a number of objects into an executable that links against libsndfile,
275the 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>
288This 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>
298This is caused by the fact that the conversion from 16 bit short to float is
299done by dividing by 32768 (0x8000 in hexadecimal) while the conversion from
300float to 16 bit short is done by multiplying by 32767 (0x7FFF in hex).
301So for instance, a value in a 16 bit PCM file of 20000 gets read as a floating
302point number of 0.6103515625 (20000.0 / 0x8000).
303Converting 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>
307You will notice that for this particular case, the error is 1 in 20000 or
3080.005%.
309Interestingly, for values of less than 16369, dividing by 0x8000 followed
310by multiplying by 0x7FFF and then rounding the result, gives back the
311original value.
312It turns out that as long as the host operating system supplies the 1999 ISO
313C Standard functions <B>lrintf</B> and <B>lrint</B> (or a replacement has
314been supplied) then the maximum possible error is 1 in 16369 or about 0.006%.
315</P>
316<P>
317Regardless of the size of the error, the reason why this is done is rather
318subtle.
319</P>
320<P>
321In 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].
323The only way to do this conversion is to do a floating point division by a value
324of 0x8000.
325Converting the other way, the only way to ensure that floating point values in
326the range [-1.0, 1.0] are within the valid range allowed by a 16 bit short is
327to multiply by 0x7FFF.
328</P>
329<P>
330Some people would say that this is a severe short-coming of libsndfile.
331I would counter that anybody who is constantly converting back and forth
332between 16 bit shorts and normalised floats is going to suffer other losses
333in audio quality that they should also be concerned about.
334</P>
335<P>
336Since this problem only occurs when converting between integer data on disk and
337normalized floats in the application, it can be avoided by using something
338other than normalized floats in the application.
339Alternatives to normalized floats are the <b>short</b> and <b>int</b> data
340types (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>
346Another way to deal with this problem is to consider 16 bit short data as a
347final destination format only, not as an intermediate storage format.
348All intermediate data (ie which is going to be processed further) should be
349stored in floating point format which is supported by all of the most common
350file formats.
351If floating point files are considered too large (2 times the size of a 16 bit
352PCM file), it would also be possible to use 24 bit PCM as an intermediate
353storage 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>
364This is actually a Winamp problem.
365The official Microsoft spec suggests that the 'fmt ' chunk should be 18 bytes.
366Unfortunately at least one of Microsoft's own applications (Sound Recorder on
367Win98 I believe) did not accept 18 bytes 'fmt ' chunks.
368</P>
369<P>
370Michael 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>
380Even this is a very small sampling of all the players out there.
381For that reason it is probably not a good idea to change this now because there
382is 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>
392An <tt>item</tt>tt> is a single sample of the data type you are reading; ie a
393single <tt>short</tt> value for <tt>sf_read_short</tt> or a single <tt>float</tt>
394for <tt>sf_read_float</tt>.
395</P>
396
397For a sound file with only one channel, a frame is the same as a item (ie a
398single sample) while for multi channel sound files, a single frame contains a
399single item for each channel.
400</P>
401
402<P>
403Here are two simple, correct examples, both of which are assumed to be working
404on a stereo file, first using items:
405</P>
406
407<PRE>
408 #define CHANNELS 2
409 short data [CHANNELS * 100] ;
410 sf_count items_read = sf_read_short (file, data, 200) ;
411 assert (items_read == 200) ;
412</PRE>
413
414<P>
415and now readng the exact same amount of data using frames:
416</P>
417
418<PRE>
419 #define CHANNELS 2
420 short data [CHANNELS * 100] ;
421 sf_count frames_read = sf_readf_short (file, data, 100) ;
422 assert (frames_read == 100) ;
423</PRE>
424
425<!-- ========================================================================= -->
426
427<A NAME="Q013"></A>
428<H2><BR/><B>Q13 : Why can't libsndfile open this Sound Designer II (SD2) file?
429</B></H2>
430
431<P>
432This is somewhat complicated.
433First some background.
434</P>
435
436<P>
437SD2 files are native to the Apple Macintosh platform and use features of
438the Mac filesystem (file resource forks) to store the file's sample rate,
439number of channels, sample width and more.
440When you look at a file and its resource fork on Mac OS X it looks like
441this:
442</P>
443
444<PRE>
445 -rw-r--r-- 1 erikd erikd 46512 Oct 18 22:57 file.sd2
446 -rw-r--r-- 1 erikd erikd 538 Oct 18 22:57 file.sd2/rsrc
447</PRE>
448
449<P>
450Notice how the file itself looks like a directory containing a single file
451named <B>rsrc</B>.
452When libsndfile is compiled for MacOS X, it should open (for write and read)
453SD2 file with resource forks like this without any problems.
454It will also handle files with the resource fork in a separate file as
455described below.
456</P>
457
458<P>
459When SD2 files are moved to other platforms, the resource fork of the file
460can sometimes be dropped altogether.
461All that remains is the raw audio data and no information about the number
462of channels, sample rate or bit width which makes it a little difficult for
463libsndfile to open the file.
464</P>
465
466<P>
467However, it is possible to safely move an SD2 file to a Linux or Windows
468machine.
469For instance, when an SD2 file is copied from inside MacOS X to a windows
470shared directory or a Samba share (ie Linux), MacOS X is clever enough to
471store the resource fork of the file in a separate hidden file in the
472same directory like this:
473</P>
474<PRE>
475 -rw-r--r-- 1 erikd erikd 538 Oct 18 22:57 ._file.sd2
476 -rw-r--r-- 1 erikd erikd 46512 Oct 18 22:57 file.sd2
477</PRE>
478
479<P>
480Regardless of what platform it is running on, when libsndfile is asked to
481open a file named <B>"foo"</B> and it can't recognize the file type from
482the data in the file, it will attempt to open the resource fork and if
483that fails, it then tries to open a file named <B>"._foo"</B> to see if
484the file has a valid resource fork.
485This is the same regardless of whether the file is being opened for read
486or write.
487</P>
488
489<P>
490In short, libsndfile should open SD2 files with a valid resource fork on
491all of the platforms that libsndfile supports.
492If a file has lost its resource fork, the only option is the open the file
493using the SF_FORMAT_RAW option and guessing its sample rate, channel count
494and bit width.
495</P>
496
497<P>
498Occasionally, when SD2 files are moved to other systems, the file is
499 <A HREF="http://www.macdisk.com/binhexen.php3">BinHexed</A>
500which wraps the resource fork and the data fork together.
501For these files, it would be possible to write a BinHex parser but
502there is not a lot to gain considering how rare these BinHexed SD2
503files are.
504</P>
505
506<!-- ========================================================================= -->
507<A NAME="Q014"></A>
508<H2><BR/><B>Q14 : I'd like to statically link libsndfile to my closed source
509 application. Can I buy a license so that this is possible?
510</B></H2>
511
512<P>
513Unfortunately no.
514libsndfile contains code written by other people who have agreed that their
515code be used under the GNU LGPL but no more.
516Even if they were to agree, there would be significant difficulties in
517dividing up the payments fairly.
518</P>
519
520<P>
521The <B>only</B> way you can legally use libsndfile as a statically linked
522library is if your application is released under the GNU GPL or LGPL.
523</P>
524
525<!-- ========================================================================= -->
526<A NAME="Q015"></A>
527<H2><BR/><B>Q15 : My program is crashing during a call to a function in libsndfile.
528 Is this a bug in libsndfile?
529</B></H2>
530
531<P>
532libsndfile is being used by large numbers of people all over the world
533without any problems like this. That means that it is much more likely
534that your code has a bug than libsndfile. However, it is still possible
535that there is a bug in libsndfile.
536</P>
537<P>
538To figure out whether it is your code or libsndfile you should do the
539following:
540</P>
541 <UL>
542 <LI>Make sure you are compiling your code with warnings switched on and
543 that you fix as many warnings as possible.
544 With the GNU compiler (gcc) I would recommend at least
545 <B>-W -Wall -Werror</B> which will force you to fix all warnings
546 before you can run the code.
547 <LI>Try using a memory debugger.
548 <A HREF="http://valgrind.kde.org/">Valgrind</A> on x86 Linux is excellent.
549 <A HREF="http://www.ibm.com/software/awdtools/purify/">Purify</A> also
550 has a good reputation.
551 <LI>If the code is clean after the above two steps and you still get
552 a crash in libsndfile, then send me a small snippet of code (no
553 more than 30-40 lines) which includes the call to sf_open() and
554 also shows how all variables passed to/returned from sf_open()
555 are defined.
556 </UL>
557
558<!-- ========================================================================= -->
559<A NAME="Q016"></A>
560<H2><BR/><B>Q16 : Will you accept a fix for compiling libsndfile with compiler X?
561</B></H2>
562
563<P>
564If compiler X is a C++ compiler then no.
565C and C++ are different enough to make writing code that compiles as valid C
566and valid C++ too difficult.
567I would rather spend my time fixing bugs and adding features.
568</P>
569
570<P>
571If compiler X is a C compiler then I will do what I can as long as that does
572not hamper the correctness, portability and maintainability of the existing
573code.
574It should be noted however that libsndfile uses features specified by the 1999
575ISO C Standard.
576This can make compiling libsndfile with some older compilers difficult.
577</P>
578
579<!-- ========================================================================= -->
580<A NAME="Q017"></A>
581<H2><BR/><B>Q17 : Can libsndfile read/write files from/to UNIX pipes?
582</B></H2>
583
584<P>
585Yes, libsndfile can read files from pipes.
586Unfortunately, the write case is much more complicated.
587</P>
588
589<P>
590File formats like AIFF and WAV have information at the start of the file (the
591file header) which states the length of the file, the number of sample frames
592etc.
593This information must be filled in correctly when the file header is written,
594but this information is not reliably known until the file is closed.
595This means that libsndfile cannot write AIFF, WAV and many other file types
596to a pipe.
597</P>
598
599<P>
600However, there is at least one file format (AU) which is specifically designed
601to be written to a pipe.
602Like AIFF and WAV, AU has a header with a sample frames field, but it is
603specifically allowable to set that frames field to 0x7FFFFFFF if the file
604length is not known when the header is written.
605The AU file format can also hold data in many of the standard formats (ie
606SF_FORMAT_PCM_16, SF_FORMAT_PCM_24, SF_FORMAT_FLOAT etc) as well as allowing
607data in both big and little endian format.
608</P>
609
610<P>
611See also <A HREF="#Q006">FAQ Q6</A>.
612</P>
613
614<!-- ========================================================================= -->
615<A NAME="Q018"></A>
616<H2><BR/><B>Q18 : Is it possible to build a Universal Binary on Mac OS X?
617</B></H2>
618
619<P>
620Yes, but you must do two separate configure/build/test runs; one on PowerPC
621and one on Intel.
622It is then possible to merge the binaries into a single universal binary using
623one of the programs in the Apple tool chain.
624</P>
625
626<P>
627It is <b>not</b> possible to build a working universal binary via a single
628compile/build run on a single CPU.
629</P>
630
631<P>
632The problem is that the libsndfile build process detects features of the CPU its
633being built for during the configure process and when building a universal binary,
634configure is only run once and that data is then used for both CPUs.
635That configure data will be wrong for one of those CPUs.
636You will still be able to compile libsndfile, and the test suite will pass on
637the machine you compiled it on.
638However, if you take the universal binary test suite programs compiled on one
639CPU and run them on the other, the test suite will fail.
640</P>
641
642<P>
643Part of the problem is the the CPU endian-ness is detected at configure time.
644Yes, I know the Apple compiler defines one of the macros __LITTLE_ENDIAN__
645and __BIG_ENDIAN__, but those macros are not part of the 1999 ISO C Standard
646and they are not portable.
647</P>
648
649<P>
650Endian issues are not the only reason why the cross compiled binary will fail.
651The configure script also detects other CPU specific idiosyncrasies to provide
652more optimized code.
653</P>
654
655<P>
656Finally, the real show stopper problem with universal binaries is the problem
657with the test suite.
658libsndfile contains a huge, comprehensive test suite.
659When you compile a universal binary and run the test suite, you only test the
660native compile.
661The cross compiled binary (the one with the much higher chance of having
662problems) cannot be tested.
663</P>
664
665<P>
666Now, if you have read this far you're probably thinking there must be a way
667to fix this and there probably is.
668The problem is that its a hell of a lot of work and would require significant
669changes to the configure process, the internal code and the test suite.
670In addition, these changes must not break compilation on any of the platforms
671libsndfile is currently working on.
672</p>
673
674
675<!-- ========================================================================= -->
676<A NAME="Q019"></A>
677<H2><BR/><B>Q19 : I have project files for Visual Studio / XCode / Whatever. Why
678 don't you distribute them with libsndfile?
679</B></H2>
680
681<P>
682There's a very good reason for this.
683I will only distribute things that I actually have an ability to test and
684maintain.
685Project files for a bunch of different compilers and Integrated Development
686Environments are simply too difficult to maintain.
687</P>
688
689<P>
690The problem is that every time I add a new file to libsndfile or rename an
691existing file I would have to modify all the project files and then test that
692libsndfile still built with all the different compilers.
693</P>
694
695<P>
696Maintaining these project files is also rather difficult if I don't have access
697to the required compiler/IDE.
698If I just edit the project files without testing them I will almost certainly
699get it wrong.
700If I release a version of libsndfile with broken project files, I'll get a bunch
701of emails from people complaining about it not building and have no way of
702fixing or even testing it.
703</P>
704
705<P>
706I currently release sources that I personally test on Win32, Linux and
707MacOS X (PowerPC) using the compiler I trust (GNU GCC).
708Supporting one compiler on three (actually much more because GCC is available
709almost everywhere) platforms is doable without too much pain.
710I also release binaries for Win32 with instructions on how to use those
711binaries with Visual Studio.
712As a guy who is mainly interested in Linux, I'm not to keen to jump through
713a bunch of hoops to support compilers and operating systems I don't use.
714</P>
715
716<P>
717So, I hear you want to volunteer to maintain the project files for Some Crappy
718Compiler 2007?
719Well sorry, that won't work either.
720I have had numerous people over the years offer to maintaining the project
721files for Microsoft's Visual Studio.
722Every single time that happened, they maintained it for a release or two and
723then disappeared off the face of the earth.
724Hence, I'm not willing to enter into an arrangement like that again.
725</P>
726
727<!-- ========================================================================= -->
728<A NAME="Q020"></A>
729<H2><BR/><B>Q20 : Why doesn't libsndfile support MP3? Lots of other Open Source
730 projects support it!
731</B></H2>
732
733<P>
734MP3 is not supported for one very good reason; doing so requires the payment
735of licensing fees.
736As can be seen from
737 <a href="http://www.mp3licensing.com/royalty/software.html">
738 mp3licensing.com</a>
739the required royalty payments are not cheap.
740</P>
741
742<p>
743Yes, I know other libraries ignore the licensing requirements, but their legal
744status is extremely dubious.
745At any time, the body selling the licenses could go after the authors of those
746libraries.
747Some of those authors may be students and hence wouldn't be worth pursuing.
748</P>
749
750<p>
751However, libsndfile is released under the name of a company, Mega Nerd Pty Ltd;
752a company which has income from from libsamplerate licensing, libsndfile based
753consulting income and other unrelated consulting income.
754Adding MP3 support to libsndfile could place that income would be under legal
755threat.
756</p>
757
758<p>
759Fortunately, Ogg Vorbis exists as an alternative to MP3.
760Support for Ogg Vorbis was added to libsndfile (mostly due to the efforts of
761John ffitch of the Csound project) in version 1.0.18.
762</p>
763
764
765<!-- ========================================================================= -->
766<A NAME="Q021"></A>
767<H2><BR/><B>Q21 : How do I use libsndfile in a closed source or commercial program
768 and comply with the license?
769</B></H2>
770
771<p>
772Here is a checklist of things you need to do to make sure your use of libsndfile
773in a closed source or commercial project complies with the license libsndfile is
774released under, the GNU Lesser General Public License (LGPL):
775</p>
776
777<ul>
778<li>Make sure you are linking to libsndfile as a shared library (Linux and Unix
779 systems), Dynamic Link Library (Microsoft Windows) or dynlib (Mac OS X).
780 If you are using some other operating system that doesn't allow dynamically
781 linked libraries, you will not be able to use libsndfile unless you release
782 the source code to your program.
783<li>In the licensing documentation for your program, add a statement that your
784 software depends on libsndfile and that libsndfile is released under the GNU
785 Lesser General Public License, either
786 <a href="http://www.gnu.org/licenses/lgpl-2.1.txt">version 2.1</a>
787 or optionally
788 <a href="http://www.gnu.org/licenses/lgpl.txt">version 3</a>.
789<li>Include the text for both versions of the license, possibly as separate
790 files named libsndfile_lgpl_v2_1.txt and libsndfile_lgpl_v3.txt.
791</ul>
792
793<!-- ========================================================================= -->
794<A NAME="Q022"></A>
795<H2><BR/><B>Q22 : What versions of Windows does libsndfile work on?
796</B></H2>
797
798<p>
799Currently the precompiled windows binaries are thoroughly tested on Windows XP.
800As such, they should also work on Win2k and Windows Vista.
801They may also work on earlier versions of Windows.
802</p>
803
804<p>
805Since version 0.1.18 I have also been releasing precompiled binaries for Win64,
806the 64 bit version of Windows.
807These binaries have received much less testing than the 32 bit versions, but
808should work as expected.
809I'd be very interested in receiving feedback on these binaries.
810</p>
811
812<!-- ========================================================================= -->
813<A NAME="Q023"></A>
814<H2><BR/><B>Q23 : I'm cross compiling libsndfile for another platform. How can I
815 run the test suite?
816</B></H2>
817
818<p>
819</p>
820
821<p>
822Since version 1.0.21 the top level Makefile has an extra make target,
823'test-tarball'.
824Building this target creates a tarball called called:
825</p>
826
827<center><tt>
828libsndfile-testsuite-${host_triplet}-${version}.tar.gz
829</tt></center>
830
831<p>
832in the top level directory.
833This tarball can then be copied to the target platform.
834Once untarred and test script <tt>test_wrapper.sh</tt> can be run from
835the top level of the extracted tarball.
836</p>
837
838<!-- ========================================================================= -->
839<HR>
840<P>
841 The libsndfile home page is here :
842 <A HREF="http://www.mega-nerd.com/libsndfile/">
843 http://www.mega-nerd.com/libsndfile/</A>.
844<BR/>
845Version : 1.0.25
846</P>
847
848</BODY>
849</HTML>