header_test.tpl 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. [+ AutoGen5 template c +]
  2. /*
  3. ** Copyright (C) 2001-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
  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. [+ FOR data_type
  42. +]static void update_seek_[+ (get "name") +]_test (const char *filename, int filetype) ;
  43. [+ ENDFOR data_type
  44. +]
  45. static void extra_header_test (const char *filename, int filetype) ;
  46. static void header_shrink_test (const char *filename, int filetype) ;
  47. /* Force the start of this buffer to be double aligned. Sparc-solaris will
  48. ** choke if its not.
  49. */
  50. static int data_out [BUFFER_LEN] ;
  51. static int data_in [BUFFER_LEN] ;
  52. int
  53. main (int argc, char *argv [])
  54. { int do_all = 0 ;
  55. int test_count = 0 ;
  56. if (argc != 2)
  57. { printf ("Usage : %s <test>\n", argv [0]) ;
  58. printf (" Where <test> is one of the following:\n") ;
  59. printf (" wav - test WAV file peak chunk\n") ;
  60. printf (" aiff - test AIFF file PEAK chunk\n") ;
  61. printf (" all - perform all tests\n") ;
  62. exit (1) ;
  63. } ;
  64. do_all= !strcmp (argv [1], "all") ;
  65. if (do_all || ! strcmp (argv [1], "wav"))
  66. { update_header_test ("header.wav", SF_FORMAT_WAV) ;
  67. update_seek_short_test ("header_short.wav", SF_FORMAT_WAV) ;
  68. update_seek_int_test ("header_int.wav", SF_FORMAT_WAV) ;
  69. update_seek_float_test ("header_float.wav", SF_FORMAT_WAV) ;
  70. update_seek_double_test ("header_double.wav", SF_FORMAT_WAV) ;
  71. header_shrink_test ("header_shrink.wav", SF_FORMAT_WAV) ;
  72. extra_header_test ("extra.wav", SF_FORMAT_WAV) ;
  73. update_header_test ("header.wavex", SF_FORMAT_WAVEX) ;
  74. update_seek_short_test ("header_short.wavex", SF_FORMAT_WAVEX) ;
  75. update_seek_int_test ("header_int.wavex", SF_FORMAT_WAVEX) ;
  76. update_seek_float_test ("header_float.wavex", SF_FORMAT_WAVEX) ;
  77. update_seek_double_test ("header_double.wavex", SF_FORMAT_WAVEX) ;
  78. header_shrink_test ("header_shrink.wavex", SF_FORMAT_WAVEX) ;
  79. extra_header_test ("extra.wavex", SF_FORMAT_WAVEX) ;
  80. test_count++ ;
  81. } ;
  82. if (do_all || ! strcmp (argv [1], "aiff"))
  83. { update_header_test ("header.aiff", SF_FORMAT_AIFF) ;
  84. update_seek_short_test ("header_short.aiff", SF_FORMAT_AIFF) ;
  85. update_seek_int_test ("header_int.aiff", SF_FORMAT_AIFF) ;
  86. update_seek_float_test ("header_float.aiff", SF_FORMAT_AIFF) ;
  87. update_seek_double_test ("header_double.aiff", SF_FORMAT_AIFF) ;
  88. header_shrink_test ("header_shrink.wav", SF_FORMAT_AIFF) ;
  89. extra_header_test ("extra.aiff", SF_FORMAT_AIFF) ;
  90. test_count++ ;
  91. } ;
  92. if (do_all || ! strcmp (argv [1], "au"))
  93. { update_header_test ("header.au", SF_FORMAT_AU) ;
  94. update_seek_short_test ("header_short.au", SF_FORMAT_AU) ;
  95. update_seek_int_test ("header_int.au", SF_FORMAT_AU) ;
  96. update_seek_float_test ("header_float.au", SF_FORMAT_AU) ;
  97. update_seek_double_test ("header_double.au", SF_FORMAT_AU) ;
  98. test_count++ ;
  99. } ;
  100. if (do_all || ! strcmp (argv [1], "caf"))
  101. { update_header_test ("header.caf", SF_FORMAT_CAF) ;
  102. update_seek_short_test ("header_short.caf", SF_FORMAT_CAF) ;
  103. update_seek_int_test ("header_int.caf", SF_FORMAT_CAF) ;
  104. update_seek_float_test ("header_float.caf", SF_FORMAT_CAF) ;
  105. update_seek_double_test ("header_double.caf", SF_FORMAT_CAF) ;
  106. /* extra_header_test ("extra.caf", SF_FORMAT_CAF) ; */
  107. test_count++ ;
  108. } ;
  109. if (do_all || ! strcmp (argv [1], "nist"))
  110. { update_header_test ("header.nist", SF_FORMAT_NIST) ;
  111. update_seek_short_test ("header_short.nist", SF_FORMAT_NIST) ;
  112. update_seek_int_test ("header_int.nist", SF_FORMAT_NIST) ;
  113. test_count++ ;
  114. } ;
  115. if (do_all || ! strcmp (argv [1], "paf"))
  116. { update_header_test ("header.paf", SF_FORMAT_PAF) ;
  117. update_seek_short_test ("header_short.paf", SF_FORMAT_PAF) ;
  118. test_count++ ;
  119. } ;
  120. if (do_all || ! strcmp (argv [1], "ircam"))
  121. { update_header_test ("header.ircam", SF_FORMAT_IRCAM) ;
  122. update_seek_short_test ("header_short.ircam", SF_FORMAT_IRCAM) ;
  123. test_count++ ;
  124. } ;
  125. if (do_all || ! strcmp (argv [1], "w64"))
  126. { update_header_test ("header.w64", SF_FORMAT_W64) ;
  127. update_seek_short_test ("header_short.w64", SF_FORMAT_W64) ;
  128. update_seek_int_test ("header_int.w64", SF_FORMAT_W64) ;
  129. update_seek_float_test ("header_float.w64", SF_FORMAT_W64) ;
  130. update_seek_double_test ("header_double.w64", SF_FORMAT_W64) ;
  131. test_count++ ;
  132. } ;
  133. if (do_all || ! strcmp (argv [1], "rf64"))
  134. { update_header_test ("header.rf64", SF_FORMAT_RF64) ;
  135. update_seek_short_test ("header_short.rf64", SF_FORMAT_RF64) ;
  136. update_seek_int_test ("header_int.rf64", SF_FORMAT_RF64) ;
  137. update_seek_float_test ("header_float.rf64", SF_FORMAT_RF64) ;
  138. update_seek_double_test ("header_double.rf64", SF_FORMAT_RF64) ;
  139. test_count++ ;
  140. } ;
  141. if (do_all || ! strcmp (argv [1], "mat4"))
  142. { update_header_test ("header.mat4", SF_FORMAT_MAT4) ;
  143. update_seek_short_test ("header_short.mat4", SF_FORMAT_MAT4) ;
  144. update_seek_int_test ("header_int.mat4", SF_FORMAT_MAT4) ;
  145. update_seek_float_test ("header_float.mat4", SF_FORMAT_MAT4) ;
  146. update_seek_double_test ("header_double.mat4", SF_FORMAT_MAT4) ;
  147. test_count++ ;
  148. } ;
  149. if (do_all || ! strcmp (argv [1], "mat5"))
  150. { update_header_test ("header.mat5", SF_FORMAT_MAT5) ;
  151. update_seek_short_test ("header_short.mat5", SF_FORMAT_MAT5) ;
  152. update_seek_int_test ("header_int.mat5", SF_FORMAT_MAT5) ;
  153. update_seek_float_test ("header_float.mat5", SF_FORMAT_MAT5) ;
  154. update_seek_double_test ("header_double.mat5", SF_FORMAT_MAT5) ;
  155. test_count++ ;
  156. } ;
  157. if (do_all || ! strcmp (argv [1], "pvf"))
  158. { update_header_test ("header.pvf", SF_FORMAT_PVF) ;
  159. update_seek_short_test ("header_short.pvf", SF_FORMAT_PVF) ;
  160. test_count++ ;
  161. } ;
  162. if (do_all || ! strcmp (argv [1], "avr"))
  163. { update_header_test ("header.avr", SF_FORMAT_AVR) ;
  164. update_seek_short_test ("header_short.avr", SF_FORMAT_AVR) ;
  165. test_count++ ;
  166. } ;
  167. if (do_all || ! strcmp (argv [1], "htk"))
  168. { update_header_test ("header.htk", SF_FORMAT_HTK) ;
  169. update_seek_short_test ("header_short.htk", SF_FORMAT_HTK) ;
  170. test_count++ ;
  171. } ;
  172. if (do_all || ! strcmp (argv [1], "svx"))
  173. { update_header_test ("header.svx", SF_FORMAT_SVX) ;
  174. update_seek_short_test ("header_short.svx", SF_FORMAT_SVX) ;
  175. test_count++ ;
  176. } ;
  177. if (do_all || ! strcmp (argv [1], "voc"))
  178. { update_header_test ("header.voc", SF_FORMAT_VOC) ;
  179. /*-update_seek_short_test ("header_short.voc", SF_FORMAT_VOC) ;-*/
  180. test_count++ ;
  181. } ;
  182. if (do_all || ! strcmp (argv [1], "sds"))
  183. { update_header_test ("header.sds", SF_FORMAT_SDS) ;
  184. /*-update_seek_short_test ("header_short.sds", SF_FORMAT_SDS) ;-*/
  185. test_count++ ;
  186. } ;
  187. if (do_all || ! strcmp (argv [1], "mpc2k"))
  188. { update_header_test ("header.mpc", SF_FORMAT_MPC2K) ;
  189. update_seek_short_test ("header_short.mpc", SF_FORMAT_MPC2K) ;
  190. test_count++ ;
  191. } ;
  192. if (test_count == 0)
  193. { printf ("Mono : ************************************\n") ;
  194. printf ("Mono : * No '%s' test defined.\n", argv [1]) ;
  195. printf ("Mono : ************************************\n") ;
  196. return 1 ;
  197. } ;
  198. return 0 ;
  199. } /* main */
  200. /*============================================================================================
  201. ** Here are the test functions.
  202. */
  203. static void
  204. update_header_sub (const char *filename, int typemajor, int write_mode)
  205. { SNDFILE *outfile, *infile ;
  206. SF_INFO sfinfo ;
  207. int k ;
  208. sfinfo.samplerate = 44100 ;
  209. sfinfo.format = (typemajor | SF_FORMAT_PCM_16) ;
  210. sfinfo.channels = 1 ;
  211. sfinfo.frames = 0 ;
  212. outfile = test_open_file_or_die (filename, write_mode, &sfinfo, SF_TRUE, __LINE__) ;
  213. for (k = 0 ; k < BUFFER_LEN ; k++)
  214. data_out [k] = k + 1 ;
  215. test_write_int_or_die (outfile, 0, data_out, BUFFER_LEN, __LINE__) ;
  216. if (typemajor != SF_FORMAT_HTK)
  217. { /* The HTK header is not correct when the file is first written. */
  218. infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  219. sf_close (infile) ;
  220. } ;
  221. sf_command (outfile, SFC_UPDATE_HEADER_NOW, NULL, 0) ;
  222. /*
  223. ** Open file and check log buffer for an error. If header update failed
  224. ** the the log buffer will contain errors.
  225. */
  226. infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  227. check_log_buffer_or_die (infile, __LINE__) ;
  228. if (sfinfo.frames < BUFFER_LEN || sfinfo.frames > BUFFER_LEN + 50)
  229. { printf ("\n\nLine %d : Incorrect sample count (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, BUFFER_LEN) ;
  230. dump_log_buffer (infile) ;
  231. exit (1) ;
  232. } ;
  233. test_read_int_or_die (infile, 0, data_in, BUFFER_LEN, __LINE__) ;
  234. for (k = 0 ; k < BUFFER_LEN ; k++)
  235. if (data_out [k] != k + 1)
  236. printf ("Error : line %d\n", __LINE__) ;
  237. sf_close (infile) ;
  238. /* Set auto update on. */
  239. sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) ;
  240. /* Write more data_out. */
  241. for (k = 0 ; k < BUFFER_LEN ; k++)
  242. data_out [k] = k + 2 ;
  243. test_write_int_or_die (outfile, 0, data_out, BUFFER_LEN, __LINE__) ;
  244. /* Open file again and make sure no errors in log buffer. */
  245. infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  246. check_log_buffer_or_die (infile, __LINE__) ;
  247. if (sfinfo.frames < 2 * BUFFER_LEN || sfinfo.frames > 2 * BUFFER_LEN + 50)
  248. { printf ("\n\nLine %d : Incorrect sample count (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, 2 * BUFFER_LEN) ;
  249. dump_log_buffer (infile) ;
  250. exit (1) ;
  251. } ;
  252. sf_close (infile) ;
  253. sf_close (outfile) ;
  254. unlink (filename) ;
  255. } /* update_header_sub */
  256. static void
  257. update_header_test (const char *filename, int typemajor)
  258. {
  259. print_test_name ("update_header_test", filename) ;
  260. update_header_sub (filename, typemajor, SFM_WRITE) ;
  261. update_header_sub (filename, typemajor, SFM_RDWR) ;
  262. unlink (filename) ;
  263. puts ("ok") ;
  264. } /* update_header_test */
  265. /*==============================================================================
  266. */
  267. [+ FOR data_type
  268. +]static void
  269. update_seek_[+ (get "name") +]_test (const char *filename, int filetype)
  270. { SNDFILE *outfile, *infile ;
  271. SF_INFO sfinfo ;
  272. sf_count_t frames ;
  273. [+ (get "name") +] buffer [8] ;
  274. int k ;
  275. print_test_name ("update_seek_[+ (get "name") +]_test", filename) ;
  276. memset (buffer, 0, sizeof (buffer)) ;
  277. /* Create sound outfile with no data. */
  278. sfinfo.format = filetype | [+ (get "format") +] ;
  279. sfinfo.samplerate = 48000 ;
  280. sfinfo.channels = 2 ;
  281. if (sf_format_check (&sfinfo) == SF_FALSE)
  282. sfinfo.channels = 1 ;
  283. outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
  284. sf_close (outfile) ;
  285. /* Open again for read/write. */
  286. outfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ;
  287. /*
  288. ** In auto header update mode, seeking to the end of the file with
  289. ** SEEK_SET will fail from the 2nd seek on. seeking to 0, SEEK_END
  290. ** will seek to 0 anyway
  291. */
  292. if (sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) == 0)
  293. { printf ("\n\nError : sf_command (SFC_SET_UPDATE_HEADER_AUTO) return error : %s\n\n", sf_strerror (outfile)) ;
  294. exit (1) ;
  295. } ;
  296. /* Now write some frames. */
  297. frames = ARRAY_LEN (buffer) / sfinfo.channels ;
  298. for (k = 0 ; k < 6 ; k++)
  299. { test_seek_or_die (outfile, k * frames, SEEK_SET, k * frames, sfinfo.channels, __LINE__) ;
  300. test_seek_or_die (outfile, 0, SEEK_END, k * frames, sfinfo.channels, __LINE__) ;
  301. /* Open file again and make sure no errors in log buffer. */
  302. infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  303. check_log_buffer_or_die (infile, __LINE__) ;
  304. sf_close (infile) ;
  305. if (sfinfo.frames != k * frames)
  306. { printf ("\n\nLine %d : Incorrect sample count (%" PRId64 " should be %" PRId64 ")\n", __LINE__, sfinfo.frames, k + frames) ;
  307. dump_log_buffer (infile) ;
  308. exit (1) ;
  309. } ;
  310. if ((k & 1) == 0)
  311. test_write_[+ (get "name") +]_or_die (outfile, k, buffer, sfinfo.channels * frames, __LINE__) ;
  312. else
  313. test_writef_[+ (get "name") +]_or_die (outfile, k, buffer, frames, __LINE__) ;
  314. } ;
  315. sf_close (outfile) ;
  316. unlink (filename) ;
  317. puts ("ok") ;
  318. return ;
  319. } /* update_seek_[+ (get "name") +]_test */
  320. [+ ENDFOR data_type
  321. +]
  322. static void
  323. header_shrink_test (const char *filename, int filetype)
  324. { SNDFILE *outfile, *infile ;
  325. SF_INFO sfinfo ;
  326. sf_count_t frames ;
  327. float buffer [8], bufferin [8] ;
  328. print_test_name ("header_shrink_test", filename) ;
  329. memset (&sfinfo, 0, sizeof (sfinfo)) ;
  330. sfinfo.samplerate = 44100 ;
  331. sfinfo.format = filetype | SF_FORMAT_FLOAT ;
  332. sfinfo.channels = 1 ;
  333. memset (buffer, 0xA0, sizeof (buffer)) ;
  334. /* Now write some frames. */
  335. frames = ARRAY_LEN (buffer) / sfinfo.channels ;
  336. /* Test the file with extra header data. */
  337. outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
  338. sf_command (outfile, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_TRUE) ;
  339. sf_command (outfile, SFC_UPDATE_HEADER_NOW, NULL, SF_FALSE) ;
  340. sf_command (outfile, SFC_SET_ADD_PEAK_CHUNK, NULL, SF_FALSE) ;
  341. test_writef_float_or_die (outfile, 0, buffer, frames, __LINE__) ;
  342. sf_close (outfile) ;
  343. /* Open again for read. */
  344. infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
  345. test_readf_float_or_die (infile, 0, bufferin, frames, __LINE__) ;
  346. sf_close (infile) ;
  347. compare_float_or_die (buffer, bufferin, frames, __LINE__) ;
  348. unlink (filename) ;
  349. puts ("ok") ;
  350. return ;
  351. } /* header_shrink_test */
  352. static void
  353. extra_header_test (const char *filename, int filetype)
  354. { SNDFILE *outfile, *infile ;
  355. SF_INFO sfinfo ;
  356. sf_count_t frames ;
  357. short buffer [8] ;
  358. int k = 0 ;
  359. print_test_name ("extra_header_test", filename) ;
  360. sfinfo.samplerate = 44100 ;
  361. sfinfo.format = (filetype | SF_FORMAT_PCM_16) ;
  362. sfinfo.channels = 1 ;
  363. memset (buffer, 0xA0, sizeof (buffer)) ;
  364. /* Now write some frames. */
  365. frames = ARRAY_LEN (buffer) / sfinfo.channels ;
  366. /* Test the file with extra header data. */
  367. outfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, [+ (tpl-file-line "%2$d") +]) ;
  368. sf_set_string (outfile, SF_STR_TITLE, filename) ;
  369. test_writef_short_or_die (outfile, k, buffer, frames, [+ (tpl-file-line "%2$d") +]) ;
  370. sf_set_string (outfile, SF_STR_COPYRIGHT, "(c) 1980 Erik") ;
  371. sf_close (outfile) ;
  372. #if 1
  373. /*
  374. ** Erik de Castro Lopo <erikd@mega-nerd.com> May 23 2004.
  375. **
  376. ** This file has extra string data in the header and therefore cannot
  377. ** currently be opened in SFM_RDWR mode. This is fixable, but its in
  378. ** a part of the code I don't want to fiddle with until the Ogg/Vorbis
  379. ** integration is done.
  380. */
  381. if ((infile = sf_open (filename, SFM_RDWR, &sfinfo)) != NULL)
  382. { printf ("\n\nError : should not be able to open this file in SFM_RDWR.\n\n") ;
  383. exit (1) ;
  384. } ;
  385. unlink (filename) ;
  386. puts ("ok") ;
  387. return ;
  388. #else
  389. hexdump_file (filename, 0, 100000) ;
  390. /* Open again for read/write. */
  391. outfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, [+ (tpl-file-line "%2$d") +]) ;
  392. /*
  393. ** In auto header update mode, seeking to the end of the file with
  394. ** SEEK_SET will fail from the 2nd seek on. seeking to 0, SEEK_END
  395. ** will seek to 0 anyway
  396. */
  397. if (sf_command (outfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) == 0)
  398. { printf ("\n\nError : sf_command (SFC_SET_UPDATE_HEADER_AUTO) return error : %s\n\n", sf_strerror (outfile)) ;
  399. exit (1) ;
  400. } ;
  401. /* Now write some frames. */
  402. frames = ARRAY_LEN (buffer) / sfinfo.channels ;
  403. for (k = 1 ; k < 6 ; k++)
  404. {
  405. printf ("\n*** pass %d\n", k) ;
  406. memset (buffer, 0xA0 + k, sizeof (buffer)) ;
  407. test_seek_or_die (outfile, k * frames, SEEK_SET, k * frames, sfinfo.channels, [+ (tpl-file-line "%2$d") +]) ;
  408. test_seek_or_die (outfile, 0, SEEK_END, k * frames, sfinfo.channels, [+ (tpl-file-line "%2$d") +]) ;
  409. /* Open file again and make sure no errors in log buffer. */
  410. if (0)
  411. { infile = test_open_file_or_die (filename, SFM_READ, &sfinfo, [+ (tpl-file-line "%2$d") +]) ;
  412. check_log_buffer_or_die (infile, [+ (tpl-file-line "%2$d") +]) ;
  413. sf_close (infile) ;
  414. } ;
  415. if (sfinfo.frames != k * frames)
  416. { printf ("\n\nLine %d : Incorrect sample count (%" PRId64 " should be %" PRId64 ")\n", [+ (tpl-file-line "%2$d") +], sfinfo.frames, k + frames) ;
  417. dump_log_buffer (infile) ;
  418. exit (1) ;
  419. } ;
  420. if ((k & 1) == 0)
  421. test_write_short_or_die (outfile, k, buffer, sfinfo.channels * frames, [+ (tpl-file-line "%2$d") +]) ;
  422. else
  423. test_writef_short_or_die (outfile, k, buffer, frames, [+ (tpl-file-line "%2$d") +]) ;
  424. hexdump_file (filename, 0, 100000) ;
  425. } ;
  426. sf_close (outfile) ;
  427. unlink (filename) ;
  428. puts ("ok") ;
  429. return ;
  430. #endif
  431. } /* extra_header_test */