Blame doc/api.html

Packit 4aff17
Packit 4aff17
<HTML>
Packit 4aff17
Packit 4aff17
<HEAD>
Packit 4aff17
	<TITLE>
Packit 4aff17
	The libsndfile API
Packit 4aff17
	</TITLE>
Packit 4aff17
	<META NAME="Author"      CONTENT="Erik de Castro Lopo (erikd AT mega-nerd DOT com)">
Packit 4aff17
	<META NAME="Description" CONTENT="The libsndfile API.">
Packit 4aff17
	<META NAME="Keywords"    CONTENT="WAV AIFF AU libsndfile sound audio dsp Linux">
Packit 4aff17
	<LINK REL="stylesheet" HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
Packit 4aff17
	<LINK REL="stylesheet" HREF="print.css" TYPE="text/css" MEDIA="print">
Packit 4aff17
</HEAD>
Packit 4aff17
Packit 4aff17
<BODY>
Packit 4aff17
Packit 4aff17

Packit 4aff17

libsndfile

Packit 4aff17

Packit 4aff17
	Libsndfile is a library designed to allow the reading and writing of many
Packit 4aff17
	different sampled sound file formats (such as MS Windows WAV and the Apple/SGI
Packit 4aff17
	AIFF format) through one standard library interface.
Packit 4aff17

Packit 4aff17
Packit 4aff17

Packit 4aff17
	During read and write operations, formats are seamlessly converted between the
Packit 4aff17
	format the application program has requested or supplied and the file's data
Packit 4aff17
	format. The application programmer can remain blissfully unaware of issues
Packit 4aff17
	such as file endian-ness and data format. See Note 1 and
Packit 4aff17
	Note 2.
Packit 4aff17

Packit 4aff17
Packit 4aff17

Packit 4aff17
	Every effort is made to keep these documents up-to-date, error free and
Packit 4aff17
	unambiguous.
Packit 4aff17
	However, since maintaining the documentation is the least fun part of working
Packit 4aff17
	on libsndfile, these docs can and do fall behind the behaviour of the library.
Packit 4aff17
	If any errors, omissions or ambiguities are found, please notify me (erikd)
Packit 4aff17
	at mega-nerd dot com.
Packit 4aff17

Packit 4aff17
Packit 4aff17

Packit 4aff17
	To supplement this reference documentation, there are simple example programs
Packit 4aff17
	included in the source code tarball.
Packit 4aff17
	The test suite which is also part of the source code tarball is also a good
Packit 4aff17
	place to look for the correct usage of the library functions.
Packit 4aff17

Packit 4aff17
Packit 4aff17

Packit 4aff17
	 Finally, if you think there is some feature missing from libsndfile, check that
Packit 4aff17
	it isn't already implemented (and documented)
Packit 4aff17
		here.
Packit 4aff17
	
Packit 4aff17

Packit 4aff17
Packit 4aff17

Synopsis

Packit 4aff17

Packit 4aff17
The functions of libsndfile are defined as follows:
Packit 4aff17

Packit 4aff17
Packit 4aff17
Packit 4aff17
      #include <stdio.h>
Packit 4aff17
      #include <sndfile.h>
Packit 4aff17
Packit 4aff17
      SNDFILE*    sf_open          (const char *path, int mode, SF_INFO *sfinfo) ;
Packit 4aff17
      SNDFILE*    sf_wchar_open    (LPCWSTR wpath, int mode, SF_INFO *sfinfo) ;
Packit 4aff17
      SNDFILE*    sf_open_fd       (int fd, int mode, SF_INFO *sfinfo, int close_desc) ;
Packit 4aff17
      SNDFILE* 	  sf_open_virtual  (SF_VIRTUAL_IO *sfvirtual, int mode, SF_INFO *sfinfo, void *user_data) ;
Packit 4aff17
      int         sf_format_check  (const SF_INFO *info) ;
Packit 4aff17
Packit 4aff17
      sf_count_t  sf_seek          (SNDFILE *sndfile, sf_count_t frames, int whence) ;
Packit 4aff17
Packit 4aff17
      int         sf_command       (SNDFILE *sndfile, int cmd, void *data, int datasize) ;
Packit 4aff17
Packit 4aff17
      int         sf_error         (SNDFILE *sndfile) ;
Packit 4aff17
      const char* sf_strerror      (SNDFILE *sndfile) ;
Packit 4aff17
      const char* sf_error_number  (int errnum) ;
Packit 4aff17
Packit 4aff17
      int         sf_perror        (SNDFILE *sndfile) ;
Packit 4aff17
      int         sf_error_str     (SNDFILE *sndfile, char* str, size_t len) ;
Packit 4aff17
Packit 4aff17
      int         sf_close         (SNDFILE *sndfile) ;
Packit 4aff17
      void        sf_write_sync    (SNDFILE *sndfile) ;
Packit 4aff17
Packit 4aff17
      sf_count_t  sf_read_short    (SNDFILE *sndfile, short *ptr, sf_count_t items) ;
Packit 4aff17
      sf_count_t  sf_read_int      (SNDFILE *sndfile, int *ptr, sf_count_t items) ;
Packit 4aff17
      sf_count_t  sf_read_float    (SNDFILE *sndfile, float *ptr, sf_count_t items) ;
Packit 4aff17
      sf_count_t  sf_read_double   (SNDFILE *sndfile, double *ptr, sf_count_t items) ;
Packit 4aff17
Packit 4aff17
      sf_count_t  sf_readf_short   (SNDFILE *sndfile, short *ptr, sf_count_t frames) ;
Packit 4aff17
      sf_count_t  sf_readf_int     (SNDFILE *sndfile, int *ptr, sf_count_t frames) ;
Packit 4aff17
      sf_count_t  sf_readf_float   (SNDFILE *sndfile, float *ptr, sf_count_t frames) ;
Packit 4aff17
      sf_count_t  sf_readf_double  (SNDFILE *sndfile, double *ptr, sf_count_t frames) ;
Packit 4aff17
Packit 4aff17
      sf_count_t  sf_write_short   (SNDFILE *sndfile, short *ptr, sf_count_t items) ;
Packit 4aff17
      sf_count_t  sf_write_int     (SNDFILE *sndfile, int *ptr, sf_count_t items) ;
Packit 4aff17
      sf_count_t  sf_write_float   (SNDFILE *sndfile, float *ptr, sf_count_t items) ;
Packit 4aff17
      sf_count_t  sf_write_double  (SNDFILE *sndfile, double *ptr, sf_count_t items) ;
Packit 4aff17
Packit 4aff17
      sf_count_t  sf_writef_short  (SNDFILE *sndfile, short *ptr, sf_count_t frames) ;
Packit 4aff17
      sf_count_t  sf_writef_int    (SNDFILE *sndfile, int *ptr, sf_count_t frames) ;
Packit 4aff17
      sf_count_t  sf_writef_float  (SNDFILE *sndfile, float *ptr, sf_count_t frames) ;
Packit 4aff17
      sf_count_t  sf_writef_double (SNDFILE *sndfile, double *ptr, sf_count_t frames) ;
Packit 4aff17
Packit 4aff17
      sf_count_t  sf_read_raw      (SNDFILE *sndfile, void *ptr, sf_count_t bytes) ;
Packit 4aff17
      sf_count_t  sf_write_raw     (SNDFILE *sndfile, void *ptr, sf_count_t bytes) ;
Packit 4aff17
Packit 4aff17
      const char* sf_get_string    (SNDFILE *sndfile, int str_type) ;
Packit 4aff17
      int         sf_set_string    (SNDFILE *sndfile, int str_type, const char* str) ;
Packit 4aff17
Packit 4aff17
Packit 4aff17
Packit 4aff17

Packit 4aff17
SNDFILE* is an anonymous pointer to data which is private to the library.
Packit 4aff17

Packit 4aff17
Packit 4aff17
Packit 4aff17
Packit 4aff17

File Open Function

Packit 4aff17
Packit 4aff17
Packit 4aff17
      SNDFILE*  sf_open    (const char *path, int mode, SF_INFO *sfinfo) ;
Packit 4aff17
Packit 4aff17
Packit 4aff17

Packit 4aff17
The sf_open() function opens the sound file at the specified path.
Packit 4aff17
The filename is byte encoded, but may be utf-8 on Linux, while on Mac OS X it
Packit 4aff17
will use the filesystem character set.
Packit 4aff17
On Windows, there is also a Windows specific sf_wchar_open() that takes a
Packit 4aff17
UTF16_BE encoded filename.
Packit 4aff17

Packit 4aff17
Packit 4aff17
Packit 4aff17
      SNDFILE*  sf_wchar_open (LPCWSTR wpath, int mode, SF_INFO *sfinfo) ;
Packit 4aff17
Packit 4aff17
Packit 4aff17

Packit 4aff17
The SF_INFO structure is for passing data between the calling function and the library
Packit 4aff17
when opening a file for reading or writing. It is defined in sndfile.h as follows:
Packit 4aff17

Packit 4aff17
Packit 4aff17
Packit 4aff17
      typedef struct
Packit 4aff17
      {    sf_count_t  frames ;     /* Used to be called samples. */
Packit 4aff17
           int         samplerate ;
Packit 4aff17
           int         channels ;
Packit 4aff17
           int         format ;
Packit 4aff17
           int         sections ;
Packit 4aff17
           int         seekable ;
Packit 4aff17
       } SF_INFO ;
Packit 4aff17
Packit 4aff17
Packit 4aff17

Packit 4aff17
The mode parameter for this function can be any one of the following three values:
Packit 4aff17

Packit 4aff17
Packit 4aff17
Packit 4aff17
      SFM_READ    - read only mode
Packit 4aff17
      SFM_WRITE   - write only mode
Packit 4aff17
      SFM_RDWR    - read/write mode
Packit 4aff17
Packit 4aff17
Packit 4aff17

Packit 4aff17
When opening a file for read, the format field should be set to zero before
Packit 4aff17
calling sf_open().
Packit 4aff17
The only exception to this is the case of RAW files where the caller has to set
Packit 4aff17
the samplerate, channels and format fields to valid values.
Packit 4aff17
All other fields of the structure are filled in by the library.
Packit 4aff17

Packit 4aff17
Packit 4aff17

Packit 4aff17
When opening a file for write, the caller must fill in structure members samplerate,
Packit 4aff17
channels, and format.
Packit 4aff17

Packit 4aff17
Packit 4aff17

Packit 4aff17
The format field in the above SF_INFO structure is made up of the bit-wise OR of a
Packit 4aff17
major format type (values between 0x10000 and 0x08000000), a minor format type
Packit 4aff17
(with values less than 0x10000) and an optional endian-ness value.
Packit 4aff17
The currently understood formats are listed in sndfile.h as follows and also include
Packit 4aff17
bitmasks for separating major and minor file types.
Packit 4aff17
Not all combinations of endian-ness and major and minor file types are valid.
Packit 4aff17

Packit 4aff17
Packit 4aff17
Packit 4aff17
      enum
Packit 4aff17
      {   /* Major formats. */
Packit 4aff17
          SF_FORMAT_WAV          = 0x010000,     /* Microsoft WAV format (little endian). */
Packit 4aff17
          SF_FORMAT_AIFF         = 0x020000,     /* Apple/SGI AIFF format (big endian). */
Packit 4aff17
          SF_FORMAT_AU           = 0x030000,     /* Sun/NeXT AU format (big endian). */
Packit 4aff17
          SF_FORMAT_RAW          = 0x040000,     /* RAW PCM data. */
Packit 4aff17
          SF_FORMAT_PAF          = 0x050000,     /* Ensoniq PARIS file format. */
Packit 4aff17
          SF_FORMAT_SVX          = 0x060000,     /* Amiga IFF / SVX8 / SV16 format. */
Packit 4aff17
          SF_FORMAT_NIST         = 0x070000,     /* Sphere NIST format. */
Packit 4aff17
          SF_FORMAT_VOC          = 0x080000,     /* VOC files. */
Packit 4aff17
          SF_FORMAT_IRCAM        = 0x0A0000,     /* Berkeley/IRCAM/CARL */
Packit 4aff17
          SF_FORMAT_W64          = 0x0B0000,     /* Sonic Foundry's 64 bit RIFF/WAV */
Packit 4aff17
          SF_FORMAT_MAT4         = 0x0C0000,     /* Matlab (tm) V4.2 / GNU Octave 2.0 */
Packit 4aff17
          SF_FORMAT_MAT5         = 0x0D0000,     /* Matlab (tm) V5.0 / GNU Octave 2.1 */
Packit 4aff17
          SF_FORMAT_PVF          = 0x0E0000,     /* Portable Voice Format */
Packit 4aff17
          SF_FORMAT_XI           = 0x0F0000,     /* Fasttracker 2 Extended Instrument */
Packit 4aff17
          SF_FORMAT_HTK          = 0x100000,     /* HMM Tool Kit format */
Packit 4aff17
          SF_FORMAT_SDS          = 0x110000,     /* Midi Sample Dump Standard */
Packit 4aff17
          SF_FORMAT_AVR          = 0x120000,     /* Audio Visual Research */
Packit 4aff17
          SF_FORMAT_WAVEX        = 0x130000,     /* MS WAVE with WAVEFORMATEX */
Packit 4aff17
          SF_FORMAT_SD2          = 0x160000,     /* Sound Designer 2 */
Packit 4aff17
          SF_FORMAT_FLAC         = 0x170000,     /* FLAC lossless file format */
Packit 4aff17
          SF_FORMAT_CAF          = 0x180000,     /* Core Audio File format */
Packit 4aff17
          SF_FORMAT_WVE          = 0x190000,     /* Psion WVE format */
Packit 4aff17
          SF_FORMAT_OGG          = 0x200000,     /* Xiph OGG container */
Packit 4aff17
          SF_FORMAT_MPC2K        = 0x210000,     /* Akai MPC 2000 sampler */
Packit 4aff17
          SF_FORMAT_RF64         = 0x220000,     /* RF64 WAV file */
Packit 4aff17
Packit 4aff17
          /* Subtypes from here on. */
Packit 4aff17
Packit 4aff17
          SF_FORMAT_PCM_S8       = 0x0001,       /* Signed 8 bit data */
Packit 4aff17
          SF_FORMAT_PCM_16       = 0x0002,       /* Signed 16 bit data */
Packit 4aff17
          SF_FORMAT_PCM_24       = 0x0003,       /* Signed 24 bit data */
Packit 4aff17
          SF_FORMAT_PCM_32       = 0x0004,       /* Signed 32 bit data */
Packit 4aff17
Packit 4aff17
          SF_FORMAT_PCM_U8       = 0x0005,       /* Unsigned 8 bit data (WAV and RAW only) */
Packit 4aff17
Packit 4aff17
          SF_FORMAT_FLOAT        = 0x0006,       /* 32 bit float data */
Packit 4aff17
          SF_FORMAT_DOUBLE       = 0x0007,       /* 64 bit float data */
Packit 4aff17
Packit 4aff17
          SF_FORMAT_ULAW         = 0x0010,       /* U-Law encoded. */
Packit 4aff17
          SF_FORMAT_ALAW         = 0x0011,       /* A-Law encoded. */
Packit 4aff17
          SF_FORMAT_IMA_ADPCM    = 0x0012,       /* IMA ADPCM. */
Packit 4aff17
          SF_FORMAT_MS_ADPCM     = 0x0013,       /* Microsoft ADPCM. */
Packit 4aff17
Packit 4aff17
          SF_FORMAT_GSM610       = 0x0020,       /* GSM 6.10 encoding. */
Packit 4aff17
          SF_FORMAT_VOX_ADPCM    = 0x0021,       /* Oki Dialogic ADPCM encoding. */
Packit 4aff17
Packit 4aff17
          SF_FORMAT_G721_32      = 0x0030,       /* 32kbs G721 ADPCM encoding. */
Packit 4aff17
          SF_FORMAT_G723_24      = 0x0031,       /* 24kbs G723 ADPCM encoding. */
Packit 4aff17
          SF_FORMAT_G723_40      = 0x0032,       /* 40kbs G723 ADPCM encoding. */
Packit 4aff17
Packit 4aff17
          SF_FORMAT_DWVW_12      = 0x0040,       /* 12 bit Delta Width Variable Word encoding. */
Packit 4aff17
          SF_FORMAT_DWVW_16      = 0x0041,       /* 16 bit Delta Width Variable Word encoding. */
Packit 4aff17
          SF_FORMAT_DWVW_24      = 0x0042,       /* 24 bit Delta Width Variable Word encoding. */
Packit 4aff17
          SF_FORMAT_DWVW_N       = 0x0043,       /* N bit Delta Width Variable Word encoding. */
Packit 4aff17
Packit 4aff17
          SF_FORMAT_DPCM_8       = 0x0050,       /* 8 bit differential PCM (XI only) */
Packit 4aff17
          SF_FORMAT_DPCM_16      = 0x0051,       /* 16 bit differential PCM (XI only) */
Packit 4aff17
Packit 4aff17
          SF_FORMAT_VORBIS       = 0x0060,       /* Xiph Vorbis encoding. */
Packit 4aff17
Packit 4aff17
          /* Endian-ness options. */
Packit 4aff17
Packit 4aff17
          SF_ENDIAN_FILE         = 0x00000000,   /* Default file endian-ness. */
Packit 4aff17
          SF_ENDIAN_LITTLE       = 0x10000000,   /* Force little endian-ness. */
Packit 4aff17
          SF_ENDIAN_BIG          = 0x20000000,   /* Force big endian-ness. */
Packit 4aff17
          SF_ENDIAN_CPU          = 0x30000000,   /* Force CPU endian-ness. */
Packit 4aff17
Packit 4aff17
          SF_FORMAT_SUBMASK      = 0x0000FFFF,
Packit 4aff17
          SF_FORMAT_TYPEMASK     = 0x0FFF0000,
Packit 4aff17
          SF_FORMAT_ENDMASK      = 0x30000000
Packit 4aff17
      } ;
Packit 4aff17
Packit 4aff17
Packit 4aff17

Packit 4aff17
Every call to sf_open() should be matched with a call to sf_close() to free up
Packit 4aff17
memory allocated during the call to sf_open().
Packit 4aff17

Packit 4aff17
Packit 4aff17

Packit 4aff17
On success, the sf_open function returns a non-NULL pointer which should be
Packit 4aff17
passed as the first parameter to all subsequent libsndfile calls dealing with
Packit 4aff17
that audio file.
Packit 4aff17
On fail, the sf_open function returns a NULL pointer.
Packit 4aff17
An explanation of the error can obtained by passing NULL to
Packit 4aff17
	sf_strerror.
Packit 4aff17

Packit 4aff17
Packit 4aff17
Packit 4aff17

File Descriptor Open

Packit 4aff17
Packit 4aff17
Packit 4aff17
      SNDFILE*  sf_open_fd (int fd, int mode, SF_INFO *sfinfo, int close_desc) ;
Packit 4aff17
Packit 4aff17
Packit 4aff17

Packit 4aff17
Note: On Microsoft Windows, this function does not work if the
Packit 4aff17
application and the libsndfile DLL are linked to different versions of the
Packit 4aff17
Microsoft C runtime DLL.
Packit 4aff17

Packit 4aff17

Packit 4aff17
The second open function takes a file descriptor of a file that has already been
Packit 4aff17
opened.
Packit 4aff17
Care should be taken to ensure that the mode of the file represented by the
Packit 4aff17
descriptor matches the mode argument.
Packit 4aff17
This function is useful in the following circumstances:
Packit 4aff17

Packit 4aff17
Packit 4aff17
    Packit 4aff17
    	
  • Opening temporary files securely (ie use the tmpfile() to return a
  • Packit 4aff17
    		FILE* pointer and then using fileno() to retrieve the file descriptor
    Packit 4aff17
    		which is then passed to libsndfile).
    Packit 4aff17
    	
  • Opening files with file names using OS specific character encodings
  • Packit 4aff17
    		and then passing the file descriptor to sf_open_fd().
    Packit 4aff17
    	
  • Opening sound files embedded within larger files.
  • Packit 4aff17
    			More info.
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    Every call to sf_open_fd() should be matched with a call to sf_close() to free up
    Packit 4aff17
    memory allocated during the call to sf_open().
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    When sf_close() is called, the file descriptor is only closed if the close_desc
    Packit 4aff17
    parameter was TRUE when the sf_open_fd() function was called.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    On success, the sf_open_fd function returns a non-NULL pointer which should be
    Packit 4aff17
    passed as the first parameter to all subsequent libsndfile calls dealing with
    Packit 4aff17
    that audio file.
    Packit 4aff17
    On fail, the sf_open_fd function returns a NULL pointer.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17

    Virtual File Open Function

    Packit 4aff17
    Packit 4aff17
          SNDFILE* 	sf_open_virtual	(SF_VIRTUAL_IO *sfvirtual, int mode, SF_INFO *sfinfo, void *user_data) ;
    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    	Opens a soundfile from a virtual file I/O context which is provided
    Packit 4aff17
    	by the caller. This is usually used to interface libsndfile to a stream or buffer
    Packit 4aff17
    	based system. Apart from the sfvirtual and the user_data parameters this function behaves
    Packit 4aff17
    	like sf_open.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
          typedef struct
    Packit 4aff17
          {    sf_vio_get_filelen  get_filelen ;
    Packit 4aff17
               sf_vio_seek         seek ;
    Packit 4aff17
               sf_vio_read         read ;
    Packit 4aff17
               sf_vio_write        write ;
    Packit 4aff17
               sf_vio_tell         tell ;
    Packit 4aff17
          } SF_VIRTUAL_IO ;
    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    Libsndfile calls the callbacks provided by the SF_VIRTUAL_IO structure when opening, reading
    Packit 4aff17
    and writing to the virtual file context. The user_data pointer is a user defined context which
    Packit 4aff17
    will be available in the callbacks.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
          typedef sf_count_t  (*sf_vio_get_filelen) (void *user_data) ;
    Packit 4aff17
          typedef sf_count_t  (*sf_vio_seek)        (sf_count_t offset, int whence, void *user_data) ;
    Packit 4aff17
          typedef sf_count_t  (*sf_vio_read)        (void *ptr, sf_count_t count, void *user_data) ;
    Packit 4aff17
          typedef sf_count_t  (*sf_vio_write)       (const void *ptr, sf_count_t count, void *user_data) ;
    Packit 4aff17
          typedef sf_count_t  (*sf_vio_tell)        (void *user_data) ;
    Packit 4aff17
    Packit 4aff17

    sf_vio_get_filelen

    Packit 4aff17
    Packit 4aff17
          typedef sf_count_t  (*sf_vio_get_filelen) (void *user_data) ;
    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    The virtual file contex must return the length of the virtual file in bytes.
    Packit 4aff17

    Packit 4aff17

    sf_vio_seek

    Packit 4aff17
    Packit 4aff17
          typedef sf_count_t  (*sf_vio_seek)        (sf_count_t offset, int whence, void *user_data) ;
    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    The virtual file context must seek to offset using the seek mode provided by whence which is one of
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
          SEEK_CUR
    Packit 4aff17
          SEEK_SET
    Packit 4aff17
          SEEK_END
    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    The return value must contain the new offset in the file.
    Packit 4aff17

    Packit 4aff17

    sf_vio_read

    Packit 4aff17
    Packit 4aff17
          typedef sf_count_t  (*sf_vio_read)        (void *ptr, sf_count_t count, void *user_data) ;
    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    The virtual file context must copy ("read") "count" bytes into the
    Packit 4aff17
    buffer provided by ptr and return the count of actually copied bytes.
    Packit 4aff17

    Packit 4aff17

    sf_vio_write

    Packit 4aff17
    Packit 4aff17
          typedef sf_count_t  (*sf_vio_write)       (const void *ptr, sf_count_t count, void *user_data) ;
    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    The virtual file context must process "count" bytes stored in the
    Packit 4aff17
    buffer passed with ptr and return the count of actually processed bytes.
    Packit 4aff17

    Packit 4aff17

    sf_vio_tell

    Packit 4aff17
    Packit 4aff17
          typedef sf_count_t  (*sf_vio_tell)        (void *user_data) ;
    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    Return the current position of the virtual file context.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17

    Format Check Function

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
          int  sf_format_check (const SF_INFO *info) ;
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    This function allows the caller to check if a set of parameters in the SF_INFO struct
    Packit 4aff17
    is valid before calling sf_open (SFM_WRITE).
    Packit 4aff17

    Packit 4aff17

    Packit 4aff17
    sf_format_check returns TRUE if the parameters are valid and FALSE otherwise.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17

    File Seek Functions

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
          sf_count_t  sf_seek  (SNDFILE *sndfile, sf_count_t frames, int whence) ;
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    The file seek functions work much like lseek in unistd.h with the exception that
    Packit 4aff17
    the non-audio data is ignored and the seek only moves within the audio data section of
    Packit 4aff17
    the file.
    Packit 4aff17
    In addition, seeks are defined in number of (multichannel) frames.
    Packit 4aff17
    Therefore, a seek in a stereo file from the current position forward with an offset
    Packit 4aff17
    of 1 would skip forward by one sample of both channels.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    like lseek(), the whence parameter can be any one of the following three values:
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
          SEEK_SET  - The offset is set to the start of the audio data plus offset (multichannel) frames.
    Packit 4aff17
          SEEK_CUR  - The offset is set to its current location plus offset (multichannel) frames.
    Packit 4aff17
          SEEK_END  - The offset is set to the end of the data plus offset (multichannel) frames.
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    Internally, libsndfile keeps track of the read and write locations using separate
    Packit 4aff17
    read and write pointers.
    Packit 4aff17
    If a file has been opened with a mode of SFM_RDWR, bitwise OR-ing the standard whence
    Packit 4aff17
    values above with either SFM_READ or SFM_WRITE allows the read and write pointers to
    Packit 4aff17
    be modified separately.
    Packit 4aff17
    If the SEEK_* values are used on their own, the read and write pointers are
    Packit 4aff17
    both modified.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    Note that the frames offset can be negative and in fact should be when SEEK_END is used for the
    Packit 4aff17
    whence parameter.
    Packit 4aff17

    Packit 4aff17

    Packit 4aff17
    sf_seek will return the offset in (multichannel) frames from the start of the audio data
    Packit 4aff17
    or -1 if an error occured (ie an attempt is made to seek beyond the start or end of the file).
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17


    Error Reporting Functions

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
          int         sf_error        (SNDFILE *sndfile) ;
    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    This function returns the current error number for the given SNDFILE.
    Packit 4aff17
    The error number may be one of the following:
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
            enum
    Packit 4aff17
            {   SF_ERR_NO_ERROR             = 0,
    Packit 4aff17
                SF_ERR_UNRECOGNISED_FORMAT  = 1,
    Packit 4aff17
                SF_ERR_SYSTEM               = 2,
    Packit 4aff17
                SF_ERR_MALFORMED_FILE       = 3,
    Packit 4aff17
                SF_ERR_UNSUPPORTED_ENCODING = 4
    Packit 4aff17
            } ;
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    or any one of many other internal error values.
    Packit 4aff17
    Applications should only test the return value against error values defined in
    Packit 4aff17
    <sndfile.h> as the internal error values are subject to change at any
    Packit 4aff17
    time.
    Packit 4aff17
    For errors not in the above list, the function sf_error_number() can be used to
    Packit 4aff17
    convert it to an error string.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
          const char* sf_strerror     (SNDFILE *sndfile) ;
    Packit 4aff17
          const char* sf_error_number (int errnum) ;
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    The error functions sf_strerror() and sf_error_number() convert the library's internal
    Packit 4aff17
    error enumerations into text strings.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
          int         sf_perror     (SNDFILE *sndfile) ;
    Packit 4aff17
          int         sf_error_str  (SNDFILE *sndfile, char* str, size_t len) ;
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    The functions sf_perror() and sf_error_str() are deprecated and will be dropped
    Packit 4aff17
    from the library at some later date.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17


    File Close Function

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
          int  sf_close  (SNDFILE *sndfile) ;
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    The close function closes the file, deallocates its internal buffers and returns
    Packit 4aff17
    0 on success or an error value otherwise.
    Packit 4aff17

    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17


    Write Sync Function

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
          void  sf_write_sync  (SNDFILE *sndfile) ;
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    If the file is opened SFM_WRITE or SFM_RDWR, call the operating system's function
    Packit 4aff17
    to force the writing of all file cache buffers to disk. If the file is opened
    Packit 4aff17
    SFM_READ no action is taken.
    Packit 4aff17

    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17


    File Read Functions

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
          sf_count_t  sf_read_short   (SNDFILE *sndfile, short *ptr, sf_count_t items) ;
    Packit 4aff17
          sf_count_t  sf_read_int     (SNDFILE *sndfile, int *ptr, sf_count_t items) ;
    Packit 4aff17
          sf_count_t  sf_read_float   (SNDFILE *sndfile, float *ptr, sf_count_t items) ;
    Packit 4aff17
          sf_count_t  sf_read_double  (SNDFILE *sndfile, double *ptr, sf_count_t items) ;
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
          sf_count_t  sf_readf_short   (SNDFILE *sndfile, short *ptr, sf_count_t frames) ;
    Packit 4aff17
          sf_count_t  sf_readf_int     (SNDFILE *sndfile, int *ptr, sf_count_t frames) ;
    Packit 4aff17
          sf_count_t  sf_readf_float   (SNDFILE *sndfile, float *ptr, sf_count_t frames) ;
    Packit 4aff17
          sf_count_t  sf_readf_double  (SNDFILE *sndfile, double *ptr, sf_count_t frames) ;
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    The file read functions fill the array pointed to by ptr with the
    Packit 4aff17
    requested number of items or frames.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    For the frames-count functions, the frames parameter specifies the number
    Packit 4aff17
    of frames. A frame is just a block of samples, one for each
    Packit 4aff17
    channel. Care must be taken to ensure that there is enough space
    Packit 4aff17
    in the array pointed to by ptr, to take (frames * channels) number of
    Packit 4aff17
    items (shorts, ints, floats or doubles).
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    For the items-count functions, the items parameter must be an integer product
    Packit 4aff17
    of the number of channels or an error will occur. Here, an item is just a
    Packit 4aff17
    sample.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    Note: The only difference between the "items" and "frames" versions of
    Packit 4aff17
    each read function is the units in which the object count is specified
    Packit 4aff17
    - calling sf_readf_short with a count argument of N, on a SNDFILE with
    Packit 4aff17
    C channels, is the same as calling sf_read_short with a count argument
    Packit 4aff17
    of N*C. The buffer pointed to by "ptr" should be the same number of
    Packit 4aff17
    bytes in each case.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    Note: The data type used by the calling program and the data format of
    Packit 4aff17
    the file do not need to be the same. For instance, it is possible to
    Packit 4aff17
    open a 16 bit PCM encoded WAV file and read the data using
    Packit 4aff17
    sf_read_float(). The library seamlessly converts between the two
    Packit 4aff17
    formats on-the-fly. See
    Packit 4aff17
    Note 1.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    The sf_read_XXXX and sf_readf_XXXX functions return the number of
    Packit 4aff17
    items or frames read, respectively. Unless the end of the file was
    Packit 4aff17
    reached during the read, the return value should equal the number of
    Packit 4aff17
    objects requested. Attempts to read beyond the end of the file will
    Packit 4aff17
    not result in an error but will cause the read functions to return
    Packit 4aff17
    less than the number of objects requested or 0 if already at the end
    Packit 4aff17
    of the file.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17


    File Write Functions

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
          sf_count_t  sf_write_short   (SNDFILE *sndfile, short *ptr, sf_count_t items) ;
    Packit 4aff17
          sf_count_t  sf_write_int     (SNDFILE *sndfile, int *ptr, sf_count_t items) ;
    Packit 4aff17
          sf_count_t  sf_write_float   (SNDFILE *sndfile, float *ptr, sf_count_t items) ;
    Packit 4aff17
          sf_count_t  sf_write_double  (SNDFILE *sndfile, double *ptr, sf_count_t items) ;
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
          sf_count_t  sf_writef_short  (SNDFILE *sndfile, short *ptr, sf_count_t frames) ;
    Packit 4aff17
          sf_count_t  sf_writef_int    (SNDFILE *sndfile, int *ptr, sf_count_t frames) ;
    Packit 4aff17
          sf_count_t  sf_writef_float  (SNDFILE *sndfile, float *ptr, sf_count_t frames) ;
    Packit 4aff17
          sf_count_t  sf_writef_double (SNDFILE *sndfile, double *ptr, sf_count_t frames) ;
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    The file write functions write the data in the array pointed to by ptr to the file.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    For items-count functions, the items parameter specifies the size of
    Packit 4aff17
    the array and must be an integer product of the number of channels or
    Packit 4aff17
    an error will occur.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    For the frames-count functions, the array is expected to be large enough
    Packit 4aff17
    to hold a number of items equal to the product of frames and the
    Packit 4aff17
    number of channels.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17

    As with the read functions above, the only

    Packit 4aff17
    difference in the items and frames version of each write function is
    Packit 4aff17
    the units in which the buffer size is specified. Again, the data type
    Packit 4aff17
    used by the calling program and the data format of the file do not
    Packit 4aff17
    need to be the same (Note 1).
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    The sf_write_XXXX and sf_writef_XXXX functions respectively return the
    Packit 4aff17
    number of items or frames written (which should be the same as the
    Packit 4aff17
    items or frames parameter).
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17


    Raw File Read and Write Functions

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
          sf_count_t  sf_read_raw     (SNDFILE *sndfile, void *ptr, sf_count_t bytes) ;
    Packit 4aff17
          sf_count_t  sf_write_raw    (SNDFILE *sndfile, void *ptr, sf_count_t bytes) ;
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    Note: Unless you are writing an external decoder/encode that uses
    Packit 4aff17
    libsndfile to handle the file headers, you should not be using these
    Packit 4aff17
    functions.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    The raw read and write functions read raw audio data from the audio file (not to be
    Packit 4aff17
    confused with reading RAW header-less PCM files). The number of bytes read or written
    Packit 4aff17
    must always be an integer multiple of the number of channels multiplied by the number
    Packit 4aff17
    of bytes required to represent one sample from one channel.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    The raw read and write functions return the number of bytes read or written (which
    Packit 4aff17
    should be the same as the bytes parameter).
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
    Note : The result of using of both regular reads/writes and raw reads/writes on
    Packit 4aff17
    compressed file formats other than SF_FORMAT_ALAW and SF_FORMAT_ULAW is undefined.
    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    See also : SFC_RAW_NEEDS_ENDSWAP
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17


    Functions for Reading and Writing String Data

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
          const char* sf_get_string   (SNDFILE *sndfile, int str_type) ;
    Packit 4aff17
          int         sf_set_string   (SNDFILE *sndfile, int str_type, const char* str) ;
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    These functions allow strings to be set on files opened for write and to be
    Packit 4aff17
    retrieved from files opened for read where supported by the given file type.
    Packit 4aff17
    The str_type parameter can be any one of the following string types:
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
              enum
    Packit 4aff17
              {   SF_STR_TITLE,
    Packit 4aff17
                  SF_STR_COPYRIGHT,
    Packit 4aff17
                  SF_STR_SOFTWARE,
    Packit 4aff17
                  SF_STR_ARTIST,
    Packit 4aff17
                  SF_STR_COMMENT,
    Packit 4aff17
                  SF_STR_DATE,
    Packit 4aff17
                  SF_STR_ALBUM,
    Packit 4aff17
                  SF_STR_LICENSE,
    Packit 4aff17
                  SF_STR_TRACKNUMBER,
    Packit 4aff17
                  SF_STR_GENRE
    Packit 4aff17
              } ;
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    The sf_get_string() function returns the specified string if it exists and a
    Packit 4aff17
    NULL pointer otherwise.
    Packit 4aff17
    In addition to the string ids above, SF_STR_FIRST (== SF_STR_TITLE) and
    Packit 4aff17
    SF_STR_LAST (always the same as the highest numbers string id) are also
    Packit 4aff17
    available to allow iteration over all the available string ids.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    The sf_set_string() function sets the string data.
    Packit 4aff17
    It returns zero on success and non-zero on error.
    Packit 4aff17
    The error code can be converted to a string using sf_error_number().
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    Strings passed to and retrieved from these two functions are assumed to be
    Packit 4aff17
    utf-8.
    Packit 4aff17
    However, while formats like Ogg/Vorbis and FLAC fully support utf-8, others
    Packit 4aff17
    like WAV and AIFF officially only support ASCII.
    Packit 4aff17
    Writing utf-8 strings to WAV and AIF files with libsndfile will work when read
    Packit 4aff17
    back with libsndfile, but may not work with other programs.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    The suggested method of dealing with tags retrived using sf_get_string() is to
    Packit 4aff17
    assume they are utf-8.
    Packit 4aff17
    Similarly if you have a string in some exotic format like utf-16, it should be
    Packit 4aff17
    encoded to utf-8 before being written using libsndfile.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17


    Note 1

    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    When converting between integer PCM formats of differing size
    Packit 4aff17
    (e.g. using sf_read_int() to read a 16 bit PCM encoded WAV file)
    Packit 4aff17
    libsndfile obeys one simple rule:
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    Whenever integer data is moved from one sized container to another sized container,
    Packit 4aff17
    the most significant bit in the source container will become the most significant bit
    Packit 4aff17
    in the destination container.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    When converting between integer data and floating point data, different rules apply.
    Packit 4aff17
    The default behaviour when reading floating point data (sf_read_float() or
    Packit 4aff17
    sf_read_double ()) from a file with integer data is normalisation. Regardless of
    Packit 4aff17
    whether data in the file is 8, 16, 24 or 32 bit wide, the data will be read as
    Packit 4aff17
    floating point data in the range [-1.0, 1.0]. Similarly, data in the range [-1.0, 1.0]
    Packit 4aff17
    will be written to an integer PCM file so that a data value of 1.0 will be the largest
    Packit 4aff17
    allowable integer for the given bit width. This normalisation can be turned on or off
    Packit 4aff17
    using the sf_command interface.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17


    Note 2

    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    Reading a file containg floating point data (allowable with WAV, AIFF, AU and other
    Packit 4aff17
    file formats) using integer read methods (sf_read_short() or sf_read_int()) can
    Packit 4aff17
    produce unexpected results.
    Packit 4aff17
    For instance the data in the file may have a maximum absolute value < 1.0 which
    Packit 4aff17
    would mean that all sample values read from the file will be zero.
    Packit 4aff17
    In order to read these files correctly using integer read methods, it is recommended
    Packit 4aff17
    that you use the
    Packit 4aff17
         sf_command
    Packit 4aff17
    interface, a command of
    Packit 4aff17
         SFC_SET_SCALE_FLOAT_INT_READ
    Packit 4aff17
    and a parameter of SF_TRUE to force correct scaling.
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17

    Packit 4aff17
    	The libsndfile home page is
    Packit 4aff17
    		here.
    Packit 4aff17

    Packit 4aff17

    Packit 4aff17
    Version : 1.0.28
    Packit 4aff17

    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
    Packit 4aff17
    </BODY>
    Packit 4aff17
    </HTML>