diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2012-10-08 22:37:06 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2012-10-09 02:35:54 (GMT) |
commit | 70f861a21b026057b5642ca9c7c9b125acf62be8 (patch) | |
tree | f92476f078b61d1ba0a73b5c19a605b4066685dd /common/Util/Clooper/ttest.c | |
parent | 98a0e16b7d8edae472770dbbc4383029edb844de (diff) |
First try to add code from tamtammini to play sounds
Play notes with physucal keyboard, not with the screen keyboard yet.
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
Diffstat (limited to 'common/Util/Clooper/ttest.c')
-rw-r--r-- | common/Util/Clooper/ttest.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/common/Util/Clooper/ttest.c b/common/Util/Clooper/ttest.c new file mode 100644 index 0000000..9ff3d85 --- /dev/null +++ b/common/Util/Clooper/ttest.c @@ -0,0 +1,53 @@ + +#include <pthread.h> +#include <stdio.h> +#include <time.h> +#include <unistd.h> +#include <sys/time.h> + +double sleeptime = 0.0; +int usleep(int); +static void * threadfn(void * _arg) +{ + double pytime(const struct timeval * tv) + { + return (double) tv->tv_sec + (double) tv->tv_usec / 1000000.0; + } + struct timeval tv0, tv1; + double m = 0.0; + + int loops = 0; + + while (1) + { + gettimeofday(&tv0, 0); + usleep( (int) (sleeptime * 1000000) ); + gettimeofday(&tv1, 0); + double t0 = pytime(&tv0); + double t1 = pytime(&tv1); + if (t1 - t0 > 1.2 * sleeptime) + { + fprintf(stderr, "critical lagginess %lf\n", t1 - t0); + } + if (m < t1 - t0) + { + m = t1 - t0; + fprintf(stderr, "maximum lag %lf\n", m); + } + + if ( ( loops % 100 ) == 0 ) + { + fprintf(stderr, "loop (%lf)\n", t0); + } + ++loops; + } + return NULL; +} +void testtimer(double st) +{ + pthread_t pth; + sleeptime = st; + + pthread_create( &pth, NULL, &threadfn, NULL ); +} + |