#include <stdio.h> #include <sndfile.h> SNDFILE* sf_open_read (const char *path, SF_INFO *sfinfo) ; SNDFILE* sf_open_write (const char *path, const SF_INFO *sfinfo) ; off_t sf_seek (SNDFILE *sndfile, off_t offset, int whence) ; size_t sf_read_raw (SNDFILE *sndfile, void *ptr, size_t bytes) ; size_t sf_write_raw (SNDFILE *sndfile, void *ptr, size_t bytes) ; size_t sf_read_short (SNDFILE *sndfile, short *ptr, size_t items) ; size_t sf_read_int (SNDFILE *sndfile, int *ptr, size_t items) ; size_t sf_read_double (SNDFILE *sndfile, double *ptr, size_t items, int normalize) ; size_t sf_write_short (SNDFILE *sndfile, short *ptr, size_t items) ; size_t sf_write_int (SNDFILE *sndfile, int *ptr, size_t items) ; size_t sf_write_double (SNDFILE *sndfile, double *ptr, size_t items, int normalize) ; int sf_close (SNDFILE *sndfile) ;
SNDFILE* sf_open_read (const char *path, SF_INFO *wfinfo) ; SNDFILE* sf_open_write (const char *path, const SF_INFO *wfinfo) ;The SF_INFO structure is for passing data between the calling function and the library when opening a file for read or writing. It is defined in sndfile.h as follows:
typedef struct { int samplerate ; int samples ; int channels ; int pcmbitwidth ; int format ; int sections ; int seekable ; } SF_INFO ;
enum { SF_FORMAT_WAV = 0x10000, /* Microsoft WAV format (big endian). */ SF_FORMAT_AIFF = 0x20000, /* Apple/SGI AIFF format (little endian). */ SF_FORMAT_AU = 0x30000, /* Sun/NeXT AU format (big endian). */ SF_FORMAT_AULE = 0x40000, /* DEC AU format (little endian). */ SF_FORMAT_PCM = 0x0001, /* PCM data of 8, 16, 24 or 32 bits. */ SF_FORMAT_FLOAT = 0x0002, /* 32 bit floats as defined by the major format type. */ SF_FORMAT_ULAW = 0x0003, /* U-Law encoded. */ SF_FORMAT_ALAW = 0x0004, /* A-Law encoded. */ SF_FORMAT_MS_ADPCM = 0x0005, /* Microsoft ADPCM. */ SF_FORMAT_IMA_ADPCM = 0x0006, /* IMA ADPCM. */ SF_FORMAT_SUBMASK = 0xFFFF, SF_FORMAT_TYPEMASK = 0x7FFF0000 } ;
off_t sf_seek (SNDFILE *sndfile, off_t offset, int whence) ;The file seek functions work much like lseek in stdio.h with the exception that the non-audio data is ignored and the seek only moves within the audio data section of the file. In addition, seeks are defined in number of (multichannel) samples, so for a seek in a stereo file from the current position forward with an offset of 1 would skip forward by one sample of both channels.
SEEK_SET - The offset is set to the start of the audio data plus offset (multichannel) samples. SEEK_CUR - The offset is set to its current location plus offset (multichannel) samples. SEEK_END - The offset is set to the end of the data plus offset (multichannel) samples.Note that offset can be negative and in fact should be when SEEK_END is used for the whence parameter.
size_t sf_read_short (SNDFILE *sndfile, short *ptr, size_t items) ; size_t sf_read_int (SNDFILE *sndfile, int *ptr, size_t items) ; size_t sf_read_double (SNDFILE *sndfile, double *ptr, size_t items, int normalize) ;The file read functions fill the array pointed to by ptr with the requested number of items. The items parameter must be an integer product of the number of channels or an error will occur.
size_t sf_write_short (SNDFILE *sndfile, short *ptr, size_t items) ; size_t sf_write_int (SNDFILE *sndfile, int *ptr, size_t items) ; size_t sf_write_double (SNDFILE *sndfile, double *ptr, size_t items, int normalize) ;The file write functions write the data in the array pointed to by ptr to the file. The items parameter must be an integer product of the number of channels or an error will occur.
size_t sf_read_raw (SNDFILE *sndfile, void *ptr, size_t bytes) ; size_t sf_write_raw (SNDFILE *sndfile, void *ptr, size_t bytes) ;The raw write and write functions read raw audio data from the audio file. The number of bytes read ot written must always be an integer multiple of the number of channels multiplied by the number of bytes required to represent one sample from one channel.
int sf_close (SNDFILE *sndfile) ;The close function closes the file, deallocates it's internal buffers and returns 0 on success or an error value.
Version : 0.0.12