annotate src/libsndfile-1.0.25/doc/api.html @ 169:223a55898ab9 tip default

Add null config files
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 02 Mar 2020 14:03:47 +0000
parents 545efbb81310
children
rev   line source
cannam@85 1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
cannam@85 2 <HTML>
cannam@85 3
cannam@85 4 <HEAD>
cannam@85 5 <TITLE>
cannam@85 6 The libsndfile API
cannam@85 7 </TITLE>
cannam@85 8 <META NAME="Author" CONTENT="Erik de Castro Lopo (erikd AT mega-nerd DOT com)">
cannam@85 9 <META NAME="Description" CONTENT="The libsndfile API.">
cannam@85 10 <META NAME="Keywords" CONTENT="WAV AIFF AU libsndfile sound audio dsp Linux">
cannam@85 11 <LINK REL="stylesheet" HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
cannam@85 12 <LINK REL="stylesheet" HREF="print.css" TYPE="text/css" MEDIA="print">
cannam@85 13 </HEAD>
cannam@85 14
cannam@85 15 <BODY>
cannam@85 16
cannam@85 17 <BR>
cannam@85 18 <H1><B>libsndfile</B></H1>
cannam@85 19 <P>
cannam@85 20 Libsndfile is a library designed to allow the reading and writing of many
cannam@85 21 different sampled sound file formats (such as MS Windows WAV and the Apple/SGI
cannam@85 22 AIFF format) through one standard library interface.
cannam@85 23 </P>
cannam@85 24 <!-- pepper -->
cannam@85 25 <P>
cannam@85 26 During read and write operations, formats are seamlessly converted between the
cannam@85 27 format the application program has requested or supplied and the file's data
cannam@85 28 format. The application programmer can remain blissfully unaware of issues
cannam@85 29 such as file endian-ness and data format. See <A HREF="#note1">Note 1</A> and
cannam@85 30 <A HREF="#note2">Note 2</A>.
cannam@85 31 </P>
cannam@85 32 <!-- pepper -->
cannam@85 33 <P>
cannam@85 34 Every effort is made to keep these documents up-to-date, error free and
cannam@85 35 unambiguous.
cannam@85 36 However, since maintaining the documentation is the least fun part of working
cannam@85 37 on libsndfile, these docs can and do fall behind the behaviour of library.
cannam@85 38 If any errors, omissions or ambiguities are found, please notify me (erikd)
cannam@85 39 at mega-nerd dot com.
cannam@85 40 </P>
cannam@85 41 <!-- pepper -->
cannam@85 42 <P>
cannam@85 43 To supplement this reference documentation, there are simple example programs
cannam@85 44 included in the source code tarball.
cannam@85 45 The test suite which is also part of the source code tarball is also a good
cannam@85 46 place to look for the correct usage of the library functions.
cannam@85 47 </P>
cannam@85 48 <!-- pepper -->
cannam@85 49 <P>
cannam@85 50 <B> Finally, if you think there is some feature missing from libsndfile, check that
cannam@85 51 it isn't already implemented (and documented)
cannam@85 52 <A HREF="command.html">here</A>.
cannam@85 53 </B>
cannam@85 54 </P>
cannam@85 55
cannam@85 56 <H2><B>Synopsis</B></H2>
cannam@85 57 <P>
cannam@85 58 The functions of libsndfile are defined as follows:
cannam@85 59 </P>
cannam@85 60 <!-- pepper -->
cannam@85 61 <PRE>
cannam@85 62 #include &lt;stdio.h&gt;
cannam@85 63 #include &lt;sndfile.h&gt;
cannam@85 64
cannam@85 65 SNDFILE* <A HREF="#open">sf_open</A> (const char *path, int mode, SF_INFO *sfinfo) ;
cannam@85 66 SNDFILE* <A HREF="#open_fd">sf_open_fd</A> (int fd, int mode, SF_INFO *sfinfo, int close_desc) ;
cannam@85 67 SNDFILE* <A HREF="#open_virtual">sf_open_virtual</A> (SF_VIRTUAL_IO *sfvirtual, int mode, SF_INFO *sfinfo, void *user_data) ;
cannam@85 68 int <A HREF="#check">sf_format_check</A> (const SF_INFO *info) ;
cannam@85 69
cannam@85 70 sf_count_t <A HREF="#seek">sf_seek</A> (SNDFILE *sndfile, sf_count_t frames, int whence) ;
cannam@85 71
cannam@85 72 int <A HREF="command.html">sf_command</A> (SNDFILE *sndfile, int cmd, void *data, int datasize) ;
cannam@85 73
cannam@85 74 int <A HREF="#error">sf_error</A> (SNDFILE *sndfile) ;
cannam@85 75 const char* <A HREF="#error">sf_strerror</A> (SNDFILE *sndfile) ;
cannam@85 76 const char* <A HREF="#error">sf_error_number</A> (int errnum) ;
cannam@85 77
cannam@85 78 int <A HREF="#error">sf_perror</A> (SNDFILE *sndfile) ;
cannam@85 79 int <A HREF="#error">sf_error_str</A> (SNDFILE *sndfile, char* str, size_t len) ;
cannam@85 80
cannam@85 81 int <A HREF="#close">sf_close</A> (SNDFILE *sndfile) ;
cannam@85 82 void <A HREF="#write_sync">sf_write_sync</A> (SNDFILE *sndfile) ;
cannam@85 83
cannam@85 84 sf_count_t <A HREF="#read">sf_read_short</A> (SNDFILE *sndfile, short *ptr, sf_count_t items) ;
cannam@85 85 sf_count_t <A HREF="#read">sf_read_int</A> (SNDFILE *sndfile, int *ptr, sf_count_t items) ;
cannam@85 86 sf_count_t <A HREF="#read">sf_read_float</A> (SNDFILE *sndfile, float *ptr, sf_count_t items) ;
cannam@85 87 sf_count_t <A HREF="#read">sf_read_double</A> (SNDFILE *sndfile, double *ptr, sf_count_t items) ;
cannam@85 88
cannam@85 89 sf_count_t <A HREF="#readf">sf_readf_short</A> (SNDFILE *sndfile, short *ptr, sf_count_t frames) ;
cannam@85 90 sf_count_t <A HREF="#readf">sf_readf_int</A> (SNDFILE *sndfile, int *ptr, sf_count_t frames) ;
cannam@85 91 sf_count_t <A HREF="#readf">sf_readf_float</A> (SNDFILE *sndfile, float *ptr, sf_count_t frames) ;
cannam@85 92 sf_count_t <A HREF="#readf">sf_readf_double</A> (SNDFILE *sndfile, double *ptr, sf_count_t frames) ;
cannam@85 93
cannam@85 94 sf_count_t <A HREF="#write">sf_write_short</A> (SNDFILE *sndfile, short *ptr, sf_count_t items) ;
cannam@85 95 sf_count_t <A HREF="#write">sf_write_int</A> (SNDFILE *sndfile, int *ptr, sf_count_t items) ;
cannam@85 96 sf_count_t <A HREF="#write">sf_write_float</A> (SNDFILE *sndfile, float *ptr, sf_count_t items) ;
cannam@85 97 sf_count_t <A HREF="#write">sf_write_double</A> (SNDFILE *sndfile, double *ptr, sf_count_t items) ;
cannam@85 98
cannam@85 99 sf_count_t <A HREF="#writef">sf_writef_short</A> (SNDFILE *sndfile, short *ptr, sf_count_t frames) ;
cannam@85 100 sf_count_t <A HREF="#writef">sf_writef_int</A> (SNDFILE *sndfile, int *ptr, sf_count_t frames) ;
cannam@85 101 sf_count_t <A HREF="#writef">sf_writef_float</A> (SNDFILE *sndfile, float *ptr, sf_count_t frames) ;
cannam@85 102 sf_count_t <A HREF="#writef">sf_writef_double</A> (SNDFILE *sndfile, double *ptr, sf_count_t frames) ;
cannam@85 103
cannam@85 104 sf_count_t <A HREF="#raw">sf_read_raw</A> (SNDFILE *sndfile, void *ptr, sf_count_t bytes) ;
cannam@85 105 sf_count_t <A HREF="#raw">sf_write_raw</A> (SNDFILE *sndfile, void *ptr, sf_count_t bytes) ;
cannam@85 106
cannam@85 107 const char* <A HREF="#string">sf_get_string</A> (SNDFILE *sndfile, int str_type) ;
cannam@85 108 int <A HREF="#string">sf_set_string</A> (SNDFILE *sndfile, int str_type, const char* str) ;
cannam@85 109
cannam@85 110 </PRE>
cannam@85 111 <!-- pepper -->
cannam@85 112 <P>
cannam@85 113 SNDFILE* is an anonymous pointer to data which is private to the library.
cannam@85 114 </P>
cannam@85 115
cannam@85 116
cannam@85 117 <A NAME="open"></A>
cannam@85 118 <H2><B>File Open Function</B></H2>
cannam@85 119
cannam@85 120 <PRE>
cannam@85 121 SNDFILE* sf_open (const char *path, int mode, SF_INFO *sfinfo) ;
cannam@85 122 </PRE>
cannam@85 123
cannam@85 124 <P>
cannam@85 125 The SF_INFO structure is for passing data between the calling function and the library
cannam@85 126 when opening a file for reading or writing. It is defined in sndfile.h as follows:
cannam@85 127 </P>
cannam@85 128 <!-- pepper -->
cannam@85 129 <PRE>
cannam@85 130 typedef struct
cannam@85 131 { sf_count_t frames ; /* Used to be called samples. */
cannam@85 132 int samplerate ;
cannam@85 133 int channels ;
cannam@85 134 int format ;
cannam@85 135 int sections ;
cannam@85 136 int seekable ;
cannam@85 137 } SF_INFO ;
cannam@85 138 </PRE>
cannam@85 139
cannam@85 140 <P>
cannam@85 141 The mode parameter for this function can be any one of the following three values:
cannam@85 142 </P>
cannam@85 143 <!-- pepper -->
cannam@85 144 <PRE>
cannam@85 145 SFM_READ - read only mode
cannam@85 146 SFM_WRITE - write only mode
cannam@85 147 SFM_RDWR - read/write mode
cannam@85 148 </PRE>
cannam@85 149
cannam@85 150 <P>
cannam@85 151 When opening a file for read, the <b>format</B> field should be set to zero before
cannam@85 152 calling sf_open().
cannam@85 153 The only exception to this is the case of RAW files where the caller has to set
cannam@85 154 the samplerate, channels and format fields to valid values.
cannam@85 155 All other fields of the structure are filled in by the library.
cannam@85 156 </P>
cannam@85 157 <!-- pepper -->
cannam@85 158 <P>
cannam@85 159 When opening a file for write, the caller must fill in structure members samplerate,
cannam@85 160 channels, and format.
cannam@85 161 </P>
cannam@85 162 <!-- pepper -->
cannam@85 163 <P>
cannam@85 164 The format field in the above SF_INFO structure is made up of the bit-wise OR of a
cannam@85 165 major format type (values between 0x10000 and 0x08000000), a minor format type
cannam@85 166 (with values less than 0x10000) and an optional endian-ness value.
cannam@85 167 The currently understood formats are listed in sndfile.h as follows and also include
cannam@85 168 bitmasks for separating major and minor file types.
cannam@85 169 Not all combinations of endian-ness and major and minor file types are valid.
cannam@85 170 </P>
cannam@85 171 <!-- pepper -->
cannam@85 172 <PRE>
cannam@85 173 enum
cannam@85 174 { /* Major formats. */
cannam@85 175 SF_FORMAT_WAV = 0x010000, /* Microsoft WAV format (little endian). */
cannam@85 176 SF_FORMAT_AIFF = 0x020000, /* Apple/SGI AIFF format (big endian). */
cannam@85 177 SF_FORMAT_AU = 0x030000, /* Sun/NeXT AU format (big endian). */
cannam@85 178 SF_FORMAT_RAW = 0x040000, /* RAW PCM data. */
cannam@85 179 SF_FORMAT_PAF = 0x050000, /* Ensoniq PARIS file format. */
cannam@85 180 SF_FORMAT_SVX = 0x060000, /* Amiga IFF / SVX8 / SV16 format. */
cannam@85 181 SF_FORMAT_NIST = 0x070000, /* Sphere NIST format. */
cannam@85 182 SF_FORMAT_VOC = 0x080000, /* VOC files. */
cannam@85 183 SF_FORMAT_IRCAM = 0x0A0000, /* Berkeley/IRCAM/CARL */
cannam@85 184 SF_FORMAT_W64 = 0x0B0000, /* Sonic Foundry's 64 bit RIFF/WAV */
cannam@85 185 SF_FORMAT_MAT4 = 0x0C0000, /* Matlab (tm) V4.2 / GNU Octave 2.0 */
cannam@85 186 SF_FORMAT_MAT5 = 0x0D0000, /* Matlab (tm) V5.0 / GNU Octave 2.1 */
cannam@85 187 SF_FORMAT_PVF = 0x0E0000, /* Portable Voice Format */
cannam@85 188 SF_FORMAT_XI = 0x0F0000, /* Fasttracker 2 Extended Instrument */
cannam@85 189 SF_FORMAT_HTK = 0x100000, /* HMM Tool Kit format */
cannam@85 190 SF_FORMAT_SDS = 0x110000, /* Midi Sample Dump Standard */
cannam@85 191 SF_FORMAT_AVR = 0x120000, /* Audio Visual Research */
cannam@85 192 SF_FORMAT_WAVEX = 0x130000, /* MS WAVE with WAVEFORMATEX */
cannam@85 193 SF_FORMAT_SD2 = 0x160000, /* Sound Designer 2 */
cannam@85 194 SF_FORMAT_FLAC = 0x170000, /* FLAC lossless file format */
cannam@85 195 SF_FORMAT_CAF = 0x180000, /* Core Audio File format */
cannam@85 196 SF_FORMAT_WVE = 0x190000, /* Psion WVE format */
cannam@85 197 SF_FORMAT_OGG = 0x200000, /* Xiph OGG container */
cannam@85 198 SF_FORMAT_MPC2K = 0x210000, /* Akai MPC 2000 sampler */
cannam@85 199 SF_FORMAT_RF64 = 0x220000, /* RF64 WAV file */
cannam@85 200
cannam@85 201 /* Subtypes from here on. */
cannam@85 202
cannam@85 203 SF_FORMAT_PCM_S8 = 0x0001, /* Signed 8 bit data */
cannam@85 204 SF_FORMAT_PCM_16 = 0x0002, /* Signed 16 bit data */
cannam@85 205 SF_FORMAT_PCM_24 = 0x0003, /* Signed 24 bit data */
cannam@85 206 SF_FORMAT_PCM_32 = 0x0004, /* Signed 32 bit data */
cannam@85 207
cannam@85 208 SF_FORMAT_PCM_U8 = 0x0005, /* Unsigned 8 bit data (WAV and RAW only) */
cannam@85 209
cannam@85 210 SF_FORMAT_FLOAT = 0x0006, /* 32 bit float data */
cannam@85 211 SF_FORMAT_DOUBLE = 0x0007, /* 64 bit float data */
cannam@85 212
cannam@85 213 SF_FORMAT_ULAW = 0x0010, /* U-Law encoded. */
cannam@85 214 SF_FORMAT_ALAW = 0x0011, /* A-Law encoded. */
cannam@85 215 SF_FORMAT_IMA_ADPCM = 0x0012, /* IMA ADPCM. */
cannam@85 216 SF_FORMAT_MS_ADPCM = 0x0013, /* Microsoft ADPCM. */
cannam@85 217
cannam@85 218 SF_FORMAT_GSM610 = 0x0020, /* GSM 6.10 encoding. */
cannam@85 219 SF_FORMAT_VOX_ADPCM = 0x0021, /* Oki Dialogic ADPCM encoding. */
cannam@85 220
cannam@85 221 SF_FORMAT_G721_32 = 0x0030, /* 32kbs G721 ADPCM encoding. */
cannam@85 222 SF_FORMAT_G723_24 = 0x0031, /* 24kbs G723 ADPCM encoding. */
cannam@85 223 SF_FORMAT_G723_40 = 0x0032, /* 40kbs G723 ADPCM encoding. */
cannam@85 224
cannam@85 225 SF_FORMAT_DWVW_12 = 0x0040, /* 12 bit Delta Width Variable Word encoding. */
cannam@85 226 SF_FORMAT_DWVW_16 = 0x0041, /* 16 bit Delta Width Variable Word encoding. */
cannam@85 227 SF_FORMAT_DWVW_24 = 0x0042, /* 24 bit Delta Width Variable Word encoding. */
cannam@85 228 SF_FORMAT_DWVW_N = 0x0043, /* N bit Delta Width Variable Word encoding. */
cannam@85 229
cannam@85 230 SF_FORMAT_DPCM_8 = 0x0050, /* 8 bit differential PCM (XI only) */
cannam@85 231 SF_FORMAT_DPCM_16 = 0x0051, /* 16 bit differential PCM (XI only) */
cannam@85 232
cannam@85 233 SF_FORMAT_VORBIS = 0x0060, /* Xiph Vorbis encoding. */
cannam@85 234
cannam@85 235 /* Endian-ness options. */
cannam@85 236
cannam@85 237 SF_ENDIAN_FILE = 0x00000000, /* Default file endian-ness. */
cannam@85 238 SF_ENDIAN_LITTLE = 0x10000000, /* Force little endian-ness. */
cannam@85 239 SF_ENDIAN_BIG = 0x20000000, /* Force big endian-ness. */
cannam@85 240 SF_ENDIAN_CPU = 0x30000000, /* Force CPU endian-ness. */
cannam@85 241
cannam@85 242 SF_FORMAT_SUBMASK = 0x0000FFFF,
cannam@85 243 SF_FORMAT_TYPEMASK = 0x0FFF0000,
cannam@85 244 SF_FORMAT_ENDMASK = 0x30000000
cannam@85 245 } ;
cannam@85 246 </PRE>
cannam@85 247 <!-- pepper -->
cannam@85 248 <P>
cannam@85 249 Every call to sf_open() should be matched with a call to sf_close() to free up
cannam@85 250 memory allocated during the call to sf_open().
cannam@85 251 </P>
cannam@85 252 <!-- pepper -->
cannam@85 253 <P>
cannam@85 254 On success, the sf_open function returns a non-NULL pointer which should be
cannam@85 255 passed as the first parameter to all subsequent libsndfile calls dealing with
cannam@85 256 that audio file.
cannam@85 257 On fail, the sf_open function returns a NULL pointer.
cannam@85 258 An explanation of the error can obtained by passing NULL to
cannam@85 259 <A HREF="#error">sf_strerror</A>.
cannam@85 260 </P>
cannam@85 261
cannam@85 262 <A NAME="open_fd"></A>
cannam@85 263 <H3><B>File Descriptor Open</B></H3>
cannam@85 264
cannam@85 265 <PRE>
cannam@85 266 SNDFILE* sf_open_fd (int fd, int mode, SF_INFO *sfinfo, int close_desc) ;
cannam@85 267 </PRE>
cannam@85 268
cannam@85 269 <P>
cannam@85 270 <b>Note:</b> On Microsoft Windows, this function does not work if the
cannam@85 271 application and the libsndfile DLL are linked to different versions of the
cannam@85 272 Microsoft C runtime DLL.
cannam@85 273 </P>
cannam@85 274 <P>
cannam@85 275 The second open function takes a file descriptor of a file that has already been
cannam@85 276 opened.
cannam@85 277 Care should be taken to ensure that the mode of the file represented by the
cannam@85 278 descriptor matches the mode argument.
cannam@85 279 This function is useful in the following circumstances:
cannam@85 280 </P>
cannam@85 281
cannam@85 282 <UL>
cannam@85 283 <LI>Opening temporary files securely (ie use the tmpfile() to return a
cannam@85 284 FILE* pointer and then using fileno() to retrieve the file descriptor
cannam@85 285 which is then passed to libsndfile).
cannam@85 286 <LI>Opening files with file names using OS specific character encodings
cannam@85 287 and then passing the file descriptor to sf_open_fd().
cannam@85 288 <LI>Opening sound files embedded within larger files.
cannam@85 289 <A HREF="embedded_files.html">More info</A>.
cannam@85 290 </UL>
cannam@85 291
cannam@85 292 <P>
cannam@85 293 Every call to sf_open_fd() should be matched with a call to sf_close() to free up
cannam@85 294 memory allocated during the call to sf_open().
cannam@85 295 </P>
cannam@85 296
cannam@85 297 <P>
cannam@85 298 When sf_close() is called, the file descriptor is only closed if the <B>close_desc</B>
cannam@85 299 parameter was TRUE when the sf_open_fd() function was called.
cannam@85 300 </P>
cannam@85 301
cannam@85 302 <P>
cannam@85 303 On success, the sf_open_fd function returns a non-NULL pointer which should be
cannam@85 304 passed as the first parameter to all subsequent libsndfile calls dealing with
cannam@85 305 that audio file.
cannam@85 306 On fail, the sf_open_fd function returns a NULL pointer.
cannam@85 307 </P>
cannam@85 308
cannam@85 309 <A NAME="open_virtual"></A>
cannam@85 310 <h3><b>Virtual File Open Function</b></h3>
cannam@85 311 <pre>
cannam@85 312 SNDFILE* sf_open_virtual (SF_VIRTUAL_IO *sfvirtual, int mode, SF_INFO *sfinfo, void *user_data) ;
cannam@85 313 </pre>
cannam@85 314 <p>
cannam@85 315 Opens a soundfile from a virtual file I/O context which is provided
cannam@85 316 by the caller. This is usually used to interface libsndfile to a stream or buffer
cannam@85 317 based system. Apart from the sfvirtual and the user_data parameters this function behaves
cannam@85 318 like <a href="#open">sf_open</a>.
cannam@85 319 </p>
cannam@85 320
cannam@85 321 <pre>
cannam@85 322 typedef struct
cannam@85 323 { sf_vio_get_filelen get_filelen ;
cannam@85 324 sf_vio_seek seek ;
cannam@85 325 sf_vio_read read ;
cannam@85 326 sf_vio_write write ;
cannam@85 327 sf_vio_tell tell ;
cannam@85 328 } SF_VIRTUAL_IO ;
cannam@85 329 </pre>
cannam@85 330 <p>
cannam@85 331 Libsndfile calls the callbacks provided by the SF_VIRTUAL_IO structure when opening, reading
cannam@85 332 and writing to the virtual file context. The user_data pointer is a user defined context which
cannam@85 333 will be available in the callbacks.
cannam@85 334 </p>
cannam@85 335 <pre>
cannam@85 336 typedef sf_count_t (*sf_vio_get_filelen) (void *user_data) ;
cannam@85 337 typedef sf_count_t (*sf_vio_seek) (sf_count_t offset, int whence, void *user_data) ;
cannam@85 338 typedef sf_count_t (*sf_vio_read) (void *ptr, sf_count_t count, void *user_data) ;
cannam@85 339 typedef sf_count_t (*sf_vio_write) (const void *ptr, sf_count_t count, void *user_data) ;
cannam@85 340 typedef sf_count_t (*sf_vio_tell) (void *user_data) ;
cannam@85 341 </pre>
cannam@85 342 <h4>sf_vio_get_filelen</h4>
cannam@85 343 <pre>
cannam@85 344 typedef sf_count_t (*sf_vio_get_filelen) (void *user_data) ;
cannam@85 345 </pre>
cannam@85 346 <p>
cannam@85 347 The virtual file contex must return the length of the virtual file in bytes.<br>
cannam@85 348 </p>
cannam@85 349 <h4>sf_vio_seek</h4>
cannam@85 350 <pre>
cannam@85 351 typedef sf_count_t (*sf_vio_seek) (sf_count_t offset, int whence, void *user_data) ;
cannam@85 352 </pre>
cannam@85 353 <p>
cannam@85 354 The virtual file context must seek to offset using the seek mode provided by whence which is one of<br>
cannam@85 355 </p>
cannam@85 356 <pre>
cannam@85 357 SEEK_CUR
cannam@85 358 SEEK_SET
cannam@85 359 SEEK_END
cannam@85 360 </pre>
cannam@85 361 <p>
cannam@85 362 The return value must contain the new offset in the file.
cannam@85 363 </p>
cannam@85 364 <h4>sf_vio_read</h4>
cannam@85 365 <pre>
cannam@85 366 typedef sf_count_t (*sf_vio_read) (void *ptr, sf_count_t count, void *user_data) ;
cannam@85 367 </pre>
cannam@85 368 <p>
cannam@85 369 The virtual file context must copy ("read") "count" bytes into the
cannam@85 370 buffer provided by ptr and return the count of actually copied bytes.
cannam@85 371 </p>
cannam@85 372 <h4>sf_vio_write</h4>
cannam@85 373 <pre>
cannam@85 374 typedef sf_count_t (*sf_vio_write) (const void *ptr, sf_count_t count, void *user_data) ;
cannam@85 375 </pre>
cannam@85 376 <p>
cannam@85 377 The virtual file context must process "count" bytes stored in the
cannam@85 378 buffer passed with ptr and return the count of actually processed bytes.<br>
cannam@85 379 </p>
cannam@85 380 <h4>sf_vio_tell</h4>
cannam@85 381 <pre>
cannam@85 382 typedef sf_count_t (*sf_vio_tell) (void *user_data) ;
cannam@85 383 </pre>
cannam@85 384 <p>
cannam@85 385 Return the current position of the virtual file context.<br>
cannam@85 386 </p>
cannam@85 387
cannam@85 388
cannam@85 389 <A NAME="check"></A>
cannam@85 390 <BR><H2><B>Format Check Function</B></H2>
cannam@85 391
cannam@85 392 <PRE>
cannam@85 393 int sf_format_check (const SF_INFO *info) ;
cannam@85 394 </PRE>
cannam@85 395 <!-- pepper -->
cannam@85 396 <P>
cannam@85 397 This function allows the caller to check if a set of parameters in the SF_INFO struct
cannam@85 398 is valid before calling sf_open (SFM_WRITE).
cannam@85 399 </P>
cannam@85 400 <P>
cannam@85 401 sf_format_check returns TRUE if the parameters are valid and FALSE otherwise.
cannam@85 402 </P>
cannam@85 403
cannam@85 404 <A NAME="seek"></A>
cannam@85 405 <BR><H2><B>File Seek Functions</B></H2>
cannam@85 406
cannam@85 407 <PRE>
cannam@85 408 sf_count_t sf_seek (SNDFILE *sndfile, sf_count_t frames, int whence) ;
cannam@85 409 </PRE>
cannam@85 410
cannam@85 411 <P>
cannam@85 412 The file seek functions work much like lseek in unistd.h with the exception that
cannam@85 413 the non-audio data is ignored and the seek only moves within the audio data section of
cannam@85 414 the file.
cannam@85 415 In addition, seeks are defined in number of (multichannel) frames.
cannam@85 416 Therefore, a seek in a stereo file from the current position forward with an offset
cannam@85 417 of 1 would skip forward by one sample of both channels.
cannam@85 418 </P>
cannam@85 419
cannam@85 420 <P>
cannam@85 421 like lseek(), the whence parameter can be any one of the following three values:
cannam@85 422 </P>
cannam@85 423
cannam@85 424 <PRE>
cannam@85 425 SEEK_SET - The offset is set to the start of the audio data plus offset (multichannel) frames.
cannam@85 426 SEEK_CUR - The offset is set to its current location plus offset (multichannel) frames.
cannam@85 427 SEEK_END - The offset is set to the end of the data plus offset (multichannel) frames.
cannam@85 428 </PRE>
cannam@85 429 <!-- pepper -->
cannam@85 430 <P>
cannam@85 431 Internally, libsndfile keeps track of the read and write locations using separate
cannam@85 432 read and write pointers.
cannam@85 433 If a file has been opened with a mode of SFM_RDWR, bitwise OR-ing the standard whence
cannam@85 434 values above with either SFM_READ or SFM_WRITE allows the read and write pointers to
cannam@85 435 be modified separately.
cannam@85 436 If the SEEK_* values are used on their own, the read and write pointers are
cannam@85 437 both modified.
cannam@85 438 </P>
cannam@85 439
cannam@85 440 <P>
cannam@85 441 Note that the frames offset can be negative and in fact should be when SEEK_END is used for the
cannam@85 442 whence parameter.
cannam@85 443 </P>
cannam@85 444 <P>
cannam@85 445 sf_seek will return the offset in (multichannel) frames from the start of the audio data
cannam@85 446 or -1 if an error occured (ie an attempt is made to seek beyond the start or end of the file).
cannam@85 447 </P>
cannam@85 448
cannam@85 449 <A NAME="error"></A>
cannam@85 450 <H2><BR><B>Error Reporting Functions</B></H2>
cannam@85 451
cannam@85 452
cannam@85 453 <PRE>
cannam@85 454 int sf_error (SNDFILE *sndfile) ;
cannam@85 455 </PRE>
cannam@85 456 <P>
cannam@85 457 This function returns the current error number for the given SNDFILE.
cannam@85 458 The error number may be one of the following:
cannam@85 459 </P>
cannam@85 460 <PRE>
cannam@85 461 enum
cannam@85 462 { SF_ERR_NO_ERROR = 0,
cannam@85 463 SF_ERR_UNRECOGNISED_FORMAT = 1,
cannam@85 464 SF_ERR_SYSTEM = 2,
cannam@85 465 SF_ERR_MALFORMED_FILE = 3,
cannam@85 466 SF_ERR_UNSUPPORTED_ENCODING = 4
cannam@85 467 } ;
cannam@85 468 </PRE>
cannam@85 469 <!-- pepper -->
cannam@85 470 <P>
cannam@85 471 or any one of many other internal error values.
cannam@85 472 Applications should only test the return value against error values defined in
cannam@85 473 &lt;sndfile.h&gt; as the internal error values are subject to change at any
cannam@85 474 time.
cannam@85 475 For errors not in the above list, the function sf_error_number() can be used to
cannam@85 476 convert it to an error string.
cannam@85 477 </P>
cannam@85 478
cannam@85 479 <PRE>
cannam@85 480 const char* sf_strerror (SNDFILE *sndfile) ;
cannam@85 481 const char* sf_error_number (int errnum) ;
cannam@85 482 </PRE>
cannam@85 483
cannam@85 484 <P>
cannam@85 485 The error functions sf_strerror() and sf_error_number() convert the library's internal
cannam@85 486 error enumerations into text strings.
cannam@85 487 </P>
cannam@85 488 <PRE>
cannam@85 489 int sf_perror (SNDFILE *sndfile) ;
cannam@85 490 int sf_error_str (SNDFILE *sndfile, char* str, size_t len) ;
cannam@85 491 </PRE>
cannam@85 492
cannam@85 493 <P>
cannam@85 494 The functions sf_perror() and sf_error_str() are deprecated and will be dropped
cannam@85 495 from the library at some later date.
cannam@85 496 </P>
cannam@85 497
cannam@85 498 <A NAME="close"></A>
cannam@85 499 <H2><BR><B>File Close Function</B></H2>
cannam@85 500
cannam@85 501 <PRE>
cannam@85 502 int sf_close (SNDFILE *sndfile) ;
cannam@85 503 </PRE>
cannam@85 504 <!-- pepper -->
cannam@85 505 <P>
cannam@85 506 The close function closes the file, deallocates its internal buffers and returns
cannam@85 507 0 on success or an error value otherwise.
cannam@85 508 </P>
cannam@85 509 <BR>
cannam@85 510
cannam@85 511 <A NAME="write_sync"></A>
cannam@85 512 <H2><BR><B>Write Sync Function</B></H2>
cannam@85 513
cannam@85 514 <PRE>
cannam@85 515 void sf_write_sync (SNDFILE *sndfile) ;
cannam@85 516 </PRE>
cannam@85 517 <!-- pepper -->
cannam@85 518 <P>
cannam@85 519 If the file is opened SFM_WRITE or SFM_RDWR, call the operating system's function
cannam@85 520 to force the writing of all file cache buffers to disk. If the file is opened
cannam@85 521 SFM_READ no action is taken.
cannam@85 522 </P>
cannam@85 523 <BR>
cannam@85 524
cannam@85 525
cannam@85 526 <A NAME="read"></A>
cannam@85 527 <H2><BR><B>File Read Functions (Items)</B></H2>
cannam@85 528
cannam@85 529 <PRE>
cannam@85 530 sf_count_t sf_read_short (SNDFILE *sndfile, short *ptr, sf_count_t items) ;
cannam@85 531 sf_count_t sf_read_int (SNDFILE *sndfile, int *ptr, sf_count_t items) ;
cannam@85 532 sf_count_t sf_read_float (SNDFILE *sndfile, float *ptr, sf_count_t items) ;
cannam@85 533 sf_count_t sf_read_double (SNDFILE *sndfile, double *ptr, sf_count_t items) ;
cannam@85 534 </PRE>
cannam@85 535
cannam@85 536 <P>
cannam@85 537 The file read items functions fill the array pointed to by ptr with the requested
cannam@85 538 number of items. The items parameter must be an integer product of the number
cannam@85 539 of channels or an error will occur.
cannam@85 540 </P>
cannam@85 541 <!-- pepper -->
cannam@85 542 <P>
cannam@85 543 It is important to note that the data type used by the calling program and the data
cannam@85 544 format of the file do not need to be the same. For instance, it is possible to open
cannam@85 545 a 16 bit PCM encoded WAV file and read the data using sf_read_float(). The library
cannam@85 546 seamlessly converts between the two formats on-the-fly. See
cannam@85 547 <A HREF="#note1">Note 1</A>.
cannam@85 548 </P>
cannam@85 549 <!-- pepper -->
cannam@85 550 <P>
cannam@85 551 The sf_read_XXXX functions return the number of items read.
cannam@85 552 Unless the end of the file was reached during the read, the return value should
cannam@85 553 equal the number of items requested.
cannam@85 554 Attempts to read beyond the end of the file will not result in an error but will
cannam@85 555 cause the sf_read_XXXX functions to return less than the number of items requested
cannam@85 556 or 0 if already at the end of the file.
cannam@85 557 </P>
cannam@85 558
cannam@85 559 <A NAME="readf"></A>
cannam@85 560 <H2><BR><B>File Read Functions (Frames)</B></H2>
cannam@85 561
cannam@85 562 <PRE>
cannam@85 563 sf_count_t sf_readf_short (SNDFILE *sndfile, short *ptr, sf_count_t frames) ;
cannam@85 564 sf_count_t sf_readf_int (SNDFILE *sndfile, int *ptr, sf_count_t frames) ;
cannam@85 565 sf_count_t sf_readf_float (SNDFILE *sndfile, float *ptr, sf_count_t frames) ;
cannam@85 566 sf_count_t sf_readf_double (SNDFILE *sndfile, double *ptr, sf_count_t frames) ;
cannam@85 567 </PRE>
cannam@85 568 <!-- pepper -->
cannam@85 569 <P>
cannam@85 570 The file read frames functions fill the array pointed to by ptr with the requested
cannam@85 571 number of frames of data. The array must be large enough to hold the product of
cannam@85 572 frames and the number of channels.
cannam@85 573 </P>
cannam@85 574
cannam@85 575 <P><B>
cannam@85 576 Care must be taken to ensure that there is enough space in the array pointed to by
cannam@85 577 ptr, to take (frames * channels) number of items (shorts, ints, floats or doubles).
cannam@85 578 </B></P>
cannam@85 579
cannam@85 580 <P>
cannam@85 581 The sf_readf_XXXX functions return the number of frames read.
cannam@85 582 Unless the end of the file was reached during the read, the return value should equal
cannam@85 583 the number of frames requested.
cannam@85 584 Attempts to read beyond the end of the file will not result in an error but will cause
cannam@85 585 the sf_readf_XXXX functions to return less than the number of frames requested or 0 if
cannam@85 586 already at the end of the file.
cannam@85 587 </P>
cannam@85 588
cannam@85 589 <A NAME="write"></A>
cannam@85 590 <H2><BR><B>File Write Functions (Items)</B></H2>
cannam@85 591
cannam@85 592 <PRE>
cannam@85 593 sf_count_t sf_write_short (SNDFILE *sndfile, short *ptr, sf_count_t items) ;
cannam@85 594 sf_count_t sf_write_int (SNDFILE *sndfile, int *ptr, sf_count_t items) ;
cannam@85 595 sf_count_t sf_write_float (SNDFILE *sndfile, float *ptr, sf_count_t items) ;
cannam@85 596 sf_count_t sf_write_double (SNDFILE *sndfile, double *ptr, sf_count_t items) ;
cannam@85 597 </PRE>
cannam@85 598
cannam@85 599 <P>
cannam@85 600 The file write items functions write the data in the array pointed to by ptr to the file.
cannam@85 601 The items parameter must be an integer product of the number of channels or an error
cannam@85 602 will occur.
cannam@85 603 </P>
cannam@85 604 <!-- pepper -->
cannam@85 605 <P>
cannam@85 606 It is important to note that the data type used by the calling program and the data
cannam@85 607 format of the file do not need to be the same. For instance, it is possible to open
cannam@85 608 a 16 bit PCM encoded WAV file and write the data using sf_write_float(). The library
cannam@85 609 seamlessly converts between the two formats on-the-fly. See
cannam@85 610 <A HREF="#note1">Note 1</A>.
cannam@85 611 </P>
cannam@85 612 <P>
cannam@85 613 The sf_write_XXXX functions return the number of items written (which should be the
cannam@85 614 same as the items parameter).
cannam@85 615 </P>
cannam@85 616
cannam@85 617 <A NAME="writef"></A>
cannam@85 618 <H2><BR><B>File Write Functions (Frames)</B></H2>
cannam@85 619
cannam@85 620 <PRE>
cannam@85 621 sf_count_t sf_writef_short (SNDFILE *sndfile, short *ptr, sf_count_t frames) ;
cannam@85 622 sf_count_t sf_writef_int (SNDFILE *sndfile, int *ptr, sf_count_t frames) ;
cannam@85 623 sf_count_t sf_writef_float (SNDFILE *sndfile, float *ptr, sf_count_t frames) ;
cannam@85 624 sf_count_t sf_writef_double (SNDFILE *sndfile, double *ptr, sf_count_t frames) ;
cannam@85 625 </PRE>
cannam@85 626
cannam@85 627 <P>
cannam@85 628 The file write frames functions write the data in the array pointed to by ptr to the file.
cannam@85 629 The array must be large enough to hold the product of frames and the number of channels.
cannam@85 630 </P>
cannam@85 631 <P>
cannam@85 632 The sf_writef_XXXX functions return the number of frames written (which should be the
cannam@85 633 same as the frames parameter).
cannam@85 634 </P>
cannam@85 635
cannam@85 636 <A NAME="raw"></A>
cannam@85 637 <H2><BR><B>Raw File Read and Write Functions</B></H2>
cannam@85 638 <!-- pepper -->
cannam@85 639 <PRE>
cannam@85 640 sf_count_t sf_read_raw (SNDFILE *sndfile, void *ptr, sf_count_t bytes) ;
cannam@85 641 sf_count_t sf_write_raw (SNDFILE *sndfile, void *ptr, sf_count_t bytes) ;
cannam@85 642 </PRE>
cannam@85 643
cannam@85 644 <P>
cannam@85 645 <b>Note:</b> Unless you are writing an external decoder/encode that uses
cannam@85 646 libsndfile to handle the file headers, you should not be using these
cannam@85 647 functions.
cannam@85 648 </P>
cannam@85 649
cannam@85 650 <P>
cannam@85 651 The raw read and write functions read raw audio data from the audio file (not to be
cannam@85 652 confused with reading RAW header-less PCM files). The number of bytes read or written
cannam@85 653 must always be an integer multiple of the number of channels multiplied by the number
cannam@85 654 of bytes required to represent one sample from one channel.
cannam@85 655 </P>
cannam@85 656 <!-- pepper -->
cannam@85 657 <P>
cannam@85 658 The raw read and write functions return the number of bytes read or written (which
cannam@85 659 should be the same as the bytes parameter).
cannam@85 660 </P>
cannam@85 661
cannam@85 662 <P>
cannam@85 663 <B>
cannam@85 664 Note : The result of using of both regular reads/writes and raw reads/writes on
cannam@85 665 compressed file formats other than SF_FORMAT_ALAW and SF_FORMAT_ULAW is undefined.
cannam@85 666 </B>
cannam@85 667 </P>
cannam@85 668
cannam@85 669 <p>
cannam@85 670 See also : <a href="command.html#SFC_RAW_NEEDS_ENDSWAP">SFC_RAW_NEEDS_ENDSWAP</a>
cannam@85 671 </p>
cannam@85 672
cannam@85 673 <A NAME="string"></A>
cannam@85 674 <H2><BR><B>Functions for Reading and Writing String Data</B></H2>
cannam@85 675
cannam@85 676
cannam@85 677 <PRE>
cannam@85 678 const char* sf_get_string (SNDFILE *sndfile, int str_type) ;
cannam@85 679 int sf_set_string (SNDFILE *sndfile, int str_type, const char* str) ;
cannam@85 680 </PRE>
cannam@85 681
cannam@85 682 <P>
cannam@85 683 These functions allow strings to be set on files opened for write and to be
cannam@85 684 retrieved from files opened for read where supported by the given file type.
cannam@85 685 The <B>str_type</B> parameter can be any one of the following string types:
cannam@85 686 </P>
cannam@85 687
cannam@85 688 <PRE>
cannam@85 689 enum
cannam@85 690 { SF_STR_TITLE,
cannam@85 691 SF_STR_COPYRIGHT,
cannam@85 692 SF_STR_SOFTWARE,
cannam@85 693 SF_STR_ARTIST,
cannam@85 694 SF_STR_COMMENT,
cannam@85 695 SF_STR_DATE,
cannam@85 696 SF_STR_ALBUM,
cannam@85 697 SF_STR_LICENSE,
cannam@85 698 SF_STR_TRACKNUMBER,
cannam@85 699 SF_STR_GENRE
cannam@85 700 } ;
cannam@85 701 </PRE>
cannam@85 702
cannam@85 703 <P>
cannam@85 704 The sf_get_string() function returns the specified string if it exists and a
cannam@85 705 NULL pointer otherwise.
cannam@85 706 In addition to the string ids above, SF_STR_FIRST (== SF_STR_TITLE) and
cannam@85 707 SF_STR_LAST (always the same as the highest numbers string id) are also
cannam@85 708 available to allow iteration over all the available string ids.
cannam@85 709 </P>
cannam@85 710
cannam@85 711 <P>
cannam@85 712 The sf_set_string() function sets the string data.
cannam@85 713 It returns zero on success and non-zero on error.
cannam@85 714 The error code can be converted to a string using sf_error_number().
cannam@85 715 </P>
cannam@85 716
cannam@85 717
cannam@85 718 <P>
cannam@85 719
cannam@85 720 </P>
cannam@85 721
cannam@85 722 <HR>
cannam@85 723
cannam@85 724 <A NAME="note1"></A>
cannam@85 725 <H2><BR><B>Note 1</B></H2>
cannam@85 726 <!-- pepper -->
cannam@85 727 <P>
cannam@85 728 When converting between integer PCM formats of differing size (ie using sf_read_int()
cannam@85 729 to read a 16 bit PCM encoded WAV file) libsndfile obeys one simple rule:
cannam@85 730 </P>
cannam@85 731
cannam@85 732 <P CLASS=indent_block>
cannam@85 733 Whenever integer data is moved from one sized container to another sized container,
cannam@85 734 the most significant bit in the source container will become the most significant bit
cannam@85 735 in the destination container.
cannam@85 736 </P>
cannam@85 737
cannam@85 738 <P>
cannam@85 739 When converting between integer data and floating point data, different rules apply.
cannam@85 740 The default behaviour when reading floating point data (sf_read_float() or
cannam@85 741 sf_read_double ()) from a file with integer data is normalisation. Regardless of
cannam@85 742 whether data in the file is 8, 16, 24 or 32 bit wide, the data will be read as
cannam@85 743 floating point data in the range [-1.0, 1.0]. Similarly, data in the range [-1.0, 1.0]
cannam@85 744 will be written to an integer PCM file so that a data value of 1.0 will be the largest
cannam@85 745 allowable integer for the given bit width. This normalisation can be turned on or off
cannam@85 746 using the <A HREF="command.html">sf_command</A> interface.
cannam@85 747 </P>
cannam@85 748
cannam@85 749 <A NAME="note2"></A>
cannam@85 750 <H2><BR><B>Note 2</B></H2>
cannam@85 751
cannam@85 752 <P>
cannam@85 753 Reading a file containg floating point data (allowable with WAV, AIFF, AU and other
cannam@85 754 file formats) using integer read methods (sf_read_short() or sf_read_int()) can
cannam@85 755 produce unexpected results.
cannam@85 756 For instance the data in the file may have a maximum absolute value &lt; 1.0 which
cannam@85 757 would mean that all sample values read from the file will be zero.
cannam@85 758 In order to read these files correctly using integer read methods, it is recommended
cannam@85 759 that you use the
cannam@85 760 <A HREF="command.html">sf_command</A>
cannam@85 761 interface, a command of
cannam@85 762 <A HREF="command.html#SFC_SET_SCALE_FLOAT_INT_READ">SFC_SET_SCALE_FLOAT_INT_READ</A>
cannam@85 763 and a parameter of SF_TRUE to force correct scaling.
cannam@85 764 </P>
cannam@85 765 <!-- pepper -->
cannam@85 766 <HR>
cannam@85 767 <!-- pepper -->
cannam@85 768 <P>
cannam@85 769 The libsndfile home page is
cannam@85 770 <A HREF="http://www.mega-nerd.com/libsndfile/">here</A>.
cannam@85 771 </P>
cannam@85 772 <P>
cannam@85 773 Version : 1.0.25
cannam@85 774 </P>
cannam@85 775 <!-- pepper -->
cannam@85 776 <!-- pepper -->
cannam@85 777 <!-- pepper -->
cannam@85 778 <!-- pepper -->
cannam@85 779
cannam@85 780 </BODY>
cannam@85 781 </HTML>