Skip to content

Commit

Permalink
Call the appropriate push_chunk function
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesbmi committed Oct 16, 2023
1 parent c4210f9 commit d3b89c1
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions pylsl/pylsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,12 @@ def push_chunk(self, x, timestamp=0.0, pushthrough=True):
# Convert timestamp to corresponding ctype
try:
timestamp_c = c_double(timestamp)
# Select the corresponding push_chunk method
liblsl_push_chunk_func = self.do_push_chunk
except TypeError:
try:
timestamp_c = (c_double * len(timestamp))(*timestamp)
liblsl_push_chunk_func = self.do_push_chunk_n
except TypeError:
raise TypeError(
"timestamp must be a float or an iterable of floats"
Expand All @@ -493,10 +496,14 @@ def push_chunk(self, x, timestamp=0.0, pushthrough=True):
try:
n_values = self.channel_count * len(x)
data_buff = (self.value_type * n_values).from_buffer(x)
handle_error(self.do_push_chunk(self.obj, data_buff,
c_long(n_values),
timestamp_c,
c_int(pushthrough)))
handle_error(
liblsl_push_chunk_func(
self.obj, data_buff,
c_long(n_values),
timestamp_c,
c_int(pushthrough)
)
)
except TypeError:
# don't send empty chunks
if len(x):
Expand All @@ -508,10 +515,14 @@ def push_chunk(self, x, timestamp=0.0, pushthrough=True):
# x is a flattened list of multiplexed values
constructor = self.value_type * len(x)
# noinspection PyCallingNonCallable
handle_error(self.do_push_chunk(self.obj, constructor(*x),
c_long(len(x)),
timestamp_c,
c_int(pushthrough)))
handle_error(
liblsl_push_chunk_func(
self.obj, constructor(*x),
c_long(len(x)),
timestamp_c,
c_int(pushthrough)
)
)
else:
raise ValueError("Each sample must have the same number of channels ("
+ str(self.channel_count) + ").")
Expand Down

0 comments on commit d3b89c1

Please sign in to comment.