1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
6 libsndfile : the sf_command function.
8 <META NAME="Author" CONTENT="Erik de Castro Lopo (erikd AT mega-nerd DOT com)">
9 <!-- Another version at the bottom of the page. -->
10 <META NAME="Description" CONTENT="The libsndfile API.">
11 <META NAME="Keywords" CONTENT="WAV AIFF AU libsndfile sound audio dsp Linux">
12 <LINK REL="stylesheet" HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
13 <LINK REL="stylesheet" HREF="print.css" TYPE="text/css" MEDIA="print">
18 <H1><B>sf_command</B></H1>
21 int sf_command (SNDFILE *sndfile, int cmd, void *data, int datasize) ;
24 This function allows the caller to retrieve information from or change aspects of the
26 Examples include retrieving a string containing the library version or changing the
27 scaling applied to floating point sample data during read and write.
28 Most of these operations are performed on a per-file basis.
31 The cmd parameter is an integer identifier which is defined in <sndfile.h>.
32 All of the valid command identifiers have names beginning with "SFC_".
33 Data is passed to and returned from the library by use of a void pointer.
34 The library will not read or write more than datasize bytes from the void pointer.
35 For some calls no data is required in which case data should be NULL and datasize
36 may be used for some other purpose.
39 The available commands are as follows:
43 <TABLE BORDER="0" WIDTH="90%" CELLPADDING="4">
45 <TD><A HREF="#SFC_GET_LIB_VERSION">SFC_GET_LIB_VERSION</A></TD>
46 <TD>Retrieve the version of the library.</TD>
49 <TD><A HREF="#SFC_GET_LOG_INFO">SFC_GET_LOG_INFO</A></TD>
50 <TD>Retrieve the internal per-file operation log.</TD>
53 <TD><A HREF="#SFC_CALC_SIGNAL_MAX">SFC_CALC_SIGNAL_MAX</A></TD>
54 <TD>Calculate the measured maximum signal value.</TD>
57 <TD><A HREF="#SFC_CALC_NORM_SIGNAL_MAX">SFC_CALC_NORM_SIGNAL_MAX</A></TD>
58 <TD>Calculate the measured normalised maximum signal value.</TD>
61 <TD><A HREF="#SFC_CALC_MAX_ALL_CHANNELS">SFC_CALC_MAX_ALL_CHANNELS</A></TD>
62 <TD>Calculate the peak value for each channel.</TD>
65 <TD><A HREF="#SFC_CALC_NORM_MAX_ALL_CHANNELS">SFC_CALC_NORM_MAX_ALL_CHANNELS</A></TD>
66 <TD>Calculate the normalised peak for each channel.</TD>
70 <TD><A HREF="#SFC_GET_SIGNAL_MAX">SFC_GET_SIGNAL_MAX</A></TD>
71 <TD>Retrieve the peak value for the file (as stored in the file header).</TD>
74 <TD><A HREF="#SFC_GET_MAX_ALL_CHANNELS">SFC_GET_MAX_ALL_CHANNELS</A></TD>
75 <TD>Retrieve the peak value for each channel (as stored in the file header).</TD>
79 <TD><A HREF="#SFC_SET_NORM_FLOAT">SFC_SET_NORM_FLOAT</A></TD>
80 <TD>Modify the normalisation behaviour of the floating point reading and writing functions.</TD>
83 <TD><A HREF="#SFC_SET_NORM_DOUBLE">SFC_SET_NORM_DOUBLE</A></TD>
84 <TD>Modify the normalisation behaviour of the double precision floating point reading and writing functions.</TD>
87 <TD><A HREF="#SFC_GET_NORM_FLOAT">SFC_GET_NORM_FLOAT</A></TD>
88 <TD>Retrieve the current normalisation behaviour of the floating point reading and writing functions.</TD>
91 <TD><A HREF="#SFC_GET_NORM_DOUBLE">SFC_GET_NORM_DOUBLE</A></TD>
92 <TD>Retrieve the current normalisation behaviour of the double precision floating point reading and writing functions.</TD>
95 <TD><A HREF="#SFC_SET_SCALE_FLOAT_INT_READ">SFC_SET_SCALE_FLOAT_INT_READ</A></TD>
96 <TD>Set/clear the scale factor when integer (short/int) data is read from a file
97 containing floating point data.</TD>
101 <TD><A HREF="#SFC_SET_SCALE_INT_FLOAT_WRITE">SFC_SET_SCALE_INT_FLOAT_WRITE</A></TD>
102 <TD>Set/clear the scale factor when integer (short/int) data is written to a file
103 as floating point data.</TD>
107 <TD><A HREF="#SFC_GET_SIMPLE_FORMAT_COUNT">SFC_GET_SIMPLE_FORMAT_COUNT</A></TD>
108 <TD>Retrieve the number of simple formats supported by libsndfile.</TD>
111 <TD><A HREF="#SFC_GET_SIMPLE_FORMAT">SFC_GET_SIMPLE_FORMAT</A></TD>
112 <TD>Retrieve information about a simple format.</TD>
116 <TD><A HREF="#SFC_GET_FORMAT_INFO">SFC_GET_FORMAT_INFO</A></TD>
117 <TD>Retrieve information about a major or subtype format.</TD>
121 <TD><A HREF="#SFC_GET_FORMAT_MAJOR_COUNT">SFC_GET_FORMAT_MAJOR_COUNT</A></TD>
122 <TD>Retrieve the number of major formats.</TD>
125 <TD><A HREF="#SFC_GET_FORMAT_MAJOR">SFC_GET_FORMAT_MAJOR</A></TD>
126 <TD>Retrieve information about a major format type.</TD>
129 <TD><A HREF="#SFC_GET_FORMAT_SUBTYPE_COUNT">SFC_GET_FORMAT_SUBTYPE_COUNT</A></TD>
130 <TD>Retrieve the number of subformats.</TD>
133 <TD><A HREF="#SFC_GET_FORMAT_SUBTYPE">SFC_GET_FORMAT_SUBTYPE</A></TD>
134 <TD>Retrieve information about a subformat.</TD>
138 <TD><A HREF="#SFC_SET_ADD_PEAK_CHUNK">SFC_SET_ADD_PEAK_CHUNK</A></TD>
139 <TD>Switch the code for adding the PEAK chunk to WAV and AIFF files on or off.</TD>
143 <TD><A HREF="#SFC_UPDATE_HEADER_NOW">SFC_UPDATE_HEADER_NOW</A></TD>
144 <TD>Used when a file is open for write, this command will update the file
145 header to reflect the data written so far.</TD>
148 <TD><A HREF="#SFC_SET_UPDATE_HEADER_AUTO">SFC_SET_UPDATE_HEADER_AUTO</A></TD>
149 <TD>Used when a file is open for write, this command will cause the file header
150 to be updated after each write to the file.</TD>
154 <TD><A HREF="#SFC_FILE_TRUNCATE">SFC_FILE_TRUNCATE</A></TD>
155 <TD>Truncate a file open for write or for read/write.</TD>
159 <TD><A HREF="#SFC_SET_RAW_START_OFFSET">SFC_SET_RAW_START_OFFSET</A></TD>
160 <TD>Change the data start offset for files opened up as SF_FORMAT_RAW.</TD>
164 <TD><A HREF="#SFC_SET_CLIPPING">SFC_SET_CLIPPING</A></TD>
165 <TD>Turn on/off automatic clipping when doing floating point to integer
170 <TD><A HREF="#SFC_GET_CLIPPING">SFC_GET_CLIPPING</A></TD>
171 <TD>Retrieve current clipping setting.</TD>
175 <TD><A HREF="#SFC_GET_EMBED_FILE_INFO">SFC_GET_EMBED_FILE_INFO</A></TD>
176 <TD>Retrieve information about audio files embedded inside other files.</TD>
180 <TD><A HREF="#SFC_WAVEX_GET_AMBISONIC">SFC_GET_AMBISONIC</A></TD>
181 <TD>Test a WAVEX file for Ambisonic format</TD>
185 <TD><A HREF="#SFC_WAVEX_SET_AMBISONIC">SFC_SET_AMBISONIC</A></TD>
186 <TD>Modify a WAVEX header for Ambisonic format</TD>
190 <TD><A HREF="#SFC_SET_VBR_ENCODING_QUALITY">SFC_SET_VBR_ENCODING_QUALITY</A></TD>
191 <TD>Set the the Variable Bit Rate encoding quality</TD>
195 <TD><A HREF="#SFC_RAW_NEEDS_ENDSWAP">SFC_RAW_NEEDS_ENDSWAP</a></td>
196 <TD>Determine if raw data needs endswapping</TD>
200 <TD><A HREF="#SFC_GET_BROADCAST_INFO">SFC_GET_BROADCAST_INFO</A></TD>
201 <TD>Retrieve the Broadcast Chunk info</TD>
205 <TD><A HREF="#SFC_SET_BROADCAST_INFO">SFC_SET_BROADCAST_INFO</A></TD>
206 <TD>Set the Broadcast Chunk info</TD>
211 <TD><A HREF="#add-dither">add dither</A></TD>
212 <TD>Add dither to output on write.</TD>
222 <!-- ========================================================================= -->
223 <A NAME="SFC_GET_LIB_VERSION"></A>
224 <H2><BR><B>SFC_GET_LIB_VERSION</B></H2>
226 Retrieve the version of the library as a string.
232 cmd : SFC_GET_LIB_VERSION
233 data : A pointer to a char buffer
234 datasize : The size of the the buffer
241 sf_command (NULL, SFC_GET_LIB_VERSION, buffer, sizeof (buffer)) ;
245 <DT>Return value:</DT>
246 <DD><DD>This call will return the length of the retrieved version string.
251 The string returned in the buffer passed to this function will not overflow
252 the buffer and will always be null terminated .
255 <!-- ========================================================================= -->
256 <A NAME="SFC_GET_LOG_INFO"></A>
257 <H2><BR><B>SFC_GET_LOG_INFO</B></H2>
259 Retrieve the log buffer generated when opening a file as a string. This log
260 buffer can often contain a good reason for why libsndfile failed to open a
266 sndfile : A valid SNDFILE* pointer
267 cmd : SFC_GET_LOG_INFO
268 data : A pointer to a char buffer
269 datasize : The size of the the buffer
276 sf_command (sndfile, SFC_GET_LOG_INFO, buffer, sizeof (buffer)) ;
280 <DT>Return value:</DT>
281 <DD><DD>This call will return the length of the retrieved version string.
286 The string returned in the buffer passed to this function will not overflow
287 the buffer and will always be null terminated .
290 <!-- ========================================================================= -->
291 <A NAME="SFC_CALC_SIGNAL_MAX"></A>
292 <H2><BR><B>SFC_CALC_SIGNAL_MAX</B></H2>
294 Retrieve the measured maximum signal value. This involves reading through
295 the whole file which can be slow on large files.
300 sndfile : A valid SNDFILE* pointer
301 cmd : SFC_CALC_SIGNAL_MAX
302 data : A pointer to a double
303 datasize : sizeof (double)
310 sf_command (sndfile, SFC_CALC_SIGNAL_MAX, &max_val, sizeof (max_val)) ;
314 <DT>Return value:</DT>
315 <DD><DD>Zero on success, non-zero otherwise.
318 <!-- ========================================================================= -->
319 <A NAME="SFC_CALC_NORM_SIGNAL_MAX"></A>
320 <H2><BR><B>SFC_CALC_NORM_SIGNAL_MAX</B></H2>
322 Retrieve the measured normalised maximum signal value. This involves reading
323 through the whole file which can be slow on large files.
328 sndfile : A valid SNDFILE* pointer
329 cmd : SFC_CALC_NORM_SIGNAL_MAX
330 data : A pointer to a double
331 datasize : sizeof (double)
338 sf_command (sndfile, SFC_CALC_NORM_SIGNAL_MAX, &max_val, sizeof (max_val)) ;
342 <DT>Return value:</DT>
343 <DD><DD>Zero on success, non-zero otherwise.
346 <!-- ========================================================================= -->
347 <A NAME="SFC_CALC_MAX_ALL_CHANNELS"></A>
348 <H2><BR><B>SFC_CALC_MAX_ALL_CHANNELS</B></H2>
350 Calculate the peak value (ie a single number) for each channel.
351 This involves reading through the whole file which can be slow on large files.
356 sndfile : A valid SNDFILE* pointer
357 cmd : SFC_CALC_MAX_ALL_CHANNELS
358 data : A pointer to a double
359 datasize : sizeof (double) * number_of_channels
365 double peaks [number_of_channels] ;
366 sf_command (sndfile, SFC_CALC_MAX_ALL_CHANNELS, peaks, sizeof (peaks)) ;
369 <DT>Return value:</DT>
370 <DD>Zero if peaks have been calculated successfully and non-zero otherwise.
374 <!-- ========================================================================= -->
375 <A NAME="SFC_CALC_NORM_MAX_ALL_CHANNELS"></A>
376 <H2><BR><B>SFC_CALC_NORM_MAX_ALL_CHANNELS</B></H2>
378 Calculate the normalised peak for each channel.
379 This involves reading through the whole file which can be slow on large files.
384 sndfile : A valid SNDFILE* pointer
385 cmd : SFC_CALC_NORM_MAX_ALL_CHANNELS
386 data : A pointer to a double
387 datasize : sizeof (double) * number_of_channels
393 double peaks [number_of_channels] ;
394 sf_command (sndfile, SFC_CALC_NORM_MAX_ALL_CHANNELS, peaks, sizeof (peaks)) ;
397 <DT>Return value:</DT>
398 <DD>Zero if peaks have been calculated successfully and non-zero otherwise.
404 <!-- ========================================================================= -->
405 <A NAME="SFC_GET_SIGNAL_MAX"></A>
406 <H2><BR><B>SFC_GET_SIGNAL_MAX</B></H2>
408 Retrieve the peak value for the file as stored in the file header.
413 sndfile : A valid SNDFILE* pointer
414 cmd : SFC_GET_SIGNAL_MAX
415 data : A pointer to a double
416 datasize : sizeof (double)
423 sf_command (sndfile, SFC_GET_SIGNAL_MAX, &max_peak, sizeof (max_peak)) ;
426 <DT>Return value:</DT>
427 <DD>SF_TRUE if the file header contained the peak value. SF_FALSE otherwise.
430 <!-- ========================================================================= -->
431 <A NAME="SFC_GET_MAX_ALL_CHANNELS"></A>
432 <H2><BR><B>SFC_GET_MAX_ALL_CHANNELS</B></H2>
434 Retrieve the peak value for the file as stored in the file header.
439 sndfile : A valid SNDFILE* pointer
440 cmd : SFC_GET_SIGNAL_MAX
441 data : A pointer to an array of doubles
442 datasize : sizeof (double) * number_of_channels
448 double peaks [number_of_channels] ;
449 sf_command (sndfile, SFC_GET_MAX_ALL_CHANNELS, peaks, sizeof (peaks)) ;
452 <DT>Return value:</DT>
453 <DD>SF_TRUE if the file header contains per channel peak values for the file.
458 <!-- ========================================================================= -->
459 <A NAME="SFC_SET_NORM_FLOAT"></A>
460 <H2><BR><B>SFC_SET_NORM_FLOAT</B></H2>
462 This command only affects data read from or written to using the floating point functions:
465 size_t <A HREF="api.html#read">sf_read_float</A> (SNDFILE *sndfile, float *ptr, size_t items) ;
466 size_t <A HREF="api.html#readf">sf_readf_float</A> (SNDFILE *sndfile, float *ptr, size_t frames) ;
468 size_t <A HREF="api.html#write">sf_write_float</A> (SNDFILE *sndfile, float *ptr, size_t items) ;
469 size_t <A HREF="api.html#writef">sf_writef_float</A> (SNDFILE *sndfile, float *ptr, size_t frames) ;
475 sndfile : A valid SNDFILE* pointer
476 cmd : SFC_SET_NORM_FLOAT
478 datasize : SF_TRUE or SF_FALSE
481 For read operations setting normalisation to SF_TRUE means that the data from all
482 subsequent reads will be be normalised to the range [-1.0, 1.0].
485 For write operations, setting normalisation to SF_TRUE means than all data supplied
486 to the float write functions should be in the range [-1.0, 1.0] and will be scaled
487 for the file format as necessary.
490 For both cases, setting normalisation to SF_FALSE means that no scaling will take place.
496 sf_command (sndfile, SFC_SET_NORM_FLOAT, NULL, SF_TRUE) ;
498 sf_command (sndfile, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
501 <DT>Return value: </DT>
502 <DD>Returns the previous float normalisation mode.
505 <!-- ========================================================================= -->
506 <A NAME="SFC_SET_NORM_DOUBLE"></A>
507 <H2><BR><B>SFC_SET_NORM_DOUBLE</B></H2>
509 This command only affects data read from or written to using the double precision
510 floating point functions:
513 size_t <A HREF="api.html#read">sf_read_double</A> (SNDFILE *sndfile, double *ptr, size_t items) ;
514 size_t <A HREF="api.html#readf">sf_readf_double</A> (SNDFILE *sndfile, double *ptr, size_t frames) ;
516 size_t <A HREF="api.html#write">sf_write_double</A> (SNDFILE *sndfile, double *ptr, size_t items) ;
517 size_t <A HREF="api.html#writef">sf_writef_double</A> (SNDFILE *sndfile, double *ptr, size_t frames) ;
523 sndfile : A valid SNDFILE* pointer
524 cmd : SFC_SET_NORM_DOUBLE
526 datasize : SF_TRUE or SF_FALSE
529 For read operations setting normalisation to SF_TRUE means that the data
530 from all subsequent reads will be be normalised to the range [-1.0, 1.0].
533 For write operations, setting normalisation to SF_TRUE means than all data supplied
534 to the double write functions should be in the range [-1.0, 1.0] and will be scaled
535 for the file format as necessary.
538 For both cases, setting normalisation to SF_FALSE means that no scaling will take place.
544 sf_command (sndfile, SFC_SET_NORM_DOUBLE, NULL, SF_TRUE) ;
546 sf_command (sndfile, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
549 <DT>Return value: </DT>
550 <DD>Returns the previous double normalisation mode.
553 <!-- ========================================================================= -->
554 <A NAME="SFC_GET_NORM_FLOAT"></A>
555 <H2><BR><B>SFC_GET_NORM_FLOAT</B></H2>
557 Retrieve the current float normalisation mode.
563 sndfile : A valid SNDFILE* pointer
564 cmd : SFC_GET_NORM_FLOAT
572 normalisation = sf_command (sndfile, SFC_GET_NORM_FLOAT, NULL, 0) ;
575 <DT>Return value: </DT>
576 <DD>Returns TRUE if normalisation is on and FALSE otherwise.
579 <!-- ========================================================================= -->
580 <A NAME="SFC_GET_NORM_DOUBLE"></A>
581 <H2><BR><B>SFC_GET_NORM_DOUBLE</B></H2>
583 Retrieve the current float normalisation mode.
589 sndfile : A valid SNDFILE* pointer
590 cmd : SFC_GET_NORM_DOUBLE
598 normalisation = sf_command (sndfile, SFC_GET_NORM_DOUBLE, NULL, 0) ;
601 <DT>Return value: </DT>
602 <DD>Returns TRUE if normalisation is on and FALSE otherwise.
606 <!-- ========================================================================= -->
607 <A NAME="SFC_SET_SCALE_FLOAT_INT_READ"></A>
608 <H2><BR><B>SFC_SET_SCALE_FLOAT_INT_READ</B></H2>
610 Set/clear the scale factor when integer (short/int) data is read from a file
611 containing floating point data.
617 sndfile : A valid SNDFILE* pointer
618 cmd : SFC_SET_SCALE_FLOAT_INT_READ
620 datasize : TRUE or FALSE
626 sf_command (sndfile, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE) ;
629 <DT>Return value: </DT>
630 <DD>Returns the previous SFC_SET_SCALE_FLOAT_INT_READ setting for this file.
634 <!-- ========================================================================= -->
635 <A NAME="SFC_SET_SCALE_INT_FLOAT_WRITE"></A>
636 <H2><BR><B>SFC_SET_SCALE_INT_FLOAT_WRITE</B></H2>
638 Set/clear the scale factor when integer (short/int) data is written to a file
639 as floating point data.
645 sndfile : A valid SNDFILE* pointer
646 cmd : SFC_SET_SCALE_FLOAT_INT_READ
648 datasize : TRUE or FALSE
654 sf_command (sndfile, SFC_SET_SCALE_INT_FLOAT_WRITE, NULL, SF_TRUE) ;
657 <DT>Return value: </DT>
658 <DD>Returns the previous SFC_SET_SCALE_INT_FLOAT_WRITE setting for this file.
661 <!-- ========================================================================= -->
662 <A NAME="SFC_GET_SIMPLE_FORMAT_COUNT"></A>
663 <H2><BR><B>SFC_GET_SIMPLE_FORMAT_COUNT</B></H2>
665 Retrieve the number of simple formats supported by libsndfile.
672 cmd : SFC_GET_SIMPLE_FORMAT_COUNT
673 data : a pointer to an int
674 datasize : sizeof (int)
681 sf_command (sndfile, SFC_GET_SIMPLE_FORMAT_COUNT, &count, sizeof (int)) ;
684 <DT>Return value: </DT>
688 <!-- ========================================================================= -->
689 <A NAME="SFC_GET_SIMPLE_FORMAT"></A>
690 <H2><BR><B>SFC_GET_SIMPLE_FORMAT</B></H2>
692 Retrieve information about a simple format.
699 cmd : SFC_GET_SIMPLE_FORMAT
700 data : a pointer to an SF_FORMAT_INFO struct
701 datasize : sizeof (SF_FORMAT_INFO)
704 The SF_FORMAT_INFO struct is defined in <sndfile.h> as:
710 const char *extension ;
714 When sf_command() is called with SF_GET_SIMPLE_FORMAT, the value of the format
715 field should be the format number (ie 0 <= format <= count value obtained using
716 SF_GET_SIMPLE_FORMAT_COUNT).
722 SF_FORMAT_INFO format_info ;
725 sf_command (sndfile, SFC_GET_SIMPLE_FORMAT_COUNT, &count, sizeof (int)) ;
727 for (k = 0 ; k < count ; k++)
728 { format_info.format = k ;
729 sf_command (sndfile, SFC_GET_SIMPLE_FORMAT, &format_info, sizeof (format_info)) ;
730 printf ("%08x %s %s\n", format_info.format, format_info.name, format_info.extension) ;
734 <DT>Return value: </DT>
735 <DD>0 on success and non-zero otherwise.
736 <DD>The value of the format field of the SF_FORMAT_INFO struct will be a value which
737 can be placed in the format field of an SF_INFO struct when a file is to be opened
739 <DD>The name field will contain a char* pointer to the name of the string, eg. "WAV (Microsoft 16 bit PCM)".
740 <DD>The extension field will contain the most commonly used file extension for that file type.
743 <!-- ========================================================================= -->
744 <A NAME="SFC_GET_FORMAT_INFO"></A>
745 <H2><BR><B>SFC_GET_FORMAT_INFO</B></H2>
747 Retrieve information about a major or subtype format.
754 cmd : SFC_GET_FORMAT_INFO
755 data : a pointer to an SF_FORMAT_INFO struct
756 datasize : sizeof (SF_FORMAT_INFO)
759 The SF_FORMAT_INFO struct is defined in <sndfile.h> as:
765 const char *extension ;
769 When sf_command() is called with SF_GET_FORMAT_INFO, the format field is
770 examined and if (format & SF_FORMAT_TYPEMASK) is a valid format then the struct
771 is filled in with information about the given major type.
772 If (format & SF_FORMAT_TYPEMASK) is FALSE and (format & SF_FORMAT_SUBMASK) is a
773 valid subtype format then the struct is filled in with information about the given
780 SF_FORMAT_INFO format_info ;
782 format_info.format = SF_FORMAT_WAV ;
783 sf_command (sndfile, SFC_GET_FORMAT_INFO, &format_info, sizeof (format_info)) ;
784 printf ("%08x %s %s\n", format_info.format, format_info.name, format_info.extension) ;
786 format_info.format = SF_FORMAT_ULAW ;
787 sf_command (sndfile, SFC_GET_FORMAT_INFO, &format_info, sizeof (format_info)) ;
788 printf ("%08x %s\n", format_info.format, format_info.name) ;
791 <DT>Return value: </DT>
792 <DD>0 on success and non-zero otherwise.
794 <!-- ========================================================================= -->
795 <A NAME="SFC_GET_FORMAT_MAJOR_COUNT"></A>
796 <H2><BR><B>SFC_GET_FORMAT_MAJOR_COUNT</B></H2>
798 Retrieve the number of major formats.
805 cmd : SFC_GET_FORMAT_MAJOR_COUNT
806 data : a pointer to an int
807 datasize : sizeof (int)
814 sf_command (sndfile, SFC_GET_FORMAT_MAJOR_COUNT, &count, sizeof (int)) ;
817 <DT>Return value: </DT>
821 <!-- ========================================================================= -->
822 <A NAME="SFC_GET_FORMAT_MAJOR"></A>
823 <H2><BR><B>SFC_GET_FORMAT_MAJOR</B></H2>
825 Retrieve information about a major format type.
832 cmd : SFC_GET_FORMAT_MAJOR
833 data : a pointer to an SF_FORMAT_INFO struct
834 datasize : sizeof (SF_FORMAT_INFO)
840 SF_FORMAT_INFO format_info ;
843 sf_command (sndfile, SFC_GET_FORMAT_MAJOR_COUNT, &count, sizeof (int)) ;
845 for (k = 0 ; k < count ; k++)
846 { format_info.format = k ;
847 sf_command (sndfile, SFC_GET_FORMAT_MAJOR, &format_info, sizeof (format_info)) ;
848 printf ("%08x %s %s\n", format_info.format, format_info.name, format_info.extension) ;
852 For a more comprehensive example, see the program list_formats.c in the examples/
853 directory of the libsndfile source code distribution.
856 <DT>Return value: </DT>
857 <DD>0 on success and non-zero otherwise.
858 <DD>The value of the format field will be one of the major format identifiers such as
859 SF_FORMAT_WAV or SF_FORMAT_AIFF.
860 <DD>The name field will contain a char* pointer to the name of the string, eg. "WAV (Microsoft)".
861 <DD>The extension field will contain the most commonly used file extension for that file type.
864 <!-- ========================================================================= -->
865 <A NAME="SFC_GET_FORMAT_SUBTYPE_COUNT"></A>
866 <H2><BR><B>SFC_GET_FORMAT_SUBTYPE_COUNT</B></H2>
868 Retrieve the number of subformats.
875 cmd : SFC_GET_FORMAT_SUBTYPE_COUNT
876 data : a pointer to an int
877 datasize : sizeof (int)
884 sf_command (sndfile, SFC_GET_FORMAT_SUBTYPE_COUNT, &count, sizeof (int)) ;
887 <DT>Return value: </DT>
891 <!-- ========================================================================= -->
892 <A NAME="SFC_GET_FORMAT_SUBTYPE"></A>
893 <H2><BR><B>SFC_GET_FORMAT_SUBTYPE</B></H2>
895 Enumerate the subtypes (this function does not translate a subtype into
896 a string describing that subtype).
897 A typical use case might be retrieving a string description of all subtypes
898 so that a dialog box can be filled in.
908 cmd : SFC_GET_FORMAT_SUBTYPE
909 data : a pointer to an SF_FORMAT_INFO struct
910 datasize : sizeof (SF_FORMAT_INFO)
913 Example 1: Retrieve all sybtypes supported by the WAV format.
916 SF_FORMAT_INFO format_info ;
919 sf_command (sndfile, SFC_GET_FORMAT_SUBTYPE_COUNT, &count, sizeof (int)) ;
921 for (k = 0 ; k < count ; k++)
922 { format_info.format = k ;
923 sf_command (sndfile, SFC_GET_FORMAT_SUBTYPE, &format_info, sizeof (format_info)) ;
924 if (! sf_format_check (format_info.format | SF_FORMAT_WAV))
926 printf ("%08x %s\n", format_info.format, format_info.name) ;
930 Example 2: Print a string describing the SF_FORMAT_PCM_16 subtype.
933 SF_FORMAT_INFO format_info ;
936 sf_command (sndfile, SFC_GET_FORMAT_SUBTYPE_COUNT, &count, sizeof (int)) ;
938 for (k = 0 ; k < count ; k++)
939 { format_info.format = k ;
940 sf_command (sndfile, SFC_GET_FORMAT_SUBTYPE, &format_info, sizeof (format_info)) ;
941 if (format_info.format == SF_FORMAT_PCM_16)
942 { printf ("%08x %s\n", format_info.format, format_info.name) ;
948 For a more comprehensive example, see the program list_formats.c in the examples/
949 directory of the libsndfile source code distribution.
952 <DT>Return value: </DT>
953 <DD>0 on success and non-zero otherwise.
954 <DD>The value of the format field will be one of the major format identifiers such as
955 SF_FORMAT_WAV or SF_FORMAT_AIFF.
956 <DD>The name field will contain a char* pointer to the name of the string; for instance
957 "WAV (Microsoft)" or "AIFF (Apple/SGI)".
958 <DD>The extension field will be a NULL pointer.
961 <!-- ========================================================================= -->
962 <A NAME="SFC_SET_ADD_PEAK_CHUNK"></A>
963 <H2><BR><B>SFC_SET_ADD_PEAK_CHUNK</B></H2>
965 By default, WAV and AIFF files which contain floating point data (subtype SF_FORMAT_FLOAT
966 or SF_FORMAT_DOUBLE) have a PEAK chunk.
967 By using this command, the addition of a PEAK chunk can be turned on or off.
970 Note : This call must be made before any data is written to the file.
975 sndfile : A valid SNDFILE* pointer
976 cmd : SFC_SET_ADD_PEAK_CHUNK
977 data : Not used (should be NULL)
978 datasize : TRUE or FALSE.
984 /* Turn on the PEAK chunk. */
985 sf_command (sndfile, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_TRUE) ;
987 /* Turn off the PEAK chunk. */
988 sf_command (sndfile, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_FALSE) ;
991 <DT>Return value:</DT>
992 <DD>Returns SF_TRUE if the peak chunk will be written after this call.
993 <DD>Returns SF_FALSE if the peak chunk will not be written after this call.
996 <!-- ========================================================================= -->
997 <A NAME="SFC_UPDATE_HEADER_NOW"></A>
998 <H2><BR><B>SFC_UPDATE_HEADER_NOW</B></H2>
1000 The header of an audio file is normally written by libsndfile when the file is
1001 closed using <B>sf_close()</B>.
1004 There are however situations where large files are being generated and it would
1005 be nice to have valid data in the header before the file is complete.
1006 Using this command will update the file header to reflect the amount of data written
1008 Other programs opening the file for read (before any more data is written) will
1009 then read a valid sound file header.
1014 sndfile : A valid SNDFILE* pointer
1015 cmd : SFC_UPDATE_HEADER_NOW
1016 data : Not used (should be NULL)
1017 datasize : Not used.
1023 /* Update the header now. */
1024 sf_command (sndfile, SFC_UPDATE_HEADER_NOW, NULL, 0) ;
1027 <DT>Return value:</DT>
1031 <!-- ========================================================================= -->
1032 <A NAME="SFC_SET_UPDATE_HEADER_AUTO"></A>
1033 <H2><BR><B>SFC_SET_UPDATE_HEADER_AUTO</B></H2>
1035 Similar to SFC_UPDATE_HEADER_NOW but updates the header at the end of every call
1036 to the <B>sf_write*</B> functions.
1041 sndfile : A valid SNDFILE* pointer
1042 cmd : SFC_UPDATE_HEADER_NOW
1043 data : Not used (should be NULL)
1044 datasize : SF_TRUE or SF_FALSE
1050 /* Turn on auto header update. */
1051 sf_command (sndfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) ;
1053 /* Turn off auto header update. */
1054 sf_command (sndfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_FALSE) ;
1057 <DT>Return value:</DT>
1058 <DD>TRUE if auto update header is now on; FALSE otherwise.
1061 <!-- ========================================================================= -->
1062 <A NAME="SFC_FILE_TRUNCATE"></A>
1063 <H2><BR><B>SFC_FILE_TRUNCATE</B></H2>
1065 Truncate a file that was opened for write or read/write.
1070 sndfile : A valid SNDFILE* pointer
1071 cmd : SFC_FILE_TRUNCATE
1072 data : A pointer to an sf_count_t.
1073 datasize : sizeof (sf_count_t)
1077 Truncate the file to the number of frames specified by the sf_count_t pointed
1079 After this command, both the read and the write pointer will be
1080 at the new end of the file.
1081 This command will fail (returning non-zero) if the requested truncate position
1082 is beyond the end of the file.
1088 /* Truncate the file to a length of 20 frames. */
1089 sf_count_t frames = 20 ;
1090 sf_command (sndfile, SFC_FILE_TRUNCATE, &frames, sizeof (frames)) ;
1093 <DT>Return value:</DT>
1094 <DD>Zero on sucess, non-zero otherwise.
1097 <!-- ========================================================================= -->
1098 <A NAME="SFC_SET_RAW_START_OFFSET"></A>
1099 <H2><BR><B>SFC_SET_RAW_START_OFFSET</B></H2>
1101 Change the data start offset for files opened up as SF_FORMAT_RAW.
1106 sndfile : A valid SNDFILE* pointer
1107 cmd : SFC_SET_RAW_START_OFFSET
1108 data : A pointer to an sf_count_t.
1109 datasize : sizeof (sf_count_t)
1113 For a file opened as format SF_FORMAT_RAW, set the data offset to the value
1120 /* Reset the data offset to 5 bytes from the start of the file. */
1121 sf_count_t offset = 5 ;
1122 sf_command (sndfile, SFC_SET_RAW_START_OFFSET, &offset, sizeof (offset)) ;
1125 <DT>Return value:</DT>
1126 <DD>Zero on success, non-zero otherwise.
1129 <!-- ========================================================================= -->
1130 <A NAME="SFC_SET_CLIPPING"></A>
1131 <H2><BR><B>SFC_SET_CLIPPING</B></H2>
1133 Turn on/off automatic clipping when doing floating point to integer conversion.
1138 sndfile : A valid SNDFILE* pointer
1139 cmd : SFC_SET_CLIPPING
1141 datasize : SF_TRUE or SF_FALSE.
1145 Turn on (datasize == SF_TRUE) or off (datasize == SF_FALSE) clipping.
1151 sf_command (sndfile, SFC_SET_CLIPPING, NULL, SF_TRUE) ;
1154 <DT>Return value:</DT>
1155 <DD>Clipping mode (SF_TRUE or SF_FALSE).
1159 <!-- ========================================================================= -->
1160 <A NAME="SFC_GET_CLIPPING"></A>
1161 <H2><BR><B>SFC_GET_CLIPPING</B></H2>
1163 Turn on/off automatic clipping when doing floating point to integer conversion.
1168 sndfile : A valid SNDFILE* pointer
1169 cmd : SFC_GET_CLIPPING
1175 Retrieve the current cliiping setting.
1181 sf_command (sndfile, SFC_GET_CLIPPING, NULL, 0) ;
1184 <DT>Return value:</DT>
1185 <DD>Clipping mode (SF_TRUE or SF_FALSE).
1188 <!-- ========================================================================= -->
1189 <A NAME="SFC_GET_EMBED_FILE_INFO"></A>
1190 <H2><BR><B>SFC_GET_EMBED_FILE_INFO</B></H2>
1192 Get the file offset and file length of a file enbedded within another
1198 sndfile : A valid SNDFILE* pointer
1199 cmd : SFC_GET_CLIPPING
1200 data : a pointer to an SF_EMBED_FILE_INFO struct
1201 datasize : sizeof (SF_EMBED_FILE_INFO)
1204 The SF_EMBED_FILE_INFO struct is defined in <sndfile.h> as:
1208 { sf_count_t offset ;
1210 } SF_EMBED_FILE_INFO ;
1213 <DT>Return value: </DT>
1214 <DD>0 on success and non-zero otherwise.
1215 <DD>The value of the offset field of the SF_EMBED_FILE_INFO struct will be
1216 the offsets in bytes from the start of the outer file to the start of
1218 <DD>The value of the offset field of the SF_EMBED_FILE_INFO struct will be
1219 the length in bytes of the embedded file.
1224 <!-- ========================================================================= -->
1225 <A NAME="SFC_WAVEX_GET_AMBISONIC"></A>
1226 <H2><BR><B>SFC_WAVEX_GET_AMBISONIC</B></H2>
1228 Test if the current file has the GUID of a WAVEX file for any of the Ambisonic
1234 sndfile : A valid SNDFILE* pointer
1235 cmd : SFC_WAVEX_GET_AMBISONIC
1240 The Ambisonic WAVEX formats are defined here :
1241 <A HREF="http://dream.cs.bath.ac.uk/researchdev/wave-ex/bformat.html">
1242 http://dream.cs.bath.ac.uk/researchdev/wave-ex/bformat.html</A>.
1245 <DT>Return value: </DT>
1246 <DD>SF_AMBISONIC_NONE or SF_AMBISONIC_B_FORMAT or zero if the file format
1247 does not support ambisonic formats.
1250 <!-- ========================================================================= -->
1251 <A NAME="SFC_WAVEX_SET_AMBISONIC"></A>
1252 <H2><BR><B>SFC_WAVEX_SET_AMBISONIC</B></H2>
1254 Set the GUID of a new WAVEX file to indicate an Ambisonics format.
1259 sndfile : A valid SNDFILE* pointer
1260 cmd : SFC_WAVEX_SET_AMBISONIC
1262 datasize : SF_AMBISONIC_NONE or SF_AMBISONIC_B_FORMAT
1265 Turn on (SF_AMBISONIC_B_FORMAT) or off (SF_AMBISONIC_NONE) encoding.
1266 This command is currently only supported for files with SF_FORMAT_WAVEX format.
1269 The Ambisonic WAVEX formats are defined here :
1270 <A HREF="http://dream.cs.bath.ac.uk/researchdev/wave-ex/bformat.html">
1271 http://dream.cs.bath.ac.uk/researchdev/wave-ex/bformat.html</A>.
1274 <DT>Return value: </DT>
1275 <DD>Return the ambisonic value that has just been set or zero if the file
1276 format does not support ambisonic encoding.
1279 <!-- ========================================================================= -->
1280 <A NAME="SFC_SET_VBR_ENCODING_QUALITY"></A>
1281 <H2><BR><B>SFC_SET_VBR_ENCODING_QUALITY</B></H2>
1283 Set the the Variable Bit Rate encoding quality.
1284 The encoding quality value should be between 0.0 (lowest quality) and 1.0
1290 sndfile : A valid SNDFILE* pointer
1291 cmd : SFC_SET_VBR_ENCODING_QUALITY
1292 data : A pointer to a double value
1293 datasize : sizeof (double)
1296 The command must be sent before any audio data is written to the file.
1301 <DT>Return value: </DT>
1302 <DD>Zero on success, non-zero otherwise.
1305 <!-- ========================================================================= -->
1306 <A NAME="SFC_RAW_NEEDS_ENDSWAP"></A>
1307 <H2><BR><B>SFC_RAW_NEEDS_ENDSWAP</B></H2>
1309 Determine if raw data read using
1310 <a href="api.html#raw">
1312 needs to be end swapped on the host CPU.
1315 For instance, will return SF_TRUE on when reading WAV containing
1316 SF_FORMAT_PCM_16 data on a big endian machine and SF_FALSE on a little endian
1322 sndfile : A valid SNDFILE* pointer
1323 cmd : SFC_RAW_NEEDS_ENDSWAP
1329 <DT>Return value: </DT>
1330 <DD>SF_TRUE or SF_FALSE
1334 <!-- ========================================================================= -->
1335 <A NAME="SFC_GET_BROADCAST_INFO"></A>
1336 <H2><BR><B>SFC_GET_BROADCAST_INFO</B></H2>
1338 Retrieve the Broadcast Extension Chunk from WAV (and related) files.
1344 sndfile : A valid SNDFILE* pointer
1345 cmd : SFC_GET_BROADCAST_INFO
1346 data : a pointer to an SF_BROADCAST_INFO struct
1347 datasize : sizeof (SF_BROADCAST_INFO)
1350 The SF_BROADCAST_INFO struct is defined in <sndfile.h> as:
1354 { char description [256] ;
1355 char originator [32] ;
1356 char originator_reference [32] ;
1357 char origination_date [10] ;
1358 char origination_time [8] ;
1359 unsigned int time_reference_low ;
1360 unsigned int time_reference_high ;
1363 char reserved [190] ;
1364 unsigned int coding_history_size ;
1365 char coding_history [256] ;
1366 } SF_BROADCAST_INFO ;
1370 <DT>Return value: </DT>
1371 <DD>SF_TRUE if the file contained a Broadcast Extension chunk or SF_FALSE
1375 <!-- ========================================================================= -->
1376 <A NAME="SFC_SET_BROADCAST_INFO"></A>
1377 <H2><BR><B>SFC_SET_BROADCAST_INFO</B></H2>
1379 Set the Broadcast Extension Chunk for WAV (and related) files.
1385 sndfile : A valid SNDFILE* pointer
1386 cmd : SFC_SET_BROADCAST_INFO
1387 data : a pointer to an SF_BROADCAST_INFO struct
1388 datasize : sizeof (SF_BROADCAST_INFO)
1392 <DT>Return value: </DT>
1393 <DD>SF_TRUE if setting the Broadcast Extension chunk was successful and SF_FALSE
1396 <!-- ========================================================================= -->
1401 The libsndfile home page is here :
1402 <A HREF="http://www.mega-nerd.com/libsndfile/">
1403 http://www.mega-nerd.com/libsndfile/</A>.