Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: libsndfile : the sf_command function. Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40:

sf_command

Chris@40:
Chris@40: 
Chris@40:         int    sf_command (SNDFILE *sndfile, int cmd, void *data, int datasize) ;
Chris@40: 
Chris@40:

Chris@40: This function allows the caller to retrieve information from or change aspects of the Chris@40: library behaviour. Chris@40: Examples include retrieving a string containing the library version or changing the Chris@40: scaling applied to floating point sample data during read and write. Chris@40: Most of these operations are performed on a per-file basis. Chris@40:

Chris@40:

Chris@40: The cmd parameter is a integer identifier which is defined in <sndfile.h>. Chris@40: All of the valid command identifiers have names begining with "SFC_". Chris@40: Data is passed to and returned from the library by use of a void pointer. Chris@40: The library will not read or write more than datasize bytes from the void pointer. Chris@40: For some calls no data is required in which case data should be NULL and datasize Chris@40: may be used for some other purpose. Chris@40:

Chris@40:

Chris@40: The available commands are as follows: Chris@40:

Chris@40: Chris@40:
Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40:
SFC_GET_LIB_VERSIONRetrieve the version of the library.
SFC_GET_LOG_INFORetrieve the internal per-file operation log.
SFC_CALC_SIGNAL_MAXRetrieve the measured maximum signal value.
SFC_CALC_NORM_SIGNAL_MAXRetrieve the measured normalised maximum signal value.
SFC_CALC_MAX_ALL_CHANNELSCalculate peaks for all channels.
SFC_CALC_NORM_MAX_ALL_CHANNELSCalculate normalised peaks for all channels.
SFC_SET_NORM_FLOATModify the normalisation behaviour of the floating point reading and writing functions.
SFC_SET_NORM_DOUBLEModify the normalisation behaviour of the double precision floating point reading and writing functions.
SFC_GET_NORM_FLOATRetrieve the current normalisation behaviour of the floating point reading and writing functions.
SFC_GET_NORM_DOUBLERetrieve the current normalisation behaviour of the double precision floating point reading and writing functions.
SFC_GET_SIMPLE_FORMAT_COUNTRetrieve the number of simple formats supported by libsndfile.
SFC_GET_SIMPLE_FORMATRetrieve information about a simple format.
SFC_GET_FORMAT_INFORetrieve information about a major or subtype format.
SFC_GET_FORMAT_MAJOR_COUNTRetrieve the number of major formats.
SFC_GET_FORMAT_MAJORRetrieve information about a major format type.
SFC_GET_FORMAT_SUBTYPE_COUNTRetrieve the number of subformats.
SFC_GET_FORMAT_SUBTYPERetrieve information about a subformat.
SFC_SET_ADD_PEAK_CHUNKSwitch the code for adding the PEAK chunk to WAV and AIFF files on or off.
SFC_UPDATE_HEADER_NOWUsed when a file is open for write, this command will update the file Chris@40: header to reflect the data written so far.
SFC_SET_UPDATE_HEADER_AUTOUsed when a file is open for write, this command will cause the file header Chris@40: to be updated after each write to the file.
SFC_FILE_TRUNCATETruncate a file open for write or for read/write.
SFC_SET_RAW_START_OFFSETChange the data start offset for files opened up as SF_FORMAT_RAW.
Chris@40:
Chris@40: Chris@40:

Chris@40: Chris@40:
Chris@40: Chris@40: Chris@40: Chris@40:


SFC_GET_LIB_VERSION

Chris@40:

Chris@40: Retrieve the version of the library as a string. Chris@40:

Chris@40:

Chris@40: Parameters: Chris@40:

Chris@40:         sndfile  : Not used
Chris@40:         cmd      : SFC_GET_LIB_VERSION
Chris@40:         data     : A pointer to a char buffer
Chris@40:         datasize : The size of the buffer
Chris@40: 
Chris@40:

Chris@40: Example: Chris@40:

Chris@40:
Chris@40:         char  buffer [128] ;
Chris@40:         sf_command (NULL, SFC_GET_LIB_VERSION, buffer, sizeof (buffer)) ;
Chris@40: 
Chris@40: Chris@40:
Chris@40:
Return value:
Chris@40:
This call will return the length of the retrieved version string. Chris@40:
Chris@40:
Chris@40:
Notes:
Chris@40:
Chris@40: The string returned in the buffer passed to this function will not overflow Chris@40: the buffer and will always be null terminated . Chris@40:
Chris@40: Chris@40: Chris@40: Chris@40:


SFC_GET_LOG_INFO

Chris@40:

Chris@40: Retrieve the log buffer generated when opening a file as a string. This log Chris@40: buffer can often contain a good reason for why libsndfile failed to open a Chris@40: particular file. Chris@40:

Chris@40:

Chris@40: Parameters: Chris@40:

Chris@40:         sndfile  : A valid SNDFILE* pointer
Chris@40:         cmd      : SFC_GET_LOG_INFO
Chris@40:         data     : A pointer to a char buffer
Chris@40:         datasize : The size of the buffer
Chris@40: 
Chris@40:

Chris@40: Example: Chris@40:

Chris@40:
Chris@40:         char  buffer [2048] ;
Chris@40:         sf_command (sndfile, SFC_GET_LOG_INFO, buffer, sizeof (buffer)) ;
Chris@40: 
Chris@40: Chris@40:
Chris@40:
Return value:
Chris@40:
This call will return the length of the retrieved version string. Chris@40:
Chris@40:
Chris@40:
Notes:
Chris@40:
Chris@40: The string returned in the buffer passed to this function will not overflow Chris@40: the buffer and will always be null terminated . Chris@40:
Chris@40: Chris@40: Chris@40: Chris@40:


SFC_CALC_SIGNAL_MAX

Chris@40:

Chris@40: Retrieve the measured maximum signal value. This involves reading through Chris@40: the whole file which can be slow on large files. Chris@40:

Chris@40:

Chris@40: Parameters: Chris@40:

Chris@40:         sndfile  : A valid SNDFILE* pointer
Chris@40:         cmd      : SFC_CALC_SIGNAL_MAX
Chris@40:         data     : A pointer to a double
Chris@40:         datasize : sizeof (double)
Chris@40: 
Chris@40:

Chris@40: Example: Chris@40:

Chris@40:
Chris@40:         double   max_val ;
Chris@40:         sf_command (sndfile, SFC_CALC_SIGNAL_MAX, &max_val, sizeof (max_val)) ;
Chris@40: 
Chris@40: Chris@40:
Chris@40:
Return value:
Chris@40:
Zero on success, non-zero otherwise. Chris@40:
Chris@40: Chris@40: Chris@40: Chris@40:


SFC_CALC_NORM_SIGNAL_MAX

Chris@40:

Chris@40: Retrieve the measured normailised maximum signal value. This involves reading Chris@40: through the whole file which can be slow on large files. Chris@40:

Chris@40:

Chris@40: Parameters: Chris@40:

Chris@40:         sndfile  : A valid SNDFILE* pointer
Chris@40:         cmd      : SFC_CALC_NORM_SIGNAL_MAX
Chris@40:         data     : A pointer to a double
Chris@40:         datasize : sizeof (double)
Chris@40: 
Chris@40:

Chris@40: Example: Chris@40:

Chris@40:
Chris@40:         double   max_val ;
Chris@40:         sf_command (sndfile, SFC_CALC_NORM_SIGNAL_MAX, &max_val, sizeof (max_val)) ;
Chris@40: 
Chris@40: Chris@40:
Chris@40:
Return value:
Chris@40:
Zero on success, non-zero otherwise. Chris@40:
Chris@40: Chris@40: Chris@40: Chris@40:


SFC_CALC_MAX_ALL_CHANNELS

Chris@40:

Chris@40: Calculate peaks for all channels. This involves reading through Chris@40: the whole file which can be slow on large files. Chris@40:

Chris@40:

Chris@40: Parameters: Chris@40:

Chris@40:         sndfile  : A valid SNDFILE* pointer
Chris@40:         cmd      : SFC_CALC_MAX_ALL_CHANNELS
Chris@40:         data     : A pointer to a double
Chris@40:         datasize : sizeof (double) * number_of_channels
Chris@40: 
Chris@40:

Chris@40: Example: Chris@40:

Chris@40:
Chris@40:         double   peaks [number_of_channels] ;
Chris@40:         sf_command (sndfile, SFC_CALC_MAX_ALL_CHANNELS, peaks, sizeof (peaks)) ;
Chris@40: 
Chris@40:
Chris@40:
Return value:
Chris@40:
Zero if peaks have been calculated successfully and non-zero otherwise. Chris@40:
Chris@40: Chris@40: Chris@40: Chris@40: Chris@40:


SFC_CALC_NORM_MAX_ALL_CHANNELS

Chris@40:

Chris@40: Calculate normalised peaks for all channels. This involves reading through Chris@40: the whole file which can be slow on large files. Chris@40:

Chris@40:

Chris@40: Parameters: Chris@40:

Chris@40:         sndfile  : A valid SNDFILE* pointer
Chris@40:         cmd      : SFC_CALC_NORM_MAX_ALL_CHANNELS
Chris@40:         data     : A pointer to a double
Chris@40:         datasize : sizeof (double) * number_of_channels
Chris@40: 
Chris@40:

Chris@40: Example: Chris@40:

Chris@40:
Chris@40:         double   peaks [number_of_channels] ;
Chris@40:         sf_command (sndfile, SFC_CALC_NORM_MAX_ALL_CHANNELS, peaks, sizeof (peaks)) ;
Chris@40: 
Chris@40:
Chris@40:
Return value:
Chris@40:
Zero if peaks have been calculated successfully and non-zero otherwise. Chris@40:
Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40: Chris@40:


SFC_SET_NORM_FLOAT

Chris@40:

Chris@40: This command only affects data read from or written to using the floating point functions: Chris@40:

Chris@40:
Chris@40: 	size_t    sf_read_float    (SNDFILE *sndfile, float *ptr, size_t items) ;
Chris@40: 	size_t    sf_readf_float   (SNDFILE *sndfile, float *ptr, size_t frames) ;
Chris@40: 
Chris@40: 	size_t    sf_write_float   (SNDFILE *sndfile, float *ptr, size_t items) ;
Chris@40: 	size_t    sf_writef_float  (SNDFILE *sndfile, float *ptr, size_t frames) ;
Chris@40: 
Chris@40:

Chris@40: Parameters: Chris@40:

Chris@40:
Chris@40:         sndfile  : A valid SNDFILE* pointer
Chris@40:         cmd      : SFC_SET_NORM_FLOAT
Chris@40:         data     : NULL
Chris@40:         datasize : SF_TRUE or SF_FALSE
Chris@40: 
Chris@40:

Chris@40: For read operations setting normalisation to SF_TRUE means that the data from all Chris@40: subsequent reads will be be normalised to the range [-1.0, 1.0]. Chris@40:

Chris@40:

Chris@40: For write operations, setting normalisation to SF_TRUE means than all data supplied Chris@40: to the float write functions should be in the range [-1.0, 1.0] and will be scaled Chris@40: for the file format as necessary. Chris@40:

Chris@40:

Chris@40: For both cases, setting normalisation to SF_FALSE means that no scaling will take place. Chris@40:

Chris@40:

Chris@40: Example: Chris@40:

Chris@40:
Chris@40:         sf_command (sndfile, SFC_SET_NORM_FLOAT, NULL, SF_TRUE) ;
Chris@40: 
Chris@40:         sf_command (sndfile, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
Chris@40: 
Chris@40:
Chris@40:
Return value:
Chris@40:
Returns 1 on success or 0 for failure. Chris@40:
Chris@40: Chris@40: Chris@40: Chris@40:


SFC_SET_NORM_DOUBLE

Chris@40:

Chris@40: This command only affects data read from or written to using the double precision Chris@40: floating point functions: Chris@40:

Chris@40:
Chris@40: 	size_t    sf_read_double    (SNDFILE *sndfile, double *ptr, size_t items) ;
Chris@40: 	size_t    sf_readf_double   (SNDFILE *sndfile, double *ptr, size_t frames) ;
Chris@40: 
Chris@40: 	size_t    sf_write_double   (SNDFILE *sndfile, double *ptr, size_t items) ;
Chris@40: 	size_t    sf_writef_double  (SNDFILE *sndfile, double *ptr, size_t frames) ;
Chris@40: 
Chris@40:

Chris@40: Parameters: Chris@40:

Chris@40:
Chris@40:         sndfile  : A valid SNDFILE* pointer
Chris@40:         cmd      : SFC_SET_NORM_DOUBLE
Chris@40:         data     : NULL
Chris@40:         datasize : SF_TRUE or SF_FALSE
Chris@40: 
Chris@40:

Chris@40: For read operations setting normalisation to SF_TRUE means that the data Chris@40: from all subsequent reads will be be normalised to the range [-1.0, 1.0]. Chris@40:

Chris@40:

Chris@40: For write operations, setting normalisation to SF_TRUE means than all data supplied Chris@40: to the double write functions should be in the range [-1.0, 1.0] and will be scaled Chris@40: for the file format as necessary. Chris@40:

Chris@40:

Chris@40: For both cases, setting normalisation to SF_FALSE means that no scaling will take place. Chris@40:

Chris@40:

Chris@40: Example: Chris@40:

Chris@40:
Chris@40:         sf_command (sndfile, SFC_SET_NORM_DOUBLE, NULL, SF_TRUE) ;
Chris@40: 
Chris@40:         sf_command (sndfile, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
Chris@40: 
Chris@40:
Chris@40:
Return value:
Chris@40:
Returns 1 on success or 0 for failure. Chris@40:
Chris@40: Chris@40: Chris@40: Chris@40:


SFC_GET_NORM_FLOAT

Chris@40:

Chris@40: Retrieve the current float normalisation mode. Chris@40:

Chris@40:

Chris@40: Parameters: Chris@40:

Chris@40:
Chris@40:         sndfile  : A valid SNDFILE* pointer
Chris@40:         cmd      : SFC_GET_NORM_FLOAT
Chris@40:         data     : NULL
Chris@40:         datasize : anything
Chris@40: 
Chris@40:

Chris@40: Example: Chris@40:

Chris@40:
Chris@40:         normalisation = sf_command (sndfile, SFC_GET_NORM_FLOAT, NULL, 0) ;
Chris@40: 
Chris@40:
Chris@40:
Return value:
Chris@40:
Returns TRUE if normaisation is on and FALSE otherwise. Chris@40:
Chris@40: Chris@40: Chris@40: Chris@40:


SFC_GET_NORM_DOUBLE

Chris@40:

Chris@40: Retrieve the current float normalisation mode. Chris@40:

Chris@40:

Chris@40: Parameters: Chris@40:

Chris@40:
Chris@40:         sndfile  : A valid SNDFILE* pointer
Chris@40:         cmd      : SFC_GET_NORM_DOUBLE
Chris@40:         data     : NULL
Chris@40:         datasize : anything
Chris@40: 
Chris@40:

Chris@40: Example: Chris@40:

Chris@40:
Chris@40:         normalisation = sf_command (sndfile, SFC_GET_NORM_DOUBLE, NULL, 0) ;
Chris@40: 
Chris@40:
Chris@40:
Return value:
Chris@40:
Returns TRUE if normalisation is on and FALSE otherwise. Chris@40:
Chris@40: Chris@40: Chris@40: Chris@40:


SFC_GET_SIMPLE_FORMAT_COUNT

Chris@40:

Chris@40: Retrieve the number of simple formats supported by libsndfile. Chris@40:

Chris@40:

Chris@40: Parameters: Chris@40:

Chris@40:
Chris@40:         sndfile  : Not used.
Chris@40:         cmd      : SFC_GET_SIMPLE_FORMAT_COUNT
Chris@40:         data     : a pointer to an int
Chris@40:         datasize : sizeof (int)
Chris@40: 
Chris@40:

Chris@40: Example: Chris@40:

Chris@40:
Chris@40:         int  count ;
Chris@40:         sf_command (sndfile, SFC_GET_SIMPLE_FORMAT_COUNT, &count, sizeof (int)) ;
Chris@40: 
Chris@40:
Chris@40:
Return value:
Chris@40:
0 Chris@40:
Chris@40: Chris@40: Chris@40: Chris@40:


SFC_GET_SIMPLE_FORMAT

Chris@40:

Chris@40: Retrieve information about a simple format. Chris@40:

Chris@40:

Chris@40: Parameters: Chris@40:

Chris@40:
Chris@40:         sndfile  : Not used.
Chris@40:         cmd      : SFC_GET_SIMPLE_FORMAT
Chris@40:         data     : a pointer to an  SF_FORMAT_INFO struct
Chris@40:         datasize : sizeof (SF_FORMAT_INFO)
Chris@40: 
Chris@40:

Chris@40: The SF_FORMAT_INFO struct is defined in <sndfile.h> as: Chris@40:

Chris@40:
Chris@40:         typedef struct
Chris@40:         {   int         format ;
Chris@40:             const char  *name ;
Chris@40:             const char  *extension ;
Chris@40:         } SF_FORMAT_INFO ;
Chris@40: 
Chris@40:

Chris@40: When sf_command() is called with SF_GET_SIMPLE_FORMAT, the value of the format Chris@40: field should be the format number (ie 0 <= format <= count value obtained using Chris@40: SF_GET_SIMPLE_FORMAT_COUNT). Chris@40:

Chris@40:

Chris@40: Example: Chris@40:

Chris@40:
Chris@40:         SF_FORMAT_INFO	format_info ;
Chris@40:         int             k, count ;
Chris@40: 
Chris@40:         sf_command (sndfile, SFC_GET_SIMPLE_FORMAT_COUNT, &count, sizeof (int)) ;
Chris@40: 
Chris@40:         for (k = 0 ; k < count ; k++)
Chris@40:         {   format_info.format = k ;
Chris@40:             sf_command (sndfile, SFC_GET_SIMPLE_FORMAT, &format_info, sizeof (format_info)) ;
Chris@40:             printf ("%08x  %s %s\n", format_info.format, format_info.name, format_info.extension) ;
Chris@40:             } ;
Chris@40: 
Chris@40:
Chris@40:
Return value:
Chris@40:
0 on success and non-zero otherwise. Chris@40:
The value of the format field of the SF_FORMAT_INFO struct will be an value which Chris@40: can be placed in the format field of an SF_INFO struct when a file is to be opened Chris@40: for write. Chris@40:
The name field will contain a char* pointer to the name of the string ie "WAV (Microsoft 16 bit PCM)". Chris@40:
The extention field will contain the most commonly used file extension for that file type. Chris@40:
Chris@40: Chris@40: Chris@40: Chris@40:


SFC_GET_FORMAT_INFO

Chris@40:

Chris@40: Retrieve information about a major or subtype format. Chris@40:

Chris@40:

Chris@40: Parameters: Chris@40:

Chris@40:
Chris@40:         sndfile  : Not used.
Chris@40:         cmd      : SFC_GET_FORMAT_INFO
Chris@40:         data     : a pointer to an SF_FORMAT_INFO struct
Chris@40:         datasize : sizeof (SF_FORMAT_INFO)
Chris@40: 
Chris@40:

Chris@40: The SF_FORMAT_INFO struct is defined in <sndfile.h> as: Chris@40:

Chris@40:
Chris@40:         typedef struct
Chris@40:         {   int         format ;
Chris@40:             const char  *name ;
Chris@40:             const char  *extension ;
Chris@40:         } SF_FORMAT_INFO ;
Chris@40: 
Chris@40:

Chris@40: When sf_command() is called with SF_GET_FORMAT_INFO, the format field is Chris@40: examined and if (format & SF_FORMAT_TYPEMASK) is a valid format then the struct Chris@40: is filled in with information about the given major type. Chris@40: If (format & SF_FORMAT_TYPEMASK) is FALSE and (format & SF_FORMAT_SUBMASK) is a Chris@40: valid subtype format then the struct is filled in with information about the given Chris@40: subtype. Chris@40:

Chris@40:

Chris@40: Example: Chris@40:

Chris@40:
Chris@40:         SF_FORMAT_INFO	format_info ;
Chris@40: 
Chris@40:         format_info.format = SF_FORMAT_WAV ;
Chris@40:         sf_command (sndfile, SFC_GET_FORMAT_INFO, &format_info, sizeof (format_info)) ;
Chris@40:         printf ("%08x  %s %s\n", format_info.format, format_info.name, format_info.extension) ;
Chris@40: 
Chris@40:         format_info.format = SF_FORMAT_ULAW ;
Chris@40:         sf_command (sndfile, SFC_GET_FORMAT_INFO, &format_info, sizeof (format_info)) ;
Chris@40:         printf ("%08x  %s\n", format_info.format, format_info.name) ;
Chris@40: 
Chris@40:
Chris@40:
Return value:
Chris@40:
0 on success and non-zero otherwise. Chris@40:
Chris@40: Chris@40: Chris@40:


SFC_GET_FORMAT_MAJOR_COUNT

Chris@40:

Chris@40: Retrieve the number of major formats. Chris@40:

Chris@40:

Chris@40: Parameters: Chris@40:

Chris@40:
Chris@40:         sndfile  : Not used.
Chris@40:         cmd      : SFC_GET_FORMAT_MAJOR_COUNT
Chris@40:         data     : a pointer to an int
Chris@40:         datasize : sizeof (int)
Chris@40: 
Chris@40:

Chris@40: Example: Chris@40:

Chris@40:
Chris@40:         int  count ;
Chris@40:         sf_command (sndfile, SFC_GET_FORMAT_MAJOR_COUNT, &count, sizeof (int)) ;
Chris@40: 
Chris@40:
Chris@40:
Return value:
Chris@40:
0 Chris@40:
Chris@40: Chris@40: Chris@40: Chris@40:


SFC_GET_FORMAT_MAJOR

Chris@40:

Chris@40: Retrieve information about a major format type. Chris@40:

Chris@40:

Chris@40: Parameters: Chris@40:

Chris@40:
Chris@40:         sndfile  : Not used.
Chris@40:         cmd      : SFC_GET_FORMAT_MAJOR
Chris@40:         data     : a pointer to an  SF_FORMAT_INFO struct
Chris@40:         datasize : sizeof (SF_FORMAT_INFO)
Chris@40: 
Chris@40:

Chris@40: Example: Chris@40:

Chris@40:
Chris@40:         SF_FORMAT_INFO	format_info ;
Chris@40:         int             k, count ;
Chris@40: 
Chris@40:         sf_command (sndfile, SFC_GET_FORMAT_MAJOR_COUNT, &count, sizeof (int)) ;
Chris@40: 
Chris@40:         for (k = 0 ; k < count ; k++)
Chris@40:         {   format_info.format = k ;
Chris@40:             sf_command (sndfile, SFC_GET_FORMAT_MAJOR, &format_info, sizeof (format_info)) ;
Chris@40:             printf ("%08x  %s %s\n", format_info.format, format_info.name, format_info.extension) ;
Chris@40:             } ;
Chris@40: 
Chris@40:

Chris@40: For a more comprehensive example, see the program list_formats.c in the examples/ Chris@40: directory of the libsndfile source code distribution. Chris@40:

Chris@40:
Chris@40:
Return value:
Chris@40:
0 on success and non-zero otherwise. Chris@40:
The value of the format field will one of the major format identifiers suc as SF_FORMAT_WAV Chris@40: SF_FORMAT_AIFF. Chris@40:
The name field will contain a char* pointer to the name of the string ie "WAV (Microsoft)". Chris@40:
The extention field will contain the most commonly used file extension for that file type. Chris@40:
Chris@40: Chris@40: Chris@40: Chris@40:


SFC_GET_FORMAT_SUBTYPE_COUNT

Chris@40:

Chris@40: Retrieve the number of subformats. Chris@40:

Chris@40:

Chris@40: Parameters: Chris@40:

Chris@40:
Chris@40:         sndfile  : Not used.
Chris@40:         cmd      : SFC_GET_FORMAT_SUBTYPE_COUNT
Chris@40:         data     : a pointer to an int
Chris@40:         datasize : sizeof (int)
Chris@40: 
Chris@40:

Chris@40: Example: Chris@40:

Chris@40:
Chris@40:         int   count ;
Chris@40:         sf_command (sndfile, SFC_GET_FORMAT_SUBTYPE_COUNT, &count, sizeof (int)) ;
Chris@40: 
Chris@40:
Chris@40:
Return value:
Chris@40:
0 Chris@40:
Chris@40: Chris@40: Chris@40: Chris@40:


SFC_GET_FORMAT_SUBTYPE

Chris@40:

Chris@40: Retrieve information about a subformat. Chris@40:

Chris@40:

Chris@40: Parameters: Chris@40:

Chris@40:
Chris@40:         sndfile  : Not used.
Chris@40:         cmd      : SFC_GET_FORMAT_SUBTYPE
Chris@40:         data     : a pointer to an SF_FORMAT_INFO struct
Chris@40:         datasize : sizeof (SF_FORMAT_INFO)
Chris@40: 
Chris@40:

Chris@40: Example: Chris@40:

Chris@40:
Chris@40:         SF_FORMAT_INFO	format_info ;
Chris@40:         int             k, count ;
Chris@40: 
Chris@40:         sf_command (sndfile, SFC_GET_FORMAT_SUBTYPE_COUNT, &count, sizeof (int)) ;
Chris@40: 
Chris@40:         /* Retrieve all the subtypes supported by the WAV format. */
Chris@40:         for (k = 0 ; k < count ; k++)
Chris@40:         {   format_info.format = k ;
Chris@40:             sf_command (sndfile, SFC_GET_FORMAT_SUBTYPE, &format_info, sizeof (format_info)) ;
Chris@40:             if (! sf_format_check (format.info | SF_FORMAT_WAV))
Chris@40:                continue ;
Chris@40:             printf ("%08x  %s\n", format_info.format, format_info.name) ;
Chris@40:             } ;
Chris@40: 
Chris@40:

Chris@40: For a more comprehensive example, see the program list_formats.c in the examples/ Chris@40: directory of the libsndfile source code distribution. Chris@40:

Chris@40:
Chris@40:
Return value:
Chris@40:
0 on success and non-zero otherwise. Chris@40:
The value of the format field will one of the major format identifiers such as SF_FORMAT_WAV Chris@40: SF_FORMAT_AIFF. Chris@40:
The name field will contain a char* pointer to the name of the string; for instance Chris@40: "WAV (Microsoft)" or "AIFF (Apple/SGI)". Chris@40:
The extention field will be a NULL pointer. Chris@40:
Chris@40: Chris@40: Chris@40: Chris@40:


SFC_SET_ADD_PEAK_CHUNK

Chris@40:

Chris@40: By default, WAV and AIFF files which contain floating point data (subtype SF_FORMAT_FLOAT Chris@40: or SF_FORMAT_DOUBLE) have a PEAK chunk. Chris@40: By using this command, the addition of a PEAK chunk can be turned on or off. Chris@40:

Chris@40:

Chris@40: Note : This call must be made before any data is written to the file. Chris@40:

Chris@40:

Chris@40: Parameters: Chris@40:

Chris@40:         sndfile  : A valid SNDFILE* pointer
Chris@40:         cmd      : SFC_SET_ADD_PEAK_CHUNK
Chris@40:         data     : Not used (should be NULL)
Chris@40:         datasize : TRUE or FALSE.
Chris@40: 
Chris@40:

Chris@40: Example: Chris@40:

Chris@40:
Chris@40:         /* Turn on the PEAK chunk. */
Chris@40:         sf_command (sndfile, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_TRUE) ;
Chris@40: 
Chris@40:         /* Turn off the PEAK chunk. */
Chris@40:         sf_command (sndfile, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_FALSE) ;
Chris@40: 
Chris@40:
Chris@40:
Return value:
Chris@40:
Returns SF_TRUE if the peak chunk will be written after this call. Chris@40:
Returns SF_FALSE if the peak chunk will not be written after this call. Chris@40:
Chris@40: Chris@40: Chris@40: Chris@40:


SFC_UPDATE_HEADER_NOW

Chris@40:

Chris@40: The header of an audio file is normally written by libsndfile when the file is Chris@40: closed using sf_close(). Chris@40:

Chris@40:

Chris@40: There are however situations where large files are being generated and it would Chris@40: be nice to have valid data in the header before the file is complete. Chris@40: Using this command will update the file header to reflect the amount of data written Chris@40: to the file so far. Chris@40: Other programs opening the file for read (before any more data is written) will Chris@40: then read a valid sound file header. Chris@40:

Chris@40:

Chris@40: Parameters: Chris@40:

Chris@40:         sndfile  : A valid SNDFILE* pointer
Chris@40:         cmd      : SFC_UPDATE_HEADER_NOW
Chris@40:         data     : Not used (should be NULL)
Chris@40:         datasize : Not used.
Chris@40: 
Chris@40:

Chris@40: Example: Chris@40:

Chris@40:
Chris@40:         /* Update the header now. */
Chris@40:         sf_command (sndfile, SFC_UPDATE_HEADER_NOW, NULL, 0) ;
Chris@40: 
Chris@40:
Chris@40:
Return value:
Chris@40:
0 Chris@40:
Chris@40: Chris@40: Chris@40: Chris@40:


SFC_SET_UPDATE_HEADER_AUTO

Chris@40:

Chris@40: Similar to SFC_UPDATE_HEADER_NOW but updates the header at the end of every call Chris@40: to the sf_write* functions. Chris@40:

Chris@40:

Chris@40: Parameters: Chris@40:

Chris@40:         sndfile  : A valid SNDFILE* pointer
Chris@40:         cmd      : SFC_UPDATE_HEADER_NOW
Chris@40:         data     : Not used (should be NULL)
Chris@40:         datasize : SF_TRUE or SF_FALSE
Chris@40: 
Chris@40:

Chris@40: Example: Chris@40:

Chris@40:
Chris@40:         /* Turn on auto header update. */
Chris@40:         sf_command (sndfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) ;
Chris@40: 
Chris@40:         /* Turn off auto header update. */
Chris@40:         sf_command (sndfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_FALSE) ;
Chris@40: 
Chris@40:
Chris@40:
Return value:
Chris@40:
TRUE if auto update header is now on; FALSE otherwise. Chris@40:
Chris@40: Chris@40: Chris@40: Chris@40:


SFC_FILE_TRUNCATE

Chris@40:

Chris@40: Truncate a file open for write or for read/write. Chris@40:

Chris@40:

Chris@40: Parameters: Chris@40:

Chris@40:         sndfile  : A valid SNDFILE* pointer
Chris@40:         cmd      : SFC_FILE_TRUNCATE
Chris@40:         data     : A pointer to an sf_count_t.
Chris@40:         datasize : sizeof (sf_count_t)
Chris@40: 
Chris@40: Chris@40:

Chris@40: Truncate the file to the number of frames specified by the sf_count_t pointed Chris@40: to by data. Chris@40: After this command, both the read and the write pointer will be Chris@40: at the new end of the file. Chris@40: This command will fail (returning non-zero) if the requested truncate position Chris@40: is beyond the end of the file. Chris@40:

Chris@40:

Chris@40: Example: Chris@40:

Chris@40:
Chris@40:         /* Truncate the file to a length of 20 frames. */
Chris@40:         sf_count_t  frames = 20 ;
Chris@40:         sf_command (sndfile, SFC_FILE_TRUNCATE, &frames, sizeof (frames)) ;
Chris@40: 
Chris@40:
Chris@40:
Return value:
Chris@40:
Zero on sucess, non-zero otherwise. Chris@40:
Chris@40: Chris@40: Chris@40: Chris@40:


SFC_SET_RAW_START_OFFSET

Chris@40:

Chris@40: Change the data start offset for files opened up as SF_FORMAT_RAW. Chris@40:

Chris@40:

Chris@40: Parameters: Chris@40:

Chris@40:         sndfile  : A valid SNDFILE* pointer
Chris@40:         cmd      : SFC_SET_RAW_START_OFFSET
Chris@40:         data     : A pointer to an sf_count_t.
Chris@40:         datasize : sizeof (sf_count_t)
Chris@40: 
Chris@40: Chris@40:

Chris@40: For a file opened as format SF_FORMAT_RAW, set the data offset to the value Chris@40: given by data. Chris@40:

Chris@40:

Chris@40: Example: Chris@40:

Chris@40:
Chris@40:         /* Reset the data offset to 5 bytes from the start of the file. */
Chris@40:         sf_count_t  offset = 5 ;
Chris@40:         sf_command (sndfile, SFC_SET_RAW_START_OFFSET, &offset, sizeof (offset)) ;
Chris@40: 
Chris@40:
Chris@40:
Return value:
Chris@40:
Zero on sucess, non-zero otherwise. Chris@40:
Chris@40: Chris@40: Chris@40: Chris@40:
Chris@40:

Chris@40: The libsndfile home page is here : Chris@40: Chris@40: http://www.mega-nerd.com/libsndfile/. Chris@40:
Chris@40: Version : 1.0.27 Chris@40:

Chris@40: Chris@40: Chris@40: