header_test.tpl 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. [+ AutoGen5 template c +]
  2. /*
  3. ** Copyright (C) 2001-2017 Erik de Castro Lopo <[email protected]>
  4. **
  5. ** This program is free software ; you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation ; either version 2 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY ; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program ; if not, write to the Free Software
  17. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. #include "sfconfig.h"
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <inttypes.h>
  24. #include <math.h>
  25. #include <sys/stat.h>
  26. #if HAVE_UNISTD_H
  27. #include <unistd.h>
  28. #endif
  29. #if (HAVE_DECL_S_IRGRP == 0)
  30. #include <sf_unistd.h>
  31. #endif
  32. #if (defined (WIN32) || defined (_WIN32))
  33. #include <io.h>
  34. #include <direct.h>
  35. #endif
  36. #include <sndfile.h>
  37. #include "utils.h"
  38. #define BUFFER_LEN (1 << 10)
  39. #define LOG_BUFFER_SIZE 1024
  40. static void update_header_test (const char *filename, int typemajor) ;
  41. static void update_header_before_write_test (const char *filename, int typemajor) ;
  42. [+ FOR data_type
  43. +]static void update_seek_[+ (get "name") +]_test (const char *filename, int filetype) ;
  44. [+ ENDFOR data_type
  45. +]
  46. static void extra_header_test (const char *filename, int filetype) ;
  47. static void header_shrink_test (const char *filename, int filetype) ;
  48. /* Force the start of this buffer to be double aligned. Sparc-solaris will
  49. ** choke if its not.
  50. */
  51. static int data_out [BUFFER_LEN] ;
  52. static int data_in [BUFFER_LEN] ;
  53. int
  54. main (int argc, char *argv [])
  55. { int do_all = 0 ;
  56. int test_count = 0 ;
  57. if (argc != 2)
  58. { printf ("Usage : %s <test>\n", argv [0]) ;
  59. printf (" Where <test> is one of the following:\n") ;
  60. printf (" wav - test WAV file peak chunk\n") ;
  61. printf (" aiff - test AIFF file PEAK chunk\n") ;
  62. printf (" all - perform all tests\n") ;
  63. exit (1) ;
  64. } ;
  65. do_all= !strcmp (argv [1], "all") ;
  66. if (do_all || ! strcmp (argv [1], "wav"))
  67. { update_header_test ("header.wav", SF_FORMAT_WAV) ;
  68. update_seek_short_test ("header_short.wav", SF_FORMAT_WAV) ;
  69. update_seek_int_test ("header_int.wav", SF_FORMAT_WAV) ;
  70. update_seek_float_test ("header_float.wav", SF_FORMAT_WAV) ;
  71. update_seek_double_test ("header_double.wav", SF_FORMAT_WAV) ;
  72. header_shrink_test ("header_shrink.wav", SF_FORMAT_WAV) ;
  73. extra_header_test ("extra.wav", SF_FORMAT_WAV) ;
  74. update_header_test ("header.wavex", SF_FORMAT_WAVEX) ;
  75. update_seek_short_test ("header_short.wavex", SF_FORMAT_WAVEX) ;
  76. update_seek_int_test ("header_int.wavex", SF_FORMAT_WAVEX) ;
  77. update_seek_float_test ("header_float.wavex", SF_FORMAT_WAVEX) ;
  78. update_seek_double_test ("header_double.wavex", SF_FORMAT_WAVEX) ;
  79. header_shrink_test ("header_shrink.wavex", SF_FORMAT_WAVEX) ;
  80. extra_header_test ("extra.wavex", SF_FORMAT_WAVEX) ;
  81. test_count++ ;
  82. } ;
  83. if (do_all || ! strcmp (argv [1], "aiff"))
  84. { update_header_test ("header.aiff", SF_FORMAT_AIFF) ;
  85. update_seek_short_test ("header_short.aiff", SF_FORMAT_AIFF) ;
  86. update_seek_int_test ("header_int.aiff", SF_FORMAT_AIFF) ;
  87. update_seek_float_test ("header_float.aiff", SF_FORMAT_AIFF) ;
  88. update_seek_double_test ("header_double.aiff", SF_FORMAT_AIFF) ;
  89. header_shrink_test ("header_shrink.aiff", SF_FORMAT_AIFF) ;
  90. extra_header_test ("extra.aiff", SF_FORMAT_AIFF) ;
  91. test_count++ ;
  92. } ;
  93. if (do_all || ! strcmp (argv [1], "au"))
  94. { update_header_test ("header.au", SF_FORMAT_AU) ;
  95. update_seek_short_test ("header_short.au", SF_FORMAT_AU) ;
  96. update_seek_int_test ("header_int.au", SF_FORMAT_AU) ;
  97. update_seek_float_test ("header_float.au", SF_FORMAT_AU) ;
  98. update_seek_double_test ("header_double.au", SF_FORMAT_AU) ;
  99. test_count++ ;
  100. } ;
  101. if (do_all || ! strcmp (argv [1], "caf"))
  102. { update_header_test ("header.caf", SF_FORMAT_CAF) ;
  103. update_seek_short_test ("header_short.caf", SF_FORMAT_CAF) ;
  104. update_seek_int_test ("header_int.caf", SF_FORMAT_CAF) ;
  105. update_seek_float_test ("header_float.caf", SF_FORMAT_CAF) ;
  106. update_seek_double_test ("header_double.caf", SF_FORMAT_CAF) ;
  107. /* extra_header_test ("extra.caf", SF_FORMAT_CAF) ; */
  108. test_count++ ;
  109. } ;
  110. if (do_all || ! strcmp (argv [1], "nist"))
  111. { update_header_test ("header.nist", SF_FORMAT_NIST) ;
  112. update_seek_short_test ("header_short.nist", SF_FORMAT_NIST) ;
  113. update_seek_int_test ("header_int.nist", SF_FORMAT_NIST) ;
  114. test_count++ ;
  115. } ;
  116. if (do_all || ! strcmp (argv [1], "paf"))
  117. { update_header_test ("header.paf", SF_FORMAT_PAF) ;
  118. update_seek_short_test ("header_short.paf", SF_FORMAT_PAF) ;
  119. test_count++ ;
  120. } ;
  121. if (do_all || ! strcmp (argv [1], "ircam"))
  122. { update_header_test ("header.ircam", SF_FORMAT_IRCAM) ;
  123. update_seek_short_test ("header_short.ircam", SF_FORMAT_IRCAM) ;
  124. test_count++ ;
  125. } ;
  126. if (do_all || ! strcmp (argv [1], "w64"))
  127. { update_header_test ("header.w64", SF_FORMAT_W64) ;
  128. update_seek_short_test ("header_short.w64", SF_FORMAT_W64) ;
  129. update_seek_int_test ("header_int.w64", SF_FORMAT_W64) ;
  130. update_seek_float_test ("header_float.w64", SF_FORMAT_W64) ;
  131. update_seek_double_test ("header_double.w64", SF_FORMAT_W64) ;
  132. test_count++ ;
  133. } ;
  134. if (do_all || ! strcmp (argv [1], "rf64"))
  135. { update_header_test ("header.rf64", SF_FORMAT_RF64) ;
  136. update_seek_short_test ("header_short.rf64", SF_FORMAT_RF64) ;
  137. update_seek_int_test ("header_int.rf64", SF_FORMAT_RF64) ;
  138. update_seek_float_test ("header_float.rf64", SF_FORMAT_RF64) ;
  139. update_seek_double_test ("header_double.rf64", SF_FORMAT_RF64) ;
  140. test_count++ ;
  141. } ;
  142. if (do_all || ! strcmp (argv [1], "mat4"))
  143. { update_header_test ("header.mat4", SF_FORMAT_MAT4) ;
  144. update_seek_short_test ("header_short.mat4", SF_FORMAT_MAT4) ;
  145. update_seek_int_test ("header_int.mat4", SF_FORMAT_MAT4) ;
  146. update_seek_float_test ("header_float.mat4", SF_FORMAT_MAT4) ;
  147. update_seek_double_test ("header_double.mat4", SF_FORMAT_MAT4) ;
  148. test_count++ ;
  149. } ;
  150. if (do_all || ! strcmp (argv [1], "mat5"))
  151. { update_header_test ("header.mat5", SF_FORMAT_MAT5) ;
  152. update_seek_short_test ("header_short.mat5", SF_FORMAT_MAT5) ;
  153. update_seek_int_test ("header_int.mat5", SF_FORMAT_MAT5) ;
  154. update_seek_float_test ("header_float.mat5", SF_FORMAT_MAT5) ;
  155. update_seek_double_test ("header_double.mat5", SF_FORMAT_MAT5) ;
  156. test_count++ ;
  157. } ;
  158. if (do_all || ! strcmp (argv [1], "pvf"))
  159. { update_header_test ("header.pvf", SF_FORMAT_PVF) ;
  160. update_seek_short_test ("header_short.pvf", SF_FORMAT_PVF) ;
  161. test_count++ ;
  162. } ;
  163. if (do_all || ! strcmp (argv [1], "avr"))
  164. { update_header_test ("header.avr", SF_FORMAT_AVR) ;
  165. update_seek_short_test ("header_short.avr", SF_FORMAT_AVR) ;
  166. test_count++ ;
  167. } ;
  168. if (do_all || ! strcmp (argv [1], "htk"))
  169. { update_header_test ("header.htk", SF_FORMAT_HTK) ;
  170. update_seek_short_test ("header_short.htk", SF_FORMAT_HTK) ;
  171. test_count++ ;
  172. } ;
  173. if (do_all || ! strcmp (argv [1], "svx"))
  174. { update_header_test ("header.svx", SF_FORMAT_SVX) ;
  175. update_seek_short_test ("header_short.svx", SF_FORMAT_SVX) ;
  176. test_count++ ;
  177. } ;
  178. if (do_all || ! strcmp (argv [1], "voc"))
  179. { update_header_test ("header.voc", SF_FORMAT_VOC) ;
  180. /*-update_seek_short_test ("header_short.voc", SF_FORMAT_VOC) ;-*/
  181. test_count++ ;
  182. } ;
  183. if (do_all || ! strcmp (argv [1], "sds"))
  184. { update_header_test ("header.sds", SF_FORMAT_SDS) ;
  185. /*-update_seek_short_test ("header_short.sds", SF_FORMAT_SDS) ;-*/
  186. test_count++ ;
  187. } ;
  188. if (do_all || ! strcmp (argv [1], "mpc2k"))
  189. { update_header_test ("header.mpc", SF_FORMAT_MPC2K) ;
  190. update_seek_short_test ("header_short.mpc", SF_FORMAT_MPC2K) ;
  191. test_count++ ;
  192. } ;
  193. if (do_all || ! strcmp (argv [1], "flac"))
  194. { if (HAVE_EXTERNAL_XIPH_LIBS)
  195. update_header_before_write_test ("header.flac", SF_FORMAT_FLAC) ;
  196. else
  197. puts (" No FLAC tests because FLAC support was not compiled in.") ;
  198. test_count++ ;
  199. } ;
  200. if (test_count == 0)
  201. { printf ("Mono : ************************************\n") ;
  202. printf ("Mono : * No '%s' test defined.\n", argv [1]) ;
  203. printf ("Mono : ************************************\n") ;
  204. return 1 ;
  205. } ;
  206. return 0 ;
  207. } /* main */
  208. /*============================================================================================
  209. ** Here are the test functions.
  210. */
  211. static void
  212. update_header_sub (const char *filename, int typemajor, int write_mode)
  213. { SNDFILE *outfile, *infile ;
  214. SF_INFO sfinfo ;
  215. int k ;
  216. memset (&sfinfo, 0, sizeof (sfinfo)) ;
  217. sfinfo.samplerate = 44100 ;
  218. sfinfo.format = (typemajor | SF_FORMAT_PCM_16) ;
  219. sfinfo.channels = 1 ;
  220. outfile = test_open_file_or_die (filename, write_mode, &sfinfo, SF_TRUE, __LINE__) ;
  221. for (k = 0 ; k < BUFFER_LEN ; k++)
  222. data_out [k] = k + 1 ;
  223. test_write_int_or_die (outfile, 0, data_out, BUFFER_LEN, __LINE__) ;
  224. if (typemajor != SF_FORMAT_HTK)
  225. { /* The HTK header is not correct when the file is first written. */
  226. infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  227. sf_close (infile) ;
  228. } ;
  229. sf_command (outfile, SFC_UPDATE_HEADER_NOW, NULL, 0) ;
  230. /*
  231. ** Open file and check log buffer for an error. If header update failed
  232. ** the the log buffer will contain errors.
  233. */
  234. infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  235. check_log_buffer_or_die (infile, __LINE__) ;
  236. if (sfinfo.frames < BUFFER_LEN || sfinfo.frames > BUFFER_LEN + 50)
  237. { printf ("\n\nLine %d : Incorrect sample count (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, BUFFER_LEN) ;
  238. dump_log_buffer (infile) ;
  239. exit (1) ;
  240. } ;
  241. test_read_int_or_die (infile, 0, data_in, BUFFER_LEN, __LINE__) ;
  242. for (k = 0 ; k < BUFFER_LEN ; k++)
  243. if (data_out [k] != k + 1)
  244. printf ("Error : line %d\n", __LINE__) ;
  245. sf_close (infile) ;
  246. /* Set auto update on. */
  247. sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) ;
  248. /* Write more data_out. */
  249. for (k = 0 ; k < BUFFER_LEN ; k++)
  250. data_out [k] = k + 2 ;
  251. test_write_int_or_die (outfile, 0, data_out, BUFFER_LEN, __LINE__) ;
  252. /* Open file again and make sure no errors in log buffer. */
  253. infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  254. check_log_buffer_or_die (infile, __LINE__) ;
  255. if (sfinfo.frames < 2 * BUFFER_LEN || sfinfo.frames > 2 * BUFFER_LEN + 50)
  256. { printf ("\n\nLine %d : Incorrect sample count (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, 2 * BUFFER_LEN) ;
  257. dump_log_buffer (infile) ;
  258. exit (1) ;
  259. } ;
  260. sf_close (infile) ;
  261. sf_close (outfile) ;
  262. unlink (filename) ;
  263. } /* update_header_sub */
  264. static void
  265. update_header_test (const char *filename, int typemajor)
  266. {
  267. print_test_name ("update_header_test", filename) ;
  268. update_header_sub (filename, typemajor, SFM_WRITE) ;
  269. update_header_sub (filename, typemajor, SFM_RDWR) ;
  270. unlink (filename) ;
  271. puts ("ok") ;
  272. } /* update_header_test */
  273. static void
  274. update_header_before_write_test (const char *filename, int typemajor)
  275. {
  276. SNDFILE *outfile ;
  277. SF_INFO sfinfo ;
  278. int k ;
  279. print_test_name ("update_header_before_write", filename) ;
  280. memset (&sfinfo, 0, sizeof (sfinfo)) ;
  281. sfinfo.samplerate = 44100 ;
  282. sfinfo.format = (typemajor | SF_FORMAT_PCM_16) ;
  283. sfinfo.channels = 1 ;
  284. outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
  285. /* FLAC can only write the header once; if the first call to sf_write() will
  286. ** also attempt to write the header, it fails. FLAC-specific regression
  287. */
  288. sf_command (outfile, SFC_UPDATE_HEADER_NOW, NULL, 0) ;
  289. for (k = 0 ; k < BUFFER_LEN ; k++)
  290. data_out [k] = k + 1 ;
  291. test_write_int_or_die (outfile, 0, data_out, BUFFER_LEN, __LINE__) ;
  292. sf_close (outfile) ;
  293. unlink (filename) ;
  294. puts ("ok") ;
  295. } /* update_header_before_write_test */
  296. /*==============================================================================
  297. */
  298. [+ FOR data_type
  299. +]static void
  300. update_seek_[+ (get "name") +]_test (const char *filename, int filetype)
  301. { SNDFILE *outfile, *infile ;
  302. SF_INFO sfinfo ;
  303. sf_count_t frames ;
  304. [+ (get "name") +] buffer [8] ;
  305. int k ;
  306. print_test_name ("update_seek_[+ (get "name") +]_test", filename) ;
  307. memset (buffer, 0, sizeof (buffer)) ;
  308. /* Create sound outfile with no data. */
  309. memset (&sfinfo, 0, sizeof (sfinfo)) ;
  310. sfinfo.format = filetype | [+ (get "format") +] ;
  311. sfinfo.samplerate = 48000 ;
  312. sfinfo.channels = 2 ;
  313. if (sf_format_check (&sfinfo) == SF_FALSE)
  314. sfinfo.channels = 1 ;
  315. outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
  316. sf_close (outfile) ;
  317. /* Open again for read/write. */
  318. outfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ;
  319. /*
  320. ** In auto header update mode, seeking to the end of the file with
  321. ** SEEK_SET will fail from the 2nd seek on. seeking to 0, SEEK_END
  322. ** will seek to 0 anyway
  323. */
  324. if (sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) == 0)
  325. { printf ("\n\nError : sf_command (SFC_SET_UPDATE_HEADER_AUTO) return error : %s\n\n", sf_strerror (outfile)) ;
  326. exit (1) ;
  327. } ;
  328. /* Now write some frames. */
  329. frames = ARRAY_LEN (buffer) / sfinfo.channels ;
  330. for (k = 0 ; k < 6 ; k++)
  331. { test_seek_or_die (outfile, k * frames, SEEK_SET, k * frames, sfinfo.channels, __LINE__) ;
  332. test_seek_or_die (outfile, 0, SEEK_END, k * frames, sfinfo.channels, __LINE__) ;
  333. /* Open file again and make sure no errors in log buffer. */
  334. infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  335. check_log_buffer_or_die (infile, __LINE__) ;
  336. sf_close (infile) ;
  337. if (sfinfo.frames != k * frames)
  338. { printf ("\n\nLine %d : Incorrect sample count (%" PRId64 " should be %" PRId64 ")\n", __LINE__, sfinfo.frames, k + frames) ;
  339. dump_log_buffer (infile) ;
  340. exit (1) ;
  341. } ;
  342. if ((k & 1) == 0)
  343. test_write_[+ (get "name") +]_or_die (outfile, k, buffer, sfinfo.channels * frames, __LINE__) ;
  344. else
  345. test_writef_[+ (get "name") +]_or_die (outfile, k, buffer, frames, __LINE__) ;
  346. } ;
  347. sf_close (outfile) ;
  348. unlink (filename) ;
  349. puts ("ok") ;
  350. return ;
  351. } /* update_seek_[+ (get "name") +]_test */
  352. [+ ENDFOR data_type
  353. +]
  354. static void
  355. header_shrink_test (const char *filename, int filetype)
  356. { SNDFILE *outfile, *infile ;
  357. SF_INFO sfinfo ;
  358. sf_count_t frames ;
  359. float buffer [8], bufferin [8] ;
  360. print_test_name ("header_shrink_test", filename) ;
  361. memset (&sfinfo, 0, sizeof (sfinfo)) ;
  362. sfinfo.samplerate = 44100 ;
  363. sfinfo.format = filetype | SF_FORMAT_FLOAT ;
  364. sfinfo.channels = 1 ;
  365. memset (buffer, 0xA0, sizeof (buffer)) ;
  366. /* Now write some frames. */
  367. frames = ARRAY_LEN (buffer) / sfinfo.channels ;
  368. /* Test the file with extra header data. */
  369. outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
  370. sf_command (outfile, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_TRUE) ;
  371. sf_command (outfile, SFC_UPDATE_HEADER_NOW, NULL, SF_FALSE) ;
  372. sf_command (outfile, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_FALSE) ;
  373. test_writef_float_or_die (outfile, 0, buffer, frames, __LINE__) ;
  374. sf_close (outfile) ;
  375. /* Open again for read. */
  376. infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
  377. test_readf_float_or_die (infile, 0, bufferin, frames, __LINE__) ;
  378. sf_close (infile) ;
  379. compare_float_or_die (buffer, bufferin, frames, __LINE__) ;
  380. unlink (filename) ;
  381. puts ("ok") ;
  382. return ;
  383. } /* header_shrink_test */
  384. static void
  385. extra_header_test (const char *filename, int filetype)
  386. { SNDFILE *outfile, *infile ;
  387. SF_INFO sfinfo ;
  388. sf_count_t frames ;
  389. short buffer [8] ;
  390. int k = 0 ;
  391. print_test_name ("extra_header_test", filename) ;
  392. memset (&sfinfo, 0, sizeof (sfinfo)) ;
  393. sfinfo.samplerate = 44100 ;
  394. sfinfo.format = (filetype | SF_FORMAT_PCM_16) ;
  395. sfinfo.channels = 1 ;
  396. memset (buffer, 0xA0, sizeof (buffer)) ;
  397. /* Now write some frames. */
  398. frames = ARRAY_LEN (buffer) / sfinfo.channels ;
  399. /* Test the file with extra header data. */
  400. outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, [+ (tpl-file-line "%2$d") +]) ;
  401. sf_set_string (outfile, SF_STR_TITLE, filename) ;
  402. test_writef_short_or_die (outfile, k, buffer, frames, [+ (tpl-file-line "%2$d") +]) ;
  403. sf_set_string (outfile, SF_STR_COPYRIGHT, "(c) 1980 Erik") ;
  404. sf_close (outfile) ;
  405. #if 1
  406. /*
  407. ** Erik de Castro Lopo <[email protected]> May 23 2004.
  408. **
  409. ** This file has extra string data in the header and therefore cannot
  410. ** currently be opened in SFM_RDWR mode. This is fixable, but its in
  411. ** a part of the code I don't want to fiddle with until the Ogg/Vorbis
  412. ** integration is done.
  413. */
  414. if ((infile = sf_open (filename, SFM_RDWR, &sfinfo)) != NULL)
  415. { printf ("\n\nError : should not be able to open this file in SFM_RDWR.\n\n") ;
  416. exit (1) ;
  417. } ;
  418. unlink (filename) ;
  419. puts ("ok") ;
  420. return ;
  421. #else
  422. hexdump_file (filename, 0, 100000) ;
  423. /* Open again for read/write. */
  424. outfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, [+ (tpl-file-line "%2$d") +]) ;
  425. /*
  426. ** In auto header update mode, seeking to the end of the file with
  427. ** SEEK_SET will fail from the 2nd seek on. seeking to 0, SEEK_END
  428. ** will seek to 0 anyway
  429. */
  430. if (sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) == 0)
  431. { printf ("\n\nError : sf_command (SFC_SET_UPDATE_HEADER_AUTO) return error : %s\n\n", sf_strerror (outfile)) ;
  432. exit (1) ;
  433. } ;
  434. /* Now write some frames. */
  435. frames = ARRAY_LEN (buffer) / sfinfo.channels ;
  436. for (k = 1 ; k < 6 ; k++)
  437. {
  438. printf ("\n*** pass %d\n", k) ;
  439. memset (buffer, 0xA0 + k, sizeof (buffer)) ;
  440. test_seek_or_die (outfile, k * frames, SEEK_SET, k * frames, sfinfo.channels, [+ (tpl-file-line "%2$d") +]) ;
  441. test_seek_or_die (outfile, 0, SEEK_END, k * frames, sfinfo.channels, [+ (tpl-file-line "%2$d") +]) ;
  442. /* Open file again and make sure no errors in log buffer. */
  443. if (0)
  444. { infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, [+ (tpl-file-line "%2$d") +]) ;
  445. check_log_buffer_or_die (infile, [+ (tpl-file-line "%2$d") +]) ;
  446. sf_close (infile) ;
  447. } ;
  448. if (sfinfo.frames != k * frames)
  449. { printf ("\n\nLine %d : Incorrect sample count (%" PRId64 " should be %" PRId64 ")\n", [+ (tpl-file-line "%2$d") +], sfinfo.frames, k + frames) ;
  450. dump_log_buffer (infile) ;
  451. exit (1) ;
  452. } ;
  453. if ((k & 1) == 0)
  454. test_write_short_or_die (outfile, k, buffer, sfinfo.channels * frames, [+ (tpl-file-line "%2$d") +]) ;
  455. else
  456. test_writef_short_or_die (outfile, k, buffer, frames, [+ (tpl-file-line "%2$d") +]) ;
  457. hexdump_file (filename, 0, 100000) ;
  458. } ;
  459. sf_close (outfile) ;
  460. unlink (filename) ;
  461. puts ("ok") ;
  462. return ;
  463. #endif
  464. } /* extra_header_test */