Skip to content

Commit 2ad59f1

Browse files
author
David Medine
committed
implemented set_postprocessing
1 parent 4fd9b7d commit 2ad59f1

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

lsl_inlet.m

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
methods
1818

19-
function self = lsl_inlet(info, maxbuffered, chunksize, recover)
19+
function self = lsl_inlet(info, maxbuffered, chunksize, recover, process)
2020
% Inlet = lsl_inlet(Streaminfo, MaxBuffered, ChunkSize, Recover)
2121
% Construct a new stream inlet from a resolved stream info.
2222
%
@@ -38,10 +38,12 @@
3838
% In all other cases (recover is false or the stream is not recoverable) functions may throw a
3939
% lost_error if the stream's source is lost (e.g., due to an app or computer crash).
4040
% (default: 1)
41+
%
42+
4143

4244
if ~exist('maxbuffered','var') || isempty(maxbuffered) maxbuffered = 360; end
4345
if ~exist('chunksize','var') || isempty(chunksize) chunksize = 0; end
44-
if ~exist('recover','var') || isempty(recover) recover = 1; end
46+
if ~exist('recover','var') || isempty(recover) recover = 1; end
4547
self.LibHandle = info.LibHandle;
4648
self.ChannelCount = info.channel_count();
4749
self.IsString = strcmp(info.channel_format(),'cf_string');
@@ -124,6 +126,25 @@ function close_stream(self)
124126
result = lsl_time_correction(self.LibHandle, self.InletHandle,timeout);
125127
end
126128

129+
function result = set_postprocessing(self, processing_flags)
130+
% Set timestamp correction postprocessing flags. This should
131+
% only be done in online scenarios. This option will destroy a
132+
% stream's original, ground-truth timestamps.
133+
%
134+
% In:
135+
% processing_flags :
136+
% 0 : no automatic post_processing
137+
% 1 : perform automatic clock synchronization
138+
% 2 : remove jitter from time stamps
139+
% 4 : force time-stamps to be monotonically ascending (only makes sense if also dejittered)
140+
% 8 : post-processing is threadsafe (same inlet can be read from by multiple threads)
141+
% 15 : combination of all options
142+
% These options can be combined by adding them
143+
% (default: proc_none)
144+
if ~exist('processing_flags','var') || isempty(processing_flags) processing_flags = 0; end
145+
lsl_set_postprocessing(self.LibHandle, self.InletHandle, processing_flags);
146+
end
147+
127148

128149
function [data,timestamp] = pull_sample(self,timeout,binary_blobs)
129150
% Pull a sample from the inlet and read it into an array of values.

mex/lsl_loadlib_.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray*prhs[]) {
109109
lsl_set_child_value_t lsl_set_child_value;
110110
lsl_set_name_t lsl_set_name;
111111
lsl_set_value_t lsl_set_value;
112+
lsl_set_postprocessing_t lsl_set_postprocessing;
112113
lsl_append_child_t lsl_append_child;
113114
lsl_prepend_child_t lsl_prepend_child;
114115
lsl_append_copy_t lsl_append_copy;
@@ -127,7 +128,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray*prhs[]) {
127128
"lsl_pull_sample_i", "lsl_pull_sample_s", "lsl_pull_sample_c", "lsl_pull_sample_str", "lsl_pull_sample_buf", "lsl_pull_sample_v", "lsl_samples_available", "lsl_first_child", "lsl_last_child", "lsl_next_sibling", "lsl_previous_sibling",
128129
"lsl_parent", "lsl_child", "lsl_next_sibling_n", "lsl_previous_sibling_n", "lsl_empty", "lsl_is_text", "lsl_name", "lsl_value", "lsl_child_value", "lsl_child_value_n", "lsl_append_child_value",
129130
"lsl_prepend_child_value", "lsl_set_child_value", "lsl_set_name", "lsl_set_value", "lsl_append_child", "lsl_prepend_child", "lsl_append_copy", "lsl_prepend_copy", "lsl_remove_child_n",
130-
"lsl_remove_child"};
131+
"lsl_remove_child", "lsl_set_postprocessing"};
131132

132133
mxArray *tmp;
133134

@@ -240,6 +241,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray*prhs[]) {
240241
lsl_set_child_value = (lsl_set_child_value_t)LOAD_FUNCTION(hlib,"lsl_set_child_value");
241242
lsl_set_name = (lsl_set_name_t)LOAD_FUNCTION(hlib,"lsl_set_name");
242243
lsl_set_value = (lsl_set_value_t)LOAD_FUNCTION(hlib,"lsl_set_value");
244+
lsl_set_postprocessing = (lsl_set_postprocessing_t)LOAD_FUNCTION(hlib,"lsl_set_postprocessing");
243245
lsl_append_child = (lsl_append_child_t)LOAD_FUNCTION(hlib,"lsl_append_child");
244246
lsl_prepend_child = (lsl_prepend_child_t)LOAD_FUNCTION(hlib,"lsl_prepend_child");
245247
lsl_append_copy = (lsl_append_copy_t)LOAD_FUNCTION(hlib,"lsl_append_copy");
@@ -338,6 +340,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray*prhs[]) {
338340
tmp = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(tmp) = (uintptr_t)lsl_set_child_value; mxSetField(plhs[0],0,"lsl_set_child_value",tmp);
339341
tmp = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(tmp) = (uintptr_t)lsl_set_name; mxSetField(plhs[0],0,"lsl_set_name",tmp);
340342
tmp = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(tmp) = (uintptr_t)lsl_set_value; mxSetField(plhs[0],0,"lsl_set_value",tmp);
343+
tmp = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(tmp) = (uintptr_t)lsl_set_postprocessing; mxSetField(plhs[0],0,"lsl_set_postprocessing",tmp);
341344
tmp = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(tmp) = (uintptr_t)lsl_append_child; mxSetField(plhs[0],0,"lsl_append_child",tmp);
342345
tmp = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(tmp) = (uintptr_t)lsl_prepend_child; mxSetField(plhs[0],0,"lsl_prepend_child",tmp);
343346
tmp = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(tmp) = (uintptr_t)lsl_append_copy; mxSetField(plhs[0],0,"lsl_append_copy",tmp);

mex/lsl_set_postprocessing.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include "lsl_common.h"
2+
3+
/* function lsl_set_processing(LibHandle,inlet, processing_flags) */
4+
5+
void mexFunction( int nlhs, mxArray *plhs[],
6+
int nrhs, const mxArray *prhs[] )
7+
{
8+
/* handle of the desired field */
9+
mxArray *field;
10+
/* temp pointer */
11+
uintptr_t *pTmp;
12+
/* function handle */
13+
lsl_set_postprocessing_t func;
14+
/* input/output variables */
15+
uintptr_t in;
16+
processing_options_t proc_flag;
17+
18+
if (nrhs != 3)
19+
mexErrMsgTxt("3 input argument(s) required.");
20+
if (nlhs != 0)
21+
mexErrMsgTxt("0 output argument(s) required.");
22+
23+
/* get function handle */
24+
field = mxGetField(prhs[0],0,"lsl_set_postprocessing");
25+
if (!field)
26+
mexErrMsgTxt("The field does not seem to exist.");
27+
pTmp = (uintptr_t*)mxGetData(field);
28+
if (!pTmp)
29+
mexErrMsgTxt("The field seems to be empty.");
30+
func = (lsl_set_postprocessing_t*)*pTmp;
31+
32+
/* get additional inputs */
33+
in = *(uintptr_t*)mxGetData(prhs[1]);
34+
if (mxGetClassID(prhs[2]) != mxDOUBLE_CLASS)
35+
mexErrMsgTxt("The processing flag must be passed as a double.");
36+
proc_flag = (int)*(double*)mxGetData(prhs[2]);
37+
/* invoke & return */
38+
func(in, proc_flag);
39+
}

0 commit comments

Comments
 (0)