/
MuseOSC.h
90 lines (68 loc) · 2.29 KB
/
MuseOSC.h
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
/*
* MuseOSC.h
*
* Created on: 7.7.2015
* Author: Tomas
*/
#ifndef MUSEOSC_H_
#define MUSEOSC_H_
#include "DataSource.h"
#include <vector>
#include <stdexcept>
#include <exception>
#include <thread>
#include <mutex>
#include <condition_variable>
namespace whiteice {
namespace resonanz {
/**
* Receives Muse OSC data from given UDP localhost port
* Currently outputs 8 values
*
* 0-4: delta, theta, alpha, beta, gamma absolute values fitted to [0,1] interval
* 5: total power: sum delta+theta+alpha+beta+gamma
* 6: spectral entropy of power signals [0,1]
* 7: average EEG phase difference between 4 measurement points (TP9, AF7, AF8, TP10)
* phase difference is computed from 250ms long history values
* (256 Hz sampling rate means 64 data points are saved to internal buffer)
*/
class MuseOSC: public DataSource {
public:
MuseOSC(const unsigned int port); // throw(std::runtime_error)
virtual ~MuseOSC();
/*
* Returns unique DataSource name
*/
virtual std::string getDataSourceName() const;
/**
* Returns true if connection and data collection
* to device is currently working.
*/
virtual bool connectionOk() const;
/**
* returns current value
*/
virtual bool data(std::vector<float>& x) const;
virtual bool getSignalNames(std::vector<std::string>& names) const;
virtual unsigned int getNumberOfSignals() const;
virtual bool extradata(std::vector<float>& x) const { x.resize(0); return true; }
virtual unsigned int getExtraNumberOfSignals() const { return 0; }
private:
const unsigned int port;
void muse_loop(); // worker thread loop
// not implemented yet! reads 4 eeg values [TP9, TP10, AF7, AF8]
//bool read_eeg(std::vector< std::vector<float> >& EEG,
// const unsigned int numpoints);
std::thread* worker_thread;
bool running;
bool hasConnection;
std::mutex connection_mutex;
std::condition_variable connection_cond;
float quality; // quality of connection [0,1]
mutable std::mutex data_mutex;
std::vector<float> value; // currently measured value
long long latest_sample_seen_t; // time of the latest measured value
};
} /* namespace resonanz */
} /* namespace whiteice */
#endif /* MUSEOSC_H_ */