Debian Codegraph @

src/tests/noise.c

raw
1 #include "config.h"
2 #include "../compat/compat.h"
3 #include "../libmpg123/dither.h"
4 #include "../common/debug.h"
5
6 /* Directly include the code for testing, avoiding
7 build of same object with and without libtool. */
8 #include "../libmpg123/dither_impl.h"
9
10 const char *typenames[] = { "white", "tpdf", "highpass_tpdf" };
11 enum mpg123_noise_type types[] = { mpg123_white_noise, mpg123_tpdf_noise, mpg123_highpass_tpdf_noise };
12
13 int main(int argc, char **argv)
14 {
15 size_t i;
16 size_t count = DITHERSIZE;
17 float *table;
18 enum mpg123_noise_type type = mpg123_highpass_tpdf_noise;
19
20 fprintf(stderr, "Note: You could give two optional arguments: noise type and table size (number count).\n");
21 if(argc > 1)
22 {
23 const char *typename = argv[1];
24 for(i=0; i<sizeof(typenames)/sizeof(char*); ++i)
25 if(strcmp(typename, typenames[i]) == 0)
26 {
27 type = types[i];
28 break;
29 }
30
31 if(i == sizeof(typenames)/sizeof(char*))
32 {
33 error("Unknown noise type!");
34 return -1;
35 }
36 }
37 if(argc > 2)
38 {
39 count = (size_t) atol(argv[2]);
40 }
41
42 table = malloc(sizeof(float)*count);
43 if(table == NULL)
44 {
45 error("Cannot allocate memory for noise table!");
46 return -2;
47 }
48
49 mpg123_noise(table, count, type);
50 for(i=0; i<count; ++i)
51 printf("%g\n", table[i]);
52
53 free(table);
54
55 return 0;
56 }