cannam@125
|
1 /*
|
cannam@125
|
2 ** Copyright (C) 2002-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
|
cannam@125
|
3 **
|
cannam@125
|
4 ** This program is free software; you can redistribute it and/or modify
|
cannam@125
|
5 ** it under the terms of the GNU General Public License as published by
|
cannam@125
|
6 ** the Free Software Foundation; either version 2 of the License, or
|
cannam@125
|
7 ** (at your option) any later version.
|
cannam@125
|
8 **
|
cannam@125
|
9 ** This program is distributed in the hope that it will be useful,
|
cannam@125
|
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
cannam@125
|
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
cannam@125
|
12 ** GNU General Public License for more details.
|
cannam@125
|
13 **
|
cannam@125
|
14 ** You should have received a copy of the GNU General Public License
|
cannam@125
|
15 ** along with this program; if not, write to the Free Software
|
cannam@125
|
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
cannam@125
|
17 */
|
cannam@125
|
18
|
cannam@125
|
19 /*
|
cannam@125
|
20 ** Utility functions to make writing the test suite easier.
|
cannam@125
|
21 **
|
cannam@125
|
22 ** The .c and .h files were generated automagically with Autogen from
|
cannam@125
|
23 ** the files utils.def and utils.tpl.
|
cannam@125
|
24 */
|
cannam@125
|
25
|
cannam@125
|
26
|
cannam@125
|
27
|
cannam@125
|
28 #ifdef __cplusplus
|
cannam@125
|
29 extern "C" {
|
cannam@125
|
30 #endif /* __cplusplus */
|
cannam@125
|
31
|
cannam@125
|
32 #include <stdint.h>
|
cannam@125
|
33 #include <stdarg.h>
|
cannam@125
|
34
|
cannam@125
|
35 #define ARRAY_LEN(x) ((int) (sizeof (x)) / (sizeof ((x) [0])))
|
cannam@125
|
36 #define SIGNED_SIZEOF(x) ((int64_t) (sizeof (x)))
|
cannam@125
|
37 #define NOT(x) (! (x))
|
cannam@125
|
38 #define ABS(x) ((x) >= 0 ? (x) : -(x))
|
cannam@125
|
39
|
cannam@125
|
40 #define PIPE_INDEX(x) ((x) + 500)
|
cannam@125
|
41 #define PIPE_TEST_LEN 12345
|
cannam@125
|
42
|
cannam@125
|
43
|
cannam@125
|
44 void gen_windowed_sine_float (float *data, int len, double maximum) ;
|
cannam@125
|
45 void gen_windowed_sine_double (double *data, int len, double maximum) ;
|
cannam@125
|
46
|
cannam@125
|
47
|
cannam@125
|
48 void create_short_sndfile (const char *filename, int format, int channels) ;
|
cannam@125
|
49
|
cannam@125
|
50 void check_file_hash_or_die (const char *filename, uint64_t target_hash, int line_num) ;
|
cannam@125
|
51
|
cannam@125
|
52 void print_test_name (const char *test, const char *filename) ;
|
cannam@125
|
53
|
cannam@125
|
54 void dump_data_to_file (const char *filename, const void *data, unsigned int datalen) ;
|
cannam@125
|
55
|
cannam@125
|
56 void write_mono_file (const char * filename, int format, int srate, float * output, int len) ;
|
cannam@125
|
57
|
cannam@125
|
58 #ifdef __GNUC__
|
cannam@125
|
59 static inline void
|
cannam@125
|
60 exit_if_true (int test, const char *format, ...)
|
cannam@125
|
61 #if (defined (__USE_MINGW_ANSI_STDIO) && __USE_MINGW_ANSI_STDIO)
|
cannam@125
|
62 __attribute__ ((format (gnu_printf, 2, 3))) ;
|
cannam@125
|
63 #else
|
cannam@125
|
64 __attribute__ ((format (printf, 2, 3))) ;
|
cannam@125
|
65 #endif
|
cannam@125
|
66 #endif
|
cannam@125
|
67
|
cannam@125
|
68 static inline void
|
cannam@125
|
69 exit_if_true (int test, const char *format, ...)
|
cannam@125
|
70 { if (test)
|
cannam@125
|
71 { va_list argptr ;
|
cannam@125
|
72 va_start (argptr, format) ;
|
cannam@125
|
73 vprintf (format, argptr) ;
|
cannam@125
|
74 va_end (argptr) ;
|
cannam@125
|
75 exit (1) ;
|
cannam@125
|
76 } ;
|
cannam@125
|
77 } /* exit_if_true */
|
cannam@125
|
78
|
cannam@125
|
79 static inline int32_t
|
cannam@125
|
80 arith_shift_left (int32_t x, int shift)
|
cannam@125
|
81 { return (int32_t) (((uint32_t) x) << shift) ;
|
cannam@125
|
82 } /* arith_shift_left */
|
cannam@125
|
83
|
cannam@125
|
84 /*
|
cannam@125
|
85 ** Functions for saving two vectors of data in an ascii text file which
|
cannam@125
|
86 ** can then be loaded into GNU octave for comparison.
|
cannam@125
|
87 */
|
cannam@125
|
88
|
cannam@125
|
89 int oct_save_short (const short *a, const short *b, int len) ;
|
cannam@125
|
90 int oct_save_int (const int *a, const int *b, int len) ;
|
cannam@125
|
91 int oct_save_float (const float *a, const float *b, int len) ;
|
cannam@125
|
92 int oct_save_double (const double *a, const double *b, int len) ;
|
cannam@125
|
93
|
cannam@125
|
94
|
cannam@125
|
95 void delete_file (int format, const char *filename) ;
|
cannam@125
|
96
|
cannam@125
|
97 void count_open_files (void) ;
|
cannam@125
|
98 void increment_open_file_count (void) ;
|
cannam@125
|
99 void check_open_file_count_or_die (int lineno) ;
|
cannam@125
|
100
|
cannam@125
|
101 #ifdef SNDFILE_H
|
cannam@125
|
102
|
cannam@125
|
103 static inline void
|
cannam@125
|
104 sf_info_clear (SF_INFO * info)
|
cannam@125
|
105 { memset (info, 0, sizeof (SF_INFO)) ;
|
cannam@125
|
106 } /* sf_info_clear */
|
cannam@125
|
107
|
cannam@125
|
108 static inline void
|
cannam@125
|
109 sf_info_setup (SF_INFO * info, int format, int samplerate, int channels)
|
cannam@125
|
110 { sf_info_clear (info) ;
|
cannam@125
|
111
|
cannam@125
|
112 info->format = format ;
|
cannam@125
|
113 info->samplerate = samplerate ;
|
cannam@125
|
114 info->channels = channels ;
|
cannam@125
|
115 } /* sf_info_setup */
|
cannam@125
|
116
|
cannam@125
|
117
|
cannam@125
|
118 void dump_log_buffer (SNDFILE *file) ;
|
cannam@125
|
119 void check_log_buffer_or_die (SNDFILE *file, int line_num) ;
|
cannam@125
|
120 int string_in_log_buffer (SNDFILE *file, const char *s) ;
|
cannam@125
|
121 void hexdump_file (const char * filename, sf_count_t offset, sf_count_t length) ;
|
cannam@125
|
122
|
cannam@125
|
123 void test_sf_format_or_die (const SF_INFO *info, int line_num) ;
|
cannam@125
|
124
|
cannam@125
|
125 SNDFILE *test_open_file_or_die
|
cannam@125
|
126 (const char *filename, int mode, SF_INFO *sfinfo, int allow_fd, int line_num) ;
|
cannam@125
|
127
|
cannam@125
|
128 void test_read_write_position_or_die
|
cannam@125
|
129 (SNDFILE *file, int line_num, int pass, sf_count_t read_pos, sf_count_t write_pos) ;
|
cannam@125
|
130
|
cannam@125
|
131 void test_seek_or_die
|
cannam@125
|
132 (SNDFILE *file, sf_count_t offset, int whence, sf_count_t new_pos, int channels, int line_num) ;
|
cannam@125
|
133
|
cannam@125
|
134
|
cannam@125
|
135 void test_read_short_or_die
|
cannam@125
|
136 (SNDFILE *file, int pass, short *test, sf_count_t items, int line_num) ;
|
cannam@125
|
137 void test_read_int_or_die
|
cannam@125
|
138 (SNDFILE *file, int pass, int *test, sf_count_t items, int line_num) ;
|
cannam@125
|
139 void test_read_float_or_die
|
cannam@125
|
140 (SNDFILE *file, int pass, float *test, sf_count_t items, int line_num) ;
|
cannam@125
|
141 void test_read_double_or_die
|
cannam@125
|
142 (SNDFILE *file, int pass, double *test, sf_count_t items, int line_num) ;
|
cannam@125
|
143
|
cannam@125
|
144 void test_readf_short_or_die
|
cannam@125
|
145 (SNDFILE *file, int pass, short *test, sf_count_t frames, int line_num) ;
|
cannam@125
|
146 void test_readf_int_or_die
|
cannam@125
|
147 (SNDFILE *file, int pass, int *test, sf_count_t frames, int line_num) ;
|
cannam@125
|
148 void test_readf_float_or_die
|
cannam@125
|
149 (SNDFILE *file, int pass, float *test, sf_count_t frames, int line_num) ;
|
cannam@125
|
150 void test_readf_double_or_die
|
cannam@125
|
151 (SNDFILE *file, int pass, double *test, sf_count_t frames, int line_num) ;
|
cannam@125
|
152
|
cannam@125
|
153
|
cannam@125
|
154 void
|
cannam@125
|
155 test_read_raw_or_die (SNDFILE *file, int pass, void *test, sf_count_t items, int line_num) ;
|
cannam@125
|
156
|
cannam@125
|
157
|
cannam@125
|
158 void test_write_short_or_die
|
cannam@125
|
159 (SNDFILE *file, int pass, const short *test, sf_count_t items, int line_num) ;
|
cannam@125
|
160 void test_write_int_or_die
|
cannam@125
|
161 (SNDFILE *file, int pass, const int *test, sf_count_t items, int line_num) ;
|
cannam@125
|
162 void test_write_float_or_die
|
cannam@125
|
163 (SNDFILE *file, int pass, const float *test, sf_count_t items, int line_num) ;
|
cannam@125
|
164 void test_write_double_or_die
|
cannam@125
|
165 (SNDFILE *file, int pass, const double *test, sf_count_t items, int line_num) ;
|
cannam@125
|
166
|
cannam@125
|
167 void test_writef_short_or_die
|
cannam@125
|
168 (SNDFILE *file, int pass, const short *test, sf_count_t frames, int line_num) ;
|
cannam@125
|
169 void test_writef_int_or_die
|
cannam@125
|
170 (SNDFILE *file, int pass, const int *test, sf_count_t frames, int line_num) ;
|
cannam@125
|
171 void test_writef_float_or_die
|
cannam@125
|
172 (SNDFILE *file, int pass, const float *test, sf_count_t frames, int line_num) ;
|
cannam@125
|
173 void test_writef_double_or_die
|
cannam@125
|
174 (SNDFILE *file, int pass, const double *test, sf_count_t frames, int line_num) ;
|
cannam@125
|
175
|
cannam@125
|
176
|
cannam@125
|
177 void
|
cannam@125
|
178 test_write_raw_or_die (SNDFILE *file, int pass, const void *test, sf_count_t items, int line_num) ;
|
cannam@125
|
179
|
cannam@125
|
180 void compare_short_or_die (const short *expected, const short *actual, unsigned count, int line_num) ;
|
cannam@125
|
181 void compare_int_or_die (const int *expected, const int *actual, unsigned count, int line_num) ;
|
cannam@125
|
182 void compare_float_or_die (const float *expected, const float *actual, unsigned count, int line_num) ;
|
cannam@125
|
183 void compare_double_or_die (const double *expected, const double *actual, unsigned count, int line_num) ;
|
cannam@125
|
184
|
cannam@125
|
185
|
cannam@125
|
186
|
cannam@125
|
187 void gen_lowpass_signal_float (float *data, int len) ;
|
cannam@125
|
188
|
cannam@125
|
189 sf_count_t file_length (const char * fname) ;
|
cannam@125
|
190 sf_count_t file_length_fd (int fd) ;
|
cannam@125
|
191
|
cannam@125
|
192 #endif
|
cannam@125
|
193
|
cannam@125
|
194 #ifdef __cplusplus
|
cannam@125
|
195 } /* extern "C" */
|
cannam@125
|
196 #endif /* __cplusplus */
|
cannam@125
|
197
|
cannam@125
|
198
|
cannam@125
|
199
|