pcm_test.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723
  1. /*
  2. ** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
  3. **
  4. ** This program is free software; you can redistribute it and/or modify
  5. ** it under the terms of the GNU General Public License as published by
  6. ** the Free Software Foundation; either version 2 of the License, or
  7. ** (at your option) any later version.
  8. **
  9. ** This program is distributed in the hope that it will be useful,
  10. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ** GNU General Public License for more details.
  13. **
  14. ** You should have received a copy of the GNU General Public License
  15. ** along with this program; if not, write to the Free Software
  16. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include "sfconfig.h"
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <math.h>
  23. #if HAVE_UNISTD_H
  24. #include <unistd.h>
  25. #endif
  26. #include <sndfile.h>
  27. #include "utils.h"
  28. #define BUFFER_SIZE (1<<12)
  29. static void lrintf_test (void) ;
  30. static void pcm_test_bits_8 (const char *filename, int filetype, uint64_t hash) ;
  31. static void pcm_test_bits_16 (const char *filename, int filetype, uint64_t hash) ;
  32. static void pcm_test_bits_24 (const char *filename, int filetype, uint64_t hash) ;
  33. static void pcm_test_bits_32 (const char *filename, int filetype, uint64_t hash) ;
  34. static void pcm_test_float (const char *filename, int filetype, uint64_t hash, int replace_float) ;
  35. static void pcm_test_double (const char *filename, int filetype, uint64_t hash, int replace_float) ;
  36. typedef union
  37. { double d [BUFFER_SIZE + 1] ;
  38. float f [BUFFER_SIZE + 1] ;
  39. int i [BUFFER_SIZE + 1] ;
  40. short s [BUFFER_SIZE + 1] ;
  41. } BUFFER ;
  42. /* Data written to the file. */
  43. static BUFFER data_out ;
  44. /* Data read back from the file. */
  45. static BUFFER data_in ;
  46. int
  47. main (void)
  48. {
  49. lrintf_test () ;
  50. pcm_test_bits_8 ("pcm-s8.raw", SF_FORMAT_RAW | SF_FORMAT_PCM_S8, 0x1cda335091249dbfLL) ;
  51. pcm_test_bits_8 ("pcm-u8.raw", SF_FORMAT_RAW | SF_FORMAT_PCM_U8, 0x7f748c433d695f3fLL) ;
  52. pcm_test_bits_16 ("le-pcm16.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_16, 0x3a2b956c881ebf08LL) ;
  53. pcm_test_bits_16 ("be-pcm16.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_16, 0xd9e2f840c55750f8LL) ;
  54. pcm_test_bits_24 ("le-pcm24.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_24, 0x933b6a759ab496f8LL) ;
  55. pcm_test_bits_24 ("be-pcm24.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_24, 0xbb1f3eaf9c30b6f8LL) ;
  56. pcm_test_bits_32 ("le-pcm32.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_32, 0xa77aece1c1c17f08LL) ;
  57. pcm_test_bits_32 ("be-pcm32.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_32, 0x3099ddf142d0b0f8LL) ;
  58. /* Lite remove start */
  59. pcm_test_float ("le-float.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0x3c2ad04f7554267aLL, SF_FALSE) ;
  60. pcm_test_float ("be-float.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0x074de3e248fa9186LL, SF_FALSE) ;
  61. pcm_test_double ("le-double.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0xc682726f958f669cLL, SF_FALSE) ;
  62. pcm_test_double ("be-double.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0xd9a3583f8ee51164LL, SF_FALSE) ;
  63. pcm_test_float ("le-float.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0x3c2ad04f7554267aLL, SF_TRUE) ;
  64. pcm_test_float ("be-float.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_FLOAT, 0x074de3e248fa9186LL, SF_TRUE) ;
  65. pcm_test_double ("le-double.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0xc682726f958f669cLL, SF_TRUE) ;
  66. pcm_test_double ("be-double.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, 0xd9a3583f8ee51164LL, SF_TRUE) ;
  67. /* Lite remove end */
  68. return 0 ;
  69. } /* main */
  70. /*============================================================================================
  71. ** Here are the test functions.
  72. */
  73. static void
  74. lrintf_test (void)
  75. { int k, items ;
  76. float *float_data ;
  77. int *int_data ;
  78. print_test_name ("lrintf_test", "") ;
  79. items = 1024 ;
  80. float_data = data_out.f ;
  81. int_data = data_in.i ;
  82. for (k = 0 ; k < items ; k++)
  83. float_data [k] = (k * ((k % 2) ? 333333.0 : -333333.0)) ;
  84. for (k = 0 ; k < items ; k++)
  85. int_data [k] = lrintf (float_data [k]) ;
  86. for (k = 0 ; k < items ; k++)
  87. if (fabs (int_data [k] - float_data [k]) > 1.0)
  88. { printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %d).\n", __LINE__, k, float_data [k], int_data [k]) ;
  89. exit (1) ;
  90. } ;
  91. printf ("ok\n") ;
  92. } /* lrintf_test */
  93. static void
  94. pcm_test_bits_8 (const char *filename, int filetype, uint64_t hash)
  95. { SNDFILE *file ;
  96. SF_INFO sfinfo ;
  97. int k, items, zero_count ;
  98. short *short_out, *short_in ;
  99. int *int_out, *int_in ;
  100. /* Lite remove start */
  101. float *float_out, *float_in ;
  102. double *double_out, *double_in ;
  103. /* Lite remove end */
  104. print_test_name ("pcm_test_bits_8", filename) ;
  105. items = 127 ;
  106. short_out = data_out.s ;
  107. short_in = data_in.s ;
  108. zero_count = 0 ;
  109. for (k = 0 ; k < items ; k++)
  110. { short_out [k] = ((k * ((k % 2) ? 1 : -1)) << 8) ;
  111. zero_count = short_out [k] ? zero_count : zero_count + 1 ;
  112. } ;
  113. if (zero_count > items / 4)
  114. { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
  115. exit (1) ;
  116. } ;
  117. sfinfo.samplerate = 44100 ;
  118. sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
  119. sfinfo.channels = 1 ;
  120. sfinfo.format = filetype ;
  121. file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
  122. test_write_short_or_die (file, 0, short_out, items, __LINE__) ;
  123. sf_close (file) ;
  124. memset (short_in, 0, items * sizeof (short)) ;
  125. file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  126. if (sfinfo.format != filetype)
  127. { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
  128. exit (1) ;
  129. } ;
  130. if (sfinfo.frames != items)
  131. { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
  132. exit (1) ;
  133. } ;
  134. if (sfinfo.channels != 1)
  135. { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
  136. exit (1) ;
  137. } ;
  138. check_log_buffer_or_die (file, __LINE__) ;
  139. test_read_short_or_die (file, 0, short_in, items, __LINE__) ;
  140. for (k = 0 ; k < items ; k++)
  141. if (short_out [k] != short_in [k])
  142. { printf ("\n\nLine %d: Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, short_out [k], short_in [k]) ;
  143. exit (1) ;
  144. } ;
  145. sf_close (file) ;
  146. /* Finally, check the file hash. */
  147. check_file_hash_or_die (filename, hash, __LINE__) ;
  148. /*--------------------------------------------------------------------------
  149. ** Test sf_read/write_int ()
  150. */
  151. zero_count = 0 ;
  152. int_out = data_out.i ;
  153. int_in = data_in.i ;
  154. for (k = 0 ; k < items ; k++)
  155. { int_out [k] = ((k * ((k % 2) ? 1 : -1)) << 24) ;
  156. zero_count = int_out [k] ? zero_count : zero_count + 1 ;
  157. } ;
  158. if (zero_count > items / 4)
  159. { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
  160. exit (1) ;
  161. } ;
  162. sfinfo.samplerate = 44100 ;
  163. sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
  164. sfinfo.channels = 1 ;
  165. sfinfo.format = filetype ;
  166. file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
  167. test_write_int_or_die (file, 0, int_out, items, __LINE__) ;
  168. sf_close (file) ;
  169. memset (int_in, 0, items * sizeof (int)) ;
  170. file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  171. if (sfinfo.format != filetype)
  172. { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
  173. exit (1) ;
  174. } ;
  175. if (sfinfo.frames != items)
  176. { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
  177. exit (1) ;
  178. } ;
  179. if (sfinfo.channels != 1)
  180. { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
  181. exit (1) ;
  182. } ;
  183. check_log_buffer_or_die (file, __LINE__) ;
  184. test_read_int_or_die (file, 0, int_in, items, __LINE__) ;
  185. for (k = 0 ; k < items ; k++)
  186. if (int_out [k] != int_in [k])
  187. { printf ("\n\nLine %d: int : Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, int_out [k], int_in [k]) ;
  188. exit (1) ;
  189. } ;
  190. sf_close (file) ;
  191. /* Lite remove start */
  192. /*--------------------------------------------------------------------------
  193. ** Test sf_read/write_float ()
  194. */
  195. zero_count = 0 ;
  196. float_out = data_out.f ;
  197. float_in = data_in.f ;
  198. for (k = 0 ; k < items ; k++)
  199. { float_out [k] = (k * ((k % 2) ? 1 : -1)) ;
  200. zero_count = (fabs (float_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
  201. } ;
  202. if (zero_count > items / 4)
  203. { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
  204. exit (1) ;
  205. } ;
  206. sfinfo.samplerate = 44100 ;
  207. sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
  208. sfinfo.channels = 1 ;
  209. sfinfo.format = filetype ;
  210. file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
  211. sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
  212. test_write_float_or_die (file, 0, float_out, items, __LINE__) ;
  213. sf_close (file) ;
  214. memset (float_in, 0, items * sizeof (float)) ;
  215. file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  216. if (sfinfo.format != filetype)
  217. { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
  218. exit (1) ;
  219. } ;
  220. if (sfinfo.frames != items)
  221. { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
  222. exit (1) ;
  223. } ;
  224. if (sfinfo.channels != 1)
  225. { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
  226. exit (1) ;
  227. } ;
  228. check_log_buffer_or_die (file, __LINE__) ;
  229. sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
  230. test_read_float_or_die (file, 0, float_in, items, __LINE__) ;
  231. for (k = 0 ; k < items ; k++)
  232. if (fabs (float_out [k] - float_in [k]) > 1e-10)
  233. { printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, (double) float_out [k], (double) float_in [k]) ;
  234. exit (1) ;
  235. } ;
  236. sf_close (file) ;
  237. /*--------------------------------------------------------------------------
  238. ** Test sf_read/write_double ()
  239. */
  240. zero_count = 0 ;
  241. double_out = data_out.d ;
  242. double_in = data_in.d ;
  243. for (k = 0 ; k < items ; k++)
  244. { double_out [k] = (k * ((k % 2) ? 1 : -1)) ;
  245. zero_count = (fabs (double_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
  246. } ;
  247. if (zero_count > items / 4)
  248. { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
  249. exit (1) ;
  250. } ;
  251. sfinfo.samplerate = 44100 ;
  252. sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
  253. sfinfo.channels = 1 ;
  254. sfinfo.format = filetype ;
  255. file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
  256. sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
  257. test_write_double_or_die (file, 0, double_out, items, __LINE__) ;
  258. sf_close (file) ;
  259. memset (double_in, 0, items * sizeof (double)) ;
  260. file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  261. if (sfinfo.format != filetype)
  262. { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
  263. exit (1) ;
  264. } ;
  265. if (sfinfo.frames != items)
  266. { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
  267. exit (1) ;
  268. } ;
  269. if (sfinfo.channels != 1)
  270. { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
  271. exit (1) ;
  272. } ;
  273. check_log_buffer_or_die (file, __LINE__) ;
  274. sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
  275. test_read_double_or_die (file, 0, double_in, items, __LINE__) ;
  276. for (k = 0 ; k < items ; k++)
  277. if (fabs (double_out [k] - double_in [k]) > 1e-10)
  278. { printf ("\n\nLine %d: double : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, double_out [k], double_in [k]) ;
  279. exit (1) ;
  280. } ;
  281. sf_close (file) ;
  282. /* Lite remove end */
  283. unlink (filename) ;
  284. puts ("ok") ;
  285. } /* pcm_test_bits_8 */
  286. static void
  287. pcm_test_bits_16 (const char *filename, int filetype, uint64_t hash)
  288. { SNDFILE *file ;
  289. SF_INFO sfinfo ;
  290. int k, items, zero_count ;
  291. short *short_out, *short_in ;
  292. int *int_out, *int_in ;
  293. /* Lite remove start */
  294. float *float_out, *float_in ;
  295. double *double_out, *double_in ;
  296. /* Lite remove end */
  297. print_test_name ("pcm_test_bits_16", filename) ;
  298. items = 1024 ;
  299. short_out = data_out.s ;
  300. short_in = data_in.s ;
  301. zero_count = 0 ;
  302. for (k = 0 ; k < items ; k++)
  303. { short_out [k] = (k * ((k % 2) ? 3 : -3)) ;
  304. zero_count = short_out [k] ? zero_count : zero_count + 1 ;
  305. } ;
  306. if (zero_count > items / 4)
  307. { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
  308. exit (1) ;
  309. } ;
  310. sfinfo.samplerate = 44100 ;
  311. sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
  312. sfinfo.channels = 1 ;
  313. sfinfo.format = filetype ;
  314. file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
  315. test_write_short_or_die (file, 0, short_out, items, __LINE__) ;
  316. sf_close (file) ;
  317. memset (short_in, 0, items * sizeof (short)) ;
  318. file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  319. if (sfinfo.format != filetype)
  320. { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
  321. exit (1) ;
  322. } ;
  323. if (sfinfo.frames != items)
  324. { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
  325. exit (1) ;
  326. } ;
  327. if (sfinfo.channels != 1)
  328. { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
  329. exit (1) ;
  330. } ;
  331. check_log_buffer_or_die (file, __LINE__) ;
  332. test_read_short_or_die (file, 0, short_in, items, __LINE__) ;
  333. for (k = 0 ; k < items ; k++)
  334. if (short_out [k] != short_in [k])
  335. { printf ("\n\nLine %d: Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, short_out [k], short_in [k]) ;
  336. exit (1) ;
  337. } ;
  338. sf_close (file) ;
  339. /* Finally, check the file hash. */
  340. check_file_hash_or_die (filename, hash, __LINE__) ;
  341. /*--------------------------------------------------------------------------
  342. ** Test sf_read/write_int ()
  343. */
  344. zero_count = 0 ;
  345. int_out = data_out.i ;
  346. int_in = data_in.i ;
  347. for (k = 0 ; k < items ; k++)
  348. { int_out [k] = ((k * ((k % 2) ? 3 : -3)) << 16) ;
  349. zero_count = int_out [k] ? zero_count : zero_count + 1 ;
  350. } ;
  351. if (zero_count > items / 4)
  352. { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
  353. exit (1) ;
  354. } ;
  355. sfinfo.samplerate = 44100 ;
  356. sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
  357. sfinfo.channels = 1 ;
  358. sfinfo.format = filetype ;
  359. file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
  360. test_write_int_or_die (file, 0, int_out, items, __LINE__) ;
  361. sf_close (file) ;
  362. memset (int_in, 0, items * sizeof (int)) ;
  363. file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  364. if (sfinfo.format != filetype)
  365. { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
  366. exit (1) ;
  367. } ;
  368. if (sfinfo.frames != items)
  369. { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
  370. exit (1) ;
  371. } ;
  372. if (sfinfo.channels != 1)
  373. { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
  374. exit (1) ;
  375. } ;
  376. check_log_buffer_or_die (file, __LINE__) ;
  377. test_read_int_or_die (file, 0, int_in, items, __LINE__) ;
  378. for (k = 0 ; k < items ; k++)
  379. if (int_out [k] != int_in [k])
  380. { printf ("\n\nLine %d: int : Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, int_out [k], int_in [k]) ;
  381. exit (1) ;
  382. } ;
  383. sf_close (file) ;
  384. /* Lite remove start */
  385. /*--------------------------------------------------------------------------
  386. ** Test sf_read/write_float ()
  387. */
  388. zero_count = 0 ;
  389. float_out = data_out.f ;
  390. float_in = data_in.f ;
  391. for (k = 0 ; k < items ; k++)
  392. { float_out [k] = (k * ((k % 2) ? 3 : -3)) ;
  393. zero_count = (fabs (float_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
  394. } ;
  395. if (zero_count > items / 4)
  396. { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
  397. exit (1) ;
  398. } ;
  399. sfinfo.samplerate = 44100 ;
  400. sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
  401. sfinfo.channels = 1 ;
  402. sfinfo.format = filetype ;
  403. file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
  404. sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
  405. test_write_float_or_die (file, 0, float_out, items, __LINE__) ;
  406. sf_close (file) ;
  407. memset (float_in, 0, items * sizeof (float)) ;
  408. file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  409. if (sfinfo.format != filetype)
  410. { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
  411. exit (1) ;
  412. } ;
  413. if (sfinfo.frames != items)
  414. { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
  415. exit (1) ;
  416. } ;
  417. if (sfinfo.channels != 1)
  418. { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
  419. exit (1) ;
  420. } ;
  421. check_log_buffer_or_die (file, __LINE__) ;
  422. sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
  423. test_read_float_or_die (file, 0, float_in, items, __LINE__) ;
  424. for (k = 0 ; k < items ; k++)
  425. if (fabs (float_out [k] - float_in [k]) > 1e-10)
  426. { printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, (double) float_out [k], (double) float_in [k]) ;
  427. exit (1) ;
  428. } ;
  429. sf_close (file) ;
  430. /*--------------------------------------------------------------------------
  431. ** Test sf_read/write_double ()
  432. */
  433. zero_count = 0 ;
  434. double_out = data_out.d ;
  435. double_in = data_in.d ;
  436. for (k = 0 ; k < items ; k++)
  437. { double_out [k] = (k * ((k % 2) ? 3 : -3)) ;
  438. zero_count = (fabs (double_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
  439. } ;
  440. if (zero_count > items / 4)
  441. { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
  442. exit (1) ;
  443. } ;
  444. sfinfo.samplerate = 44100 ;
  445. sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
  446. sfinfo.channels = 1 ;
  447. sfinfo.format = filetype ;
  448. file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
  449. sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
  450. test_write_double_or_die (file, 0, double_out, items, __LINE__) ;
  451. sf_close (file) ;
  452. memset (double_in, 0, items * sizeof (double)) ;
  453. file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  454. if (sfinfo.format != filetype)
  455. { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
  456. exit (1) ;
  457. } ;
  458. if (sfinfo.frames != items)
  459. { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
  460. exit (1) ;
  461. } ;
  462. if (sfinfo.channels != 1)
  463. { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
  464. exit (1) ;
  465. } ;
  466. check_log_buffer_or_die (file, __LINE__) ;
  467. sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
  468. test_read_double_or_die (file, 0, double_in, items, __LINE__) ;
  469. for (k = 0 ; k < items ; k++)
  470. if (fabs (double_out [k] - double_in [k]) > 1e-10)
  471. { printf ("\n\nLine %d: double : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, double_out [k], double_in [k]) ;
  472. exit (1) ;
  473. } ;
  474. sf_close (file) ;
  475. /* Lite remove end */
  476. unlink (filename) ;
  477. puts ("ok") ;
  478. } /* pcm_test_bits_16 */
  479. static void
  480. pcm_test_bits_24 (const char *filename, int filetype, uint64_t hash)
  481. { SNDFILE *file ;
  482. SF_INFO sfinfo ;
  483. int k, items, zero_count ;
  484. short *short_out, *short_in ;
  485. int *int_out, *int_in ;
  486. /* Lite remove start */
  487. float *float_out, *float_in ;
  488. double *double_out, *double_in ;
  489. /* Lite remove end */
  490. print_test_name ("pcm_test_bits_24", filename) ;
  491. items = 1024 ;
  492. short_out = data_out.s ;
  493. short_in = data_in.s ;
  494. zero_count = 0 ;
  495. for (k = 0 ; k < items ; k++)
  496. { short_out [k] = (k * ((k % 2) ? 3 : -3)) ;
  497. zero_count = short_out [k] ? zero_count : zero_count + 1 ;
  498. } ;
  499. if (zero_count > items / 4)
  500. { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
  501. exit (1) ;
  502. } ;
  503. sfinfo.samplerate = 44100 ;
  504. sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
  505. sfinfo.channels = 1 ;
  506. sfinfo.format = filetype ;
  507. file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
  508. test_write_short_or_die (file, 0, short_out, items, __LINE__) ;
  509. sf_close (file) ;
  510. memset (short_in, 0, items * sizeof (short)) ;
  511. file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  512. if (sfinfo.format != filetype)
  513. { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
  514. exit (1) ;
  515. } ;
  516. if (sfinfo.frames != items)
  517. { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
  518. exit (1) ;
  519. } ;
  520. if (sfinfo.channels != 1)
  521. { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
  522. exit (1) ;
  523. } ;
  524. check_log_buffer_or_die (file, __LINE__) ;
  525. test_read_short_or_die (file, 0, short_in, items, __LINE__) ;
  526. for (k = 0 ; k < items ; k++)
  527. if (short_out [k] != short_in [k])
  528. { printf ("\n\nLine %d: Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, short_out [k], short_in [k]) ;
  529. exit (1) ;
  530. } ;
  531. sf_close (file) ;
  532. /* Finally, check the file hash. */
  533. check_file_hash_or_die (filename, hash, __LINE__) ;
  534. /*--------------------------------------------------------------------------
  535. ** Test sf_read/write_int ()
  536. */
  537. zero_count = 0 ;
  538. int_out = data_out.i ;
  539. int_in = data_in.i ;
  540. for (k = 0 ; k < items ; k++)
  541. { int_out [k] = ((k * ((k % 2) ? 3333 : -3333)) << 8) ;
  542. zero_count = int_out [k] ? zero_count : zero_count + 1 ;
  543. } ;
  544. if (zero_count > items / 4)
  545. { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
  546. exit (1) ;
  547. } ;
  548. sfinfo.samplerate = 44100 ;
  549. sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
  550. sfinfo.channels = 1 ;
  551. sfinfo.format = filetype ;
  552. file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
  553. test_write_int_or_die (file, 0, int_out, items, __LINE__) ;
  554. sf_close (file) ;
  555. memset (int_in, 0, items * sizeof (int)) ;
  556. file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  557. if (sfinfo.format != filetype)
  558. { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
  559. exit (1) ;
  560. } ;
  561. if (sfinfo.frames != items)
  562. { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
  563. exit (1) ;
  564. } ;
  565. if (sfinfo.channels != 1)
  566. { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
  567. exit (1) ;
  568. } ;
  569. check_log_buffer_or_die (file, __LINE__) ;
  570. test_read_int_or_die (file, 0, int_in, items, __LINE__) ;
  571. for (k = 0 ; k < items ; k++)
  572. if (int_out [k] != int_in [k])
  573. { printf ("\n\nLine %d: int : Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, int_out [k], int_in [k]) ;
  574. exit (1) ;
  575. } ;
  576. sf_close (file) ;
  577. /* Lite remove start */
  578. /*--------------------------------------------------------------------------
  579. ** Test sf_read/write_float ()
  580. */
  581. zero_count = 0 ;
  582. float_out = data_out.f ;
  583. float_in = data_in.f ;
  584. for (k = 0 ; k < items ; k++)
  585. { float_out [k] = (k * ((k % 2) ? 3333 : -3333)) ;
  586. zero_count = (fabs (float_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
  587. } ;
  588. if (zero_count > items / 4)
  589. { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
  590. exit (1) ;
  591. } ;
  592. sfinfo.samplerate = 44100 ;
  593. sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
  594. sfinfo.channels = 1 ;
  595. sfinfo.format = filetype ;
  596. file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
  597. sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
  598. test_write_float_or_die (file, 0, float_out, items, __LINE__) ;
  599. sf_close (file) ;
  600. memset (float_in, 0, items * sizeof (float)) ;
  601. file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  602. if (sfinfo.format != filetype)
  603. { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
  604. exit (1) ;
  605. } ;
  606. if (sfinfo.frames != items)
  607. { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
  608. exit (1) ;
  609. } ;
  610. if (sfinfo.channels != 1)
  611. { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
  612. exit (1) ;
  613. } ;
  614. check_log_buffer_or_die (file, __LINE__) ;
  615. sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
  616. test_read_float_or_die (file, 0, float_in, items, __LINE__) ;
  617. for (k = 0 ; k < items ; k++)
  618. if (fabs (float_out [k] - float_in [k]) > 1e-10)
  619. { printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, (double) float_out [k], (double) float_in [k]) ;
  620. exit (1) ;
  621. } ;
  622. sf_close (file) ;
  623. /*--------------------------------------------------------------------------
  624. ** Test sf_read/write_double ()
  625. */
  626. zero_count = 0 ;
  627. double_out = data_out.d ;
  628. double_in = data_in.d ;
  629. for (k = 0 ; k < items ; k++)
  630. { double_out [k] = (k * ((k % 2) ? 3333 : -3333)) ;
  631. zero_count = (fabs (double_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
  632. } ;
  633. if (zero_count > items / 4)
  634. { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
  635. exit (1) ;
  636. } ;
  637. sfinfo.samplerate = 44100 ;
  638. sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
  639. sfinfo.channels = 1 ;
  640. sfinfo.format = filetype ;
  641. file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
  642. sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
  643. test_write_double_or_die (file, 0, double_out, items, __LINE__) ;
  644. sf_close (file) ;
  645. memset (double_in, 0, items * sizeof (double)) ;
  646. file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  647. if (sfinfo.format != filetype)
  648. { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
  649. exit (1) ;
  650. } ;
  651. if (sfinfo.frames != items)
  652. { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
  653. exit (1) ;
  654. } ;
  655. if (sfinfo.channels != 1)
  656. { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
  657. exit (1) ;
  658. } ;
  659. check_log_buffer_or_die (file, __LINE__) ;
  660. sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
  661. test_read_double_or_die (file, 0, double_in, items, __LINE__) ;
  662. for (k = 0 ; k < items ; k++)
  663. if (fabs (double_out [k] - double_in [k]) > 1e-10)
  664. { printf ("\n\nLine %d: double : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, double_out [k], double_in [k]) ;
  665. exit (1) ;
  666. } ;
  667. sf_close (file) ;
  668. /* Lite remove end */
  669. unlink (filename) ;
  670. puts ("ok") ;
  671. } /* pcm_test_bits_24 */
  672. static void
  673. pcm_test_bits_32 (const char *filename, int filetype, uint64_t hash)
  674. { SNDFILE *file ;
  675. SF_INFO sfinfo ;
  676. int k, items, zero_count ;
  677. short *short_out, *short_in ;
  678. int *int_out, *int_in ;
  679. /* Lite remove start */
  680. float *float_out, *float_in ;
  681. double *double_out, *double_in ;
  682. /* Lite remove end */
  683. print_test_name ("pcm_test_bits_32", filename) ;
  684. items = 1024 ;
  685. short_out = data_out.s ;
  686. short_in = data_in.s ;
  687. zero_count = 0 ;
  688. for (k = 0 ; k < items ; k++)
  689. { short_out [k] = (k * ((k % 2) ? 3 : -3)) ;
  690. zero_count = short_out [k] ? zero_count : zero_count + 1 ;
  691. } ;
  692. if (zero_count > items / 4)
  693. { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
  694. exit (1) ;
  695. } ;
  696. sfinfo.samplerate = 44100 ;
  697. sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
  698. sfinfo.channels = 1 ;
  699. sfinfo.format = filetype ;
  700. file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
  701. test_write_short_or_die (file, 0, short_out, items, __LINE__) ;
  702. sf_close (file) ;
  703. memset (short_in, 0, items * sizeof (short)) ;
  704. file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  705. if (sfinfo.format != filetype)
  706. { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
  707. exit (1) ;
  708. } ;
  709. if (sfinfo.frames != items)
  710. { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
  711. exit (1) ;
  712. } ;
  713. if (sfinfo.channels != 1)
  714. { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
  715. exit (1) ;
  716. } ;
  717. check_log_buffer_or_die (file, __LINE__) ;
  718. test_read_short_or_die (file, 0, short_in, items, __LINE__) ;
  719. for (k = 0 ; k < items ; k++)
  720. if (short_out [k] != short_in [k])
  721. { printf ("\n\nLine %d: Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, short_out [k], short_in [k]) ;
  722. exit (1) ;
  723. } ;
  724. sf_close (file) ;
  725. /* Finally, check the file hash. */
  726. check_file_hash_or_die (filename, hash, __LINE__) ;
  727. /*--------------------------------------------------------------------------
  728. ** Test sf_read/write_int ()
  729. */
  730. zero_count = 0 ;
  731. int_out = data_out.i ;
  732. int_in = data_in.i ;
  733. for (k = 0 ; k < items ; k++)
  734. { int_out [k] = (k * ((k % 2) ? 333333 : -333333)) ;
  735. zero_count = int_out [k] ? zero_count : zero_count + 1 ;
  736. } ;
  737. if (zero_count > items / 4)
  738. { printf ("\n\nLine %d: too many zeros.\n", __LINE__) ;
  739. exit (1) ;
  740. } ;
  741. sfinfo.samplerate = 44100 ;
  742. sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
  743. sfinfo.channels = 1 ;
  744. sfinfo.format = filetype ;
  745. file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
  746. test_write_int_or_die (file, 0, int_out, items, __LINE__) ;
  747. sf_close (file) ;
  748. memset (int_in, 0, items * sizeof (int)) ;
  749. file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  750. if (sfinfo.format != filetype)
  751. { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
  752. exit (1) ;
  753. } ;
  754. if (sfinfo.frames != items)
  755. { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
  756. exit (1) ;
  757. } ;
  758. if (sfinfo.channels != 1)
  759. { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
  760. exit (1) ;
  761. } ;
  762. check_log_buffer_or_die (file, __LINE__) ;
  763. test_read_int_or_die (file, 0, int_in, items, __LINE__) ;
  764. for (k = 0 ; k < items ; k++)
  765. if (int_out [k] != int_in [k])
  766. { printf ("\n\nLine %d: int : Incorrect sample (#%d : 0x%x => 0x%x).\n", __LINE__, k, int_out [k], int_in [k]) ;
  767. exit (1) ;
  768. } ;
  769. sf_close (file) ;
  770. /* Lite remove start */
  771. /*--------------------------------------------------------------------------
  772. ** Test sf_read/write_float ()
  773. */
  774. zero_count = 0 ;
  775. float_out = data_out.f ;
  776. float_in = data_in.f ;
  777. for (k = 0 ; k < items ; k++)
  778. { float_out [k] = (k * ((k % 2) ? 333333 : -333333)) ;
  779. zero_count = (fabs (float_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
  780. } ;
  781. if (zero_count > items / 4)
  782. { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
  783. exit (1) ;
  784. } ;
  785. sfinfo.samplerate = 44100 ;
  786. sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
  787. sfinfo.channels = 1 ;
  788. sfinfo.format = filetype ;
  789. file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
  790. sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
  791. test_write_float_or_die (file, 0, float_out, items, __LINE__) ;
  792. sf_close (file) ;
  793. memset (float_in, 0, items * sizeof (float)) ;
  794. file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  795. if (sfinfo.format != filetype)
  796. { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
  797. exit (1) ;
  798. } ;
  799. if (sfinfo.frames != items)
  800. { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
  801. exit (1) ;
  802. } ;
  803. if (sfinfo.channels != 1)
  804. { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
  805. exit (1) ;
  806. } ;
  807. check_log_buffer_or_die (file, __LINE__) ;
  808. sf_command (file, SFC_SET_NORM_FLOAT, NULL, SF_FALSE) ;
  809. test_read_float_or_die (file, 0, float_in, items, __LINE__) ;
  810. for (k = 0 ; k < items ; k++)
  811. if (fabs (float_out [k] - float_in [k]) > 1e-10)
  812. { printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, (double) float_out [k], (double) float_in [k]) ;
  813. exit (1) ;
  814. } ;
  815. sf_close (file) ;
  816. /*--------------------------------------------------------------------------
  817. ** Test sf_read/write_double ()
  818. */
  819. zero_count = 0 ;
  820. double_out = data_out.d ;
  821. double_in = data_in.d ;
  822. for (k = 0 ; k < items ; k++)
  823. { double_out [k] = (k * ((k % 2) ? 333333 : -333333)) ;
  824. zero_count = (fabs (double_out [k]) > 1e-10) ? zero_count : zero_count + 1 ;
  825. } ;
  826. if (zero_count > items / 4)
  827. { printf ("\n\nLine %d: too many zeros (%d/%d).\n", __LINE__, zero_count, items) ;
  828. exit (1) ;
  829. } ;
  830. sfinfo.samplerate = 44100 ;
  831. sfinfo.frames = 123456789 ; /* Wrong length. Library should correct this on sf_close. */
  832. sfinfo.channels = 1 ;
  833. sfinfo.format = filetype ;
  834. file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
  835. sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
  836. test_write_double_or_die (file, 0, double_out, items, __LINE__) ;
  837. sf_close (file) ;
  838. memset (double_in, 0, items * sizeof (double)) ;
  839. file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  840. if (sfinfo.format != filetype)
  841. { printf ("\n\nLine %d: Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, filetype, sfinfo.format) ;
  842. exit (1) ;
  843. } ;
  844. if (sfinfo.frames != items)
  845. { printf ("\n\nLine %d: Incorrect number of frames in file. (%d => %ld)\n", __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
  846. exit (1) ;
  847. } ;
  848. if (sfinfo.channels != 1)
  849. { printf ("\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ;
  850. exit (1) ;
  851. } ;
  852. check_log_buffer_or_die (file, __LINE__) ;
  853. sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
  854. test_read_double_or_die (file, 0, double_in, items, __LINE__) ;
  855. for (k = 0 ; k < items ; k++)
  856. if (fabs (double_out [k] - double_in [k]) > 1e-10)
  857. { printf ("\n\nLine %d: double : Incorrect sample (#%d : %f => %f).\n", __LINE__, k, double_out [k], double_in [k]) ;
  858. exit (1) ;
  859. } ;
  860. sf_close (file) ;
  861. /* Lite remove end */
  862. unlink (filename) ;
  863. puts ("ok") ;
  864. } /* pcm_test_bits_32 */
  865. /*==============================================================================
  866. */
  867. static void
  868. pcm_test_float (const char *filename, int filetype, uint64_t hash, int replace_float)
  869. { SNDFILE *file ;
  870. SF_INFO sfinfo ;
  871. int k, items, frames ;
  872. int sign ;
  873. double *data, error ;
  874. print_test_name (replace_float ? "pcm_test_float (replace)" : "pcm_test_float", filename) ;
  875. items = BUFFER_SIZE ;
  876. data = data_out.d ;
  877. for (sign = 1, k = 0 ; k < items ; k++)
  878. { data [k] = ((double) (k * sign)) / 100.0 ;
  879. sign = (sign > 0) ? -1 : 1 ;
  880. } ;
  881. sfinfo.samplerate = 44100 ;
  882. sfinfo.frames = items ;
  883. sfinfo.channels = 1 ;
  884. sfinfo.format = filetype ;
  885. file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
  886. sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
  887. if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
  888. { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
  889. dump_log_buffer (file) ;
  890. exit (1) ;
  891. } ;
  892. test_write_double_or_die (file, 0, data, items, __LINE__) ;
  893. sf_close (file) ;
  894. check_file_hash_or_die (filename, hash, __LINE__) ;
  895. memset (data, 0, items * sizeof (double)) ;
  896. if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
  897. memset (&sfinfo, 0, sizeof (sfinfo)) ;
  898. file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  899. sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
  900. if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
  901. { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
  902. dump_log_buffer (file) ;
  903. exit (1) ;
  904. } ;
  905. if (sfinfo.format != filetype)
  906. { printf ("\n\nError (%s:%d) Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ;
  907. exit (1) ;
  908. } ;
  909. if (sfinfo.frames != items)
  910. { printf ("\n\nError (%s:%d) Mono : Incorrect number of frames in file. (%d => %ld)\n", __FILE__, __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
  911. exit (1) ;
  912. } ;
  913. if (sfinfo.channels != 1)
  914. { printf ("\n\nError (%s:%d) Mono : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
  915. exit (1) ;
  916. } ;
  917. check_log_buffer_or_die (file, __LINE__) ;
  918. test_read_double_or_die (file, 0, data, items, __LINE__) ;
  919. for (sign = -1, k = 0 ; k < items ; k++)
  920. { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
  921. if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
  922. { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
  923. exit (1) ;
  924. } ;
  925. } ;
  926. /* Seek to start of file. */
  927. test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
  928. test_read_double_or_die (file, 0, data, 4, __LINE__) ;
  929. for (k = 0 ; k < 4 ; k++)
  930. { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
  931. if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
  932. { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
  933. exit (1) ;
  934. } ;
  935. } ;
  936. /* Seek to offset from start of file. */
  937. test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
  938. test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
  939. for (k = 10 ; k < 14 ; k++)
  940. { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
  941. if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
  942. { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
  943. exit (1) ;
  944. } ;
  945. } ;
  946. /* Seek to offset from current position. */
  947. test_seek_or_die (file, 6, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
  948. test_read_double_or_die (file, 0, data + 20, 4, __LINE__) ;
  949. for (k = 20 ; k < 24 ; k++)
  950. { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
  951. if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
  952. { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
  953. exit (1) ;
  954. } ;
  955. } ;
  956. /* Seek to offset from end of file. */
  957. test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
  958. test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
  959. for (k = 10 ; k < 14 ; k++)
  960. { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
  961. if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
  962. { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
  963. exit (1) ;
  964. } ;
  965. } ;
  966. sf_close (file) ;
  967. /* Now test Stereo. */
  968. if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_SVX) /* SVX is mono only */
  969. { printf ("ok\n") ;
  970. return ;
  971. } ;
  972. items = BUFFER_SIZE ;
  973. data = data_out.d ;
  974. for (sign = -1, k = 0 ; k < items ; k++)
  975. data [k] = ((double) k) / 100.0 * (sign *= -1) ;
  976. sfinfo.samplerate = 44100 ;
  977. sfinfo.frames = items ;
  978. sfinfo.channels = 2 ;
  979. sfinfo.format = filetype ;
  980. frames = items / sfinfo.channels ;
  981. file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
  982. sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
  983. if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
  984. { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
  985. dump_log_buffer (file) ;
  986. exit (1) ;
  987. } ;
  988. test_writef_double_or_die (file, 0, data, frames, __LINE__) ;
  989. sf_close (file) ;
  990. check_file_hash_or_die (filename, hash, __LINE__) ;
  991. memset (data, 0, items * sizeof (double)) ;
  992. if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
  993. memset (&sfinfo, 0, sizeof (sfinfo)) ;
  994. file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  995. sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
  996. if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
  997. { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
  998. dump_log_buffer (file) ;
  999. exit (1) ;
  1000. } ;
  1001. if (sfinfo.format != filetype)
  1002. { printf ("\n\nError (%s:%d) Stereo : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ;
  1003. exit (1) ;
  1004. } ;
  1005. if (sfinfo.frames != frames)
  1006. { printf ("\n\nError (%s:%d) Stereo : Incorrect number of frames in file. (%d => %ld)\n", __FILE__, __LINE__, frames, SF_COUNT_TO_LONG (sfinfo.frames)) ;
  1007. exit (1) ;
  1008. } ;
  1009. if (sfinfo.channels != 2)
  1010. { printf ("\n\nError (%s:%d) Stereo : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
  1011. exit (1) ;
  1012. } ;
  1013. check_log_buffer_or_die (file, __LINE__) ;
  1014. test_readf_double_or_die (file, 0, data, frames, __LINE__) ;
  1015. for (sign = -1, k = 0 ; k < items ; k++)
  1016. { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
  1017. if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
  1018. { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
  1019. exit (1) ;
  1020. } ;
  1021. } ;
  1022. /* Seek to start of file. */
  1023. test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
  1024. test_readf_double_or_die (file, 0, data, 4, __LINE__) ;
  1025. for (k = 0 ; k < 4 ; k++)
  1026. { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
  1027. if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
  1028. { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
  1029. exit (1) ;
  1030. } ;
  1031. } ;
  1032. /* Seek to offset from start of file. */
  1033. test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
  1034. test_readf_double_or_die (file, 0, data + 20, 2, __LINE__) ;
  1035. for (k = 20 ; k < 24 ; k++)
  1036. { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
  1037. if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
  1038. { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
  1039. exit (1) ;
  1040. } ;
  1041. } ;
  1042. /* Seek to offset from current position. */
  1043. test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
  1044. test_readf_double_or_die (file, 0, data + 40, 2, __LINE__) ;
  1045. for (k = 40 ; k < 44 ; k++)
  1046. { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
  1047. if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
  1048. { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
  1049. exit (1) ;
  1050. } ;
  1051. } ;
  1052. /* Seek to offset from end of file. */
  1053. test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
  1054. test_readf_double_or_die (file, 0, data + 20, 2, __LINE__) ;
  1055. for (k = 20 ; k < 24 ; k++)
  1056. { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
  1057. if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
  1058. { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
  1059. exit (1) ;
  1060. } ;
  1061. } ;
  1062. sf_close (file) ;
  1063. printf ("ok\n") ;
  1064. unlink (filename) ;
  1065. } /* pcm_test_float */
  1066. static void
  1067. pcm_test_double (const char *filename, int filetype, uint64_t hash, int replace_float)
  1068. { SNDFILE *file ;
  1069. SF_INFO sfinfo ;
  1070. int k, items, frames ;
  1071. int sign ;
  1072. double *data, error ;
  1073. /* This is the best test routine. Other should be brought up to this standard. */
  1074. print_test_name (replace_float ? "pcm_test_double (replace)" : "pcm_test_double", filename) ;
  1075. items = BUFFER_SIZE ;
  1076. data = data_out.d ;
  1077. for (sign = 1, k = 0 ; k < items ; k++)
  1078. { data [k] = ((double) (k * sign)) / 100.0 ;
  1079. sign = (sign > 0) ? -1 : 1 ;
  1080. } ;
  1081. sfinfo.samplerate = 44100 ;
  1082. sfinfo.frames = items ;
  1083. sfinfo.channels = 1 ;
  1084. sfinfo.format = filetype ;
  1085. file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
  1086. sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
  1087. if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
  1088. { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
  1089. dump_log_buffer (file) ;
  1090. exit (1) ;
  1091. } ;
  1092. test_write_double_or_die (file, 0, data, items, __LINE__) ;
  1093. sf_close (file) ;
  1094. #if (defined (WIN32) || defined (_WIN32))
  1095. /* File hashing on Win32 fails due to slighty different
  1096. ** calculated values of the sin() function.
  1097. */
  1098. hash = hash ; /* Avoid compiler warning. */
  1099. #else
  1100. check_file_hash_or_die (filename, hash, __LINE__) ;
  1101. #endif
  1102. memset (data, 0, items * sizeof (double)) ;
  1103. if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
  1104. memset (&sfinfo, 0, sizeof (sfinfo)) ;
  1105. file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  1106. sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
  1107. if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
  1108. { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
  1109. dump_log_buffer (file) ;
  1110. exit (1) ;
  1111. } ;
  1112. if (sfinfo.format != filetype)
  1113. { printf ("\n\nError (%s:%d) Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ;
  1114. exit (1) ;
  1115. } ;
  1116. if (sfinfo.frames != items)
  1117. { printf ("\n\nError (%s:%d) Mono : Incorrect number of frames in file. (%d => %ld)\n", __FILE__, __LINE__, items, SF_COUNT_TO_LONG (sfinfo.frames)) ;
  1118. exit (1) ;
  1119. } ;
  1120. if (sfinfo.channels != 1)
  1121. { printf ("\n\nError (%s:%d) Mono : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
  1122. exit (1) ;
  1123. } ;
  1124. check_log_buffer_or_die (file, __LINE__) ;
  1125. test_read_double_or_die (file, 0, data, items, __LINE__) ;
  1126. for (sign = -1, k = 0 ; k < items ; k++)
  1127. { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
  1128. if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
  1129. { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
  1130. exit (1) ;
  1131. } ;
  1132. } ;
  1133. /* Seek to start of file. */
  1134. test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
  1135. test_read_double_or_die (file, 0, data, 4, __LINE__) ;
  1136. for (k = 0 ; k < 4 ; k++)
  1137. { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
  1138. if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
  1139. { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
  1140. exit (1) ;
  1141. } ;
  1142. } ;
  1143. /* Seek to offset from start of file. */
  1144. test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
  1145. test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
  1146. test_seek_or_die (file, 0, SEEK_CUR, 14, sfinfo.channels, __LINE__) ;
  1147. for (k = 10 ; k < 14 ; k++)
  1148. { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
  1149. if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
  1150. { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
  1151. exit (1) ;
  1152. } ;
  1153. } ;
  1154. /* Seek to offset from current position. */
  1155. test_seek_or_die (file, 6, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
  1156. test_read_double_or_die (file, 0, data + 20, 4, __LINE__) ;
  1157. for (k = 20 ; k < 24 ; k++)
  1158. { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
  1159. if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
  1160. { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
  1161. exit (1) ;
  1162. } ;
  1163. } ;
  1164. /* Seek to offset from end of file. */
  1165. test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
  1166. test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
  1167. for (k = 10 ; k < 14 ; k++)
  1168. { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
  1169. if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
  1170. { printf ("\n\nError (%s:%d) Mono : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
  1171. exit (1) ;
  1172. } ;
  1173. } ;
  1174. sf_close (file) ;
  1175. /* Now test Stereo. */
  1176. if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_SVX) /* SVX is mono only */
  1177. { printf ("ok\n") ;
  1178. return ;
  1179. } ;
  1180. items = BUFFER_SIZE ;
  1181. data = data_out.d ;
  1182. for (sign = -1, k = 0 ; k < items ; k++)
  1183. data [k] = ((double) k) / 100.0 * (sign *= -1) ;
  1184. sfinfo.samplerate = 44100 ;
  1185. sfinfo.frames = items ;
  1186. sfinfo.channels = 2 ;
  1187. sfinfo.format = filetype ;
  1188. frames = items / sfinfo.channels ;
  1189. file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
  1190. sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
  1191. if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
  1192. { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
  1193. dump_log_buffer (file) ;
  1194. exit (1) ;
  1195. } ;
  1196. test_writef_double_or_die (file, 0, data, frames, __LINE__) ;
  1197. sf_close (file) ;
  1198. #if (defined (WIN32) || defined (_WIN32))
  1199. /* File hashing on Win32 fails due to slighty different
  1200. ** calculated values.
  1201. */
  1202. hash = hash ; /* Avoid compiler warning. */
  1203. #else
  1204. check_file_hash_or_die (filename, hash, __LINE__) ;
  1205. #endif
  1206. memset (data, 0, items * sizeof (double)) ;
  1207. if ((filetype & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW)
  1208. memset (&sfinfo, 0, sizeof (sfinfo)) ;
  1209. file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
  1210. sf_command (file, SFC_TEST_IEEE_FLOAT_REPLACE, NULL, replace_float) ;
  1211. if (replace_float && string_in_log_buffer (file, "Using IEEE replacement") == 0)
  1212. { printf ("\n\nLine %d : Float replacement code not working.\n\n", __LINE__) ;
  1213. dump_log_buffer (file) ;
  1214. exit (1) ;
  1215. } ;
  1216. if (sfinfo.format != filetype)
  1217. { printf ("\n\nError (%s:%d) Stereo : Returned format incorrect (0x%08X => 0x%08X).\n", __FILE__, __LINE__, filetype, sfinfo.format) ;
  1218. exit (1) ;
  1219. } ;
  1220. if (sfinfo.frames != frames)
  1221. { printf ("\n\nError (%s:%d) Stereo : Incorrect number of frames in file. (%d => %ld)\n", __FILE__, __LINE__, frames, SF_COUNT_TO_LONG (sfinfo.frames)) ;
  1222. exit (1) ;
  1223. } ;
  1224. if (sfinfo.channels != 2)
  1225. { printf ("\n\nError (%s:%d) Stereo : Incorrect number of channels in file.\n", __FILE__, __LINE__) ;
  1226. exit (1) ;
  1227. } ;
  1228. check_log_buffer_or_die (file, __LINE__) ;
  1229. test_readf_double_or_die (file, 0, data, frames, __LINE__) ;
  1230. for (sign = -1, k = 0 ; k < items ; k++)
  1231. { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
  1232. if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
  1233. { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
  1234. exit (1) ;
  1235. } ;
  1236. } ;
  1237. /* Seek to start of file. */
  1238. test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
  1239. test_read_double_or_die (file, 0, data, 4, __LINE__) ;
  1240. for (k = 0 ; k < 4 ; k++)
  1241. { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
  1242. if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
  1243. { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
  1244. exit (1) ;
  1245. } ;
  1246. } ;
  1247. /* Seek to offset from start of file. */
  1248. test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ;
  1249. test_read_double_or_die (file, 0, data + 10, 4, __LINE__) ;
  1250. for (k = 20 ; k < 24 ; k++)
  1251. { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
  1252. if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
  1253. { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
  1254. exit (1) ;
  1255. } ;
  1256. } ;
  1257. /* Seek to offset from current position. */
  1258. test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ;
  1259. test_readf_double_or_die (file, 0, data + 40, 4, __LINE__) ;
  1260. for (k = 40 ; k < 44 ; k++)
  1261. { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
  1262. if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
  1263. { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
  1264. exit (1) ;
  1265. } ;
  1266. } ;
  1267. /* Seek to offset from end of file. */
  1268. test_seek_or_die (file, -1 * (sfinfo.frames -10), SEEK_END, 10, sfinfo.channels, __LINE__) ;
  1269. test_readf_double_or_die (file, 0, data + 20, 4, __LINE__) ;
  1270. for (k = 20 ; k < 24 ; k++)
  1271. { error = fabs (data [k] - ((double) k) / 100.0 * (sign *= -1)) ;
  1272. if (fabs (data [k]) > 1e-100 && fabs (error / data [k]) > 1e-5)
  1273. { printf ("\n\nError (%s:%d) Stereo : Incorrect sample (#%d : %f => %f).\n", __FILE__, __LINE__, k, ((double) k) / 100.0, data [k]) ;
  1274. exit (1) ;
  1275. } ;
  1276. } ;
  1277. sf_close (file) ;
  1278. printf ("ok\n") ;
  1279. unlink (filename) ;
  1280. } /* pcm_test_double */
  1281. /*==============================================================================
  1282. */