Skip to content

Commit dad9c99

Browse files
committed
Added minimal data sending example
1 parent 5eded5c commit dad9c99

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

examples/SendDataMinimal.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <chrono>
2+
#include <thread>
3+
#include <lsl_cpp.h>
4+
5+
/**
6+
* This is a minimal example of how a multi-channel data stream can be sent to LSL.
7+
* Here, the stream is named SimpleStream, has content-type EEG, 8 channels, and 200 Hz.
8+
* The transmitted samples contain random numbers.
9+
*/
10+
11+
const int nchannels = 8;
12+
13+
int main(int argc, char *argv[]) {
14+
// make a new stream_info and open an outlet with it
15+
lsl::stream_info info("SimpleStream", "EEG", nchannels, 200.0);
16+
lsl::stream_outlet outlet(info);
17+
18+
// send data forever
19+
float sample[nchannels];
20+
while (true) {
21+
// generate random data
22+
for (int c = 0; c < nchannels; c++) sample[c] = (float)((rand() % 1500) / 500.0 - 1.5);
23+
// send it
24+
outlet.push_sample(sample);
25+
// maintain our desired sampling rate (approximately; real software might do something else)
26+
std::this_thread::sleep_for(std::chrono::milliseconds(5));
27+
}
28+
29+
return 0;
30+
}

0 commit comments

Comments
 (0)