FAQ.html 31 KB

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