Skip to content

Commit d891645

Browse files
committed
Further tweak to Chunks examples.
1 parent b044b49 commit d891645

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

examples/ReceiveDataInChunks.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@
44

55

66
int main(int argc, char **argv) {
7+
std::cout << "ReceiveDataInChunks" << std::endl;
8+
std::cout << "ReceiveDataInChunks StreamName max_buflen" << std::endl;
9+
710
try {
811

912
std::string name{argc > 1 ? argv[1] : "MyAudioStream"};
13+
int32_t max_buflen = argc > 2 ? std::stol(argv[2]) : 360;
1014
// resolve the stream of interest & make an inlet
11-
lsl::stream_inlet inlet(lsl::resolve_stream("name", name).at(0));
15+
lsl::stream_inlet inlet(lsl::resolve_stream("name", name).at(0), max_buflen);
1216

1317
inlet.flush();
1418

15-
double starttime = lsl::local_clock(), next_display = starttime + 1;
19+
double starttime = lsl::local_clock(), next_display = starttime + 1,
20+
next_reset = starttime + 10;
1621

1722
// and retrieve the chunks
1823
uint64_t k = 0, num_samples = 0;
@@ -29,7 +34,13 @@ int main(int argc, char **argv) {
2934
std::cout << num_samples / (now - starttime) << " samples/sec" << std::endl;
3035
next_display = now + 1;
3136
}
37+
if (now > next_reset) { std::cout << "Resetting counters..." << std::endl;
38+
starttime = now;
39+
next_reset = now + 10;
40+
num_samples = 0;
41+
}
3242
}
43+
3344
}
3445

3546
} catch (std::exception &e) { std::cerr << "Got an exception: " << e.what() << std::endl; }

examples/SendDataInChunks.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ struct stereo_sample {
1515

1616
// fill buffer with data from device -- Normally your device SDK would provide such a function. Here we use a random number generator.
1717
void get_data_from_device(std::vector<std::vector<int16_t>> buffer, uint64_t &sample_counter) {
18-
static std::uniform_int_distribution<int16_t> distribution(
19-
std::numeric_limits<int16_t>::min(), std::numeric_limits<int16_t>::max());
20-
static std::default_random_engine generator;
18+
//static std::uniform_int_distribution<int16_t> distribution(
19+
// std::numeric_limits<int16_t>::min(), std::numeric_limits<int16_t>::max());
20+
//static std::default_random_engine generator;
2121

2222
if (buffer[0].size() == 2) {
2323
// If there are only 2 channels then we'll do a sine wave, pretending this is an audio device.
@@ -30,7 +30,8 @@ void get_data_from_device(std::vector<std::vector<int16_t>> buffer, uint64_t &sa
3030
else {
3131
for (auto &frame : buffer) {
3232
for (std::size_t chan_idx = 0; chan_idx < frame.size(); ++chan_idx) {
33-
frame[chan_idx] = distribution(generator);
33+
frame[chan_idx] = 23;
34+
// distribution(generator);
3435
}
3536
sample_counter++;
3637
}

0 commit comments

Comments
 (0)