/
MuseOSCSampler.cpp
110 lines (80 loc) · 2.42 KB
/
MuseOSCSampler.cpp
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "MuseOSCSampler.h"
#include <stdio.h>
#include <stdlib.h>
#include <string>
static MuseOSCSampler* __sampler_instance = NULL;
void muse_error(int num, const char* m, const char *path){
if(__sampler_instance) __sampler_instance->error(num, m, path);
}
int muse_eeg_handler(const char *path, const char *types, lo_arg ** argv,
int argc, void *data, void *user_data)
{
if(__sampler_instance)
return __sampler_instance->eeg_handler(path, types, argv, argc,
data, user_data);
}
int muse_quantization_handler(const char *path, const char *types,
lo_arg ** argv,
int argc, void *data, void *user_data)
{
if(__sampler_instance)
return __sampler_instance->quantization_handler(path, types, argv, argc,
data, user_data);
}
MuseOSCSampler::MuseOSCSampler(const std::string& bind_address)
{
__sampler_instance = this;
st = lo_server_thread_new(bind_address.c_str(), muse_error);
lo_server_thread_add_method(st, "/muse/eeg", "ffff",
muse_eeg_handler, NULL);
lo_server_thread_add_method(st, "/muse/eeg/quantization", "iiii",
muse_quantization_handler, NULL);
}
MuseOSCSampler::~MuseOSCSampler() throw()
{
__sampler_instance = NULL;
lo_server_thread_free(st);
}
// handles EEG ffff OSC messages
int MuseOSCSampler::eeg_handler(const char *path, const char *types,
lo_arg ** argv, int argc, void *data,
void *user_data)
{
int i;
printf("path: <%s>\n", path);
for (i = 0; i < argc; i++) {
printf("arg %d '%c' ", i, types[i]);
lo_arg_pp((lo_type)types[i], argv[i]);
printf("\n");
}
printf("\n");
fflush(stdout);
// TODO: properly sample and process EEG-data
// store Muse EEG samples for 1 sec long buffer (220 Hz)
return 0;
}
// handles EEG ffff OSC messages
int MuseOSCSampler::quantization_handler(const char *path,
const char *types,
lo_arg ** argv,
int argc, void *data,
void *user_data)
{
int i;
printf("path: <%s>\n", path);
for (i = 0; i < argc; i++) {
printf("arg %d '%c' ", i, types[i]);
lo_arg_pp((lo_type)types[i], argv[i]);
printf("\n");
}
printf("\n");
fflush(stdout);
// TODO: properly sample and process EEG-data
// store Muse EEG quantization that is always used
// to multiply EEG filters
return 0;
}
void MuseOSCSampler::error(int num, const char* m, const char *path)
{
// silently ignores all errors
}