Chris@0: Chris@0: Chris@0: Chris@0:
Chris@0:Chris@0: Chris@0: int sf_command (SNDFILE *sndfile, int cmd, void *data, int datasize) ; Chris@0:Chris@0:
Chris@0: This function allows the caller to retrieve information from or change aspects of the Chris@0: library behaviour. Chris@0: Examples include retrieving a string containing the library version or changing the Chris@0: scaling applied to floating point sample data during read and write. Chris@0: Most of these operations are performed on a per-file basis. Chris@0:
Chris@0:Chris@0: The cmd parameter is an integer identifier which is defined in <sndfile.h>. Chris@0: All of the valid command identifiers have names beginning with "SFC_". Chris@0: Data is passed to and returned from the library by use of a void pointer. Chris@0: The library will not read or write more than datasize bytes from the void pointer. Chris@0: For some calls no data is required in which case data should be NULL and datasize Chris@0: may be used for some other purpose. Chris@0:
Chris@0:Chris@0: The available commands are as follows: Chris@0:
Chris@0: Chris@0:SFC_GET_LIB_VERSION | Chris@0:Retrieve the version of the library. | Chris@0:
SFC_GET_LOG_INFO | Chris@0:Retrieve the internal per-file operation log. | Chris@0:
SFC_CALC_SIGNAL_MAX | Chris@0:Calculate the measured maximum signal value. | Chris@0:
SFC_CALC_NORM_SIGNAL_MAX | Chris@0:Calculate the measured normalised maximum signal value. | Chris@0:
SFC_CALC_MAX_ALL_CHANNELS | Chris@0:Calculate the peak value for each channel. | Chris@0:
SFC_CALC_NORM_MAX_ALL_CHANNELS | Chris@0:Calculate the normalised peak for each channel. | Chris@0:
SFC_GET_SIGNAL_MAX | Chris@0:Retrieve the peak value for the file (as stored in the file header). | Chris@0:
SFC_GET_MAX_ALL_CHANNELS | Chris@0:Retrieve the peak value for each channel (as stored in the file header). | Chris@0:
SFC_SET_NORM_FLOAT | Chris@0:Modify the normalisation behaviour of the floating point reading and writing functions. | Chris@0:
SFC_SET_NORM_DOUBLE | Chris@0:Modify the normalisation behaviour of the double precision floating point reading and writing functions. | Chris@0:
SFC_GET_NORM_FLOAT | Chris@0:Retrieve the current normalisation behaviour of the floating point reading and writing functions. | Chris@0:
SFC_GET_NORM_DOUBLE | Chris@0:Retrieve the current normalisation behaviour of the double precision floating point reading and writing functions. | Chris@0:
SFC_SET_SCALE_FLOAT_INT_READ | Chris@0:Set/clear the scale factor when integer (short/int) data is read from a file Chris@0: containing floating point data. | Chris@0:
SFC_SET_SCALE_INT_FLOAT_WRITE | Chris@0:Set/clear the scale factor when integer (short/int) data is written to a file Chris@0: as floating point data. | Chris@0:
SFC_GET_SIMPLE_FORMAT_COUNT | Chris@0:Retrieve the number of simple formats supported by libsndfile. | Chris@0:
SFC_GET_SIMPLE_FORMAT | Chris@0:Retrieve information about a simple format. | Chris@0:
SFC_GET_FORMAT_INFO | Chris@0:Retrieve information about a major or subtype format. | Chris@0:
SFC_GET_FORMAT_MAJOR_COUNT | Chris@0:Retrieve the number of major formats. | Chris@0:
SFC_GET_FORMAT_MAJOR | Chris@0:Retrieve information about a major format type. | Chris@0:
SFC_GET_FORMAT_SUBTYPE_COUNT | Chris@0:Retrieve the number of subformats. | Chris@0:
SFC_GET_FORMAT_SUBTYPE | Chris@0:Retrieve information about a subformat. | Chris@0:
SFC_SET_ADD_PEAK_CHUNK | Chris@0:Switch the code for adding the PEAK chunk to WAV and AIFF files on or off. | Chris@0:
SFC_UPDATE_HEADER_NOW | Chris@0:Used when a file is open for write, this command will update the file Chris@0: header to reflect the data written so far. | Chris@0:
SFC_SET_UPDATE_HEADER_AUTO | Chris@0:Used when a file is open for write, this command will cause the file header Chris@0: to be updated after each write to the file. | Chris@0:
SFC_FILE_TRUNCATE | Chris@0:Truncate a file open for write or for read/write. | Chris@0:
SFC_SET_RAW_START_OFFSET | Chris@0:Change the data start offset for files opened up as SF_FORMAT_RAW. | Chris@0:
SFC_SET_CLIPPING | Chris@0:Turn on/off automatic clipping when doing floating point to integer Chris@0: conversion. | Chris@0:
SFC_GET_CLIPPING | Chris@0:Retrieve current clipping setting. | Chris@0:
SFC_GET_EMBED_FILE_INFO | Chris@0:Retrieve information about audio files embedded inside other files. | Chris@0:
SFC_GET_AMBISONIC | Chris@0:Test a WAVEX file for Ambisonic format | Chris@0:
SFC_SET_AMBISONIC | Chris@0:Modify a WAVEX header for Ambisonic format | Chris@0:
SFC_SET_VBR_ENCODING_QUALITY | Chris@0:Set the the Variable Bit Rate encoding quality | Chris@0:
SFC_RAW_NEEDS_ENDSWAP | Chris@0:Determine if raw data needs endswapping | Chris@0:
SFC_GET_BROADCAST_INFO | Chris@0:Retrieve the Broadcast Chunk info | Chris@0:
SFC_SET_BROADCAST_INFO | Chris@0:Set the Broadcast Chunk info | Chris@0:
SFC_GET_LOOP_INFO | Chris@0:Get loop info | Chris@0:
SFC_GET_INSTRUMENT | Chris@0:Get instrument info | Chris@0:
SFC_SET_INSTRUMENT | Chris@0:Set instrument info | Chris@0:
SFC_SET_VBR_ENCODING_QUALITY | Chris@0:Set variable bit rate encoding quality | Chris@0:
Chris@0: Retrieve the version of the library as a string. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0: sndfile : Not used Chris@0: cmd : SFC_GET_LIB_VERSION Chris@0: data : A pointer to a char buffer Chris@0: datasize : The size of the the buffer Chris@0:Chris@0:
Chris@0: Example: Chris@0:
Chris@0:Chris@0: char buffer [128] ; Chris@0: sf_command (NULL, SFC_GET_LIB_VERSION, buffer, sizeof (buffer)) ; Chris@0:Chris@0: Chris@0:
Chris@0: Retrieve the log buffer generated when opening a file as a string. This log Chris@0: buffer can often contain a good reason for why libsndfile failed to open a Chris@0: particular file. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_GET_LOG_INFO Chris@0: data : A pointer to a char buffer Chris@0: datasize : The size of the the buffer Chris@0:Chris@0:
Chris@0: Example: Chris@0:
Chris@0:Chris@0: char buffer [2048] ; Chris@0: sf_command (sndfile, SFC_GET_LOG_INFO, buffer, sizeof (buffer)) ; Chris@0:Chris@0: Chris@0:
Chris@0: Retrieve the measured maximum signal value. This involves reading through Chris@0: the whole file which can be slow on large files. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_CALC_SIGNAL_MAX Chris@0: data : A pointer to a double Chris@0: datasize : sizeof (double) Chris@0:Chris@0:
Chris@0: Example: Chris@0:
Chris@0:Chris@0: double max_val ; Chris@0: sf_command (sndfile, SFC_CALC_SIGNAL_MAX, &max_val, sizeof (max_val)) ; Chris@0:Chris@0: Chris@0:
Chris@0: Retrieve the measured normalised maximum signal value. This involves reading Chris@0: through the whole file which can be slow on large files. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_CALC_NORM_SIGNAL_MAX Chris@0: data : A pointer to a double Chris@0: datasize : sizeof (double) Chris@0:Chris@0:
Chris@0: Example: Chris@0:
Chris@0:Chris@0: double max_val ; Chris@0: sf_command (sndfile, SFC_CALC_NORM_SIGNAL_MAX, &max_val, sizeof (max_val)) ; Chris@0:Chris@0: Chris@0:
Chris@0: Calculate the peak value (ie a single number) for each channel. Chris@0: This involves reading through the whole file which can be slow on large files. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_CALC_MAX_ALL_CHANNELS Chris@0: data : A pointer to a double Chris@0: datasize : sizeof (double) * number_of_channels Chris@0:Chris@0:
Chris@0: Example: Chris@0:
Chris@0:Chris@0: double peaks [number_of_channels] ; Chris@0: sf_command (sndfile, SFC_CALC_MAX_ALL_CHANNELS, peaks, sizeof (peaks)) ; Chris@0:Chris@0:
Chris@0: Calculate the normalised peak for each channel. Chris@0: This involves reading through the whole file which can be slow on large files. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_CALC_NORM_MAX_ALL_CHANNELS Chris@0: data : A pointer to a double Chris@0: datasize : sizeof (double) * number_of_channels Chris@0:Chris@0:
Chris@0: Example: Chris@0:
Chris@0:Chris@0: double peaks [number_of_channels] ; Chris@0: sf_command (sndfile, SFC_CALC_NORM_MAX_ALL_CHANNELS, peaks, sizeof (peaks)) ; Chris@0:Chris@0:
Chris@0: Retrieve the peak value for the file as stored in the file header. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_GET_SIGNAL_MAX Chris@0: data : A pointer to a double Chris@0: datasize : sizeof (double) Chris@0:Chris@0:
Chris@0: Example: Chris@0:
Chris@0:Chris@0: double max_peak ; Chris@0: sf_command (sndfile, SFC_GET_SIGNAL_MAX, &max_peak, sizeof (max_peak)) ; Chris@0:Chris@0:
Chris@0: Retrieve the peak value for the file as stored in the file header. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_GET_SIGNAL_MAX Chris@0: data : A pointer to an array of doubles Chris@0: datasize : sizeof (double) * number_of_channels Chris@0:Chris@0:
Chris@0: Example: Chris@0:
Chris@0:Chris@0: double peaks [number_of_channels] ; Chris@0: sf_command (sndfile, SFC_GET_MAX_ALL_CHANNELS, peaks, sizeof (peaks)) ; Chris@0:Chris@0:
Chris@0: This command only affects data read from or written to using the floating point functions: Chris@0:
Chris@0:Chris@0: size_t sf_read_float (SNDFILE *sndfile, float *ptr, size_t items) ; Chris@0: size_t sf_readf_float (SNDFILE *sndfile, float *ptr, size_t frames) ; Chris@0: Chris@0: size_t sf_write_float (SNDFILE *sndfile, float *ptr, size_t items) ; Chris@0: size_t sf_writef_float (SNDFILE *sndfile, float *ptr, size_t frames) ; Chris@0:Chris@0:
Chris@0: Parameters: Chris@0:
Chris@0:Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_SET_NORM_FLOAT Chris@0: data : NULL Chris@0: datasize : SF_TRUE or SF_FALSE Chris@0:Chris@0:
Chris@0: For read operations setting normalisation to SF_TRUE means that the data from all Chris@0: subsequent reads will be be normalised to the range [-1.0, 1.0]. Chris@0:
Chris@0:Chris@0: For write operations, setting normalisation to SF_TRUE means than all data supplied Chris@0: to the float write functions should be in the range [-1.0, 1.0] and will be scaled Chris@0: for the file format as necessary. Chris@0:
Chris@0:Chris@0: For both cases, setting normalisation to SF_FALSE means that no scaling will take place. Chris@0:
Chris@0:Chris@0: Example: Chris@0:
Chris@0:Chris@0: sf_command (sndfile, SFC_SET_NORM_FLOAT, NULL, SF_TRUE) ; Chris@0: Chris@0: sf_command (sndfile, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ; Chris@0:Chris@0:
Chris@0: This command only affects data read from or written to using the double precision Chris@0: floating point functions: Chris@0:
Chris@0:Chris@0: size_t sf_read_double (SNDFILE *sndfile, double *ptr, size_t items) ; Chris@0: size_t sf_readf_double (SNDFILE *sndfile, double *ptr, size_t frames) ; Chris@0: Chris@0: size_t sf_write_double (SNDFILE *sndfile, double *ptr, size_t items) ; Chris@0: size_t sf_writef_double (SNDFILE *sndfile, double *ptr, size_t frames) ; Chris@0:Chris@0:
Chris@0: Parameters: Chris@0:
Chris@0:Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_SET_NORM_DOUBLE Chris@0: data : NULL Chris@0: datasize : SF_TRUE or SF_FALSE Chris@0:Chris@0:
Chris@0: For read operations setting normalisation to SF_TRUE means that the data Chris@0: from all subsequent reads will be be normalised to the range [-1.0, 1.0]. Chris@0:
Chris@0:Chris@0: For write operations, setting normalisation to SF_TRUE means than all data supplied Chris@0: to the double write functions should be in the range [-1.0, 1.0] and will be scaled Chris@0: for the file format as necessary. Chris@0:
Chris@0:Chris@0: For both cases, setting normalisation to SF_FALSE means that no scaling will take place. Chris@0:
Chris@0:Chris@0: Example: Chris@0:
Chris@0:Chris@0: sf_command (sndfile, SFC_SET_NORM_DOUBLE, NULL, SF_TRUE) ; Chris@0: Chris@0: sf_command (sndfile, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ; Chris@0:Chris@0:
Chris@0: Retrieve the current float normalisation mode. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0:Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_GET_NORM_FLOAT Chris@0: data : NULL Chris@0: datasize : anything Chris@0:Chris@0:
Chris@0: Example: Chris@0:
Chris@0:Chris@0: normalisation = sf_command (sndfile, SFC_GET_NORM_FLOAT, NULL, 0) ; Chris@0:Chris@0:
Chris@0: Retrieve the current float normalisation mode. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0:Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_GET_NORM_DOUBLE Chris@0: data : NULL Chris@0: datasize : anything Chris@0:Chris@0:
Chris@0: Example: Chris@0:
Chris@0:Chris@0: normalisation = sf_command (sndfile, SFC_GET_NORM_DOUBLE, NULL, 0) ; Chris@0:Chris@0:
Chris@0: Set/clear the scale factor when integer (short/int) data is read from a file Chris@0: containing floating point data. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0:Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_SET_SCALE_FLOAT_INT_READ Chris@0: data : NULL Chris@0: datasize : TRUE or FALSE Chris@0:Chris@0:
Chris@0: Example: Chris@0:
Chris@0:Chris@0: sf_command (sndfile, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ; Chris@0:Chris@0:
Chris@0: Set/clear the scale factor when integer (short/int) data is written to a file Chris@0: as floating point data. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0:Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_SET_SCALE_FLOAT_INT_READ Chris@0: data : NULL Chris@0: datasize : TRUE or FALSE Chris@0:Chris@0:
Chris@0: Example: Chris@0:
Chris@0:Chris@0: sf_command (sndfile, SFC_SET_SCALE_INT_FLOAT_WRITE, NULL, SF_TRUE) ; Chris@0:Chris@0:
Chris@0: Retrieve the number of simple formats supported by libsndfile. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0:Chris@0: sndfile : Not used. Chris@0: cmd : SFC_GET_SIMPLE_FORMAT_COUNT Chris@0: data : a pointer to an int Chris@0: datasize : sizeof (int) Chris@0:Chris@0:
Chris@0: Example: Chris@0:
Chris@0:Chris@0: int count ; Chris@0: sf_command (sndfile, SFC_GET_SIMPLE_FORMAT_COUNT, &count, sizeof (int)) ; Chris@0:Chris@0:
Chris@0: Retrieve information about a simple format. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0:Chris@0: sndfile : Not used. Chris@0: cmd : SFC_GET_SIMPLE_FORMAT Chris@0: data : a pointer to an SF_FORMAT_INFO struct Chris@0: datasize : sizeof (SF_FORMAT_INFO) Chris@0:Chris@0:
Chris@0: The SF_FORMAT_INFO struct is defined in <sndfile.h> as: Chris@0:
Chris@0:Chris@0: typedef struct Chris@0: { int format ; Chris@0: const char *name ; Chris@0: const char *extension ; Chris@0: } SF_FORMAT_INFO ; Chris@0:Chris@0:
Chris@0: When sf_command() is called with SF_GET_SIMPLE_FORMAT, the value of the format Chris@0: field should be the format number (ie 0 <= format <= count value obtained using Chris@0: SF_GET_SIMPLE_FORMAT_COUNT). Chris@0:
Chris@0:Chris@0: Example: Chris@0:
Chris@0:Chris@0: SF_FORMAT_INFO format_info ; Chris@0: int k, count ; Chris@0: Chris@0: sf_command (sndfile, SFC_GET_SIMPLE_FORMAT_COUNT, &count, sizeof (int)) ; Chris@0: Chris@0: for (k = 0 ; k < count ; k++) Chris@0: { format_info.format = k ; Chris@0: sf_command (sndfile, SFC_GET_SIMPLE_FORMAT, &format_info, sizeof (format_info)) ; Chris@0: printf ("%08x %s %s\n", format_info.format, format_info.name, format_info.extension) ; Chris@0: } ; Chris@0:Chris@0:
Chris@0: Retrieve information about a major or subtype format. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0:Chris@0: sndfile : Not used. Chris@0: cmd : SFC_GET_FORMAT_INFO Chris@0: data : a pointer to an SF_FORMAT_INFO struct Chris@0: datasize : sizeof (SF_FORMAT_INFO) Chris@0:Chris@0:
Chris@0: The SF_FORMAT_INFO struct is defined in <sndfile.h> as: Chris@0:
Chris@0:Chris@0: typedef struct Chris@0: { int format ; Chris@0: const char *name ; Chris@0: const char *extension ; Chris@0: } SF_FORMAT_INFO ; Chris@0:Chris@0:
Chris@0: When sf_command() is called with SF_GET_FORMAT_INFO, the format field is Chris@0: examined and if (format & SF_FORMAT_TYPEMASK) is a valid format then the struct Chris@0: is filled in with information about the given major type. Chris@0: If (format & SF_FORMAT_TYPEMASK) is FALSE and (format & SF_FORMAT_SUBMASK) is a Chris@0: valid subtype format then the struct is filled in with information about the given Chris@0: subtype. Chris@0:
Chris@0:Chris@0: Example: Chris@0:
Chris@0:Chris@0: SF_FORMAT_INFO format_info ; Chris@0: Chris@0: format_info.format = SF_FORMAT_WAV ; Chris@0: sf_command (sndfile, SFC_GET_FORMAT_INFO, &format_info, sizeof (format_info)) ; Chris@0: printf ("%08x %s %s\n", format_info.format, format_info.name, format_info.extension) ; Chris@0: Chris@0: format_info.format = SF_FORMAT_ULAW ; Chris@0: sf_command (sndfile, SFC_GET_FORMAT_INFO, &format_info, sizeof (format_info)) ; Chris@0: printf ("%08x %s\n", format_info.format, format_info.name) ; Chris@0:Chris@0:
Chris@0: Retrieve the number of major formats. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0:Chris@0: sndfile : Not used. Chris@0: cmd : SFC_GET_FORMAT_MAJOR_COUNT Chris@0: data : a pointer to an int Chris@0: datasize : sizeof (int) Chris@0:Chris@0:
Chris@0: Example: Chris@0:
Chris@0:Chris@0: int count ; Chris@0: sf_command (sndfile, SFC_GET_FORMAT_MAJOR_COUNT, &count, sizeof (int)) ; Chris@0:Chris@0:
Chris@0: Retrieve information about a major format type. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0:Chris@0: sndfile : Not used. Chris@0: cmd : SFC_GET_FORMAT_MAJOR Chris@0: data : a pointer to an SF_FORMAT_INFO struct Chris@0: datasize : sizeof (SF_FORMAT_INFO) Chris@0:Chris@0:
Chris@0: Example: Chris@0:
Chris@0:Chris@0: SF_FORMAT_INFO format_info ; Chris@0: int k, count ; Chris@0: Chris@0: sf_command (sndfile, SFC_GET_FORMAT_MAJOR_COUNT, &count, sizeof (int)) ; Chris@0: Chris@0: for (k = 0 ; k < count ; k++) Chris@0: { format_info.format = k ; Chris@0: sf_command (sndfile, SFC_GET_FORMAT_MAJOR, &format_info, sizeof (format_info)) ; Chris@0: printf ("%08x %s %s\n", format_info.format, format_info.name, format_info.extension) ; Chris@0: } ; Chris@0:Chris@0:
Chris@0: For a more comprehensive example, see the program list_formats.c in the examples/ Chris@0: directory of the libsndfile source code distribution. Chris@0:
Chris@0:Chris@0: Retrieve the number of subformats. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0:Chris@0: sndfile : Not used. Chris@0: cmd : SFC_GET_FORMAT_SUBTYPE_COUNT Chris@0: data : a pointer to an int Chris@0: datasize : sizeof (int) Chris@0:Chris@0:
Chris@0: Example: Chris@0:
Chris@0:Chris@0: int count ; Chris@0: sf_command (sndfile, SFC_GET_FORMAT_SUBTYPE_COUNT, &count, sizeof (int)) ; Chris@0:Chris@0:
Chris@0: Enumerate the subtypes (this function does not translate a subtype into Chris@0: a string describing that subtype). Chris@0: A typical use case might be retrieving a string description of all subtypes Chris@0: so that a dialog box can be filled in. Chris@0:
Chris@0:Chris@0: Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0:Chris@0: sndfile : Not used. Chris@0: cmd : SFC_GET_FORMAT_SUBTYPE Chris@0: data : a pointer to an SF_FORMAT_INFO struct Chris@0: datasize : sizeof (SF_FORMAT_INFO) Chris@0:Chris@0:
Chris@0: Example 1: Retrieve all sybtypes supported by the WAV format. Chris@0:
Chris@0:Chris@0: SF_FORMAT_INFO format_info ; Chris@0: int k, count ; Chris@0: Chris@0: sf_command (sndfile, SFC_GET_FORMAT_SUBTYPE_COUNT, &count, sizeof (int)) ; Chris@0: Chris@0: for (k = 0 ; k < count ; k++) Chris@0: { format_info.format = k ; Chris@0: sf_command (sndfile, SFC_GET_FORMAT_SUBTYPE, &format_info, sizeof (format_info)) ; Chris@0: if (! sf_format_check (format_info.format | SF_FORMAT_WAV)) Chris@0: continue ; Chris@0: printf ("%08x %s\n", format_info.format, format_info.name) ; Chris@0: } ; Chris@0:Chris@0:
Chris@0: Example 2: Print a string describing the SF_FORMAT_PCM_16 subtype. Chris@0:
Chris@0:Chris@0: SF_FORMAT_INFO format_info ; Chris@0: int k, count ; Chris@0: Chris@0: sf_command (sndfile, SFC_GET_FORMAT_SUBTYPE_COUNT, &count, sizeof (int)) ; Chris@0: Chris@0: for (k = 0 ; k < count ; k++) Chris@0: { format_info.format = k ; Chris@0: sf_command (sndfile, SFC_GET_FORMAT_SUBTYPE, &format_info, sizeof (format_info)) ; Chris@0: if (format_info.format == SF_FORMAT_PCM_16) Chris@0: { printf ("%08x %s\n", format_info.format, format_info.name) ; Chris@0: break ; Chris@0: } ; Chris@0: } ; Chris@0:Chris@0:
Chris@0: For a more comprehensive example, see the program list_formats.c in the examples/ Chris@0: directory of the libsndfile source code distribution. Chris@0:
Chris@0:Chris@0: By default, WAV and AIFF files which contain floating point data (subtype SF_FORMAT_FLOAT Chris@0: or SF_FORMAT_DOUBLE) have a PEAK chunk. Chris@0: By using this command, the addition of a PEAK chunk can be turned on or off. Chris@0:
Chris@0:Chris@0: Note : This call must be made before any data is written to the file. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_SET_ADD_PEAK_CHUNK Chris@0: data : Not used (should be NULL) Chris@0: datasize : TRUE or FALSE. Chris@0:Chris@0:
Chris@0: Example: Chris@0:
Chris@0:Chris@0: /* Turn on the PEAK chunk. */ Chris@0: sf_command (sndfile, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_TRUE) ; Chris@0: Chris@0: /* Turn off the PEAK chunk. */ Chris@0: sf_command (sndfile, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_FALSE) ; Chris@0:Chris@0:
Chris@0: The header of an audio file is normally written by libsndfile when the file is Chris@0: closed using sf_close(). Chris@0:
Chris@0:Chris@0: There are however situations where large files are being generated and it would Chris@0: be nice to have valid data in the header before the file is complete. Chris@0: Using this command will update the file header to reflect the amount of data written Chris@0: to the file so far. Chris@0: Other programs opening the file for read (before any more data is written) will Chris@0: then read a valid sound file header. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_UPDATE_HEADER_NOW Chris@0: data : Not used (should be NULL) Chris@0: datasize : Not used. Chris@0:Chris@0:
Chris@0: Example: Chris@0:
Chris@0:Chris@0: /* Update the header now. */ Chris@0: sf_command (sndfile, SFC_UPDATE_HEADER_NOW, NULL, 0) ; Chris@0:Chris@0:
Chris@0: Similar to SFC_UPDATE_HEADER_NOW but updates the header at the end of every call Chris@0: to the sf_write* functions. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_UPDATE_HEADER_NOW Chris@0: data : Not used (should be NULL) Chris@0: datasize : SF_TRUE or SF_FALSE Chris@0:Chris@0:
Chris@0: Example: Chris@0:
Chris@0:Chris@0: /* Turn on auto header update. */ Chris@0: sf_command (sndfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) ; Chris@0: Chris@0: /* Turn off auto header update. */ Chris@0: sf_command (sndfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_FALSE) ; Chris@0:Chris@0:
Chris@0: Truncate a file that was opened for write or read/write. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_FILE_TRUNCATE Chris@0: data : A pointer to an sf_count_t. Chris@0: datasize : sizeof (sf_count_t) Chris@0:Chris@0: Chris@0:
Chris@0: Truncate the file to the number of frames specified by the sf_count_t pointed Chris@0: to by data. Chris@0: After this command, both the read and the write pointer will be Chris@0: at the new end of the file. Chris@0: This command will fail (returning non-zero) if the requested truncate position Chris@0: is beyond the end of the file. Chris@0:
Chris@0:Chris@0: Example: Chris@0:
Chris@0:Chris@0: /* Truncate the file to a length of 20 frames. */ Chris@0: sf_count_t frames = 20 ; Chris@0: sf_command (sndfile, SFC_FILE_TRUNCATE, &frames, sizeof (frames)) ; Chris@0:Chris@0:
Chris@0: Change the data start offset for files opened up as SF_FORMAT_RAW. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_SET_RAW_START_OFFSET Chris@0: data : A pointer to an sf_count_t. Chris@0: datasize : sizeof (sf_count_t) Chris@0:Chris@0: Chris@0:
Chris@0: For a file opened as format SF_FORMAT_RAW, set the data offset to the value Chris@0: given by data. Chris@0:
Chris@0:Chris@0: Example: Chris@0:
Chris@0:Chris@0: /* Reset the data offset to 5 bytes from the start of the file. */ Chris@0: sf_count_t offset = 5 ; Chris@0: sf_command (sndfile, SFC_SET_RAW_START_OFFSET, &offset, sizeof (offset)) ; Chris@0:Chris@0:
Chris@0: Turn on/off automatic clipping when doing floating point to integer conversion. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_SET_CLIPPING Chris@0: data : NULL Chris@0: datasize : SF_TRUE or SF_FALSE. Chris@0:Chris@0: Chris@0:
Chris@0: Turn on (datasize == SF_TRUE) or off (datasize == SF_FALSE) clipping. Chris@0:
Chris@0:Chris@0: Example: Chris@0:
Chris@0:Chris@0: sf_command (sndfile, SFC_SET_CLIPPING, NULL, SF_TRUE) ; Chris@0:Chris@0:
Chris@0: Turn on/off automatic clipping when doing floating point to integer conversion. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_GET_CLIPPING Chris@0: data : NULL Chris@0: datasize : 0 Chris@0:Chris@0: Chris@0:
Chris@0: Retrieve the current cliiping setting. Chris@0:
Chris@0:Chris@0: Example: Chris@0:
Chris@0:Chris@0: sf_command (sndfile, SFC_GET_CLIPPING, NULL, 0) ; Chris@0:Chris@0:
Chris@0: Get the file offset and file length of a file enbedded within another Chris@0: larger file. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_GET_CLIPPING Chris@0: data : a pointer to an SF_EMBED_FILE_INFO struct Chris@0: datasize : sizeof (SF_EMBED_FILE_INFO) Chris@0:Chris@0:
Chris@0: The SF_EMBED_FILE_INFO struct is defined in <sndfile.h> as: Chris@0:
Chris@0:Chris@0: typedef struct Chris@0: { sf_count_t offset ; Chris@0: sf_count_t length ; Chris@0: } SF_EMBED_FILE_INFO ; Chris@0:Chris@0:
Chris@0: Test if the current file has the GUID of a WAVEX file for any of the Ambisonic Chris@0: formats. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_WAVEX_GET_AMBISONIC Chris@0: data : NULL Chris@0: datasize : 0 Chris@0:Chris@0:
Chris@0: The Ambisonic WAVEX formats are defined here : Chris@0: Chris@0: http://dream.cs.bath.ac.uk/researchdev/wave-ex/bformat.html. Chris@0:
Chris@0:Chris@0: Set the GUID of a new WAVEX file to indicate an Ambisonics format. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_WAVEX_SET_AMBISONIC Chris@0: data : NULL Chris@0: datasize : SF_AMBISONIC_NONE or SF_AMBISONIC_B_FORMAT Chris@0:Chris@0:
Chris@0: Turn on (SF_AMBISONIC_B_FORMAT) or off (SF_AMBISONIC_NONE) encoding. Chris@0: This command is currently only supported for files with SF_FORMAT_WAVEX format. Chris@0:
Chris@0:Chris@0: The Ambisonic WAVEX formats are defined here : Chris@0: Chris@0: http://dream.cs.bath.ac.uk/researchdev/wave-ex/bformat.html. Chris@0:
Chris@0:Chris@0: Set the the Variable Bit Rate encoding quality. Chris@0: The encoding quality value should be between 0.0 (lowest quality) and 1.0 Chris@0: (highest quality). Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_SET_VBR_ENCODING_QUALITY Chris@0: data : A pointer to a double value Chris@0: datasize : sizeof (double) Chris@0:Chris@0:
Chris@0: The command must be sent before any audio data is written to the file. Chris@0:
Chris@0:Chris@0:
Chris@0:Chris@0: Determine if raw data read using Chris@0: Chris@0: sf_read_raw Chris@0: needs to be end swapped on the host CPU. Chris@0:
Chris@0:Chris@0: For instance, will return SF_TRUE on when reading WAV containing Chris@0: SF_FORMAT_PCM_16 data on a big endian machine and SF_FALSE on a little endian Chris@0: machine. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_RAW_NEEDS_ENDSWAP Chris@0: data : NULL Chris@0: datasize : 0 Chris@0:Chris@0: Chris@0:
Chris@0: Retrieve the Broadcast Extension Chunk from WAV (and related) files. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0:Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_GET_BROADCAST_INFO Chris@0: data : a pointer to an SF_BROADCAST_INFO struct Chris@0: datasize : sizeof (SF_BROADCAST_INFO) Chris@0:Chris@0:
Chris@0: The SF_BROADCAST_INFO struct is defined in <sndfile.h> as: Chris@0:
Chris@0:Chris@0: typedef struct Chris@0: { char description [256] ; Chris@0: char originator [32] ; Chris@0: char originator_reference [32] ; Chris@0: char origination_date [10] ; Chris@0: char origination_time [8] ; Chris@0: unsigned int time_reference_low ; Chris@0: unsigned int time_reference_high ; Chris@0: short version ; Chris@0: char umid [64] ; Chris@0: char reserved [190] ; Chris@0: unsigned int coding_history_size ; Chris@0: char coding_history [256] ; Chris@0: } SF_BROADCAST_INFO ; Chris@0:Chris@0: Chris@0:
Chris@0: Set the Broadcast Extension Chunk for WAV (and related) files. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0:Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_SET_BROADCAST_INFO Chris@0: data : a pointer to an SF_BROADCAST_INFO struct Chris@0: datasize : sizeof (SF_BROADCAST_INFO) Chris@0:Chris@0: Chris@0:
Chris@0: Retrieve loop information for file including time signature, length in Chris@0: beats and original MIDI base note Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0:Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_GET_LOOP_INFO Chris@0: data : a pointer to an SF_LOOP_INFO struct Chris@0: datasize : sizeof (SF_LOOP_INFO) Chris@0:Chris@0:
Chris@0: The SF_BROADCAST_INFO struct is defined in <sndfile.h> as: Chris@0:
Chris@0:Chris@0: typedef struct Chris@0: { short time_sig_num ; /* any positive integer > 0 */ Chris@0: short time_sig_den ; /* any positive power of 2 > 0 */ Chris@0: int loop_mode ; /* see SF_LOOP enum */ Chris@0: Chris@0: int num_beats ; /* this is NOT the amount of quarter notes !!!*/ Chris@0: /* a full bar of 4/4 is 4 beats */ Chris@0: /* a full bar of 7/8 is 7 beats */ Chris@0: Chris@0: float bpm ; /* suggestion, as it can be calculated using other fields:*/ Chris@0: /* file's lenght, file's sampleRate and our time_sig_den*/ Chris@0: /* -> bpms are always the amount of _quarter notes_ per minute */ Chris@0: Chris@0: int root_key ; /* MIDI note, or -1 for None */ Chris@0: int future [6] ; Chris@0: } SF_LOOP_INFO ; Chris@0:Chris@0:
Chris@0: Example: Chris@0:
Chris@0:Chris@0: SF_LOOP_INFO loop; Chris@0: sf_command (sndfile, SFC_GET_LOOP_INFO, &loop, sizeof (loop)) ; Chris@0:Chris@0:
Chris@0: Retrieve instrument information from file including MIDI base note, Chris@0: keyboard mapping and looping informations(start/stop and mode). Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0:Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_GET_INSTRUMENT Chris@0: data : a pointer to an SF_INSTRUMENT struct Chris@0: datasize : sizeof (SF_INSTRUMENT) Chris@0:Chris@0: Chris@0:
Chris@0: The SF_INSTRUMENT struct is defined in <sndfile.h> as: Chris@0:
Chris@0:Chris@0: enum Chris@0: { /* Chris@0: ** The loop mode field in SF_INSTRUMENT will be one of the following. Chris@0: */ Chris@0: SF_LOOP_NONE = 800, Chris@0: SF_LOOP_FORWARD, Chris@0: SF_LOOP_BACKWARD, Chris@0: SF_LOOP_ALTERNATING Chris@0: } ; Chris@0: Chris@0: typedef struct Chris@0: { int gain ; Chris@0: char basenote, detune ; Chris@0: char velocity_lo, velocity_hi ; Chris@0: char key_lo, key_hi ; Chris@0: int loop_count ; Chris@0: Chris@0: struct Chris@0: { int mode ; Chris@0: unsigned int start ; Chris@0: unsigned int end ; Chris@0: unsigned int count ; Chris@0: } loops [16] ; /* make variable in a sensible way */ Chris@0: } SF_INSTRUMENT ; Chris@0:Chris@0: Chris@0:
Chris@0: Example: Chris@0:
Chris@0:Chris@0: SF_INSTRUMENT inst ; Chris@0: sf_command (sndfile, SFC_GET_INSTRUMENT, &inst, sizeof (inst)) ; Chris@0:Chris@0:
Chris@0: Set the instrument information for the file. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0:Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_GET_INSTRUMENT Chris@0: data : a pointer to an SF_INSTRUMENT struct Chris@0: datasize : sizeof (SF_INSTRUMENT) Chris@0:Chris@0:
Chris@0: Example: Chris@0:
Chris@0:Chris@0: SF_INSTRUMENT inst ; Chris@0: sf_command (sndfile, SFC_SET_INSTRUMENT, &inst, sizeof (inst)) ; Chris@0:Chris@0:
Chris@0: Set the Variable Bite Rate encoding quality. Chris@0: Currenly only implemented fro Ogg/Vorbis files. Chris@0:
Chris@0:Chris@0: Parameters: Chris@0:
Chris@0:Chris@0: sndfile : A valid SNDFILE* pointer Chris@0: cmd : SFC_SET_VBR_ENCODING_QUALITY Chris@0: data : a pointer to double specifing VBR quality Chris@0: datasize : sizeof (double) Chris@0:Chris@0:
Chris@0: Example: Chris@0:
Chris@0:Chris@0: double quality = 0.5 ; Chris@0: sf_command (sndfile, SFC_SET_VBR_ENCODING_QUALITY, &quality, sizeof (double)) ; Chris@0:Chris@0:
Chris@0: The libsndfile home page is here :
Chris@0:
Chris@0: http://www.mega-nerd.com/libsndfile/.
Chris@0:
Chris@0: Version : 1.0.25
Chris@0: