checksum_test.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. ** Copyright (C) 2008-2017 Erik de Castro Lopo <[email protected]>
  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. 0xbd99d34ccbe2fLL, 0xda82168ed82e9LL
  39. },
  40. { SF_FORMAT_RAW | SF_FORMAT_ALAW,
  41. "checksum.alaw", "cksum_alaw.pcm16",
  42. 0x0004afddc0fcf4bdLL, 0x2e7320230b88LL
  43. },
  44. { SF_FORMAT_RAW | SF_FORMAT_GSM610,
  45. "checksum.gsm", "cksum_gsm.pcm16",
  46. 0xa06a3faaaf684LL, 0x2d7ff668efeb9LL
  47. },
  48. { SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM,
  49. "checksum.vox", "cksum_vox.pcm16",
  50. 0x7c9d7afdb96a1LL, 0xe540df74a4b14LL
  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. memset (&info, 0, sizeof (info)) ;
  72. info.format = cksum->enc_fmt ;
  73. info.channels = 1 ;
  74. info.samplerate = SAMPLE_RATE ;
  75. file = test_open_file_or_die (cksum->enc_name, SFM_WRITE, &info, 0, __LINE__) ;
  76. test_write_float_or_die (file, 0, orig, ARRAY_LEN (orig), __LINE__) ;
  77. sf_close (file) ;
  78. check_file_hash_or_die (cksum->enc_name, cksum->enc_cksum, __LINE__) ;
  79. puts ("ok") ;
  80. /*------------------------------------------------------------------------*/
  81. print_test_name (__func__, cksum->dec_name) ;
  82. info.format = cksum->enc_fmt ;
  83. info.channels = 1 ;
  84. info.samplerate = SAMPLE_RATE ;
  85. file = test_open_file_or_die (cksum->enc_name, SFM_READ, &info, 0, __LINE__) ;
  86. test_read_short_or_die (file, 0, data, ARRAY_LEN (data), __LINE__) ;
  87. sf_close (file) ;
  88. info.format = SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_16 ;
  89. info.channels = 1 ;
  90. info.samplerate = SAMPLE_RATE ;
  91. file = test_open_file_or_die (cksum->dec_name, SFM_WRITE, &info, 0, __LINE__) ;
  92. test_write_short_or_die (file, 0, data, ARRAY_LEN (data), __LINE__) ;
  93. sf_close (file) ;
  94. check_file_hash_or_die (cksum->dec_name, cksum->dec_cksum, __LINE__) ;
  95. remove (cksum->enc_name) ;
  96. remove (cksum->dec_name) ;
  97. puts ("ok") ;
  98. } /* checksum_test */