tests/utils_tests.h: make sure M_PI and RAND_MAX are defined
[aubio.git] / tests / utils_tests.h
1 #include <time.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <math.h>
5 #include <assert.h>
6 #include "config.h"
7
8 #ifdef HAVE_C99_VARARGS_MACROS
9 #define PRINT_ERR(...)   fprintf(stderr, "AUBIO-TESTS ERROR: " __VA_ARGS__)
10 #define PRINT_MSG(...)   fprintf(stdout, __VA_ARGS__)
11 #define PRINT_DBG(...)   fprintf(stderr, __VA_ARGS__)
12 #define PRINT_WRN(...)   fprintf(stderr, "AUBIO-TESTS WARNING: " __VA_ARGS__)
13 #else
14 #define PRINT_ERR(format, args...)   fprintf(stderr, "AUBIO-TESTS ERROR: " format , ##args)
15 #define PRINT_MSG(format, args...)   fprintf(stdout, format , ##args)
16 #define PRINT_DBG(format, args...)   fprintf(stderr, format , ##args)
17 #define PRINT_WRN(format, args...)   fprintf(stderr, "AUBIO-TESTS WARNING: " format, ##args)
18 #endif
19
20 #ifndef M_PI
21 #define M_PI         (3.14159265358979323846)
22 #endif
23
24 #ifndef RAND_MAX
25 #define RAND_MAX 32767
26 #endif
27
28 #ifdef HAVE_WIN_HACKS
29 // http://en.wikipedia.org/wiki/Linear_congruential_generator
30 // no srandom/random on win32
31
32 uint_t srandom_seed = 1029;
33
34 void srandom(uint_t new_seed) {
35     srandom_seed = new_seed;
36 }
37
38 uint_t random(void) {
39     srandom_seed = 1664525 * srandom_seed + 1013904223;
40     return srandom_seed;
41 }
42 #endif
43
44 void utils_init_random (void);
45
46 void utils_init_random (void) {
47   time_t now = time(0);
48   struct tm *tm_struct = localtime(&now);
49   int seed = tm_struct->tm_sec;
50   //PRINT_WRN("current seed: %d\n", seed);
51   srandom (seed);
52 }