Chris@40: Chris@40: Chris@40: Chris@40:
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 an integer identifier which is defined in <sndfile.h>. Chris@40: All of the valid command identifiers have names beginning 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:SFC_GET_LIB_VERSION | Chris@40:Retrieve the version of the library. | Chris@40:
SFC_GET_LOG_INFO | Chris@40:Retrieve the internal per-file operation log. | Chris@40:
SFC_CALC_SIGNAL_MAX | Chris@40:Calculate the measured maximum signal value. | Chris@40:
SFC_CALC_NORM_SIGNAL_MAX | Chris@40:Calculate the measured normalised maximum signal value. | Chris@40:
SFC_CALC_MAX_ALL_CHANNELS | Chris@40:Calculate the peak value for each channel. | Chris@40:
SFC_CALC_NORM_MAX_ALL_CHANNELS | Chris@40:Calculate the normalised peak for each channel. | Chris@40:
SFC_GET_SIGNAL_MAX | Chris@40:Retrieve the peak value for the file (as stored in the file header). | Chris@40:
SFC_GET_MAX_ALL_CHANNELS | Chris@40:Retrieve the peak value for each channel (as stored in the file header). | Chris@40:
SFC_SET_NORM_FLOAT | Chris@40:Modify the normalisation behaviour of the floating point reading and writing functions. | Chris@40:
SFC_SET_NORM_DOUBLE | Chris@40:Modify the normalisation behaviour of the double precision floating point reading and writing functions. | Chris@40:
SFC_GET_NORM_FLOAT | Chris@40:Retrieve the current normalisation behaviour of the floating point reading and writing functions. | Chris@40:
SFC_GET_NORM_DOUBLE | Chris@40:Retrieve the current normalisation behaviour of the double precision floating point reading and writing functions. | Chris@40:
SFC_SET_SCALE_FLOAT_INT_READ | Chris@40:Set/clear the scale factor when integer (short/int) data is read from a file Chris@40: containing floating point data. | Chris@40:
SFC_SET_SCALE_INT_FLOAT_WRITE | Chris@40:Set/clear the scale factor when integer (short/int) data is written to a file Chris@40: as floating point data. | Chris@40:
SFC_GET_SIMPLE_FORMAT_COUNT | Chris@40:Retrieve the number of simple formats supported by libsndfile. | Chris@40:
SFC_GET_SIMPLE_FORMAT | Chris@40:Retrieve information about a simple format. | Chris@40:
SFC_GET_FORMAT_INFO | Chris@40:Retrieve information about a major or subtype format. | Chris@40:
SFC_GET_FORMAT_MAJOR_COUNT | Chris@40:Retrieve the number of major formats. | Chris@40:
SFC_GET_FORMAT_MAJOR | Chris@40:Retrieve information about a major format type. | Chris@40:
SFC_GET_FORMAT_SUBTYPE_COUNT | Chris@40:Retrieve the number of subformats. | Chris@40:
SFC_GET_FORMAT_SUBTYPE | Chris@40:Retrieve information about a subformat. | Chris@40:
SFC_SET_ADD_PEAK_CHUNK | Chris@40:Switch the code for adding the PEAK chunk to WAV and AIFF files on or off. | Chris@40:
SFC_UPDATE_HEADER_NOW | Chris@40:Used when a file is open for write, this command will update the file Chris@40: header to reflect the data written so far. | Chris@40:
SFC_SET_UPDATE_HEADER_AUTO | Chris@40:Used 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. | Chris@40:
SFC_FILE_TRUNCATE | Chris@40:Truncate a file open for write or for read/write. | Chris@40:
SFC_SET_RAW_START_OFFSET | Chris@40:Change the data start offset for files opened up as SF_FORMAT_RAW. | Chris@40:
SFC_SET_CLIPPING | Chris@40:Turn on/off automatic clipping when doing floating point to integer Chris@40: conversion. | Chris@40:
SFC_GET_CLIPPING | Chris@40:Retrieve current clipping setting. | Chris@40:
SFC_GET_EMBED_FILE_INFO | Chris@40:Retrieve information about audio files embedded inside other files. | Chris@40:
SFC_GET_AMBISONIC | Chris@40:Test a WAVEX file for Ambisonic format | Chris@40:
SFC_SET_AMBISONIC | Chris@40:Modify a WAVEX header for Ambisonic format | Chris@40:
SFC_SET_VBR_ENCODING_QUALITY | Chris@40:Set the Variable Bit Rate encoding quality | Chris@40:
SFC_SET_COMPRESSION_LEVEL | Chris@40:Set the compression level. | Chris@40:
SFC_RAW_NEEDS_ENDSWAP | Chris@40:Determine if raw data needs endswapping | Chris@40:
SFC_GET_BROADCAST_INFO | Chris@40:Retrieve the Broadcast Chunk info | Chris@40:
SFC_SET_BROADCAST_INFO | Chris@40:Set the Broadcast Chunk info | Chris@40:
SFC_SET_CART_INFO | Chris@40:Set the Cart Chunk info | Chris@40:
SFC_GET_CART_INFO | Chris@40:Retrieve the Cart Chunk info | Chris@40:
SFC_GET_LOOP_INFO | Chris@40:Get loop info | Chris@40:
SFC_GET_INSTRUMENT | Chris@40:Get instrument info | Chris@40:
SFC_SET_INSTRUMENT | Chris@40:Set instrument info | Chris@40:
SFC_GET_CUE_COUNT | Chris@40:Get the cue marker count | Chris@40:
SFC_GET_CUE | Chris@40:Get cue marker info | Chris@40:
SFC_SET_CUE | Chris@40:Set cue marker info | Chris@40:
SFC_RF64_AUTO_DOWNGRADE | Chris@40:Enable auto downgrade from RF64 to WAV | 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: 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: 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: Retrieve the measured normalised 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: Calculate the peak value (ie a single number) for each channel. Chris@40: This involves reading 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_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: Calculate the normalised peak for each channel. Chris@40: This involves reading 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_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: Retrieve the peak value for the file as stored in the file header. Chris@40:
Chris@40:Chris@40: Parameters: Chris@40:
Chris@40: sndfile : A valid SNDFILE* pointer Chris@40: cmd : SFC_GET_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_peak ; Chris@40: sf_command (sndfile, SFC_GET_SIGNAL_MAX, &max_peak, sizeof (max_peak)) ; Chris@40:Chris@40:
Chris@40: Retrieve the peak value for the file as stored in the file header. Chris@40:
Chris@40:Chris@40: Parameters: Chris@40:
Chris@40: sndfile : A valid SNDFILE* pointer Chris@40: cmd : SFC_GET_SIGNAL_MAX Chris@40: data : A pointer to an array of doubles 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_GET_MAX_ALL_CHANNELS, peaks, sizeof (peaks)) ; Chris@40: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: 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: 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: 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: Set/clear the scale factor when integer (short/int) data is read from a file Chris@40: containing floating point data. Chris@40:
Chris@40:Chris@40: Parameters: Chris@40:
Chris@40:Chris@40: sndfile : A valid SNDFILE* pointer Chris@40: cmd : SFC_SET_SCALE_FLOAT_INT_READ Chris@40: data : NULL Chris@40: datasize : TRUE or FALSE Chris@40:Chris@40:
Chris@40: Example: Chris@40:
Chris@40:Chris@40: sf_command (sndfile, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ; Chris@40:Chris@40:
Chris@40: Set/clear the scale factor when integer (short/int) data is written to a file Chris@40: as floating point data. Chris@40:
Chris@40:Chris@40: Parameters: Chris@40:
Chris@40:Chris@40: sndfile : A valid SNDFILE* pointer Chris@40: cmd : SFC_SET_SCALE_FLOAT_INT_READ Chris@40: data : NULL Chris@40: datasize : TRUE or FALSE Chris@40:Chris@40:
Chris@40: Example: Chris@40:
Chris@40:Chris@40: sf_command (sndfile, SFC_SET_SCALE_INT_FLOAT_WRITE, NULL, SF_TRUE) ; Chris@40: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: 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: 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: 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: 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: 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: Enumerate the subtypes (this function does not translate a subtype into Chris@40: a string describing that subtype). Chris@40: A typical use case might be retrieving a string description of all subtypes Chris@40: so that a dialog box can be filled in. Chris@40:
Chris@40:Chris@40: 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 1: Retrieve all sybtypes supported by the WAV format. 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: 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.format | 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: Example 2: Print a string describing the SF_FORMAT_PCM_16 subtype. 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: 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 (format_info.format == SF_FORMAT_PCM_16) Chris@40: { printf ("%08x %s\n", format_info.format, format_info.name) ; Chris@40: break ; Chris@40: } ; 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: 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: 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: 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: Truncate a file that was opened for write or 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: 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: Turn on/off automatic clipping when doing floating point to integer conversion. Chris@40:
Chris@40:Chris@40: Parameters: Chris@40:
Chris@40: sndfile : A valid SNDFILE* pointer Chris@40: cmd : SFC_SET_CLIPPING Chris@40: data : NULL Chris@40: datasize : SF_TRUE or SF_FALSE. Chris@40:Chris@40: Chris@40:
Chris@40: Turn on (datasize == SF_TRUE) or off (datasize == SF_FALSE) clipping. Chris@40:
Chris@40:Chris@40: Example: Chris@40:
Chris@40:Chris@40: sf_command (sndfile, SFC_SET_CLIPPING, NULL, SF_TRUE) ; Chris@40:Chris@40:
Chris@40: Turn on/off automatic clipping when doing floating point to integer conversion. Chris@40:
Chris@40:Chris@40: Parameters: Chris@40:
Chris@40: sndfile : A valid SNDFILE* pointer Chris@40: cmd : SFC_GET_CLIPPING Chris@40: data : NULL Chris@40: datasize : 0 Chris@40:Chris@40: Chris@40:
Chris@40: Retrieve the current cliiping setting. Chris@40:
Chris@40:Chris@40: Example: Chris@40:
Chris@40:Chris@40: sf_command (sndfile, SFC_GET_CLIPPING, NULL, 0) ; Chris@40:Chris@40:
Chris@40: Get the file offset and file length of a file enbedded within another Chris@40: larger file. Chris@40:
Chris@40:Chris@40: Parameters: Chris@40:
Chris@40: sndfile : A valid SNDFILE* pointer Chris@40: cmd : SFC_GET_CLIPPING Chris@40: data : a pointer to an SF_EMBED_FILE_INFO struct Chris@40: datasize : sizeof (SF_EMBED_FILE_INFO) Chris@40:Chris@40:
Chris@40: The SF_EMBED_FILE_INFO struct is defined in <sndfile.h> as: Chris@40:
Chris@40:Chris@40: typedef struct Chris@40: { sf_count_t offset ; Chris@40: sf_count_t length ; Chris@40: } SF_EMBED_FILE_INFO ; Chris@40:Chris@40:
Chris@40: Test if the current file has the GUID of a WAVEX file for any of the Ambisonic Chris@40: formats. Chris@40:
Chris@40:Chris@40: Parameters: Chris@40:
Chris@40: sndfile : A valid SNDFILE* pointer Chris@40: cmd : SFC_WAVEX_GET_AMBISONIC Chris@40: data : NULL Chris@40: datasize : 0 Chris@40:Chris@40:
Chris@40: The Ambisonic WAVEX formats are defined here : Chris@40: Chris@40: http://dream.cs.bath.ac.uk/researchdev/wave-ex/bformat.html. Chris@40:
Chris@40:Chris@40: Set the GUID of a new WAVEX file to indicate an Ambisonics format. Chris@40:
Chris@40:Chris@40: Parameters: Chris@40:
Chris@40: sndfile : A valid SNDFILE* pointer Chris@40: cmd : SFC_WAVEX_SET_AMBISONIC Chris@40: data : NULL Chris@40: datasize : SF_AMBISONIC_NONE or SF_AMBISONIC_B_FORMAT Chris@40:Chris@40:
Chris@40: Turn on (SF_AMBISONIC_B_FORMAT) or off (SF_AMBISONIC_NONE) encoding. Chris@40: This command is currently only supported for files with SF_FORMAT_WAVEX format. Chris@40:
Chris@40:Chris@40: The Ambisonic WAVEX formats are defined here : Chris@40: Chris@40: http://dream.cs.bath.ac.uk/researchdev/wave-ex/bformat.html. Chris@40:
Chris@40:Chris@40: Set the Variable Bit Rate encoding quality. Chris@40: The encoding quality value should be between 0.0 (lowest quality) and 1.0 Chris@40: (highest quality). Chris@40: Currenly this command is only implemented for FLAC and Ogg/Vorbis files. Chris@40: It has no effect on un-compressed file formats. Chris@40:
Chris@40:Chris@40: Parameters: Chris@40:
Chris@40: sndfile : A valid SNDFILE* pointer Chris@40: cmd : SFC_SET_VBR_ENCODING_QUALITY Chris@40: data : A pointer to a double value Chris@40: datasize : sizeof (double) Chris@40:Chris@40:
Chris@40: The command must be sent before any audio data is written to the file. Chris@40:
Chris@40:Chris@40:
Chris@40:Chris@40: Set the compression level. Chris@40: The compression level should be between 0.0 (minimum compression level) and 1.0 Chris@40: (highest compression level). Chris@40: Currenly this command is only implemented for FLAC and Ogg/Vorbis files. Chris@40: It has no effect on un-compressed file formats. Chris@40:
Chris@40:Chris@40: Parameters: Chris@40:
Chris@40: sndfile : A valid SNDFILE* pointer Chris@40: cmd : SFC_SET_COMPRESSION_LEVEL Chris@40: data : A pointer to a double value Chris@40: datasize : sizeof (double) Chris@40:Chris@40:
Chris@40: The command must be sent before any audio data is written to the file. Chris@40:
Chris@40:Chris@40:
Chris@40:Chris@40: Determine if raw data read using Chris@40: Chris@40: sf_read_raw Chris@40: needs to be end swapped on the host CPU. Chris@40:
Chris@40:Chris@40: For instance, will return SF_TRUE on when reading WAV containing Chris@40: SF_FORMAT_PCM_16 data on a big endian machine and SF_FALSE on a little endian Chris@40: machine. Chris@40:
Chris@40:Chris@40: Parameters: Chris@40:
Chris@40: sndfile : A valid SNDFILE* pointer Chris@40: cmd : SFC_RAW_NEEDS_ENDSWAP Chris@40: data : NULL Chris@40: datasize : 0 Chris@40:Chris@40: Chris@40:
Chris@40: Retrieve the Broadcast Extension Chunk from WAV (and related) files. Chris@40:
Chris@40:Chris@40: Parameters: Chris@40:
Chris@40:Chris@40: sndfile : A valid SNDFILE* pointer Chris@40: cmd : SFC_GET_BROADCAST_INFO Chris@40: data : a pointer to an SF_BROADCAST_INFO struct Chris@40: datasize : sizeof (SF_BROADCAST_INFO) Chris@40:Chris@40:
Chris@40: The SF_BROADCAST_INFO struct is defined in <sndfile.h> as: Chris@40:
Chris@40:Chris@40: typedef struct Chris@40: { char description [256] ; Chris@40: char originator [32] ; Chris@40: char originator_reference [32] ; Chris@40: char origination_date [10] ; Chris@40: char origination_time [8] ; Chris@40: unsigned int time_reference_low ; Chris@40: unsigned int time_reference_high ; Chris@40: short version ; Chris@40: char umid [64] ; Chris@40: char reserved [190] ; Chris@40: unsigned int coding_history_size ; Chris@40: char coding_history [256] ; Chris@40: } SF_BROADCAST_INFO ; Chris@40:Chris@40: Chris@40:
Chris@40: Set the Broadcast Extension Chunk for WAV (and related) files. Chris@40:
Chris@40:Chris@40: Parameters: Chris@40:
Chris@40:Chris@40: sndfile : A valid SNDFILE* pointer Chris@40: cmd : SFC_SET_BROADCAST_INFO Chris@40: data : a pointer to an SF_BROADCAST_INFO struct Chris@40: datasize : sizeof (SF_BROADCAST_INFO) Chris@40:Chris@40: Chris@40:
Retrieve the Cart Chunk from WAV (and related) files. Based on AES46 standard for CartChunk (see CartChunk.org for more information. Chris@40:
Chris@40:Chris@40: Parameters: Chris@40:
Chris@40:Chris@40: sndfile : A valid SNDFILE* pointer Chris@40: cmd : SFC_GET_CART_INFO Chris@40: data : a pointer to an SF_CART_INFO struct Chris@40: datasize : sizeof (SF_CART_INFO) Chris@40:Chris@40:
Chris@40: The SF_CART_INFO struct is defined in <sndfile.h> as: Chris@40:
Chris@40:Chris@40: #define SF_CART_INFO_VAR(p_tag_text_size) \ Chris@40: struct Chris@40: { char version [4] ; Chris@40: char title [64] ; Chris@40: char artist [64] ; Chris@40: char cut_id [64] ; Chris@40: char client_id [64] ; Chris@40: char category [64] ; Chris@40: char classification [64] ; Chris@40: char out_cue [64] ; Chris@40: char start_date [10] ; Chris@40: char start_time [8] ; Chris@40: char end_date [10] ; Chris@40: char end_time [8] ; Chris@40: char producer_app_id [64] ; Chris@40: char producer_app_version [64] ; Chris@40: char user_def [64] ; Chris@40: long level_reference ; Chris@40: SF_CART_TIMER post_timers [8] ; Chris@40: char reserved [276] ; Chris@40: char url [1024] ; Chris@40: unsigned int tag_text_size ; Chris@40: char tag_text[p_tag_text_size] ; Chris@40: } Chris@40:Chris@40: Chris@40:
Chris@40: Set the Cart Chunk for WAV (and related) files. Chris@40:
Chris@40:Chris@40: Parameters: Chris@40:
Chris@40:Chris@40: sndfile : A valid SNDFILE* pointer Chris@40: cmd : SFC_SET_CART_INFO Chris@40: data : a pointer to an SF_CART_INFO struct Chris@40: datasize : sizeof (SF_CART_INFO) Chris@40:Chris@40: Chris@40:
Chris@40: Retrieve loop information for file including time signature, length in Chris@40: beats and original MIDI base note Chris@40:
Chris@40:Chris@40: Parameters: Chris@40:
Chris@40:Chris@40: sndfile : A valid SNDFILE* pointer Chris@40: cmd : SFC_GET_LOOP_INFO Chris@40: data : a pointer to an SF_LOOP_INFO struct Chris@40: datasize : sizeof (SF_LOOP_INFO) Chris@40:Chris@40:
Chris@40: The SF_BROADCAST_INFO struct is defined in <sndfile.h> as: Chris@40:
Chris@40:Chris@40: typedef struct Chris@40: { short time_sig_num ; /* any positive integer > 0 */ Chris@40: short time_sig_den ; /* any positive power of 2 > 0 */ Chris@40: int loop_mode ; /* see SF_LOOP enum */ Chris@40: Chris@40: int num_beats ; /* this is NOT the amount of quarter notes !!!*/ Chris@40: /* a full bar of 4/4 is 4 beats */ Chris@40: /* a full bar of 7/8 is 7 beats */ Chris@40: Chris@40: float bpm ; /* suggestion, as it can be calculated using other fields:*/ Chris@40: /* file's lenght, file's sampleRate and our time_sig_den*/ Chris@40: /* -> bpms are always the amount of _quarter notes_ per minute */ Chris@40: Chris@40: int root_key ; /* MIDI note, or -1 for None */ Chris@40: int future [6] ; Chris@40: } SF_LOOP_INFO ; Chris@40:Chris@40:
Chris@40: Example: Chris@40:
Chris@40:Chris@40: SF_LOOP_INFO loop; Chris@40: sf_command (sndfile, SFC_GET_LOOP_INFO, &loop, sizeof (loop)) ; Chris@40:Chris@40:
Chris@40: Retrieve instrument information from file including MIDI base note, Chris@40: keyboard mapping and looping informations(start/stop and mode). Chris@40:
Chris@40:Chris@40: Parameters: Chris@40:
Chris@40:Chris@40: sndfile : A valid SNDFILE* pointer Chris@40: cmd : SFC_GET_INSTRUMENT Chris@40: data : a pointer to an SF_INSTRUMENT struct Chris@40: datasize : sizeof (SF_INSTRUMENT) Chris@40:Chris@40: Chris@40:
Chris@40: The SF_INSTRUMENT struct is defined in <sndfile.h> as: Chris@40:
Chris@40:Chris@40: enum Chris@40: { /* Chris@40: ** The loop mode field in SF_INSTRUMENT will be one of the following. Chris@40: */ Chris@40: SF_LOOP_NONE = 800, Chris@40: SF_LOOP_FORWARD, Chris@40: SF_LOOP_BACKWARD, Chris@40: SF_LOOP_ALTERNATING Chris@40: } ; Chris@40: Chris@40: typedef struct Chris@40: { int gain ; Chris@40: char basenote, detune ; Chris@40: char velocity_lo, velocity_hi ; Chris@40: char key_lo, key_hi ; Chris@40: int loop_count ; Chris@40: Chris@40: struct Chris@40: { int mode ; Chris@40: unsigned int start ; Chris@40: unsigned int end ; Chris@40: unsigned int count ; Chris@40: } loops [16] ; /* make variable in a sensible way */ Chris@40: } SF_INSTRUMENT ; Chris@40:Chris@40: Chris@40:
Chris@40: Example: Chris@40:
Chris@40:Chris@40: SF_INSTRUMENT inst ; Chris@40: sf_command (sndfile, SFC_GET_INSTRUMENT, &inst, sizeof (inst)) ; Chris@40:Chris@40:
Chris@40: Set the instrument information for the file. Chris@40:
Chris@40:Chris@40: Parameters: Chris@40:
Chris@40:Chris@40: sndfile : A valid SNDFILE* pointer Chris@40: cmd : SFC_SET_INSTRUMENT Chris@40: data : a pointer to an SF_INSTRUMENT struct Chris@40: datasize : sizeof (SF_INSTRUMENT) Chris@40:Chris@40:
Chris@40: Example: Chris@40:
Chris@40:Chris@40: SF_INSTRUMENT inst ; Chris@40: sf_command (sndfile, SFC_SET_INSTRUMENT, &inst, sizeof (inst)) ; Chris@40:Chris@40:
Chris@40: Retrieve the number of cue markers available for retrieval using the Chris@40: SFC_GET_CUE command. Chris@40:
Chris@40:Chris@40: Parameters: Chris@40:
Chris@40:Chris@40: sndfile : A valid SNDFILE* pointer Chris@40: cmd : SFC_GET_CUE Chris@40: data : a pointer to a uint32_t Chris@40: datasize : sizeof (uint32_t) Chris@40:Chris@40: Chris@40: Chris@40:
Chris@40: Example: Chris@40:
Chris@40:Chris@40: uint32_t cue_count ; Chris@40: sf_command (sndfile, SFC_GET_CUE_COUNT, &cue_count, sizeof (cue_count)) ; Chris@40:Chris@40:
Chris@40: Retrieve cue marker information from file. Chris@40:
Chris@40:Chris@40: Parameters: Chris@40:
Chris@40:Chris@40: sndfile : A valid SNDFILE* pointer Chris@40: cmd : SFC_GET_CUE Chris@40: data : a pointer to an SF_CUES struct Chris@40: datasize : sizeof (SF_CUES) Chris@40:Chris@40: Chris@40:
Chris@40: The SF_CUES struct is defined in <sndfile.h> as: Chris@40:
Chris@40:Chris@40: typedef struct Chris@40: { int cue_count ; Chris@40: Chris@40: struct Chris@40: { int32_t indx ; Chris@40: uint32_t position ; Chris@40: int32_t fcc_chunk ; Chris@40: int32_t chunk_start ; Chris@40: int32_t block_start ; Chris@40: uint32_t sample_offset ; Chris@40: char name [256] ; Chris@40: } cue_points [100] ; Chris@40: } SF_CUES ; Chris@40:Chris@40: Chris@40:
Chris@40: There is also an SF_CUES_VAR #define that allows reading/writing more than 100 Chris@40: cue markers. Chris@40:
Chris@40: Chris@40:Chris@40: Example: Chris@40:
Chris@40:Chris@40: SF_CUES cues ; Chris@40: sf_command (sndfile, SFC_GET_CUE, &cues, sizeof (cues)) ; Chris@40:Chris@40:
Chris@40: Set the cue marker information for the file. Chris@40:
Chris@40:Chris@40: Parameters: Chris@40:
Chris@40:Chris@40: sndfile : A valid SNDFILE* pointer Chris@40: cmd : SFC_SET_CUE Chris@40: data : a pointer to an SF_CUES struct Chris@40: datasize : sizeof (SF_CUES) Chris@40:Chris@40:
Chris@40: Example: Chris@40:
Chris@40:Chris@40: SF_CUES cues ; Chris@40: sf_command (sndfile, SFC_SET_CUE, &cues, sizeof (cues)) ; Chris@40:Chris@40:
Chris@40: Enable auto downgrade from RF64 to WAV. Chris@40:
Chris@40:Chris@40: The EBU recomendation is that when writing RF64 files and the resulting file is Chris@40: less than 4Gig in size, it should be downgraded to a WAV file (WAV files have a Chris@40: maximum size of 4Gig). Chris@40: libsndfile doesn't follow the EBU recommendations exactly, , mainly because the Chris@40: test suite needs to be able test reading/writing RF64 files without having to Chris@40: generate files larger than 4 gigabytes. Chris@40:
Chris@40:Chris@40: Note: This command should be issued before the first bit of audio data has been Chris@40: written to the file. Chris@40: Calling this command after audio data has been written will return the current Chris@40: value of this setting, but will not allow it to be changed. Chris@40:
Chris@40:Chris@40: Parameters: Chris@40:
Chris@40:Chris@40: sndfile : A valid SNDFILE* pointer Chris@40: cmd : SFC_RF64_AUTO_DOWNGRADE Chris@40: data : NULL Chris@40: datasize : SF_TRUE or SF_FALSE Chris@40:Chris@40:
Chris@40: Example: Chris@40:
Chris@40:Chris@40: /* Enable auto downgrade on file close. */ Chris@40: sf_command (sndfile, SFC_RF64_AUTO_DOWNGRADE, NULL, SF_TRUE) ; 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.25
Chris@40: