#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 frames, 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_readf_short (SNDFILE *sndfile, short *ptr, size_t frames) ; size_t sf_readf_int (SNDFILE *sndfile, int *ptr, size_t frames) ; size_t sf_readf_double (SNDFILE *sndfile, double *ptr, size_t frames, 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) ; size_t sf_writef_short (SNDFILE *sndfile, short *ptr, size_t frames) ; size_t sf_writef_int (SNDFILE *sndfile, int *ptr, size_t frames) ; size_t sf_writef_double (SNDFILE *sndfile, double *ptr, size_t frames, 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_RAW = 0x50000, /* RAW PCM data. */ SF_FORMAT_PAF = 0x60000, /* Ensoniq PARIS file format. */ SF_FORMAT_SVX = 0x70000, /* Amiga IFF / SVX8 / SV16 format. */ SF_FORMAT_PCM = 0x0001, /* PCM data in 8, 16, 24 or 32 bits. */ SF_FORMAT_FLOAT = 0x0002, /* 32 bit floats. */ SF_FORMAT_ULAW = 0x0003, /* U-Law encoded. */ SF_FORMAT_ALAW = 0x0004, /* A-Law encoded. */ SF_FORMAT_IMA_ADPCM = 0x0005, /* IMA ADPCM. */ SF_FORMAT_MS_ADPCM = 0x0006, /* Microsoft ADPCM. */ SF_FORMAT_PCM_BE = 0x0007, /* Big endian PCM data. */ SF_FORMAT_PCM_LE = 0x0008, /* Little endian PCM data. */ SF_FORMAT_PCM_S8 = 0x0009, /* Signed 8 bit PCM. */ SF_FORMAT_PCM_U8 = 0x000A, /* Unsigned 8 bit PCM. */ SF_FORMAT_PCM_BE = 0x0007, /* RAW PCM (big endian). */ SF_FORMAT_PCM_LE = 0x0008, /* RAW PCM (little endian). */ SF_FORMAT_RAW_S8 = 0x0009, /* Signed 8 bit RAW PCM. */ SF_FORMAT_RAW_U8 = 0x000A, /* Unsigned 8 bit RAW PCM. */ SF_FORMAT_SUBMASK = 0xFFFF, SF_FORMAT_TYPEMASK = 0x7FFF0000 } ;
off_t sf_seek (SNDFILE *sndfile, off_t frames, 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 or frames. Therefor, 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 frames 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 items 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_readf_short (SNDFILE *sndfile, short *ptr, size_t frames) ; size_t sf_readf_int (SNDFILE *sndfile, int *ptr, size_t frames) ; size_t sf_readf_double (SNDFILE *sndfile, double *ptr, size_t frames, int normalize) ;The file read frames functions fill the array pointed to by ptr with the requested number of frames of data. The array must be large enough to hold the product of frames and the number of channels.
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 items 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_writef_short (SNDFILE *sndfile, short *ptr, size_t frames) ; size_t sf_writef_int (SNDFILE *sndfile, int *ptr, size_t frames) ; size_t sf_writef_double (SNDFILE *sndfile, double *ptr, size_t frames, int normalize) ;The file write frames functions write the data in the array pointed to by ptr to the file. The array must be large enough to hold the product of frames and the number of channels.
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 (not to be confused with reading RAW header-less PCM files). The number of bytes read or 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.18