beats in music

This commit is contained in:
Frank Villaro-Dixon 2015-01-01 12:34:36 +01:00
parent 561aedd930
commit 4eb20ea52c
8 changed files with 316 additions and 5 deletions

8
convert_to_h.sh Executable file
View file

@ -0,0 +1,8 @@
#!/bin/bash
echo 'float mus_beats[] = {'
for line in `cat mus.beats`; do
echo $line,
done
echo '};'

3
game.c
View file

@ -41,8 +41,6 @@ change_game_color(struct s_game *g) {
union color col;
col.col = g->color;
printf("%x - %d %d %d\n", col.col, col.rgb.col[0], col.rgb.col[1], col.rgb.col[2]);
col.rgb.col[from_canal]--;
col.rgb.col[to_canal]++;
@ -53,7 +51,6 @@ change_game_color(struct s_game *g) {
}
g->color = col.col;
puts("changed");
}

13
main.c
View file

@ -11,6 +11,7 @@
#include "game.h"
#include "sdl.h"
#include "obs.h"
#include "music.h"
#include "patterns.h"
@ -29,6 +30,10 @@ start:
while(1) {
SDL_FillRect(ga.screen, NULL, 0);
if(did_have_beat()) {
ga.sexual_pulsation = 60;
puts("Pulse");
}
/*
if(!(ga.counter % 28)) {
@ -57,12 +62,16 @@ start:
ga.general_rotation = ga.counter*3;
ga.sexual_pulsation = 0.3 * fabs(cos(ga.counter*M_PI/45)) + 1 +
0.3 * fabs(sin(ga.counter*M_PI/90));
// ga.sexual_pulsation = 0.3 * fabs(cos(ga.counter*M_PI/45)) + 1 +
// 0.3 * fabs(sin(ga.counter*M_PI/90));
if(!(ga.counter % 10))
change_game_color(&ga);
ga.sexual_pulsation -= 2;
if(ga.sexual_pulsation < 0)
ga.sexual_pulsation = 0;
}
return EXIT_SUCCESS;

120
mus.beats Normal file
View file

@ -0,0 +1,120 @@
3.478971504
3.908721077
4.403935869
4.802079513
5.231328869
5.726398469
6.292892650
6.651166277
7.281341085
7.838964401
8.174127654
8.845021297
9.250352215
9.979038255
10.263189375
10.717596702
11.516638157
11.906187719
12.320373739
12.486463105
13.092972177
13.458849538
13.833720025
14.536104822
14.741685451
14.955862462
15.114124260
15.304128177
15.485349969
16.164889760
16.370940952
16.536728410
16.703110419
16.868993919
17.051304610
17.746002574
17.903978254
18.069505746
18.227990623
18.385867342
18.559098016
18.693787809
19.252436005
19.409790749
19.576902863
19.742827603
19.908818622
20.074708474
20.770184100
20.927291428
21.109685436
21.299194030
21.465285948
21.655520865
22.302186210
22.468318590
22.649564228
22.816768086
22.990643496
23.188521385
23.843267128
24.001009355
24.175080651
24.341629235
24.507805410
24.729735231
25.376552678
25.526366629
25.716080665
25.874346371
26.048735281
26.230810459
26.900772354
27.067036963
27.257092015
27.430609985
27.620737425
27.827840102
28.458482964
28.616059764
28.805939082
28.980286985
29.146212536
29.328634725
29.959476487
30.132907390
30.315087769
30.488907413
30.662347602
30.845392986
31.539602881
31.705751894
31.872098030
32.053844272
32.220097929
32.402418987
33.065130109
33.230875059
33.412743977
33.586377752
33.769063976
33.942760398
34.581584314
34.738743523
34.903622313
35.077701542
35.275951959
35.459199422
36.130339242
36.280349194
36.446580092
36.612444517
36.795051048
37.017111426
37.647930747
37.829569193
38.003692143
38.202124950
38.375920708
38.573240177

BIN
mus.mp3 Normal file

Binary file not shown.

122
mus_beats.h Normal file
View file

@ -0,0 +1,122 @@
float mus_beats[] = {
3.478971504,
3.908721077,
4.403935869,
4.802079513,
5.231328869,
5.726398469,
6.292892650,
6.651166277,
7.281341085,
7.838964401,
8.174127654,
8.845021297,
9.250352215,
9.979038255,
10.263189375,
10.717596702,
11.516638157,
11.906187719,
12.320373739,
12.486463105,
13.092972177,
13.458849538,
13.833720025,
14.536104822,
14.741685451,
14.955862462,
15.114124260,
15.304128177,
15.485349969,
16.164889760,
16.370940952,
16.536728410,
16.703110419,
16.868993919,
17.051304610,
17.746002574,
17.903978254,
18.069505746,
18.227990623,
18.385867342,
18.559098016,
18.693787809,
19.252436005,
19.409790749,
19.576902863,
19.742827603,
19.908818622,
20.074708474,
20.770184100,
20.927291428,
21.109685436,
21.299194030,
21.465285948,
21.655520865,
22.302186210,
22.468318590,
22.649564228,
22.816768086,
22.990643496,
23.188521385,
23.843267128,
24.001009355,
24.175080651,
24.341629235,
24.507805410,
24.729735231,
25.376552678,
25.526366629,
25.716080665,
25.874346371,
26.048735281,
26.230810459,
26.900772354,
27.067036963,
27.257092015,
27.430609985,
27.620737425,
27.827840102,
28.458482964,
28.616059764,
28.805939082,
28.980286985,
29.146212536,
29.328634725,
29.959476487,
30.132907390,
30.315087769,
30.488907413,
30.662347602,
30.845392986,
31.539602881,
31.705751894,
31.872098030,
32.053844272,
32.220097929,
32.402418987,
33.065130109,
33.230875059,
33.412743977,
33.586377752,
33.769063976,
33.942760398,
34.581584314,
34.738743523,
34.903622313,
35.077701542,
35.275951959,
35.459199422,
36.130339242,
36.280349194,
36.446580092,
36.612444517,
36.795051048,
37.017111426,
37.647930747,
37.829569193,
38.003692143,
38.202124950,
38.375920708,
38.573240177,
};

41
music.c Normal file
View file

@ -0,0 +1,41 @@
/*
** 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;
}

14
music.h Normal file
View file

@ -0,0 +1,14 @@
/*
** music.h - <+DESC+>
**
** 2014 - Frank Villaro-Dixon <Frank@Villaro-Dixon.eu>
*/
#ifndef MUSIC_H
#define MUSIC_H
int
did_have_beat(void);
#endif /* ndef MUSIC_H */