[474a573] | 1 | #include <time.h> |
---|
[248da64] | 2 | #include <stdlib.h> |
---|
| 3 | #include <stdio.h> |
---|
[474a573] | 4 | #include <math.h> |
---|
| 5 | #include <assert.h> |
---|
[06dba46] | 6 | #include "config.h" |
---|
[248da64] | 7 | |
---|
[abe67e1] | 8 | #ifdef HAVE_LIMITS_H |
---|
| 9 | #include <limits.h> // PATH_MAX |
---|
| 10 | #endif /* HAVE_LIMITS_H */ |
---|
| 11 | #ifndef PATH_MAX |
---|
| 12 | #define PATH_MAX 1024 |
---|
| 13 | #endif |
---|
| 14 | |
---|
[dc08c4f] | 15 | #ifdef HAVE_C99_VARARGS_MACROS |
---|
| 16 | #define PRINT_ERR(...) fprintf(stderr, "AUBIO-TESTS ERROR: " __VA_ARGS__) |
---|
| 17 | #define PRINT_MSG(...) fprintf(stdout, __VA_ARGS__) |
---|
| 18 | #define PRINT_DBG(...) fprintf(stderr, __VA_ARGS__) |
---|
| 19 | #define PRINT_WRN(...) fprintf(stderr, "AUBIO-TESTS WARNING: " __VA_ARGS__) |
---|
| 20 | #else |
---|
[474a573] | 21 | #define PRINT_ERR(format, args...) fprintf(stderr, "AUBIO-TESTS ERROR: " format , ##args) |
---|
[248da64] | 22 | #define PRINT_MSG(format, args...) fprintf(stdout, format , ##args) |
---|
| 23 | #define PRINT_DBG(format, args...) fprintf(stderr, format , ##args) |
---|
[474a573] | 24 | #define PRINT_WRN(format, args...) fprintf(stderr, "AUBIO-TESTS WARNING: " format, ##args) |
---|
[dc08c4f] | 25 | #endif |
---|
[474a573] | 26 | |
---|
[8b42c7d] | 27 | #ifndef M_PI |
---|
| 28 | #define M_PI (3.14159265358979323846) |
---|
| 29 | #endif |
---|
| 30 | |
---|
| 31 | #ifndef RAND_MAX |
---|
| 32 | #define RAND_MAX 32767 |
---|
| 33 | #endif |
---|
| 34 | |
---|
[da632d3] | 35 | // are we on windows ? or are we using -std=c99 ? |
---|
| 36 | #if defined(HAVE_WIN_HACKS) || defined(__STRICT_ANSI__) |
---|
[06dba46] | 37 | // http://en.wikipedia.org/wiki/Linear_congruential_generator |
---|
| 38 | // no srandom/random on win32 |
---|
| 39 | |
---|
| 40 | uint_t srandom_seed = 1029; |
---|
| 41 | |
---|
| 42 | void srandom(uint_t new_seed) { |
---|
| 43 | srandom_seed = new_seed; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | uint_t random(void) { |
---|
| 47 | srandom_seed = 1664525 * srandom_seed + 1013904223; |
---|
| 48 | return srandom_seed; |
---|
| 49 | } |
---|
| 50 | #endif |
---|
| 51 | |
---|
[158e031] | 52 | void utils_init_random (void); |
---|
| 53 | |
---|
| 54 | void utils_init_random (void) { |
---|
[474a573] | 55 | time_t now = time(0); |
---|
| 56 | struct tm *tm_struct = localtime(&now); |
---|
| 57 | int seed = tm_struct->tm_sec; |
---|
| 58 | //PRINT_WRN("current seed: %d\n", seed); |
---|
| 59 | srandom (seed); |
---|
| 60 | } |
---|
[abe67e1] | 61 | |
---|
| 62 | int run_on_default_sink( int main(int, char**) ) |
---|
| 63 | { |
---|
| 64 | int argc = 2, err; |
---|
| 65 | char* argv[argc]; |
---|
| 66 | char sink_path[PATH_MAX] = "tmp_aubio_XXXXXX"; |
---|
| 67 | int fd = mkstemp(sink_path); |
---|
| 68 | argv[0] = __FILE__; |
---|
| 69 | if (!fd) return 1; |
---|
| 70 | argv[1] = sink_path; |
---|
| 71 | err = main(argc, argv); |
---|
| 72 | unlink(sink_path); |
---|
| 73 | close(fd); |
---|
| 74 | return err; |
---|
| 75 | } |
---|