/
MuseOSC4.h
87 lines (66 loc) · 2.16 KB
/
MuseOSC4.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
/*
* MuseOSC4.h
*
* 4 channel MuseOSC values reading.
* Assumes headband can read all values from sensors without problems.
*
* Created on: 18.2.2023
* Author: Tomas Ukkonen
*/
#ifndef MUSEOSC4_H_
#define MUSEOSC4_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 25 values = 4 channels and 6 measurements, + total power
*
* delta, theta, alpha, beta, gamma, spectral entropy absolute values fitted to [0,1] interval
* total power: sum delta+theta+alpha+beta+gamma
* spectral entropy: [0,1] interval value, 1 means max entropy (equal distribution), 0 means minimum entropy (single peak)
*
*/
class MuseOSC4: public DataSource {
public:
MuseOSC4(const unsigned int port); // throw(std::runtime_error)
virtual ~MuseOSC4();
/*
* 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
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 /* MUSEOSC4_H_ */