summaryrefslogtreecommitdiff
path: root/tests/test5/test5.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test5/test5.c')
-rw-r--r--tests/test5/test5.c213
1 files changed, 47 insertions, 166 deletions
diff --git a/tests/test5/test5.c b/tests/test5/test5.c
index 373efb0..33ec53d 100644
--- a/tests/test5/test5.c
+++ b/tests/test5/test5.c
@@ -1,176 +1,57 @@
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-
#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;
+
+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_v=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);
+
+ pthread_create (&audio_analyzer, (void *)NULL, (void *)audio_thread, (void *)vals_for_vumeters);
+ g_timeout_add (10, win_main_update_vumeters, (gpointer)vals_for_vumeters);
+
+ gtk_main ();
+ gdk_threads_leave();
-#include <pulse/pulseaudio.h>
-#include <pulse/glib-mainloop.h>
-
-#define APP_TITLE "Test 5 lpo"
-#define BUFSIZE 1024
-
-pa_context *context;
-
-void create_stream();
-
-static void stream_state_callback(pa_stream *s, void *unused) {
- switch (pa_stream_get_state(s)) {
- case PA_STREAM_UNCONNECTED:
- case PA_STREAM_CREATING:
- break;
-
- case PA_STREAM_READY:
- printf("PA_STREAM_READY\n");
-/*
- g_assert(!mainWindow);
- mainWindow = new MainWindow(*pa_stream_get_channel_map(s), device_name, device_description);
-
- g_timeout_add(100, latency_func, NULL);
- pa_operation_unref(pa_stream_update_timing_info(stream, stream_update_timing_info_callback, NULL));
-*/
- break;
-
- case PA_STREAM_FAILED:
- printf("PA_STREAM_FAILED\n");
- break;
-
- case PA_STREAM_TERMINATED:
- printf("PA_STREAM_TERMINATED\n");
- //Gtk::Main::quit();
- }
-}
-
-static void context_get_source_info_callback(pa_context *c, const pa_source_info *si, int is_last, void *unused) {
- printf("context_get_source_info_callback\n");
-
- if (is_last < 0) {
- printf("Failed to get source information");
- return;
- }
-
- if (!si)
- return;
-
- create_stream(si->name, si->description, si->sample_spec, si->channel_map);
-}
-
-static void context_get_sink_info_callback(pa_context *c, const pa_sink_info *si, int is_last, void *unused) {
- printf("context_get_sink_info_callback\n");
- if (is_last < 0) {
- printf("Failed to get sink information");
- return;
- }
-
- if (!si)
- return;
-
- create_stream(si->monitor_source_name, si->description, si->sample_spec, si->channel_map);
-}
-
-
-static void stream_read_callback(pa_stream *s, size_t l, void *unused) {
- const void *p;
-
- if (pa_stream_peek(s, &p, &l) < 0) {
- printf("pa_stream_peek() failed: %s", pa_strerror(pa_context_errno(context)));
- return;
- }
-
- printf("%f, %i\n", *((const float*)p), l/sizeof(float));
-
- pa_stream_drop(s);
+ return 0;
}
-static void context_state_callback(pa_context *c, void *unused) {
- switch (pa_context_get_state(c)) {
- case PA_CONTEXT_UNCONNECTED:
- printf("PA_CONTEXT_UNCONNECTED\n");
- break;
- case PA_CONTEXT_CONNECTING:
- printf("PA_CONTEXT_CONNECTING\n");
- break;
- case PA_CONTEXT_AUTHORIZING:
- printf("PA_CONTEXT_AUTHORIZING\n");
- break;
- case PA_CONTEXT_SETTING_NAME:
- printf("PA_CONTEXT_SETTING_NAME\n");
- break;
+void process(gint sound_level, void *userdata) {
- case PA_CONTEXT_READY:
- printf("PA_CONTEXT_READY\n");
- //g_assert(!stream);
+ // Dummy code for audio capture
+ *audio_vumeter_val=sound_level;
- //if (device_name && mode == RECORD)
- //pa_operation_unref(pa_context_get_source_info_by_name(c, device_name, context_get_source_info_callback, NULL));
- /*else if (device_name && mode == PLAYBACK)
- pa_operation_unref(pa_context_get_sink_info_by_name(c, device_name, context_get_sink_info_callback, NULL));
- else
- pa_operation_unref(pa_context_get_server_info(c, context_get_server_info_callback, NULL));
- */
- break;
+ // Transfert Function
+ audio2hsv_1(*audio_vumeter_val,light_h,light_s,light_v);
- case PA_CONTEXT_FAILED:
- printf("PA_CONTEXT_FAILED\n");
- break;
+ // Conversion
+ hsv2rgb(*light_h,*light_s,*light_v,light_r,light_g,light_b);
+
+ // Send to DMX
+ //TODO
- case PA_CONTEXT_TERMINATED:
- printf("PA_CONTEXT_TERMINATED\n");
- break;
- }
}
-void create_stream(const char *name, const char *description, const pa_sample_spec *ss, const pa_channel_map *cmap) {
- /* The sample type to use */
- static const pa_sample_spec nss = {
- .format = PA_SAMPLE_S16LE,
- .rate = 44100,
- .channels = 1
- };
-
- pa_stream *stream=NULL;
- char t[256];
-/*
- g_free(device_name);
- device_name = g_strdup(name);
- g_free(device_description);
- device_description = g_strdup(description);
-*/
-
- printf("Using sample format: %s", pa_sample_spec_snprint(t, sizeof(t), &nss));
- printf("Using channel map: %s", pa_channel_map_snprint(t, sizeof(t), cmap));
-
- stream = pa_stream_new(context, APP_TITLE, &nss, cmap);
- pa_stream_set_state_callback(stream, stream_state_callback, NULL);
- pa_stream_set_read_callback(stream, stream_read_callback, NULL);
- pa_stream_connect_record(stream, name, NULL, (enum pa_stream_flags) 0);
-}
-
-
-int main(int argc, char*argv[]) {
-/*
- int ret = 1;
- int error;
- int i,j;
- float sum;
-*/
- pa_glib_mainloop *m;
-
- m = pa_glib_mainloop_new(g_main_context_default());
-// g_assert(m);
-
- context = pa_context_new(pa_glib_mainloop_get_api(m), APP_TITLE);
-// g_assert(context);
-
- pa_context_set_state_callback(context, context_state_callback, NULL);
- pa_context_connect(context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL);
-
- sleep(60);
-
- return 0;
-}