annotate src/libsndfile-1.0.25/doc/FAQ.html @ 23:619f715526df sv_v2.1

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