summaryrefslogtreecommitdiff
path: root/tests/test5/test5.c
blob: a80bf753103bdc3fc908517af3dc1640dfa86187 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <gtk/gtk.h>
#include <stdlib.h>
#include <pthread.h>
#include "gtkvumeter.h"
#include "win_main.h"
#include "compute.h"
#include "capture.h"

gint *audio_vumeter_val, *light_h, *light_s, *light_v, *light_r, *light_g, *light_b; 
void my_process(float *data, size_t nsamples, size_t nchan);

int main (int argc, char **argv) {
	GtkWidget *mainwin;
	gint vals_for_vumeters[7]={0,0,0,0,0,0,0}; //sound,h,s,v,r,g,b
	//Some handy references to the previous array items to make things clear whenever possible
	audio_vumeter_val=vals_for_vumeters+0;
	light_h=vals_for_vumeters+1;
	light_s=vals_for_vumeters+2;
	light_v=vals_for_vumeters+3;
	light_r=vals_for_vumeters+4;
	light_g=vals_for_vumeters+5;
	light_b=vals_for_vumeters+6;

	pthread_t audio_analyzer;

	g_thread_init(NULL);
	gdk_threads_init();
	gdk_threads_enter();
	gtk_init (&argc, &argv);

	mainwin=win_main_build();
	gtk_widget_show_all (mainwin);

	printf("debug : main my_process==%p\n", my_process);
	printf("debug : main (void *)my_process==%p\n", (void *)my_process);
	pthread_create (&audio_analyzer, (void *)NULL, (void *)audio_thread, (void *)my_process);
	g_timeout_add (25, win_main_update_vumeters, (gpointer)vals_for_vumeters);

	gtk_main ();
	gdk_threads_leave();

	return 0;
}

void my_process(float *data, size_t nsamples, size_t nchan) {

	float sound_level;

	sound_level=compute_level(data, nsamples, nchan);

	// Update sound vumeter value (refreshed asynchronously)
	*audio_vumeter_val=(int)(sound_level*100.f);

	// Transfert Function
	audio2hsv_1(*audio_vumeter_val,light_h,light_s,light_v);

	// Conversion
	hsv2rgb(*light_h,*light_s,*light_v,light_r,light_g,light_b);
	
	// Send to DMX
	//TODO
}