Skip to content

Commit

Permalink
implemented set_postprocessing
Browse files Browse the repository at this point in the history
  • Loading branch information
David Medine committed Jun 4, 2019
1 parent 4fd9b7d commit 2ad59f1
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
25 changes: 23 additions & 2 deletions lsl_inlet.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

methods

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


if ~exist('maxbuffered','var') || isempty(maxbuffered) maxbuffered = 360; end
if ~exist('chunksize','var') || isempty(chunksize) chunksize = 0; end
if ~exist('recover','var') || isempty(recover) recover = 1; end
if ~exist('recover','var') || isempty(recover) recover = 1; end
self.LibHandle = info.LibHandle;
self.ChannelCount = info.channel_count();
self.IsString = strcmp(info.channel_format(),'cf_string');
Expand Down Expand Up @@ -124,6 +126,25 @@ function close_stream(self)
result = lsl_time_correction(self.LibHandle, self.InletHandle,timeout);
end

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


function [data,timestamp] = pull_sample(self,timeout,binary_blobs)
% Pull a sample from the inlet and read it into an array of values.
Expand Down
5 changes: 4 additions & 1 deletion mex/lsl_loadlib_.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray*prhs[]) {
lsl_set_child_value_t lsl_set_child_value;
lsl_set_name_t lsl_set_name;
lsl_set_value_t lsl_set_value;
lsl_set_postprocessing_t lsl_set_postprocessing;
lsl_append_child_t lsl_append_child;
lsl_prepend_child_t lsl_prepend_child;
lsl_append_copy_t lsl_append_copy;
Expand All @@ -127,7 +128,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray*prhs[]) {
"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",
"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",
"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",
"lsl_remove_child"};
"lsl_remove_child", "lsl_set_postprocessing"};

mxArray *tmp;

Expand Down Expand Up @@ -240,6 +241,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray*prhs[]) {
lsl_set_child_value = (lsl_set_child_value_t)LOAD_FUNCTION(hlib,"lsl_set_child_value");
lsl_set_name = (lsl_set_name_t)LOAD_FUNCTION(hlib,"lsl_set_name");
lsl_set_value = (lsl_set_value_t)LOAD_FUNCTION(hlib,"lsl_set_value");
lsl_set_postprocessing = (lsl_set_postprocessing_t)LOAD_FUNCTION(hlib,"lsl_set_postprocessing");
lsl_append_child = (lsl_append_child_t)LOAD_FUNCTION(hlib,"lsl_append_child");
lsl_prepend_child = (lsl_prepend_child_t)LOAD_FUNCTION(hlib,"lsl_prepend_child");
lsl_append_copy = (lsl_append_copy_t)LOAD_FUNCTION(hlib,"lsl_append_copy");
Expand Down Expand Up @@ -338,6 +340,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray*prhs[]) {
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);
tmp = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(tmp) = (uintptr_t)lsl_set_name; mxSetField(plhs[0],0,"lsl_set_name",tmp);
tmp = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(tmp) = (uintptr_t)lsl_set_value; mxSetField(plhs[0],0,"lsl_set_value",tmp);
tmp = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(tmp) = (uintptr_t)lsl_set_postprocessing; mxSetField(plhs[0],0,"lsl_set_postprocessing",tmp);
tmp = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(tmp) = (uintptr_t)lsl_append_child; mxSetField(plhs[0],0,"lsl_append_child",tmp);
tmp = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(tmp) = (uintptr_t)lsl_prepend_child; mxSetField(plhs[0],0,"lsl_prepend_child",tmp);
tmp = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(tmp) = (uintptr_t)lsl_append_copy; mxSetField(plhs[0],0,"lsl_append_copy",tmp);
Expand Down
39 changes: 39 additions & 0 deletions mex/lsl_set_postprocessing.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "lsl_common.h"

/* function lsl_set_processing(LibHandle,inlet, processing_flags) */

void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[] )
{
/* handle of the desired field */
mxArray *field;
/* temp pointer */
uintptr_t *pTmp;
/* function handle */
lsl_set_postprocessing_t func;
/* input/output variables */
uintptr_t in;
processing_options_t proc_flag;

if (nrhs != 3)
mexErrMsgTxt("3 input argument(s) required.");
if (nlhs != 0)
mexErrMsgTxt("0 output argument(s) required.");

/* get function handle */
field = mxGetField(prhs[0],0,"lsl_set_postprocessing");
if (!field)
mexErrMsgTxt("The field does not seem to exist.");
pTmp = (uintptr_t*)mxGetData(field);
if (!pTmp)
mexErrMsgTxt("The field seems to be empty.");
func = (lsl_set_postprocessing_t*)*pTmp;

/* get additional inputs */
in = *(uintptr_t*)mxGetData(prhs[1]);
if (mxGetClassID(prhs[2]) != mxDOUBLE_CLASS)
mexErrMsgTxt("The processing flag must be passed as a double.");
proc_flag = (int)*(double*)mxGetData(prhs[2]);
/* invoke & return */
func(in, proc_flag);
}

0 comments on commit 2ad59f1

Please sign in to comment.