2
0

checksum_test.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. ** Copyright (C) 2008-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. #include <sndfile.h>
  24. #include "utils.h"
  25. #define SAMPLE_RATE 8000
  26. typedef struct
  27. { int enc_fmt ;
  28. const char * enc_name ;
  29. const char * dec_name ;
  30. uint64_t enc_cksum ;
  31. uint64_t dec_cksum ;
  32. } CHECKSUM ;
  33. static CHECKSUM
  34. checksum_orig [] =
  35. {
  36. { SF_FORMAT_RAW | SF_FORMAT_ULAW,
  37. "checksum.ulaw", "cksum_ulaw.pcm16",
  38. 0x33aefae029e0c888LL, 0x595cd6e47edd0cffLL
  39. },
  40. { SF_FORMAT_RAW | SF_FORMAT_ALAW,
  41. "checksum.alaw", "cksum_alaw.pcm16",
  42. 0x48c798da3572d468LL, 0x6837d74869af5bb6LL
  43. },
  44. { SF_FORMAT_RAW | SF_FORMAT_GSM610,
  45. "checksum.gsm", "cksum_gsm.pcm16",
  46. 0x1b1f64ff2acf858fLL, 0x504179dbadd4bce6LL
  47. },
  48. { SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM,
  49. "checksum.vox", "cksum_vox.pcm16",
  50. 0xf1147fb3a298f4dfLL, 0xfc9c0cb8b12cb0abLL
  51. },
  52. } ;
  53. static void checksum_test (const CHECKSUM * cksum) ;
  54. static float orig [1 << 14] ;
  55. static short data [1 << 14] ;
  56. int
  57. main (void)
  58. { unsigned k ;
  59. gen_windowed_sine_float (orig, ARRAY_LEN (orig), 0.9) ;
  60. for (k = 0 ; k < ARRAY_LEN (checksum_orig) ; k++)
  61. checksum_test (&checksum_orig [k]) ;
  62. return 0 ;
  63. } /* main */
  64. /*==============================================================================
  65. */
  66. static void
  67. checksum_test (const CHECKSUM * cksum)
  68. { SNDFILE * file ;
  69. SF_INFO info ;
  70. print_test_name (__func__, cksum->enc_name) ;
  71. info.format = cksum->enc_fmt ;
  72. info.channels = 1 ;
  73. info.samplerate = SAMPLE_RATE ;
  74. file = test_open_file_or_die (cksum->enc_name, SFM_WRITE, &info, 0, __LINE__) ;
  75. test_write_float_or_die (file, 0, orig, ARRAY_LEN (orig), __LINE__) ;
  76. sf_close (file) ;
  77. check_file_hash_or_die (cksum->enc_name, cksum->enc_cksum, __LINE__) ;
  78. puts ("ok") ;
  79. /*------------------------------------------------------------------------*/
  80. print_test_name (__func__, cksum->dec_name) ;
  81. info.format = cksum->enc_fmt ;
  82. info.channels = 1 ;
  83. info.samplerate = SAMPLE_RATE ;
  84. file = test_open_file_or_die (cksum->enc_name, SFM_READ, &info, 0, __LINE__) ;
  85. test_read_short_or_die (file, 0, data, ARRAY_LEN (data), __LINE__) ;
  86. sf_close (file) ;
  87. info.format = SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_16 ;
  88. info.channels = 1 ;
  89. info.samplerate = SAMPLE_RATE ;
  90. file = test_open_file_or_die (cksum->dec_name, SFM_WRITE, &info, 0, __LINE__) ;
  91. test_write_short_or_die (file, 0, data, ARRAY_LEN (data), __LINE__) ;
  92. sf_close (file) ;
  93. check_file_hash_or_die (cksum->dec_name, cksum->dec_cksum, __LINE__) ;
  94. remove (cksum->enc_name) ;
  95. remove (cksum->dec_name) ;
  96. puts ("ok") ;
  97. } /* checksum_test */