utils.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. ** Copyright (C) 2002-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. /*
  19. ** Utility functions to make writing the test suite easier.
  20. **
  21. ** The .c and .h files were generated automagically with Autogen from
  22. ** the files utils.def and utils.tpl.
  23. */
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif /* __cplusplus */
  27. #include <stdint.h>
  28. #include <stdarg.h>
  29. #define SF_COUNT_TO_LONG(x) ((long) (x))
  30. #define ARRAY_LEN(x) ((int) (sizeof (x)) / (sizeof ((x) [0])))
  31. #define SIGNED_SIZEOF(x) ((int64_t) (sizeof (x)))
  32. #define NOT(x) (! (x))
  33. #define PIPE_INDEX(x) ((x) + 500)
  34. #define PIPE_TEST_LEN 12345
  35. void gen_windowed_sine_float (float *data, int len, double maximum) ;
  36. void gen_windowed_sine_double (double *data, int len, double maximum) ;
  37. void create_short_sndfile (const char *filename, int format, int channels) ;
  38. void check_file_hash_or_die (const char *filename, uint64_t target_hash, int line_num) ;
  39. void print_test_name (const char *test, const char *filename) ;
  40. void dump_data_to_file (const char *filename, const void *data, unsigned int datalen) ;
  41. void write_mono_file (const char * filename, int format, int srate, float * output, int len) ;
  42. static inline void
  43. exit_if_true (int test, const char *format, ...)
  44. { if (test)
  45. { va_list argptr ;
  46. va_start (argptr, format) ;
  47. vprintf (format, argptr) ;
  48. va_end (argptr) ;
  49. exit (1) ;
  50. } ;
  51. } /* exit_if_true */
  52. /*
  53. ** Functions for saving two vectors of data in an ascii text file which
  54. ** can then be loaded into GNU octave for comparison.
  55. */
  56. int oct_save_short (const short *a, const short *b, int len) ;
  57. int oct_save_int (const int *a, const int *b, int len) ;
  58. int oct_save_float (const float *a, const float *b, int len) ;
  59. int oct_save_double (const double *a, const double *b, int len) ;
  60. void delete_file (int format, const char *filename) ;
  61. void count_open_files (void) ;
  62. void increment_open_file_count (void) ;
  63. void check_open_file_count_or_die (int lineno) ;
  64. #ifdef SNDFILE_H
  65. static inline void
  66. sf_info_clear (SF_INFO * info)
  67. { memset (info, 0, sizeof (SF_INFO)) ;
  68. } /* sf_info_clear */
  69. static inline void
  70. sf_info_setup (SF_INFO * info, int format, int samplerate, int channels)
  71. { sf_info_clear (info) ;
  72. info->format = format ;
  73. info->samplerate = samplerate ;
  74. info->channels = channels ;
  75. } /* sf_info_setup */
  76. void dump_log_buffer (SNDFILE *file) ;
  77. void check_log_buffer_or_die (SNDFILE *file, int line_num) ;
  78. int string_in_log_buffer (SNDFILE *file, const char *s) ;
  79. void hexdump_file (const char * filename, sf_count_t offset, sf_count_t length) ;
  80. SNDFILE *test_open_file_or_die
  81. (const char *filename, int mode, SF_INFO *sfinfo, int allow_fd, int line_num) ;
  82. void test_read_write_position_or_die
  83. (SNDFILE *file, int line_num, int pass, sf_count_t read_pos, sf_count_t write_pos) ;
  84. void test_seek_or_die
  85. (SNDFILE *file, sf_count_t offset, int whence, sf_count_t new_pos, int channels, int line_num) ;
  86. void test_read_short_or_die
  87. (SNDFILE *file, int pass, short *test, sf_count_t items, int line_num) ;
  88. void test_read_int_or_die
  89. (SNDFILE *file, int pass, int *test, sf_count_t items, int line_num) ;
  90. void test_read_float_or_die
  91. (SNDFILE *file, int pass, float *test, sf_count_t items, int line_num) ;
  92. void test_read_double_or_die
  93. (SNDFILE *file, int pass, double *test, sf_count_t items, int line_num) ;
  94. void test_readf_short_or_die
  95. (SNDFILE *file, int pass, short *test, sf_count_t frames, int line_num) ;
  96. void test_readf_int_or_die
  97. (SNDFILE *file, int pass, int *test, sf_count_t frames, int line_num) ;
  98. void test_readf_float_or_die
  99. (SNDFILE *file, int pass, float *test, sf_count_t frames, int line_num) ;
  100. void test_readf_double_or_die
  101. (SNDFILE *file, int pass, double *test, sf_count_t frames, int line_num) ;
  102. void
  103. test_read_raw_or_die (SNDFILE *file, int pass, void *test, sf_count_t items, int line_num) ;
  104. void test_write_short_or_die
  105. (SNDFILE *file, int pass, const short *test, sf_count_t items, int line_num) ;
  106. void test_write_int_or_die
  107. (SNDFILE *file, int pass, const int *test, sf_count_t items, int line_num) ;
  108. void test_write_float_or_die
  109. (SNDFILE *file, int pass, const float *test, sf_count_t items, int line_num) ;
  110. void test_write_double_or_die
  111. (SNDFILE *file, int pass, const double *test, sf_count_t items, int line_num) ;
  112. void test_writef_short_or_die
  113. (SNDFILE *file, int pass, const short *test, sf_count_t frames, int line_num) ;
  114. void test_writef_int_or_die
  115. (SNDFILE *file, int pass, const int *test, sf_count_t frames, int line_num) ;
  116. void test_writef_float_or_die
  117. (SNDFILE *file, int pass, const float *test, sf_count_t frames, int line_num) ;
  118. void test_writef_double_or_die
  119. (SNDFILE *file, int pass, const double *test, sf_count_t frames, int line_num) ;
  120. void
  121. test_write_raw_or_die (SNDFILE *file, int pass, const void *test, sf_count_t items, int line_num) ;
  122. void compare_short_or_die (const short *left, const short *right, unsigned count, int line_num) ;
  123. void compare_int_or_die (const int *left, const int *right, unsigned count, int line_num) ;
  124. void compare_float_or_die (const float *left, const float *right, unsigned count, int line_num) ;
  125. void compare_double_or_die (const double *left, const double *right, unsigned count, int line_num) ;
  126. void gen_lowpass_noise_float (float *data, int len) ;
  127. sf_count_t file_length (const char * fname) ;
  128. sf_count_t file_length_fd (int fd) ;
  129. #endif
  130. #ifdef __cplusplus
  131. } /* extern "C" */
  132. #endif /* __cplusplus */