dither.html 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <TITLE>
  5. libsndfile : the sf_command function.
  6. </TITLE>
  7. <META NAME="Author" CONTENT="Erik de Castro Lopo (erikd AT mega-nerd DOT com)">
  8. <!-- Another version at the bottom of the page. -->
  9. <META NAME="Description" CONTENT="The libsndfile API.">
  10. <META NAME="Keywords" CONTENT="WAV AIFF AU libsndfile sound audio dsp Linux">
  11. <LINK REL="stylesheet" HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
  12. <LINK REL="stylesheet" HREF="print.css" TYPE="text/css" MEDIA="print">
  13. </HEAD>
  14. <BODY>
  15. <H1><B>sf_command</B></H1>
  16. <PRE>
  17. int sf_command (SNDFILE *sndfile, int cmd, void *data, int datasize) ;
  18. </PRE>
  19. <P>
  20. This function allows the caller to retrieve information from or change aspects of the
  21. library behaviour.
  22. Examples include retrieving a string containing the library version or changing the
  23. scaling applied to floating point sample data during read and write.
  24. Most of these operations are performed on a per-file basis.
  25. </P>
  26. <P>
  27. The cmd parameter is a integer identifier which is defined in &lt;sndfile.h&gt;.
  28. All of the valid command identifiers have names begining with "SFC_".
  29. Data is passed to and returned from the library by use of a void pointer.
  30. The library will not read or write more than datasize bytes from the void pointer.
  31. For some calls no data is required in which case data should be NULL and datasize
  32. may be used for some other purpose.
  33. </P>
  34. <P>
  35. The available commands are as follows:
  36. </P>
  37. <CENTER>
  38. <TABLE BORDER="0" WIDTH="90%" CELLPADDING="4">
  39. <TR>
  40. <TD><A HREF="#SFC_GET_LIB_VERSION">SFC_GET_LIB_VERSION</A></TD>
  41. <TD>Retrieve the version of the library.</TD>
  42. </TR>
  43. <TR>
  44. <TD><A HREF="#SFC_GET_LOG_INFO">SFC_GET_LOG_INFO</A></TD>
  45. <TD>Retrieve the internal per-file operation log.</TD>
  46. </TR>
  47. <TR>
  48. <TD><A HREF="#SFC_CALC_SIGNAL_MAX">SFC_CALC_SIGNAL_MAX</A></TD>
  49. <TD>Retrieve the measured maximum signal value.</TD>
  50. </TR>
  51. <TR>
  52. <TD><A HREF="#SFC_CALC_NORM_SIGNAL_MAX">SFC_CALC_NORM_SIGNAL_MAX</A></TD>
  53. <TD>Retrieve the measured normalised maximum signal value.</TD>
  54. </TR>
  55. <TR>
  56. <TD><A HREF="#SFC_CALC_MAX_ALL_CHANNELS">SFC_CALC_MAX_ALL_CHANNELS</A></TD>
  57. <TD>Calculate peaks for all channels.</TD>
  58. </TR>
  59. <TR>
  60. <TD><A HREF="#SFC_CALC_NORM_MAX_ALL_CHANNELS">SFC_CALC_NORM_MAX_ALL_CHANNELS</A></TD>
  61. <TD>Calculate normalised peaks for all channels.</TD>
  62. </TR>
  63. <TR>
  64. <TD><A HREF="#SFC_SET_NORM_FLOAT">SFC_SET_NORM_FLOAT</A></TD>
  65. <TD>Modify the normalisation behaviour of the floating point reading and writing functions.</TD>
  66. </TR>
  67. <TR>
  68. <TD><A HREF="#SFC_SET_NORM_DOUBLE">SFC_SET_NORM_DOUBLE</A></TD>
  69. <TD>Modify the normalisation behaviour of the double precision floating point reading and writing functions.</TD>
  70. </TR>
  71. <TR>
  72. <TD><A HREF="#SFC_GET_NORM_FLOAT">SFC_GET_NORM_FLOAT</A></TD>
  73. <TD>Retrieve the current normalisation behaviour of the floating point reading and writing functions.</TD>
  74. </TR>
  75. <TR>
  76. <TD><A HREF="#SFC_GET_NORM_DOUBLE">SFC_GET_NORM_DOUBLE</A></TD>
  77. <TD>Retrieve the current normalisation behaviour of the double precision floating point reading and writing functions.</TD>
  78. </TR>
  79. <TR>
  80. <TD><A HREF="#SFC_GET_SIMPLE_FORMAT_COUNT">SFC_GET_SIMPLE_FORMAT_COUNT</A></TD>
  81. <TD>Retrieve the number of simple formats supported by libsndfile.</TD>
  82. </TR>
  83. <TR>
  84. <TD><A HREF="#SFC_GET_SIMPLE_FORMAT">SFC_GET_SIMPLE_FORMAT</A></TD>
  85. <TD>Retrieve information about a simple format.</TD>
  86. </TR>
  87. <TR>
  88. <TD><A HREF="#SFC_GET_FORMAT_INFO">SFC_GET_FORMAT_INFO</A></TD>
  89. <TD>Retrieve information about a major or subtype format.</TD>
  90. </TR>
  91. <TR>
  92. <TD><A HREF="#SFC_GET_FORMAT_MAJOR_COUNT">SFC_GET_FORMAT_MAJOR_COUNT</A></TD>
  93. <TD>Retrieve the number of major formats.</TD>
  94. </TR>
  95. <TR>
  96. <TD><A HREF="#SFC_GET_FORMAT_MAJOR">SFC_GET_FORMAT_MAJOR</A></TD>
  97. <TD>Retrieve information about a major format type.</TD>
  98. </TR>
  99. <TR>
  100. <TD><A HREF="#SFC_GET_FORMAT_SUBTYPE_COUNT">SFC_GET_FORMAT_SUBTYPE_COUNT</A></TD>
  101. <TD>Retrieve the number of subformats.</TD>
  102. </TR>
  103. <TR>
  104. <TD><A HREF="#SFC_GET_FORMAT_SUBTYPE">SFC_GET_FORMAT_SUBTYPE</A></TD>
  105. <TD>Retrieve information about a subformat.</TD>
  106. </TR>
  107. <TR>
  108. <TD><A HREF="#SFC_SET_ADD_PEAK_CHUNK">SFC_SET_ADD_PEAK_CHUNK</A></TD>
  109. <TD>Switch the code for adding the PEAK chunk to WAV and AIFF files on or off.</TD>
  110. </TR>
  111. <TR>
  112. <TD><A HREF="#SFC_UPDATE_HEADER_NOW">SFC_UPDATE_HEADER_NOW</A></TD>
  113. <TD>Used when a file is open for write, this command will update the file
  114. header to reflect the data written so far.</TD>
  115. </TR>
  116. <TR>
  117. <TD><A HREF="#SFC_SET_UPDATE_HEADER_AUTO">SFC_SET_UPDATE_HEADER_AUTO</A></TD>
  118. <TD>Used when a file is open for write, this command will cause the file header
  119. to be updated after each write to the file.</TD>
  120. </TR>
  121. <TR>
  122. <TD><A HREF="#SFC_FILE_TRUNCATE">SFC_FILE_TRUNCATE</A></TD>
  123. <TD>Truncate a file open for write or for read/write.</TD>
  124. </TR>
  125. <TR>
  126. <TD><A HREF="#SFC_SET_RAW_START_OFFSET">SFC_SET_RAW_START_OFFSET</A></TD>
  127. <TD>Change the data start offset for files opened up as SF_FORMAT_RAW.</TD>
  128. </TR>
  129. <!--
  130. <TR>
  131. <TD><A HREF="#add-dither">add dither</A></TD>
  132. <TD>Add dither to output on write.</TD>
  133. </TR>
  134. -->
  135. </TABLE>
  136. </CENTER>
  137. <BR><BR>
  138. <HR>
  139. <!-- ========================================================================= -->
  140. <A NAME="SFC_GET_LIB_VERSION"></A>
  141. <H2><BR><B>SFC_GET_LIB_VERSION</B></H2>
  142. <P>
  143. Retrieve the version of the library as a string.
  144. </P>
  145. <P>
  146. Parameters:
  147. <PRE>
  148. sndfile : Not used
  149. cmd : SFC_GET_LIB_VERSION
  150. data : A pointer to a char buffer
  151. datasize : The size of the the buffer
  152. </PRE>
  153. <P>
  154. Example:
  155. </P>
  156. <PRE>
  157. char buffer [128] ;
  158. sf_command (NULL, SFC_GET_LIB_VERSION, buffer, sizeof (buffer)) ;
  159. </PRE>
  160. <DL>
  161. <DT>Return value:</DT>
  162. <DD><DD>This call will return the length of the retrieved version string.
  163. </DL>
  164. <DL>
  165. <DT>Notes:</DT>
  166. <DD>
  167. The string returned in the buffer passed to this function will not overflow
  168. the buffer and will always be null terminated .
  169. </DL>
  170. <!-- ========================================================================= -->
  171. <A NAME="SFC_GET_LOG_INFO"></A>
  172. <H2><BR><B>SFC_GET_LOG_INFO</B></H2>
  173. <P>
  174. Retrieve the log buffer generated when opening a file as a string. This log
  175. buffer can often contain a good reason for why libsndfile failed to open a
  176. particular file.
  177. </P>
  178. <P>
  179. Parameters:
  180. <PRE>
  181. sndfile : A valid SNDFILE* pointer
  182. cmd : SFC_GET_LOG_INFO
  183. data : A pointer to a char buffer
  184. datasize : The size of the the buffer
  185. </PRE>
  186. <P>
  187. Example:
  188. </P>
  189. <PRE>
  190. char buffer [2048] ;
  191. sf_command (sndfile, SFC_GET_LOG_INFO, buffer, sizeof (buffer)) ;
  192. </PRE>
  193. <DL>
  194. <DT>Return value:</DT>
  195. <DD><DD>This call will return the length of the retrieved version string.
  196. </DL>
  197. <DL>
  198. <DT>Notes:</DT>
  199. <DD>
  200. The string returned in the buffer passed to this function will not overflow
  201. the buffer and will always be null terminated .
  202. </DL>
  203. <!-- ========================================================================= -->
  204. <A NAME="SFC_CALC_SIGNAL_MAX"></A>
  205. <H2><BR><B>SFC_CALC_SIGNAL_MAX</B></H2>
  206. <P>
  207. Retrieve the measured maximum signal value. This involves reading through
  208. the whole file which can be slow on large files.
  209. </P>
  210. <P>
  211. Parameters:
  212. <PRE>
  213. sndfile : A valid SNDFILE* pointer
  214. cmd : SFC_CALC_SIGNAL_MAX
  215. data : A pointer to a double
  216. datasize : sizeof (double)
  217. </PRE>
  218. <P>
  219. Example:
  220. </P>
  221. <PRE>
  222. double max_val ;
  223. sf_command (sndfile, SFC_CALC_SIGNAL_MAX, &amp;max_val, sizeof (max_val)) ;
  224. </PRE>
  225. <DL>
  226. <DT>Return value:</DT>
  227. <DD><DD>Zero on success, non-zero otherwise.
  228. </DL>
  229. <!-- ========================================================================= -->
  230. <A NAME="SFC_CALC_NORM_SIGNAL_MAX"></A>
  231. <H2><BR><B>SFC_CALC_NORM_SIGNAL_MAX</B></H2>
  232. <P>
  233. Retrieve the measured normailised maximum signal value. This involves reading
  234. through the whole file which can be slow on large files.
  235. </P>
  236. <P>
  237. Parameters:
  238. <PRE>
  239. sndfile : A valid SNDFILE* pointer
  240. cmd : SFC_CALC_NORM_SIGNAL_MAX
  241. data : A pointer to a double
  242. datasize : sizeof (double)
  243. </PRE>
  244. <P>
  245. Example:
  246. </P>
  247. <PRE>
  248. double max_val ;
  249. sf_command (sndfile, SFC_CALC_NORM_SIGNAL_MAX, &amp;max_val, sizeof (max_val)) ;
  250. </PRE>
  251. <DL>
  252. <DT>Return value:</DT>
  253. <DD><DD>Zero on success, non-zero otherwise.
  254. </DL>
  255. <!-- ========================================================================= -->
  256. <A NAME="SFC_CALC_MAX_ALL_CHANNELS"></A>
  257. <H2><BR><B>SFC_CALC_MAX_ALL_CHANNELS</B></H2>
  258. <P>
  259. Calculate peaks for all channels. This involves reading through
  260. the whole file which can be slow on large files.
  261. </P>
  262. <P>
  263. Parameters:
  264. <PRE>
  265. sndfile : A valid SNDFILE* pointer
  266. cmd : SFC_CALC_MAX_ALL_CHANNELS
  267. data : A pointer to a double
  268. datasize : sizeof (double) * number_of_channels
  269. </PRE>
  270. <P>
  271. Example:
  272. </P>
  273. <PRE>
  274. double peaks [number_of_channels] ;
  275. sf_command (sndfile, SFC_CALC_MAX_ALL_CHANNELS, peaks, sizeof (peaks)) ;
  276. </PRE>
  277. <DL>
  278. <DT>Return value:</DT>
  279. <DD>Zero if peaks have been calculated successfully and non-zero otherwise.
  280. </DL>
  281. <!-- ========================================================================= -->
  282. <A NAME="SFC_CALC_NORM_MAX_ALL_CHANNELS"></A>
  283. <H2><BR><B>SFC_CALC_NORM_MAX_ALL_CHANNELS</B></H2>
  284. <P>
  285. Calculate normalised peaks for all channels. This involves reading through
  286. the whole file which can be slow on large files.
  287. </P>
  288. <P>
  289. Parameters:
  290. <PRE>
  291. sndfile : A valid SNDFILE* pointer
  292. cmd : SFC_CALC_NORM_MAX_ALL_CHANNELS
  293. data : A pointer to a double
  294. datasize : sizeof (double) * number_of_channels
  295. </PRE>
  296. <P>
  297. Example:
  298. </P>
  299. <PRE>
  300. double peaks [number_of_channels] ;
  301. sf_command (sndfile, SFC_CALC_NORM_MAX_ALL_CHANNELS, peaks, sizeof (peaks)) ;
  302. </PRE>
  303. <DL>
  304. <DT>Return value:</DT>
  305. <DD>Zero if peaks have been calculated successfully and non-zero otherwise.
  306. </DL>
  307. <!-- ========================================================================= -->
  308. <!--
  309. <A NAME="read-text"></A>
  310. <H2><BR><B>Read text</B></H2>
  311. <P>
  312. Many sound file formats contain allow the inclusion of a text string describing the nature
  313. of the file. If a file contains such a string, this functions will return it to the caller.
  314. </P>
  315. <P>
  316. It should be noted that the way the string is added to the file is file format dependant
  317. but that any string added with <A HREF="#write-text">write text</A> will be returned by
  318. <A HREF="#read-text">read text</A>.
  319. </P>
  320. <P>
  321. <P>
  322. Parameters:
  323. </P>
  324. <PRE>
  325. sndfile : A valid SNDFILE* pointer
  326. cmd : The text string "read text".
  327. data : A pointer to a char buffer.
  328. datasize : The size of the the buffer.
  329. </PRE>
  330. <P>
  331. Example:
  332. </P>
  333. <PRE>
  334. char buffer [128] ;
  335. sf_command (sndfile, "read text", buffer, sizeof (buffer)) ;
  336. </PRE>
  337. <DL>
  338. <DT>Return value:</DT>
  339. <DD>If a text string is found, this call will return the length of the retrieved text
  340. string.
  341. <DD>If no text string is found, zero will be returned and the first element in the
  342. buffer will be set to the null character.
  343. <DT>Notes:</DT>
  344. <DD>The string returned in the buffer passed to this function will not overflow
  345. the buffer and will be correctly null terminated .
  346. </DL>
  347. <A NAME="write-text"></A>
  348. <H2><BR><B>Write text</B></H2>
  349. <P>
  350. Add a text string to a file. The text string added can be retrieved when the file is
  351. read using <A HREF="#read-text">read text</A>.
  352. </P>
  353. <P>
  354. Parameters:
  355. </P>
  356. <PRE>
  357. sndfile : A valid SNDFILE* pointer
  358. cmd : The text string "write text".
  359. data : A pointer to the string to be added.
  360. datasize : Not used.
  361. </PRE>
  362. <P>
  363. Example:
  364. </P>
  365. <PRE>
  366. char text = "The sound of one hand clapping." ;
  367. sf_command (sndfile, "write text", text, strlen (text)) ;
  368. </PRE>
  369. <DL>
  370. <DT>Return value: </DT>
  371. <DD>If the current file format allows the addition of text strings, the string will
  372. be added and the length of the string will be returned.
  373. <DD>If the file format does not allow the addition of text strings zero will be returned.
  374. <DD>If this function is called after the file is openned but before
  375. </DL>
  376. -->
  377. <!-- ========================================================================= -->
  378. <A NAME="SFC_SET_NORM_FLOAT"></A>
  379. <H2><BR><B>SFC_SET_NORM_FLOAT</B></H2>
  380. <P>
  381. This command only affects data read from or written to using the floating point functions:
  382. </P>
  383. <PRE>
  384. size_t <A HREF="api.html#read">sf_read_float</A> (SNDFILE *sndfile, float *ptr, size_t items) ;
  385. size_t <A HREF="api.html#readf">sf_readf_float</A> (SNDFILE *sndfile, float *ptr, size_t frames) ;
  386. size_t <A HREF="api.html#write">sf_write_float</A> (SNDFILE *sndfile, float *ptr, size_t items) ;
  387. size_t <A HREF="api.html#writef">sf_writef_float</A> (SNDFILE *sndfile, float *ptr, size_t frames) ;
  388. </PRE>
  389. <P>
  390. Parameters:
  391. </P>
  392. <PRE>
  393. sndfile : A valid SNDFILE* pointer
  394. cmd : SFC_SET_NORM_FLOAT
  395. data : NULL
  396. datasize : SF_TRUE or SF_FALSE
  397. </PRE>
  398. <P>
  399. For read operations setting normalisation to SF_TRUE means that the data from all
  400. subsequent reads will be be normalised to the range [-1.0, 1.0].
  401. </P>
  402. <P>
  403. For write operations, setting normalisation to SF_TRUE means than all data supplied
  404. to the float write functions should be in the range [-1.0, 1.0] and will be scaled
  405. for the file format as necessary.
  406. </P>
  407. <P>
  408. For both cases, setting normalisation to SF_FALSE means that no scaling will take place.
  409. </P>
  410. <P>
  411. Example:
  412. </P>
  413. <PRE>
  414. sf_command (sndfile, SFC_SET_NORM_FLOAT, NULL, SF_TRUE) ;
  415. sf_command (sndfile, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
  416. </PRE>
  417. <DL>
  418. <DT>Return value: </DT>
  419. <DD>Returns 1 on success or 0 for failure.
  420. </DL>
  421. <!-- ========================================================================= -->
  422. <A NAME="SFC_SET_NORM_DOUBLE"></A>
  423. <H2><BR><B>SFC_SET_NORM_DOUBLE</B></H2>
  424. <P>
  425. This command only affects data read from or written to using the double precision
  426. floating point functions:
  427. </P>
  428. <PRE>
  429. size_t <A HREF="api.html#read">sf_read_double</A> (SNDFILE *sndfile, double *ptr, size_t items) ;
  430. size_t <A HREF="api.html#readf">sf_readf_double</A> (SNDFILE *sndfile, double *ptr, size_t frames) ;
  431. size_t <A HREF="api.html#write">sf_write_double</A> (SNDFILE *sndfile, double *ptr, size_t items) ;
  432. size_t <A HREF="api.html#writef">sf_writef_double</A> (SNDFILE *sndfile, double *ptr, size_t frames) ;
  433. </PRE>
  434. <P>
  435. Parameters:
  436. </P>
  437. <PRE>
  438. sndfile : A valid SNDFILE* pointer
  439. cmd : SFC_SET_NORM_DOUBLE
  440. data : NULL
  441. datasize : SF_TRUE or SF_FALSE
  442. </PRE>
  443. <P>
  444. For read operations setting normalisation to SF_TRUE means that the data
  445. from all subsequent reads will be be normalised to the range [-1.0, 1.0].
  446. </P>
  447. <P>
  448. For write operations, setting normalisation to SF_TRUE means than all data supplied
  449. to the double write functions should be in the range [-1.0, 1.0] and will be scaled
  450. for the file format as necessary.
  451. </P>
  452. <P>
  453. For both cases, setting normalisation to SF_FALSE means that no scaling will take place.
  454. </P>
  455. <P>
  456. Example:
  457. </P>
  458. <PRE>
  459. sf_command (sndfile, SFC_SET_NORM_DOUBLE, NULL, SF_TRUE) ;
  460. sf_command (sndfile, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
  461. </PRE>
  462. <DL>
  463. <DT>Return value: </DT>
  464. <DD>Returns 1 on success or 0 for failure.
  465. </DL>
  466. <!-- ========================================================================= -->
  467. <A NAME="SFC_GET_NORM_FLOAT"></A>
  468. <H2><BR><B>SFC_GET_NORM_FLOAT</B></H2>
  469. <P>
  470. Retrieve the current float normalisation mode.
  471. </P>
  472. <P>
  473. Parameters:
  474. </P>
  475. <PRE>
  476. sndfile : A valid SNDFILE* pointer
  477. cmd : SFC_GET_NORM_FLOAT
  478. data : NULL
  479. datasize : anything
  480. </PRE>
  481. <P>
  482. Example:
  483. </P>
  484. <PRE>
  485. normalisation = sf_command (sndfile, SFC_GET_NORM_FLOAT, NULL, 0) ;
  486. </PRE>
  487. <DL>
  488. <DT>Return value: </DT>
  489. <DD>Returns TRUE if normaisation is on and FALSE otherwise.
  490. </DL>
  491. <!-- ========================================================================= -->
  492. <A NAME="SFC_GET_NORM_DOUBLE"></A>
  493. <H2><BR><B>SFC_GET_NORM_DOUBLE</B></H2>
  494. <P>
  495. Retrieve the current float normalisation mode.
  496. </P>
  497. <P>
  498. Parameters:
  499. </P>
  500. <PRE>
  501. sndfile : A valid SNDFILE* pointer
  502. cmd : SFC_GET_NORM_DOUBLE
  503. data : NULL
  504. datasize : anything
  505. </PRE>
  506. <P>
  507. Example:
  508. </P>
  509. <PRE>
  510. normalisation = sf_command (sndfile, SFC_GET_NORM_DOUBLE, NULL, 0) ;
  511. </PRE>
  512. <DL>
  513. <DT>Return value: </DT>
  514. <DD>Returns TRUE if normalisation is on and FALSE otherwise.
  515. </DL>
  516. <!-- ========================================================================= -->
  517. <A NAME="SFC_GET_SIMPLE_FORMAT_COUNT"></A>
  518. <H2><BR><B>SFC_GET_SIMPLE_FORMAT_COUNT</B></H2>
  519. <P>
  520. Retrieve the number of simple formats supported by libsndfile.
  521. </P>
  522. <P>
  523. Parameters:
  524. </P>
  525. <PRE>
  526. sndfile : Not used.
  527. cmd : SFC_GET_SIMPLE_FORMAT_COUNT
  528. data : a pointer to an int
  529. datasize : sizeof (int)
  530. </PRE>
  531. <P>
  532. Example:
  533. </P>
  534. <PRE>
  535. int count ;
  536. sf_command (sndfile, SFC_GET_SIMPLE_FORMAT_COUNT, &amp;count, sizeof (int)) ;
  537. </PRE>
  538. <DL>
  539. <DT>Return value: </DT>
  540. <DD>0
  541. </DL>
  542. <!-- ========================================================================= -->
  543. <A NAME="SFC_GET_SIMPLE_FORMAT"></A>
  544. <H2><BR><B>SFC_GET_SIMPLE_FORMAT</B></H2>
  545. <P>
  546. Retrieve information about a simple format.
  547. </P>
  548. <P>
  549. Parameters:
  550. </P>
  551. <PRE>
  552. sndfile : Not used.
  553. cmd : SFC_GET_SIMPLE_FORMAT
  554. data : a pointer to an SF_FORMAT_INFO struct
  555. datasize : sizeof (SF_FORMAT_INFO)
  556. </PRE>
  557. <P>
  558. The SF_FORMAT_INFO struct is defined in &lt;sndfile.h&gt; as:
  559. </P>
  560. <PRE>
  561. typedef struct
  562. { int format ;
  563. const char *name ;
  564. const char *extension ;
  565. } SF_FORMAT_INFO ;
  566. </PRE>
  567. <P>
  568. When sf_command() is called with SF_GET_SIMPLE_FORMAT, the value of the format
  569. field should be the format number (ie 0 <= format <= count value obtained using
  570. SF_GET_SIMPLE_FORMAT_COUNT).
  571. </P>
  572. <P>
  573. Example:
  574. </P>
  575. <PRE>
  576. SF_FORMAT_INFO format_info ;
  577. int k, count ;
  578. sf_command (sndfile, SFC_GET_SIMPLE_FORMAT_COUNT, &amp;count, sizeof (int)) ;
  579. for (k = 0 ; k < count ; k++)
  580. { format_info.format = k ;
  581. sf_command (sndfile, SFC_GET_SIMPLE_FORMAT, &amp;format_info, sizeof (format_info)) ;
  582. printf ("%08x %s %s\n", format_info.format, format_info.name, format_info.extension) ;
  583. } ;
  584. </PRE>
  585. <DL>
  586. <DT>Return value: </DT>
  587. <DD>0 on success and non-zero otherwise.
  588. <DD>The value of the format field of the SF_FORMAT_INFO struct will be an value which
  589. can be placed in the format field of an SF_INFO struct when a file is to be opened
  590. for write.
  591. <DD>The name field will contain a char* pointer to the name of the string ie "WAV (Microsoft 16 bit PCM)".
  592. <DD>The extention field will contain the most commonly used file extension for that file type.
  593. </DL>
  594. <!-- ========================================================================= -->
  595. <A NAME="SFC_GET_FORMAT_INFO"></A>
  596. <H2><BR><B>SFC_GET_FORMAT_INFO</B></H2>
  597. <P>
  598. Retrieve information about a major or subtype format.
  599. </P>
  600. <P>
  601. Parameters:
  602. </P>
  603. <PRE>
  604. sndfile : Not used.
  605. cmd : SFC_GET_FORMAT_INFO
  606. data : a pointer to an SF_FORMAT_INFO struct
  607. datasize : sizeof (SF_FORMAT_INFO)
  608. </PRE>
  609. <P>
  610. The SF_FORMAT_INFO struct is defined in &lt;sndfile.h&gt; as:
  611. </P>
  612. <PRE>
  613. typedef struct
  614. { int format ;
  615. const char *name ;
  616. const char *extension ;
  617. } SF_FORMAT_INFO ;
  618. </PRE>
  619. <P>
  620. When sf_command() is called with SF_GET_FORMAT_INFO, the format field is
  621. examined and if (format & SF_FORMAT_TYPEMASK) is a valid format then the struct
  622. is filled in with information about the given major type.
  623. If (format & SF_FORMAT_TYPEMASK) is FALSE and (format & SF_FORMAT_SUBMASK) is a
  624. valid subtype format then the struct is filled in with information about the given
  625. subtype.
  626. </P>
  627. <P>
  628. Example:
  629. </P>
  630. <PRE>
  631. SF_FORMAT_INFO format_info ;
  632. format_info.format = SF_FORMAT_WAV ;
  633. sf_command (sndfile, SFC_GET_FORMAT_INFO, &amp;format_info, sizeof (format_info)) ;
  634. printf ("%08x %s %s\n", format_info.format, format_info.name, format_info.extension) ;
  635. format_info.format = SF_FORMAT_ULAW ;
  636. sf_command (sndfile, SFC_GET_FORMAT_INFO, &amp;format_info, sizeof (format_info)) ;
  637. printf ("%08x %s\n", format_info.format, format_info.name) ;
  638. </PRE>
  639. <DL>
  640. <DT>Return value: </DT>
  641. <DD>0 on success and non-zero otherwise.
  642. </DL>
  643. <!-- ========================================================================= -->
  644. <A NAME="SFC_GET_FORMAT_MAJOR_COUNT"></A>
  645. <H2><BR><B>SFC_GET_FORMAT_MAJOR_COUNT</B></H2>
  646. <P>
  647. Retrieve the number of major formats.
  648. </P>
  649. <P>
  650. Parameters:
  651. </P>
  652. <PRE>
  653. sndfile : Not used.
  654. cmd : SFC_GET_FORMAT_MAJOR_COUNT
  655. data : a pointer to an int
  656. datasize : sizeof (int)
  657. </PRE>
  658. <P>
  659. Example:
  660. </P>
  661. <PRE>
  662. int count ;
  663. sf_command (sndfile, SFC_GET_FORMAT_MAJOR_COUNT, &amp;count, sizeof (int)) ;
  664. </PRE>
  665. <DL>
  666. <DT>Return value: </DT>
  667. <DD>0
  668. </DL>
  669. <!-- ========================================================================= -->
  670. <A NAME="SFC_GET_FORMAT_MAJOR"></A>
  671. <H2><BR><B>SFC_GET_FORMAT_MAJOR</B></H2>
  672. <P>
  673. Retrieve information about a major format type.
  674. </P>
  675. <P>
  676. Parameters:
  677. </P>
  678. <PRE>
  679. sndfile : Not used.
  680. cmd : SFC_GET_FORMAT_MAJOR
  681. data : a pointer to an SF_FORMAT_INFO struct
  682. datasize : sizeof (SF_FORMAT_INFO)
  683. </PRE>
  684. <P>
  685. Example:
  686. </P>
  687. <PRE>
  688. SF_FORMAT_INFO format_info ;
  689. int k, count ;
  690. sf_command (sndfile, SFC_GET_FORMAT_MAJOR_COUNT, &amp;count, sizeof (int)) ;
  691. for (k = 0 ; k < count ; k++)
  692. { format_info.format = k ;
  693. sf_command (sndfile, SFC_GET_FORMAT_MAJOR, &amp;format_info, sizeof (format_info)) ;
  694. printf ("%08x %s %s\n", format_info.format, format_info.name, format_info.extension) ;
  695. } ;
  696. </PRE>
  697. <P>
  698. For a more comprehensive example, see the program list_formats.c in the examples/
  699. directory of the libsndfile source code distribution.
  700. </P>
  701. <DL>
  702. <DT>Return value: </DT>
  703. <DD>0 on success and non-zero otherwise.
  704. <DD>The value of the format field will one of the major format identifiers suc as SF_FORMAT_WAV
  705. SF_FORMAT_AIFF.
  706. <DD>The name field will contain a char* pointer to the name of the string ie "WAV (Microsoft)".
  707. <DD>The extention field will contain the most commonly used file extension for that file type.
  708. </DL>
  709. <!-- ========================================================================= -->
  710. <A NAME="SFC_GET_FORMAT_SUBTYPE_COUNT"></A>
  711. <H2><BR><B>SFC_GET_FORMAT_SUBTYPE_COUNT</B></H2>
  712. <P>
  713. Retrieve the number of subformats.
  714. </P>
  715. <P>
  716. Parameters:
  717. </P>
  718. <PRE>
  719. sndfile : Not used.
  720. cmd : SFC_GET_FORMAT_SUBTYPE_COUNT
  721. data : a pointer to an int
  722. datasize : sizeof (int)
  723. </PRE>
  724. <P>
  725. Example:
  726. </P>
  727. <PRE>
  728. int count ;
  729. sf_command (sndfile, SFC_GET_FORMAT_SUBTYPE_COUNT, &amp;count, sizeof (int)) ;
  730. </PRE>
  731. <DL>
  732. <DT>Return value: </DT>
  733. <DD>0
  734. </DL>
  735. <!-- ========================================================================= -->
  736. <A NAME="SFC_GET_FORMAT_SUBTYPE"></A>
  737. <H2><BR><B>SFC_GET_FORMAT_SUBTYPE</B></H2>
  738. <P>
  739. Retrieve information about a subformat.
  740. </P>
  741. <P>
  742. Parameters:
  743. </P>
  744. <PRE>
  745. sndfile : Not used.
  746. cmd : SFC_GET_FORMAT_SUBTYPE
  747. data : a pointer to an SF_FORMAT_INFO struct
  748. datasize : sizeof (SF_FORMAT_INFO)
  749. </PRE>
  750. <P>
  751. Example:
  752. </P>
  753. <PRE>
  754. SF_FORMAT_INFO format_info ;
  755. int k, count ;
  756. sf_command (sndfile, SFC_GET_FORMAT_SUBTYPE_COUNT, &amp;count, sizeof (int)) ;
  757. /* Retrieve all the subtypes supported by the WAV format. */
  758. for (k = 0 ; k < count ; k++)
  759. { format_info.format = k ;
  760. sf_command (sndfile, SFC_GET_FORMAT_SUBTYPE, &amp;format_info, sizeof (format_info)) ;
  761. if (! sf_format_check (format.info | SF_FORMAT_WAV))
  762. continue ;
  763. printf ("%08x %s\n", format_info.format, format_info.name) ;
  764. } ;
  765. </PRE>
  766. <P>
  767. For a more comprehensive example, see the program list_formats.c in the examples/
  768. directory of the libsndfile source code distribution.
  769. </P>
  770. <DL>
  771. <DT>Return value: </DT>
  772. <DD>0 on success and non-zero otherwise.
  773. <DD>The value of the format field will one of the major format identifiers such as SF_FORMAT_WAV
  774. SF_FORMAT_AIFF.
  775. <DD>The name field will contain a char* pointer to the name of the string; for instance
  776. "WAV (Microsoft)" or "AIFF (Apple/SGI)".
  777. <DD>The extention field will be a NULL pointer.
  778. </DL>
  779. <!-- ========================================================================= -->
  780. <A NAME="SFC_SET_ADD_PEAK_CHUNK"></A>
  781. <H2><BR><B>SFC_SET_ADD_PEAK_CHUNK</B></H2>
  782. <P>
  783. By default, WAV and AIFF files which contain floating point data (subtype SF_FORMAT_FLOAT
  784. or SF_FORMAT_DOUBLE) have a PEAK chunk.
  785. By using this command, the addition of a PEAK chunk can be turned on or off.
  786. </P>
  787. <P>
  788. Note : This call must be made before any data is written to the file.
  789. </P>
  790. <P>
  791. Parameters:
  792. <PRE>
  793. sndfile : A valid SNDFILE* pointer
  794. cmd : SFC_SET_ADD_PEAK_CHUNK
  795. data : Not used (should be NULL)
  796. datasize : TRUE or FALSE.
  797. </PRE>
  798. <P>
  799. Example:
  800. </P>
  801. <PRE>
  802. /* Turn on the PEAK chunk. */
  803. sf_command (sndfile, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_TRUE) ;
  804. /* Turn off the PEAK chunk. */
  805. sf_command (sndfile, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_FALSE) ;
  806. </PRE>
  807. <DL>
  808. <DT>Return value:</DT>
  809. <DD>Returns SF_TRUE if the peak chunk will be written after this call.
  810. <DD>Returns SF_FALSE if the peak chunk will not be written after this call.
  811. </DL>
  812. <!-- ========================================================================= -->
  813. <A NAME="SFC_UPDATE_HEADER_NOW"></A>
  814. <H2><BR><B>SFC_UPDATE_HEADER_NOW</B></H2>
  815. <P>
  816. The header of an audio file is normally written by libsndfile when the file is
  817. closed using <B>sf_close()</B>.
  818. </P>
  819. <P>
  820. There are however situations where large files are being generated and it would
  821. be nice to have valid data in the header before the file is complete.
  822. Using this command will update the file header to reflect the amount of data written
  823. to the file so far.
  824. Other programs opening the file for read (before any more data is written) will
  825. then read a valid sound file header.
  826. </P>
  827. <P>
  828. Parameters:
  829. <PRE>
  830. sndfile : A valid SNDFILE* pointer
  831. cmd : SFC_UPDATE_HEADER_NOW
  832. data : Not used (should be NULL)
  833. datasize : Not used.
  834. </PRE>
  835. <P>
  836. Example:
  837. </P>
  838. <PRE>
  839. /* Update the header now. */
  840. sf_command (sndfile, SFC_UPDATE_HEADER_NOW, NULL, 0) ;
  841. </PRE>
  842. <DL>
  843. <DT>Return value:</DT>
  844. <DD>0
  845. </DL>
  846. <!-- ========================================================================= -->
  847. <A NAME="SFC_SET_UPDATE_HEADER_AUTO"></A>
  848. <H2><BR><B>SFC_SET_UPDATE_HEADER_AUTO</B></H2>
  849. <P>
  850. Similar to SFC_UPDATE_HEADER_NOW but updates the header at the end of every call
  851. to the <B>sf_write*</B> functions.
  852. </P>
  853. <P>
  854. Parameters:
  855. <PRE>
  856. sndfile : A valid SNDFILE* pointer
  857. cmd : SFC_UPDATE_HEADER_NOW
  858. data : Not used (should be NULL)
  859. datasize : SF_TRUE or SF_FALSE
  860. </PRE>
  861. <P>
  862. Example:
  863. </P>
  864. <PRE>
  865. /* Turn on auto header update. */
  866. sf_command (sndfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) ;
  867. /* Turn off auto header update. */
  868. sf_command (sndfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_FALSE) ;
  869. </PRE>
  870. <DL>
  871. <DT>Return value:</DT>
  872. <DD>TRUE if auto update header is now on; FALSE otherwise.
  873. </DL>
  874. <!-- ========================================================================= -->
  875. <A NAME="SFC_FILE_TRUNCATE"></A>
  876. <H2><BR><B>SFC_FILE_TRUNCATE</B></H2>
  877. <P>
  878. Truncate a file open for write or for read/write.
  879. </P>
  880. <P>
  881. Parameters:
  882. <PRE>
  883. sndfile : A valid SNDFILE* pointer
  884. cmd : SFC_FILE_TRUNCATE
  885. data : A pointer to an sf_count_t.
  886. datasize : sizeof (sf_count_t)
  887. </PRE>
  888. <P>
  889. Truncate the file to the number of frames specified by the sf_count_t pointed
  890. to by data.
  891. After this command, both the read and the write pointer will be
  892. at the new end of the file.
  893. This command will fail (returning non-zero) if the requested truncate position
  894. is beyond the end of the file.
  895. </P>
  896. <P>
  897. Example:
  898. </P>
  899. <PRE>
  900. /* Truncate the file to a length of 20 frames. */
  901. sf_count_t frames = 20 ;
  902. sf_command (sndfile, SFC_FILE_TRUNCATE, &amp;frames, sizeof (frames)) ;
  903. </PRE>
  904. <DL>
  905. <DT>Return value:</DT>
  906. <DD>Zero on sucess, non-zero otherwise.
  907. </DL>
  908. <!-- ========================================================================= -->
  909. <A NAME="SFC_SET_RAW_START_OFFSET"></A>
  910. <H2><BR><B>SFC_SET_RAW_START_OFFSET</B></H2>
  911. <P>
  912. Change the data start offset for files opened up as SF_FORMAT_RAW.
  913. </P>
  914. <P>
  915. Parameters:
  916. <PRE>
  917. sndfile : A valid SNDFILE* pointer
  918. cmd : SFC_SET_RAW_START_OFFSET
  919. data : A pointer to an sf_count_t.
  920. datasize : sizeof (sf_count_t)
  921. </PRE>
  922. <P>
  923. For a file opened as format SF_FORMAT_RAW, set the data offset to the value
  924. given by data.
  925. </P>
  926. <P>
  927. Example:
  928. </P>
  929. <PRE>
  930. /* Reset the data offset to 5 bytes from the start of the file. */
  931. sf_count_t offset = 5 ;
  932. sf_command (sndfile, SFC_SET_RAW_START_OFFSET, &amp;offset, sizeof (offset)) ;
  933. </PRE>
  934. <DL>
  935. <DT>Return value:</DT>
  936. <DD>Zero on sucess, non-zero otherwise.
  937. </DL>
  938. <!-- ========================================================================= -->
  939. <HR>
  940. <P>
  941. The libsndfile home page is here :
  942. <A HREF="http://www.mega-nerd.com/libsndfile/">
  943. http://www.mega-nerd.com/libsndfile/</A>.
  944. <BR>
  945. Version : 1.0.25
  946. </P>
  947. </BODY>
  948. </HTML>