Skip to content

Commit f90225f

Browse files
committed
Add support for double-typed buflen to interface.
1 parent d2ec186 commit f90225f

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

include/lsl/inlet.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
* @return A newly created lsl_inlet handle or NULL in the event that an error occurred.
4040
*/
4141
extern LIBLSL_C_API lsl_inlet lsl_create_inlet(lsl_streaminfo info, int32_t max_buflen, int32_t max_chunklen, int32_t recover);
42+
extern LIBLSL_C_API lsl_inlet lsl_create_inlet_d(
43+
lsl_streaminfo info, double max_buflen, int32_t max_chunklen, int32_t recover);
4244

4345
/**
4446
* Destructor.

include/lsl/outlet.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
* @return A newly created lsl_outlet handle or NULL in the event that an error occurred.
3535
*/
3636
extern LIBLSL_C_API lsl_outlet lsl_create_outlet(lsl_streaminfo info, int32_t chunk_size, int32_t max_buffered);
37+
extern LIBLSL_C_API lsl_outlet lsl_create_outlet_d(
38+
lsl_streaminfo info, int32_t chunk_size, double max_buffered);
3739

3840
/**
3941
* Destroy an outlet.

include/lsl_cpp.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,10 @@ class stream_outlet {
400400
: channel_count(info.channel_count()),
401401
sample_rate(info.nominal_srate()),
402402
obj(lsl_create_outlet(info.handle().get(), chunk_size, max_buffered), &lsl_destroy_outlet) {}
403+
stream_outlet(const stream_info &info, int32_t chunk_size, double max_buffered)
404+
: channel_count(info.channel_count()), sample_rate(info.nominal_srate()),
405+
obj(lsl_create_outlet_d(info.handle().get(), chunk_size, max_buffered),
406+
&lsl_destroy_outlet) {}
403407

404408
// ========================================
405409
// === Pushing a sample into the outlet ===
@@ -903,6 +907,11 @@ class stream_inlet {
903907
bool recover = true)
904908
: channel_count(info.channel_count()),
905909
obj(lsl_create_inlet(info.handle().get(), max_buflen, max_chunklen, recover), &lsl_destroy_inlet) {}
910+
stream_inlet(const stream_info &info, double max_buflen, int32_t max_chunklen = 0,
911+
bool recover = true)
912+
: channel_count(info.channel_count()),
913+
obj(lsl_create_inlet_d(info.handle().get(), max_buflen, max_chunklen, recover),
914+
&lsl_destroy_inlet) {}
906915

907916
/// Return a shared pointer to pass to C-API functions that aren't wrapped yet
908917
///

src/lsl_inlet_c.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@ extern "C" {
1414

1515
using namespace lsl;
1616

17-
LIBLSL_C_API lsl_inlet lsl_create_inlet(
18-
lsl_streaminfo info, int32_t max_buflen, int32_t max_chunklen, int32_t recover) {
17+
LIBLSL_C_API lsl_inlet lsl_create_inlet_d(
18+
lsl_streaminfo info, double max_buflen, int32_t max_chunklen, int32_t recover) {
19+
if ((info->nominal_srate() * max_buflen) < 1) max_buflen = 1.5 / info->nominal_srate();
1920
return create_object_noexcept<stream_inlet_impl>(*info,
2021
(info->nominal_srate() ? (int)(info->nominal_srate() * max_buflen) : max_buflen * 100) + 1,
2122
max_chunklen, recover != 0);
2223
}
2324

25+
LIBLSL_C_API lsl_inlet lsl_create_inlet(
26+
lsl_streaminfo info, int32_t max_buflen, int32_t max_chunklen, int32_t recover) {
27+
return lsl_create_inlet_d(info, (double)max_buflen, max_chunklen, recover);
28+
}
29+
2430
LIBLSL_C_API void lsl_destroy_inlet(lsl_inlet in) {
2531
try {
2632
delete in;

src/lsl_outlet_c.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,20 @@ extern "C" {
1515
using namespace lsl;
1616

1717
// boilerplate wrapper code
18-
LIBLSL_C_API lsl_outlet lsl_create_outlet(
19-
lsl_streaminfo info, int32_t chunk_size, int32_t max_buffered) {
18+
LIBLSL_C_API lsl_outlet lsl_create_outlet_d(
19+
lsl_streaminfo info, int32_t chunk_size, double max_buffered) {
2020
double buftime = info->nominal_srate();
2121
if (buftime <= 0) buftime = 100;
22+
if ((buftime * max_buffered) < 1) max_buffered = 1.5 / buftime;
2223
return create_object_noexcept<stream_outlet_impl>(
2324
*info, chunk_size, static_cast<int>(buftime * max_buffered));
2425
}
2526

27+
LIBLSL_C_API lsl_outlet lsl_create_outlet(
28+
lsl_streaminfo info, int32_t chunk_size, int32_t max_buffered) {
29+
return lsl_create_outlet_d(info, chunk_size, (double)max_buffered);
30+
}
31+
2632
LIBLSL_C_API void lsl_destroy_outlet(lsl_outlet out) {
2733
try {
2834
delete out;

0 commit comments

Comments
 (0)