rotagon/music.c
Frank Villaro-Dixon 4eb20ea52c beats in music
2015-01-01 12:34:36 +01:00

41 lines
795 B
C

/*
** music.c - <+DESC+>
**
** 2014 - Frank Villaro-Dixon <Frank@Villaro-Dixon.eu>
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <time.h>
#include "game.h"
#include "mus_beats.h"
int
did_have_beat(void) {
static struct timespec start_time;
static int inited = 0;
static int already_done = 0;
if(!inited) {
inited = 1;
clock_gettime(CLOCK_REALTIME, &start_time);
}
struct timespec actual_time;
clock_gettime(CLOCK_REALTIME, &actual_time);
float secs_passed = actual_time.tv_sec - start_time.tv_sec +
(actual_time.tv_nsec - start_time.tv_nsec) / 1e9;
// printf("Secs passed: %lf, actual: %lf\n", secs_passed, mus_beats[already_done]);
if(mus_beats[already_done] < secs_passed) {
already_done++;
return 1;
}
return 0;
}