├── .gitignore ├── GetExtinctions.m ├── NinjaGUI.prj ├── PROBE_2021test_fixed.SD ├── PROBE_NEW1.SD ├── PROBE_NEW1.nSD ├── PROBE_right_hemisphere_12optodes.nSD ├── README.md ├── SD2nSD.m ├── config2021a.cfg ├── config24optodescom3.cfg ├── desktop.ini ├── device_functions ├── fNIRS1kv1 │ ├── fNIRS1kCOM6.cfg │ ├── fNIRS1k_Ask4Status.m │ ├── fNIRS1k_MapFrequencies.m │ ├── fNIRS1k_ReadBytesAvailable.m │ ├── fNIRS1k_ReadBytesAvailable2.m │ ├── fNIRS1k_convBytes2nirs.m │ └── fb_probe.nsd ├── loadCFG.m ├── ninjaNIRS1 │ ├── ninja_Ask4Status.m │ ├── ninja_MapFrequencies.m │ └── ninja_ReadBytesAvailable.m ├── ninjaNIRS2 │ ├── ninja_Ask4Status.m │ ├── ninja_MapFrequencies.m │ └── ninja_ReadBytesAvailable.m └── setEnv.m ├── fNIRSapp.mlapp ├── fNIRSapp.prj ├── hardwareselect.mlapp ├── hwcompatlist.txt ├── liblsl-Matlab.zip ├── liblsl-Matlab ├── .bintray.json ├── .gitignore ├── .travis.yml ├── 16.txt ├── README.md ├── appveyor.yml ├── build_mex.m ├── dummy.m ├── dynamicplotexample.m ├── dynamicreceive.m ├── env_add.m ├── example1.m ├── example2.m ├── examples │ ├── HandleMetaData.m │ ├── LSLVersion.m │ ├── README.md │ ├── ReceiveData.m │ ├── ReceiveDataInChunks.m │ ├── ReceiveStringMarkers.m │ ├── SendData.m │ ├── SendDataInChunks.m │ └── SendStringMarkers.m ├── experiment15-23-20.158.txt ├── experiment15-39-05.045.txt ├── experiment16-02-49.484.txt ├── experiment16-09-35.052.txt ├── experiment16-09-45.572.txt ├── experiment16-10-52.466.txt ├── experiment16-11-38.702.txt ├── experiment16-21-22.601.txt ├── experiment16-24-48.111.txt ├── experiment16-27-34.328.txt ├── experiment16-28-01.857.txt ├── experiment16-29-56.403.txt ├── foo.txt ├── liblsl64.lib ├── lsl_inlet.m ├── lsl_loadlib.m ├── lsl_outlet.m ├── lsl_resolve_all.m ├── lsl_resolve_bypred.m ├── lsl_resolve_byprop.m ├── lsl_streaminfo.m ├── lsl_xml_ptr.m └── mex │ ├── env_compile.m │ ├── lsl_append_child.c │ ├── lsl_append_child_value.c │ ├── lsl_append_copy.c │ ├── lsl_child.c │ ├── lsl_child_value.c │ ├── lsl_child_value_n.c │ ├── lsl_close_stream.c │ ├── lsl_common.h │ ├── lsl_create_inlet.c │ ├── lsl_create_outlet.c │ ├── lsl_create_streaminfo.c │ ├── lsl_destroy_inlet.c │ ├── lsl_destroy_outlet.c │ ├── lsl_destroy_streaminfo.c │ ├── lsl_empty.c │ ├── lsl_first_child.c │ ├── lsl_freelib_.c │ ├── lsl_get_channel_count.c │ ├── lsl_get_channel_format.c │ ├── lsl_get_created_at.c │ ├── lsl_get_desc.c │ ├── lsl_get_fullinfo.c │ ├── lsl_get_hostname.c │ ├── lsl_get_info.c │ ├── lsl_get_name.c │ ├── lsl_get_nominal_srate.c │ ├── lsl_get_session_id.c │ ├── lsl_get_source_id.c │ ├── lsl_get_type.c │ ├── lsl_get_uid.c │ ├── lsl_get_version.c │ ├── lsl_get_xml.c │ ├── lsl_have_consumers.c │ ├── lsl_is_text.c │ ├── lsl_last_child.c │ ├── lsl_library_version.c │ ├── lsl_loadlib_.c │ ├── lsl_local_clock.c │ ├── lsl_name.c │ ├── lsl_next_sibling.c │ ├── lsl_next_sibling_n.c │ ├── lsl_open_stream.c │ ├── lsl_parent.c │ ├── lsl_prepend_child.c │ ├── lsl_prepend_child_value.c │ ├── lsl_prepend_copy.c │ ├── lsl_previous_sibling.c │ ├── lsl_previous_sibling_n.c │ ├── lsl_protocol_version.c │ ├── lsl_pull_chunk_d.c │ ├── lsl_pull_sample_buf.c │ ├── lsl_pull_sample_d.c │ ├── lsl_pull_sample_str.c │ ├── lsl_push_chunk.c │ ├── lsl_push_sample.c │ ├── lsl_remove_child.c │ ├── lsl_remove_child_n.c │ ├── lsl_resolve_all_.c │ ├── lsl_resolve_bypred_.c │ ├── lsl_resolve_byprop_.c │ ├── lsl_samples_available.c │ ├── lsl_set_child_value.c │ ├── lsl_set_name.c │ ├── lsl_set_value.c │ ├── lsl_time_correction.c │ ├── lsl_value.c │ └── lsl_wait_for_consumers.c ├── ninjaGUI.m ├── ninjaGUIinstaller.prj ├── sdfilesetu2nirs1000.m ├── sdfilesetupexample.m └── snirf ├── README.md ├── Snirf ├── AuxClass.m ├── DataClass.m ├── DataTypeLabelValues.m ├── DataTypeValues.m ├── Examples │ ├── demo_snirf.m │ ├── demo_snirf_readfile.m │ ├── findexamplesdir.m │ └── snirf_load_save.m ├── MeasListClass.m ├── MetaDataTagsClass.m ├── ProbeClass.m ├── SnirfClass.m └── StimClass.m ├── Utils ├── CopyHandles.m ├── Hdf5 │ ├── HDF5_DatasetLoad.m │ ├── HDF5_DatasetWrite.m │ ├── HDF5_DatasetWriteStrings.m │ ├── HDF5_GroupClose.m │ ├── HDF5_GroupOpen.m │ ├── HDF5_PostProcessing.m │ ├── HDF5_Transpose.m │ ├── convertHDF5StrToMatlabStr.m │ ├── h5loadgroup.m │ └── hdf5write_safe.m ├── cell2str_new.m ├── isproperty.m ├── iswholenum.m ├── pretty_print_struct.m ├── propnames.m └── strtrim_improve.m └── setpaths.m /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | *.nirs 3 | *.bin 4 | *.snirf 5 | ninja12testB.nsd 6 | ninja12test.nsd 7 | configninja12com7.cfg 8 | PROBE_NEW1 copy.nSD 9 | PROBE_NEW1 copy.SD 10 | SD2nSD.asv 11 | snirf/Snirf/PROBE_NEW3 (3).SD 12 | snirf/Snirf/analyser.m 13 | snirf/Snirf/sd12opt.xlsx 14 | ninjaGUIinstaller.prj 15 | device_functions/fNIRS1kv1/matlab.mat 16 | device_functions/fNIRS1kv1/probe_test_2021.nsd 17 | matlab.mat 18 | device_functions/ninjaNIRS2/ninja_ReadBytesAvailable.asv 19 | dummy.mat 20 | config24optodescom7.cfg 21 | config2021a_fake.cfg 22 | config2021ab.cfg 23 | autosave/2021-05-26/analyzebin.m 24 | *.asv 25 | liblsl-Matlab1/mex/lsl_remove_child_n.c 26 | liblsl-Matlab1/mex/lsl_resolve_all_.c 27 | liblsl-Matlab1/mex/lsl_resolve_bypred_.c 28 | liblsl-Matlab1/mex/lsl_resolve_byprop_.c 29 | liblsl-Matlab1/mex/lsl_samples_available.c 30 | liblsl-Matlab1/mex/lsl_set_child_value.c 31 | liblsl-Matlab1/mex/lsl_set_name.c 32 | liblsl-Matlab1/mex/lsl_set_value.c 33 | liblsl-Matlab1/mex/lsl_time_correction.c 34 | liblsl-Matlab1/mex/lsl_value.c 35 | liblsl-Matlab1/mex/lsl_wait_for_consumers.c 36 | liblsl-Matlab1/README.md 37 | *.c 38 | config2.cfg 39 | frontal_walking_20210713.SD 40 | frontal_walking_AO.SD 41 | autosave/2021-09-7/ninjaNIRS2021a2021-09-7-20-27-48.nirs.mat 42 | config files test/config2021a_1moredetector.cfg 43 | config files test/tested/config2021_correct_parameters.cfg 44 | config files test/tested/config2021a_1lessdetector.cfg 45 | config files test/testprobefulloptodes.SD 46 | config files test/testprobelessdetectors.SD 47 | config files test/testprobelesssources.SD 48 | config files test/testprobelesssourcesanddetectors.SD 49 | config files test/testprobemoredetectors.SD 50 | config files test/testprobemoresources.SD 51 | config files test/testprobemoresourcesanddetectors.SD 52 | config_wrongport.cfg 53 | file2021example.cfg 54 | temp.mat 55 | configCOM5.cfg 56 | config.cfg 57 | -------------------------------------------------------------------------------- /GetExtinctions.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUNPC/ninjaGUI/9746ca0be4a7519f3f43b6f446786849b7109606/GetExtinctions.m -------------------------------------------------------------------------------- /NinjaGUI.prj: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /PROBE_2021test_fixed.SD: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUNPC/ninjaGUI/9746ca0be4a7519f3f43b6f446786849b7109606/PROBE_2021test_fixed.SD -------------------------------------------------------------------------------- /PROBE_NEW1.SD: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUNPC/ninjaGUI/9746ca0be4a7519f3f43b6f446786849b7109606/PROBE_NEW1.SD -------------------------------------------------------------------------------- /PROBE_NEW1.nSD: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUNPC/ninjaGUI/9746ca0be4a7519f3f43b6f446786849b7109606/PROBE_NEW1.nSD -------------------------------------------------------------------------------- /PROBE_right_hemisphere_12optodes.nSD: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUNPC/ninjaGUI/9746ca0be4a7519f3f43b6f446786849b7109606/PROBE_right_hemisphere_12optodes.nSD -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ninjaGUI 2 | fNIRS data acquisition GUI 3 | 4 | Beta version 1.4 5 | 6 | Compatible with ninjaNIRS 2020 and NIRS1k (rev1) hardware. 7 | Support for CW6 to be added in the future. 8 | Built with MATLAB's app designer. 9 | Due to the app designer being a new feature, some functions will only work with the newest versions of MATLAB. Version 2019a+ recommended. 10 | 11 | Usage: 12 | On the command line, type ninjaGUI(cfgname), where cfgname is a configuration file (.cfg) designed for the specific hardware to use. Omitting the cfgname will open a GUI to create the .cfg file for your device. 13 | -------------------------------------------------------------------------------- /SD2nSD.m: -------------------------------------------------------------------------------- 1 | function SD2nSD(SDfname,devType) 2 | %SD2NSD Converts .SD probe files to ninjaGUI .nSD probe files 3 | % SDfname is the file name of the SDfile to convert. devType indicates 4 | % the hardware type ('ninjaNIRS' or 'NIRS1k'). There is no Matlab output, the 5 | % function simply creates an nSD file in the folder this function was 6 | % caled. The nSD file has the same name as the SD file, just with a 7 | % different extension. 8 | %% load 9 | load(SDfname,'-mat','SD') 10 | 11 | %% Initialize structure 12 | %nSD=SD; 13 | nSD=struct('device',devType,'lambda',500,'nLambdas',2,'nSrcs',0,... 14 | 'nDets',0,'spatialUnit','mm','measList',[0,0,0,0],... 15 | 'srcPos',[0,0,0],'detPos',[0,0,0],'nStates',1,... 16 | 'srcFreqMap',[],'freqMap',[]); 17 | 18 | %% Copy the parameters that can simply be copy/pasted 19 | 20 | nSD.lambda=SD.Lambda; 21 | nSD.nLambdas=length(SD.Lambda); 22 | nSD.nDummys=SD.nDummys; %this one is unused by ninjaNIRS but keeping it just in case 23 | nSD.spatiaUnit=SD.SpatialUnit; 24 | nSD.xmin=SD.xmin; 25 | nSD.xmax=SD.xmax; 26 | nSD.ymin=SD.ymin; 27 | nSD.ymax=SD.ymax; 28 | nSD.auxChannels=SD.auxChannels; %for ninjaNIRS and NIRS1k, the auxiliaries are defined in the hardware configuration file, I might need to do something to reconcile this 29 | 30 | 31 | 32 | %% The following will depend on the type of system 33 | switch devType 34 | case 'ninjaNIRS' 35 | %for ninjaNIRS, I need to do a bunch of calculations to assign 36 | %sources and detectors as, by convention, ninjaNIRS operates with 37 | %dual optode (source+detector) and thus the number of sources and 38 | %detector are identical... physically, yet not functionally. This 39 | %will change in the future though, so we will need to find a way to 40 | %specify it... 41 | 42 | % check the grommet type of the sources; a source with 'none' 43 | % for now will be considered a short separation source 44 | SSsrcssIDX=find(contains(SD.SrcGrommetType,'none')); %short separation detector indices 45 | nOptodes=SD.nSrcs+SD.nDets-length(SSsrcssIDX); 46 | nSD.nSrcs=nOptodes; 47 | nSD.nDets=nOptodes; 48 | 49 | %now I need to find the location of the optodes; this will be kind 50 | %of easy, at least this part, first I will list the detectors and 51 | %then the sources SANS the SS ones 52 | indiLSsrc=setdiff(1:SD.nSrcs,SSsrcssIDX); %we need to remove repeats, that is, the SS sources 53 | optPos=[SD.DetPos;SD.SrcPos(indiLSsrc,:)]; 54 | %the ID number of the sources remains the same, but the detectors 55 | %get a new index which is simply the original plus the number of 56 | %sources; the SS detectors get the index of the closest source 57 | %instead, as they are part of the same optode 58 | newSrcId=zeros(SD.nSrcs,1); 59 | %assign the new IDs to LS separation 60 | newSrcId(indiLSsrc)=SD.nDets+(1:(SD.nSrcs-length(SSsrcssIDX))); 61 | %now I need to assign IDs to the SS ones, for this I need to find 62 | %the closest detectors to each one of them 63 | for ki=1:length(SSsrcssIDX) 64 | %find minimum distance; assumes no ambiguity 65 | [~,indiTemp]=min(sqrt(sum((SD.DetPos-SD.SrcPos(SSsrcssIDX(ki),:)).^2,2))); 66 | newSrcId(SSsrcssIDX(ki))=indiTemp; 67 | end 68 | 69 | %now I need to update the measurement list; since I put the 70 | %detectors 71 | %at the beggining, their IDs remain the same :). But the sources 72 | %need to be changed from their original values to the value in 73 | %newSrcId 74 | nSD.measList=SD.MeasList; 75 | nSD.measList(:,1)=newSrcId(SD.MeasList(:,1)); 76 | nSD.newSrcId=newSrcId; %new variable; each row indicates what the sources were renumbered to; for example, if there is a 5 in position 10, it means source 10 in the original design was renumbered as 5 77 | 78 | %now, the source and detector positions are simply the optode 79 | %positions with an offset (as the sources and detectors are 80 | %separated by 5 mm on the optode). So: 81 | offset=5; 82 | nSD.srcPos=optPos; 83 | nSD.detPos=optPos; 84 | nSD.srcPos(:,1)=nSD.srcPos(:,1)-offset/2; 85 | nSD.detPos(:,1)=nSD.detPos(:,1)+offset/2; 86 | 87 | %I need to assign the frequencies now; it will only actually work 88 | %if the sources are spread apart; otherwise, users will need to 89 | %change the frequencies manually. Also, as everything else in this 90 | %script, assumes just 1 state. It also assumes the system still 91 | %only has 6 available frequencies. All optodes have to have set 92 | %frequencies, but the ones configured as detector only should have a 93 | %frequency of zero (interpreted by ninjaGUI as "source off") 94 | 95 | %first set all optodes to zero frequency 96 | nSD.freqMap=zeros(nOptodes,nSD.nStates,nSD.nLambdas); 97 | 98 | %make a list of the source optodes 99 | srcOptList=sort(unique(nSD.measList(:,1))); 100 | 101 | %I will now sort them in order of distance to the source closest to 102 | %the origin 103 | [~,sb]=sort(sqrt(sum(nSD.srcPos(srcOptList,:).^2,2))); 104 | %sb(1) has the index of the source closest to the origin; now we will 105 | %find the distance of all sources to this one 106 | dista1=sqrt(sum((nSD.srcPos(srcOptList,:)-nSD.srcPos(srcOptList(sb(1)),:)).^2,2)); 107 | %find the "rank" of closeness to that source 108 | [~,sb1]=sort(dista1); 109 | %in sb1, the first element indicates first place in closeness, 110 | %second the second place etc 111 | 112 | %now assign frequencies sequentially by their rank 113 | for ki=1:length(sb1) 114 | nSD.freqMap(srcOptList(sb1(ki)),1,1)=mod(ki-1,3)+1; 115 | nSD.freqMap(srcOptList(sb1(ki)),1,2)=mod(ki-1,3)+4; 116 | end 117 | 118 | %now make negative the short separation sources; they are easy to 119 | %identify as their optode IDs are at the beginning of the list 120 | %before the LS sources (as they share an ID with a detector, and 121 | %they were put at the beginning) 122 | nSD.freqMap(1:SD.nDets,:,:)=-nSD.freqMap(1:SD.nDets,:,:); 123 | 124 | 125 | case 'NIRS1k' 126 | %for NIRS1k, we can pretty much copy the parameters as they are 127 | nSD.nSrcs=SD.nSrcs; 128 | nSD.nDets=SD.nDets; 129 | nSD.measList=SD.MeasList; 130 | nSD.srcPos=SD.SrcPos; 131 | nSD.detPos=SD.DetPos; 132 | end 133 | 134 | 135 | %% save 136 | fname=SDfname(1:end-3); 137 | save([fname,'.nSD'],'-mat','SD','nSD') 138 | end 139 | 140 | -------------------------------------------------------------------------------- /config2021a.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUNPC/ninjaGUI/9746ca0be4a7519f3f43b6f446786849b7109606/config2021a.cfg -------------------------------------------------------------------------------- /config24optodescom3.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUNPC/ninjaGUI/9746ca0be4a7519f3f43b6f446786849b7109606/config24optodescom3.cfg -------------------------------------------------------------------------------- /desktop.ini: -------------------------------------------------------------------------------- 1 | [LocalizedFileNames] 2 | PROBE_2021test_fixed.SD=@PROBE_~3.SD,0 3 | -------------------------------------------------------------------------------- /device_functions/fNIRS1kv1/fNIRS1kCOM6.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUNPC/ninjaGUI/9746ca0be4a7519f3f43b6f446786849b7109606/device_functions/fNIRS1kv1/fNIRS1kCOM6.cfg -------------------------------------------------------------------------------- /device_functions/fNIRS1kv1/fNIRS1k_Ask4Status.m: -------------------------------------------------------------------------------- 1 | function status=fNIRS1k_Ask4Status(app) 2 | % Queries the status of the device. Right now it doesn't actually query 3 | % anything, it's just used as an excuse to to initialize the detectors 4 | 5 | % disp('Querying fNIRS1000 status...') 6 | 7 | CMDSTRING = [254 0 0 0 0 255-255 255-255 0 0 1]; 8 | write(app.sp,CMDSTRING,"uint8"); 9 | status=1; 10 | 11 | -------------------------------------------------------------------------------- /device_functions/fNIRS1kv1/fNIRS1k_MapFrequencies.m: -------------------------------------------------------------------------------- 1 | function result = fNIRS1k_MapFrequencies(sp,statefMap) 2 | %fNIRS1000_MAPFREQUENCIES Dummy function 3 | 4 | % frequencies cannot be set in the current version of fNIRS1000. This dummy 5 | % function only exists to not alter the flow of the program for devices 6 | % with adjustable frequencies, but it does nothing. 7 | 8 | result=1; 9 | end 10 | 11 | -------------------------------------------------------------------------------- /device_functions/fNIRS1kv1/fNIRS1k_ReadBytesAvailable2.m: -------------------------------------------------------------------------------- 1 | function [dataoutput,packlen,datab,statusdata]=fNIRS1k_ReadBytesAvailable2(s,dev,SD) 2 | % Reads the serial port for a fNIRS1000 device. 3 | 4 | %% hardware constants 5 | N_OPTODES=dev.nDets; 6 | N_WORDS_PER_DFT = 2; 7 | N_BYTES_IN_DFT_WORD = 5; 8 | N_FREQ = 8; 9 | N_AUX = dev.nAux; 10 | N_BYTES_PER_AUX = 2; 11 | 12 | N_BYTES_TO_READ_PER_SAMPLE=N_WORDS_PER_DFT * N_BYTES_IN_DFT_WORD * (N_FREQ+1) +3; % N_FREQ+1 : for max/avg data; +3 for [channel, #bytes, DFT count]; 13 | 14 | 15 | 16 | 17 | %% DFT constants and data offsets 18 | 19 | DFT_N=512; 20 | KD = [56 60 64 70 80 84 96 105]; % demodulation k 21 | 22 | offsetA = (0:N_FREQ-1)*N_BYTES_IN_DFT_WORD*N_WORDS_PER_DFT +3; 23 | offsetB=offsetA+N_BYTES_IN_DFT_WORD; 24 | wordpos=1:N_BYTES_IN_DFT_WORD; 25 | part1=wordpos+offsetA'; 26 | part2=wordpos+offsetB'; 27 | powso256=256.^(0:N_BYTES_IN_DFT_WORD-1); 28 | Kernel=exp(-1i*(2*pi/DFT_N)*KD(1:N_FREQ)); 29 | 30 | %% read ALL bytes available 31 | 32 | ba=s.BytesAvailable; 33 | rb=floor(ba/N_BYTES_TO_READ_PER_SAMPLE)*N_BYTES_TO_READ_PER_SAMPLE; 34 | raw = fread(s,rb,'uchar'); 35 | 36 | 37 | %% initialize databuffer 38 | ML=SD.measList; 39 | 40 | rawN=length(raw); 41 | maxsampN=1+ceil(rawN/(N_OPTODES+1)/N_BYTES_TO_READ_PER_SAMPLE); %max number of samples possibly contained in the data package 42 | datab=complex(nan(N_OPTODES,maxsampN,N_FREQ)); %complex data buffer 43 | auxb=nan(N_AUX,maxsampN); %aux data buffer 44 | 45 | data=nan(size(ML,1),maxsampN); %buffer for intensity data 46 | 47 | 48 | 49 | 50 | %% parse the data package 51 | 52 | nBs=find(raw==N_BYTES_TO_READ_PER_SAMPLE-2); %find all possible indicators of the correct number of bytes read 53 | nBs(nBs<2)=[]; %discard possible data packages in which I did not get the first byte 54 | Optind=nBs(raw(nBs-1)(2^39-1); 84 | pnm1(indi)=pnm1(indi)-2^40; 85 | pnm0=sum(rawp(part2).*powso256,2)'; 86 | indi=pnm0>(2^39-1); 87 | pnm0(indi)=pnm0(indi)-2^40; 88 | datab(k+1,m,:)=pnm0 - Kernel.*pnm1; 89 | end 90 | end 91 | end 92 | 93 | %% now decode the aux data packets 94 | 95 | %discard incomplete aux packets 96 | Auxind(Auxind+2>rawN)=[]; 97 | 98 | 99 | seqAux=raw(Auxind+2); %contains the sequence data of potential aux packets 100 | 101 | try 102 | Auxdataindk=Auxind([diff(seqAux)==1]); %again, will lose data at each jump :(, and the last one of the data package 103 | catch 104 | disp('This is a bug!') 105 | end 106 | pows256b=256.^(0:N_BYTES_PER_AUX-1)'; 107 | 108 | for m=1:length(Auxdataindk) 109 | indi1=Auxdataindk(m):Auxdataindk(m)+92; 110 | if all(indi1 2 | 3 | fNIRSapp 4 | 5 | 6 | 0.1 7 | Antonio Ortega 8 | aortegam@bu.edu 9 | Boston University 10 | Beta version, for testing purposes 11 | 12 | 13 | 14 | \Boston University\fNIRSapp\ 15 | option.installpath.programfiles 16 | 17 | 18 | 19 | ${PROJECT_ROOT}\fNIRSapp\for_testing 20 | ${PROJECT_ROOT}\fNIRSapp\for_redistribution_files_only 21 | ${PROJECT_ROOT}\fNIRSapp\for_redistribution 22 | ${PROJECT_ROOT}\fNIRSapp 23 | false 24 | 25 | subtarget.standalone 26 | 27 | true 28 | false 29 | false 30 | MyAppInstaller_web 31 | MyAppInstaller_mcr 32 | MyAppInstaller_app 33 | false 34 | false 35 | 36 | false 37 | false 38 | 39 | Syntax 40 | fNIRS -? 41 | fNIRS fname 42 | Input Arguments 43 | -? print help on how to use the application 44 | fname input arguments 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | ${PROJECT_ROOT}\fNIRS.m 78 | 79 | 80 | 81 | 82 | ${PROJECT_ROOT}\cw6.cfg 83 | ${PROJECT_ROOT}\device_functions\CW6\cw6_loadCFG.m 84 | ${PROJECT_ROOT}\device_functions\CW6\setEnvCW6.m 85 | ${PROJECT_ROOT}\device_functions\loadCFG.m 86 | ${PROJECT_ROOT}\device_functions\ninjaNIRS1\ninja_FlushBuffer.m 87 | ${PROJECT_ROOT}\device_functions\ninjaNIRS1\ninja_MapFrequencies.m 88 | ${PROJECT_ROOT}\device_functions\ninjaNIRS1\ninja_ReadBytesAvailable.m 89 | ${PROJECT_ROOT}\device_functions\setEnv.m 90 | ${PROJECT_ROOT}\fNIRSapp.mlapp 91 | ${PROJECT_ROOT}\hardwareselect.mlapp 92 | ${PROJECT_ROOT}\hwcompatlist.txt 93 | ${PROJECT_ROOT}\mental_math.nsd 94 | 95 | 96 | C:\Users\Antonio\Documents\MATLAB\work\BU\boas lab\rtfNIRS\fNIRS_interface\fNIRSapp\for_testing\fNIRSapp.exe 97 | C:\Users\Antonio\Documents\MATLAB\work\BU\boas lab\rtfNIRS\fNIRS_interface\fNIRSapp\for_testing\readme.txt 98 | C:\Users\Antonio\Documents\MATLAB\work\BU\boas lab\rtfNIRS\fNIRS_interface\fNIRSapp\for_testing\splash.png 99 | 100 | 101 | 102 | C:\Program Files\MATLAB\R2019a 103 | 104 | 105 | 106 | 107 | 108 | true 109 | 110 | 111 | 112 | 113 | false 114 | false 115 | true 116 | false 117 | false 118 | false 119 | false 120 | false 121 | 10.0 122 | false 123 | true 124 | win64 125 | true 126 | 127 | 128 | -------------------------------------------------------------------------------- /hardwareselect.mlapp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUNPC/ninjaGUI/9746ca0be4a7519f3f43b6f446786849b7109606/hardwareselect.mlapp -------------------------------------------------------------------------------- /hwcompatlist.txt: -------------------------------------------------------------------------------- 1 | 2 | ninjaNIRS2020 3 | ninjaNIRS2021a 4 | NIRS1k -------------------------------------------------------------------------------- /liblsl-Matlab.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUNPC/ninjaGUI/9746ca0be4a7519f3f43b6f446786849b7109606/liblsl-Matlab.zip -------------------------------------------------------------------------------- /liblsl-Matlab/.bintray.json: -------------------------------------------------------------------------------- 1 | { 2 | "package": { 3 | "name": "liblsl-Matlab", 4 | "repo": "LSL", 5 | "subject": "labstreaminglayer", 6 | "desc": "Travis CI build", 7 | "website_url": "https://github.com/labstreaminglayer/liblsl-matlab", 8 | "issue_tracker_url": "https://github.com/labstreaminglayer/liblsl-matlab/issues", 9 | "vcs_url": "https://github.com/labstreaminglayer/liblsl-matlab.git", 10 | "github_use_tag_release_notes": true, 11 | "licenses": ["MIT"], 12 | "public_download_numbers": false, 13 | "public_stats": false 14 | }, 15 | 16 | "version": { 17 | "name": "1.12", 18 | "desc": "Matlab bindings for liblsl", 19 | "released": "2018-05-02", 20 | "vcs_tag": "", 21 | "gpgSign": false 22 | }, 23 | "files": [ { 24 | "includePattern": "./((.)[^/]*\.tar\.bz2)", 25 | "uploadPattern": "$1", 26 | "matrixParams": { "override": 1 } 27 | }], 28 | "publish": true 29 | } 30 | -------------------------------------------------------------------------------- /liblsl-Matlab/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | -------------------------------------------------------------------------------- /liblsl-Matlab/.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | env: 3 | LSLDIST_URL="https://dl.bintray.com/labstreaminglayer/LSL/" 4 | UBUNTU_DIST="trusty" 5 | LSL_VERSION="1.1.2" 6 | - CMakeArgs="" 7 | script: 8 | - cp ${LSL_INSTALL_ROOT}/lib/* bin/ 9 | - octave-cli --eval build_mex 10 | - rm bin/*.o 11 | - tar --transform "s/^\.\?/liblsl-matlab/" -cjf liblsl-matlab-${LSL_VERSION}.tar.bz2 . || true 12 | matrix: 13 | include: 14 | - os: linux 15 | addons: 16 | apt: 17 | packages: 18 | - liboctave-dev 19 | before_script: 20 | - travis_retry wget --quiet ${LSLDIST_URL}/lsl-liblsl{,-dev}_${LSL_VERSION}-${UBUNTU_DIST}_amd64.deb 21 | - for deb in *.deb; do dpkg -x ${deb} LSL; done 22 | - export LSL_INSTALL_ROOT=LSL/usr 23 | - os: osx 24 | before_install: 25 | - brew install octave 26 | before_script: 27 | - travis_retry wget --quiet ${LSLDIST_URL}/LSL-${LSL_VERSION}-Darwin-liblsl{,-dev}.tar.bz2 28 | - mkdir LSL; for file in *.tar.bz2; do tar -xf ${file} -C LSL; done 29 | - export LSL_INSTALL_ROOT=LSL 30 | deploy: 31 | skip_cleanup: true 32 | provider: bintray 33 | user: tstenner 34 | key: 35 | secure: "PoHMsNdp5UgFtAPljabOVC+6r5wjwHZwGgVDLEgKs0b+EwgkShj42Li03vQCz2u0cRkgHutv5cGCe8L5+ez4zyqnF98gXrgflbhcfdjhHEB6hp65kV2+9myNOPcrlsm+gR0Ex1kN1owfDRfBIasa6SMp2+4Ii4mxm/aiSaLnvaB1lM6zknNZMpW0lucdQVqKH+HatUaHRc0EB1KgzSRU7jKxA/XWqHQ8lRk2Hnk5bVOWCu755DLbKquuZUV1KmxvF5TolDahhwh/DuCFa/UJ9G2eHdt/1/7Pb2w1Dx+9oyW4D6kjbxuYLuUjeeRBnRg/XUNQ6HPywC9b4jMgyu7bRnfKgXmM323FYRp3iybuK8BQpv7QbRbX3s4VEjEp/LbPqLBIqiSShy2lRloNI2YfCFyaOunYVSPCavXslzyURdx/l/RiweZe9YDUq03GL8QNs2vMmnS5ieVIqW6X2PNGZqitV5nXNnTPfU+mJk51vzv32C1vQQFZTJ9qBg57GAfp3WfRI3MVfx62ix8Zc1TTjevSB1ISQKRuqv5zFrMsx+5Ymj7mZxokkGqYA1/OS9SxWISZ8+nd9veYB4ykKA3qZEvmF3vaC559pY00IpjlSoI38cQADsSd1EivMhM9JuIxFpOmnLtZJyk1AvW47hxXgXupf099Vfea3ycBElk7eqQ=" 36 | file: .bintray.json 37 | -------------------------------------------------------------------------------- /liblsl-Matlab/16.txt: -------------------------------------------------------------------------------- 1 | 1, 2.00 2 | 3, 4.00 3 | 5, 6.00 4 | 7, 8.00 5 | 9,10.00 6 | 3.570277e-01, 0.90 7 | 1.276439e-01, 0.55 8 | 3.800924e-02, 0.75 9 | 3.686106e-01, 0.35 10 | 4.967391e-01, 0.27 11 | -------------------------------------------------------------------------------- /liblsl-Matlab/README.md: -------------------------------------------------------------------------------- 1 | This is the MATLAB interface for liblsl. 2 | 3 | * You need to add this directory to your MATLAB path recursively 4 | * Using the MATLAB GUI, use File/Set Path... 5 | * Alternatively, in a script, use `addpath(genpath('path/to/liblsl-Matlab'));` 6 | * The bin/ directory needs to contain an up-to-date build of the library file for your MATLAB version. 7 | * e.g. liblsl64.dll for 64-bit MATLAB on Windows. 8 | * e.g. `liblsl64.dylib` and `liblsl64.1.4.0.dylib` for 64-bit MATLAB on MacOS. 9 | * e.g. `liblsl64.so` and `liblsl64.so.1.4.0` for 64-bit MATLAB in Linux 10 | * Once this taken care of, see the example files in the examples/ directory for how to use this interface in a MATLAB program. 11 | 12 | ### Troubleshooting 13 | 14 | If you get an error similar to `lsl_loadlib_ undefined`, then you may need to run the `build_mex.m` script from within the liblsl-Matlab directory. In Linux, you may need to run `build_linux.sh` instead. 15 | 16 | On MacOS, you may still get an error similar to `Invalid MEX-file [...] lsl_loadlib_.mexmaci64; Reason: image not found.`. To fix this run the following command in a Terminal window from within the liblsl-Matlab directory: `install_name_tool -add_rpath "@loader_path/" bin/lsl_loadlib_.mexmaci64` 17 | -------------------------------------------------------------------------------- /liblsl-Matlab/appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 1.12.0.{build} 2 | pull_requests: 3 | do_not_increment_build_number: true 4 | shallow_clone: true 5 | environment: 6 | LSLVERSION: 1.12 7 | OCTAVE_VER: 4.4.0-w64 8 | VCVER: 14.0 9 | install: 10 | - cmd: >- 11 | appveyor DownloadFile https://ftp.gnu.org/gnu/octave/windows/octave-%OCTAVE_VER%.7z -FileName octave.7z 12 | 13 | 7z x octave.7z -o"c:\dev" -y 14 | 15 | build_script: 16 | - cmd: >- 17 | call "C:\Program Files (x86)\Microsoft Visual Studio %VCVER%\VC\vcvarsall.bat" x64 18 | 19 | appveyor DownloadFile https://bintray.com/labstreaminglayer/LSL/download_file?file_path=liblsl_x64_%LSLVERSION%.zip -FileName liblsl.zip 20 | 21 | 7z x liblsl.zip 22 | 23 | cp LSL/lib/liblsl64.dll bin/ 24 | 25 | c:\dev\octave-%OCTAVE_VER%\bin\octave-gui.exe --eval build_mex 26 | 27 | del bin\*.o 28 | artifacts: 29 | - path: . 30 | name: ${APPVEYOR_PROJECT_NAME}_x64_${APPVEYOR_BUILD_VERSION} 31 | deploy: 32 | - provider: BinTray 33 | username: tstenner 34 | api_key: 35 | secure: Fo9tIQnGjVnCXB3euItvYrt85A5O9FPqq7LEpsdOuwW+eOg1rwA5Q1HLp4yWDXAl 36 | subject: labstreaminglayer 37 | version: 1.12 38 | repo: LSL 39 | package: liblsl-matlab 40 | override: true 41 | -------------------------------------------------------------------------------- /liblsl-Matlab/build_mex.m: -------------------------------------------------------------------------------- 1 | % Build mex bindings 2 | % For Octave on Linux, you need the package liboctave-dev installed 3 | % You also need the liblsl64 binary in the bin folder and a configured 4 | % C compiler (mex -setup) 5 | 6 | libs = '-llsl64'; 7 | if ispc 8 | dllext = 'dll'; 9 | elseif ismac 10 | dllext = 'dylib'; 11 | elseif isunix 12 | dllext = 'so'; 13 | libs = ['-llsl64 -ldl']; 14 | end 15 | 16 | 17 | if isempty(dir(['bin/liblsl64.', dllext])) 18 | error(['liblsl64.' dllext ' not found in bin/']); 19 | end 20 | 21 | ext = ['.' mexext]; 22 | 23 | files = dir('mex/*.c'); 24 | cd('bin'); 25 | for i = 1:length(files) 26 | f = files(i); 27 | [~, base, ~] = fileparts(f.name); 28 | targetstats = dir([base, ext]); 29 | if isempty(targetstats) || f.datenum > targetstats.datenum 30 | mex('-I../../liblsl/include','-L.', libs, ['../mex/', f.name]); 31 | else 32 | disp([base, ext, ' up to date']); 33 | end 34 | end 35 | cd('..'); 36 | -------------------------------------------------------------------------------- /liblsl-Matlab/dummy.m: -------------------------------------------------------------------------------- 1 | tic; 2 | t=[]; 3 | x=[]; 4 | tspan=10; 5 | while true 6 | 7 | tcur=toc; 8 | t=[t,tcur]; 9 | 10 | a=randn(1,1); 11 | x=[x,a]; 12 | plot(t,x) 13 | xlim([t(end)-10,t(end)]) 14 | drawnow 15 | pause(0.1) 16 | end -------------------------------------------------------------------------------- /liblsl-Matlab/dynamicplotexample.m: -------------------------------------------------------------------------------- 1 | %%function that plots the samples being pushed to LSL 2 | 3 | fs=200; 4 | ndata=fs; 5 | tspan=10; %visualization span in seconds 6 | 7 | %% initialize LSL 8 | % instantiate the library 9 | disp('Loading library...'); 10 | lib = lsl_loadlib(); 11 | 12 | % make a new stream outlet 13 | disp('Creating a new streaminfo...'); 14 | info = lsl_streaminfo(lib,'SimpleStream1','EEG',ndata,100,'cf_float32','sdfwerr32432'); 15 | 16 | disp('Opening an outlet...'); 17 | outlet = lsl_outlet(info); 18 | 19 | % send data into the outlet, sample by sample 20 | 21 | 22 | disp('Now transmitting data...'); 23 | 24 | 25 | %% initialize stuff 26 | 27 | fname=['experiment',num2str(datestr(now,'HH-MM-SS.FFF')),'.txt']; 28 | fID = fopen(fname,'a'); 29 | 30 | Nsamples=tspan*fs; 31 | x=zeros(1,Nsamples); 32 | t=linspace(-10,0,Nsamples); 33 | tic; 34 | tcur=toc; 35 | %% main loop 36 | 37 | while 1 38 | datos=randn(1,ndata); 39 | outlet.push_sample(datos); 40 | 41 | 42 | pause(1); 43 | tcur=toc; 44 | x=circshift(x,-ndata); 45 | x(end-ndata+1:end)=datos; 46 | 47 | t=circshift(t,-ndata); 48 | ttemp=linspace(tcur-1,tcur,ndata); 49 | t(end-ndata+1:end)=ttemp; 50 | 51 | %fprintf(fID,'%6s %12s \n',ttemp',datos'); 52 | fprintf(fID, '%5.4f,%5.4f\r\n', [ttemp;datos]); 53 | 54 | %t=[t,linspace(t(end),tcur,ndata)]; 55 | %plot(t(2:end),x) 56 | % 57 | plot(t,x) 58 | xlim([t(end)-10,t(end)]) 59 | drawnow 60 | end 61 | 62 | fclose(fID); 63 | -------------------------------------------------------------------------------- /liblsl-Matlab/dynamicreceive.m: -------------------------------------------------------------------------------- 1 | %%receiving data example display 2 | 3 | %% instantiate the library 4 | disp('Loading the library...'); 5 | lib = lsl_loadlib(); 6 | 7 | % resolve a stream... 8 | disp('Resolving an EEG stream...'); 9 | result = {}; 10 | while isempty(result) 11 | result = lsl_resolve_byprop(lib,'type','EEG'); end 12 | % create a new inlet 13 | disp('Opening an inlet...'); 14 | inlet = lsl_inlet(result{1}); 15 | 16 | disp('Now receiving data...'); 17 | N=100000; 18 | x=zeros(1,N)*NaN; 19 | t=x*NaN; 20 | 21 | tic; 22 | tcur=toc; 23 | dcount=0; 24 | while true 25 | % k=k+1; 26 | % get data from the inlet 27 | [vec,ts] = inlet.pull_sample(); 28 | ndata=length(vec); 29 | tprev=tcur; 30 | tcur=toc; 31 | 32 | t=circshift(t,-ndata); 33 | ttemp=linspace(tprev,tcur,ndata); 34 | t(end-ndata+1:end)=ttemp; 35 | %t=[t,ts]; 36 | x=circshift(x,-ndata); 37 | x(end-ndata+1:end)=vec; 38 | figure(1) 39 | plot(t,x) 40 | xlim([t(end)-10,t(end)]) 41 | drawnow 42 | 43 | if floor(t(end)/10)>dcount 44 | dcount=dcount+1; 45 | figure(2) 46 | histogram(x) 47 | title('Histrogam of data buffer') 48 | end 49 | 50 | % 51 | % vec2(k,:)=vec; 52 | % t(k)=ts; 53 | % % and display it 54 | % % fprintf('%.2f\t',vec); 55 | % % fprintf('%.5f\n',ts); 56 | % 57 | end 58 | 59 | 60 | % 61 | % vec2=zeros(500,8); 62 | % t=zeros(1,500); 63 | % k=0; 64 | % while k<500 65 | % k=k+1; 66 | % % get data from the inlet 67 | % [vec,ts] = inlet.pull_sample(); 68 | % 69 | % vec2(k,:)=vec; 70 | % t(k)=ts; 71 | % % and display it 72 | % % fprintf('%.2f\t',vec); 73 | % % fprintf('%.5f\n',ts); 74 | % 75 | % end 76 | -------------------------------------------------------------------------------- /liblsl-Matlab/env_add.m: -------------------------------------------------------------------------------- 1 | % This file is here only so that you can put this directory into the dependencies folder of a BCILAB installation. -------------------------------------------------------------------------------- /liblsl-Matlab/example1.m: -------------------------------------------------------------------------------- 1 | %%receiving data example 2 | 3 | %% instantiate the library 4 | disp('Loading the library...'); 5 | lib = lsl_loadlib(); 6 | 7 | % resolve a stream... 8 | disp('Resolving an EEG stream...'); 9 | result = {}; 10 | while isempty(result) 11 | result = lsl_resolve_byprop(lib,'type','EEG'); end 12 | % create a new inlet 13 | disp('Opening an inlet...'); 14 | inlet = lsl_inlet(result{1}); 15 | 16 | disp('Now receiving data...'); 17 | vec2=zeros(500,8); 18 | t=zeros(1,500); 19 | k=0; 20 | while k<500 21 | k=k+1; 22 | % get data from the inlet 23 | [vec,ts] = inlet.pull_sample(); 24 | 25 | vec2(k,:)=vec; 26 | t(k)=ts; 27 | % and display it 28 | % fprintf('%.2f\t',vec); 29 | % fprintf('%.5f\n',ts); 30 | 31 | end 32 | -------------------------------------------------------------------------------- /liblsl-Matlab/example2.m: -------------------------------------------------------------------------------- 1 | %%send data example 2 | 3 | %% instantiate the library 4 | disp('Loading the library...'); 5 | lib = lsl_loadlib(); 6 | 7 | % make a new stream outlet 8 | disp('Creating a new streaminfo...'); 9 | info = lsl_streaminfo(lib,'BioSemi','EEG',8,100,'cf_float32','sdfwerr32432'); 10 | 11 | disp('Opening an outlet...'); 12 | outlet = lsl_outlet(info); 13 | 14 | % send data into the outlet, sample by sample 15 | disp('Now transmitting data...'); 16 | while true 17 | datos=randn(8,1) 18 | outlet.push_sample(datos); 19 | pause(1); 20 | end -------------------------------------------------------------------------------- /liblsl-Matlab/examples/HandleMetaData.m: -------------------------------------------------------------------------------- 1 | %% instantiate the library 2 | lib = lsl_loadlib(); 3 | 4 | % create a new StreamInfo and declare some meta-data (in accordance with XDF format) 5 | info = lsl_streaminfo(lib,'MetaTester','EEG',8,100,'cf_float32','myuid56872'); 6 | chns = info.desc().append_child('channels'); 7 | for label = {'C3','C4','Cz','FPz','POz','CPz','O1','O2'} 8 | ch = chns.append_child('channel'); 9 | ch.append_child_value('label',label{1}); 10 | ch.append_child_value('unit','microvolts'); 11 | ch.append_child_value('type','EEG'); 12 | end 13 | info.desc().append_child_value('manufacturer','SCCN'); 14 | cap = info.desc().append_child('cap'); 15 | cap.append_child_value('name','EasyCap'); 16 | cap.append_child_value('size','54'); 17 | cap.append_child_value('labelscheme','10-20'); 18 | 19 | % create outlet for the stream 20 | outlet = lsl_outlet(info); 21 | 22 | 23 | % === the following could run on another computer === 24 | 25 | % resolve the stream and open an inlet 26 | lib = lsl_loadlib(); 27 | result = {}; 28 | while isempty(result) 29 | result = lsl_resolve_byprop(lib,'type','EEG'); end 30 | inlet = lsl_inlet(result{1}); 31 | % get the full stream info (including custom meta-data) and dissect it 32 | inf = inlet.info(); 33 | fprintf('The stream''s XML meta-data is: \n'); 34 | fprintf([inf.as_xml() '\n']); 35 | fprintf(['The manufacturer is: ' inf.desc().child_value('manufacturer') '\n']); 36 | fprintf(['The cap circumference is: ' inf.desc().child('cap').child_value('size') '\n']); 37 | fprintf('The channel labels are as follows:\n'); 38 | ch = inf.desc().child('channels').child('channel'); 39 | for k = 1:inf.channel_count() 40 | fprintf([' ' ch.child_value('label') '\n']); 41 | ch = ch.next_sibling(); 42 | end 43 | -------------------------------------------------------------------------------- /liblsl-Matlab/examples/LSLVersion.m: -------------------------------------------------------------------------------- 1 | disp('Loading library...'); 2 | lib = lsl_loadlib(); 3 | disp('Displaying library version'); 4 | version = lsl_library_version(lib) 5 | -------------------------------------------------------------------------------- /liblsl-Matlab/examples/README.md: -------------------------------------------------------------------------------- 1 | # MATLAB Example Programs: Basic to Advanced 2 | 3 | These examples show how to transmit a numeric multi-channel time series through LSL: 4 | * [Sending a multi-channel time series into LSL.](SendData.m) 5 | * [Receiving a multi-channel time series from LSL.](ReceiveData.m) 6 | 7 | These examples do the same as before, but now transmit the data at the granularity of chunks. 8 | For the purposes of network transmission the same effect can be achieved by creating the inlet or 9 | outlet with an extra argument to indicate that multiple samples should be batched into a chunk for 10 | transmission. 11 | 12 | However, since MATLAB's interpreter is relatively slow, the library calls should be made in a 13 | vectorized manner, i.e. at chunk granularity, whenever possible (at least for high-rate streams). 14 | 15 | Note that for LSL the data is always a linear sequence of samples and data that is pushed as 16 | samples can be pulled out as chunks or vice versa: 17 | 18 | * [Sending data at chunk granularity.](SendDataInChunks.m) 19 | * [Receiving data at chunk granularity.](ReceiveDataInChunks.m) 20 | 21 | These examples show a special-purpose use case that is mostly relevant for stimulus-presentation 22 | programs or other applications that want to emit 'event' markers or other application state. 23 | 24 | The stream here is single-channel and has irregular sampling rate, but the value per channel is a 25 | string: 26 | 27 | * [Sending string-formatted irregular streams.](SendStringMarkers.m) 28 | * [Receiving string-formatted irregular streams.](ReceiveStringMarkers.m) 29 | 30 | The last example shows how to attach properly formatted meta-data to a stream, and how to read it 31 | out again at the receiving end. 32 | While meta-data is strictly optional, it is very useful to make streams self-describing. 33 | LSL has adopted the convention to name meta-data fields according to the XDF file format 34 | specification whenever the content type matches (for example EEG, Gaze, MoCap, VideoRaw, etc); 35 | the spec is [here](https://github.com/sccn/xdf/wiki/Meta-Data). 36 | 37 | Note that some older example programs (SendData/ReceiveData) predate this convention and name the 38 | channels inconsistently. 39 | 40 | * [Handling stream meta-data.](HandleMetaData.m) 41 | 42 | ## Running the examples 43 | To run these examples, you must have added the folder `include/lsl_matlab` to your MATLAB path (recursively). 44 | You can do this either via the File/Path... menu or via the command `addpath(genpath('your_path_to/liblsl-1.xx/include/lsl_matlab'))` 45 | Also, if you have rebuilt the library, make sure that `liblsl-1.xx/include/lsl_matlab/bin` contains a copy of the library files in the `liblsl-1.xx/bin`. 46 | -------------------------------------------------------------------------------- /liblsl-Matlab/examples/ReceiveData.m: -------------------------------------------------------------------------------- 1 | %% instantiate the library 2 | disp('Loading the library...'); 3 | lib = lsl_loadlib(); 4 | 5 | % resolve a stream... 6 | disp('Resolving an EEG stream...'); 7 | result = {}; 8 | while isempty(result) 9 | result = lsl_resolve_byprop(lib,'type','EEG'); end 10 | 11 | % create a new inlet 12 | disp('Opening an inlet...'); 13 | inlet = lsl_inlet(result{1}); 14 | 15 | disp('Now receiving data...'); 16 | while true 17 | % get data from the inlet 18 | [vec,ts] = inlet.pull_sample(); 19 | % and display it 20 | fprintf('%.2f\t',vec); 21 | fprintf('%.5f\n',ts); 22 | end -------------------------------------------------------------------------------- /liblsl-Matlab/examples/ReceiveDataInChunks.m: -------------------------------------------------------------------------------- 1 | % instantiate the library 2 | disp('Loading the library...'); 3 | lib = lsl_loadlib(); 4 | 5 | % resolve a stream... 6 | disp('Resolving an EEG stream...'); 7 | result = {}; 8 | while isempty(result) 9 | result = lsl_resolve_byprop(lib,'type','EEG'); end 10 | 11 | % create a new inlet 12 | disp('Opening an inlet...'); 13 | inlet = lsl_inlet(result{1}); 14 | 15 | disp('Now receiving chunked data...'); 16 | while true 17 | % get chunk from the inlet 18 | [chunk,stamps] = inlet.pull_chunk(); 19 | for s=1:length(stamps) 20 | % and display it 21 | fprintf('%.2f\t',chunk(:,s)); 22 | fprintf('%.5f\n',stamps(s)); 23 | end 24 | pause(0.05); 25 | end -------------------------------------------------------------------------------- /liblsl-Matlab/examples/ReceiveStringMarkers.m: -------------------------------------------------------------------------------- 1 | % instantiate the library 2 | addpath(genpath('./../../liblsl-Matlab/')) 3 | disp('Loading the library...'); 4 | lib = lsl_loadlib(); 5 | 6 | % resolve a stream... 7 | disp('Resolving a Markers stream...'); 8 | result = {}; 9 | while isempty(result) 10 | result = lsl_resolve_byprop(lib,'type','Markers'); end 11 | 12 | % create a new inlet 13 | disp('Opening an inlet...'); 14 | inlet = lsl_inlet(result{1}); 15 | 16 | disp('Now receiving data...'); 17 | while true 18 | % get data from the inlet 19 | [mrks,ts] = inlet.pull_sample(); 20 | % and display it 21 | fprintf('got %s at time %.5f\n',mrks{1},ts); 22 | end 23 | -------------------------------------------------------------------------------- /liblsl-Matlab/examples/SendData.m: -------------------------------------------------------------------------------- 1 | %% instantiate the library 2 | disp('Loading library...'); 3 | lib = lsl_loadlib(); 4 | 5 | % make a new stream outlet 6 | disp('Creating a new streaminfo...'); 7 | info = lsl_streaminfo(lib,'BioSemi','EEG',8,100,'cf_float32','sdfwerr32432'); 8 | 9 | disp('Opening an outlet...'); 10 | outlet = lsl_outlet(info); 11 | 12 | % send data into the outlet, sample by sample 13 | disp('Now transmitting data...'); 14 | while true 15 | outlet.push_sample(randn(8,1)); 16 | pause(0.01); 17 | end -------------------------------------------------------------------------------- /liblsl-Matlab/examples/SendDataInChunks.m: -------------------------------------------------------------------------------- 1 | addpath(genpath('..')) 2 | % instantiate the library 3 | disp('Loading library...'); 4 | lib = lsl_loadlib(); 5 | 6 | % make a new stream outlet 7 | disp('Creating a new streaminfo...'); 8 | info = lsl_streaminfo(lib,'ninja','EEG',8,100,'cf_float32','sdfwerr32432'); 9 | 10 | disp('Opening an outlet...'); 11 | outlet = lsl_outlet(info); 12 | 13 | % send data into the outlet 14 | disp('Now transmitting chunked data...'); 15 | while true 16 | outlet.push_chunk(randn(8,50)); 17 | pause(5); 18 | end -------------------------------------------------------------------------------- /liblsl-Matlab/examples/SendStringMarkers.m: -------------------------------------------------------------------------------- 1 | % instantiate the library 2 | disp('Loading library...'); 3 | lib = lsl_loadlib(); 4 | 5 | % make a new stream outlet 6 | % the name (here MyMarkerStream) is visible to the experimenter and should be chosen so that 7 | % it is clearly recognizable as your MATLAB software's marker stream 8 | % The content-type should be Markers by convention, and the next three arguments indicate the 9 | % data format (1 channel, irregular rate, string-formatted). 10 | % The so-called source id is an optional string that allows for uniquely identifying your 11 | % marker stream across re-starts (or crashes) of your script (i.e., after a crash of your script 12 | % other programs could continue to record from the stream with only a minor interruption). 13 | disp('Creating a new marker stream info...'); 14 | info = lsl_streaminfo(lib,'MyMarkerStream','Markers',1,0,'cf_string','myuniquesourceid23443'); 15 | 16 | disp('Opening an outlet...'); 17 | outlet = lsl_outlet(info); 18 | 19 | % send markers into the outlet 20 | disp('Now transmitting data...'); 21 | markers = {'Test', 'Blah', 'Marker', 'XXX', 'Testtest', 'Test-1-2-3'}; 22 | while true 23 | pause(rand()*3); 24 | mrk = markers{min(length(markers), 1+floor(rand()*(length(markers))))}; 25 | disp(['now sending ' mrk]); 26 | outlet.push_sample({mrk}); % note that the string is wrapped into a cell-array 27 | end 28 | -------------------------------------------------------------------------------- /liblsl-Matlab/experiment16-09-35.052.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUNPC/ninjaGUI/9746ca0be4a7519f3f43b6f446786849b7109606/liblsl-Matlab/experiment16-09-35.052.txt -------------------------------------------------------------------------------- /liblsl-Matlab/experiment16-09-45.572.txt: -------------------------------------------------------------------------------- 1 | datos ttemp 2 | datos ttemp 3 | datos ttemp 4 | datos ttemp 5 | datos ttemp 6 | datos ttemp 7 | datos ttemp 8 | datos ttemp 9 | datos ttemp 10 | datos ttemp 11 | datos ttemp 12 | datos ttemp 13 | datos ttemp 14 | datos ttemp 15 | datos ttemp 16 | datos ttemp 17 | datos ttemp 18 | datos ttemp 19 | datos ttemp 20 | datos ttemp 21 | datos ttemp 22 | datos ttemp 23 | datos ttemp 24 | datos ttemp 25 | datos ttemp 26 | datos ttemp 27 | datos ttemp 28 | datos ttemp 29 | datos ttemp 30 | datos ttemp 31 | datos ttemp 32 | datos ttemp 33 | datos ttemp 34 | datos ttemp 35 | datos ttemp 36 | datos ttemp 37 | datos ttemp 38 | datos ttemp 39 | datos ttemp 40 | datos ttemp 41 | datos ttemp 42 | datos ttemp 43 | datos ttemp 44 | datos ttemp 45 | datos ttemp 46 | datos ttemp 47 | datos ttemp 48 | datos ttemp 49 | datos ttemp 50 | datos ttemp 51 | datos ttemp 52 | datos ttemp 53 | datos ttemp 54 | datos ttemp 55 | datos ttemp 56 | datos ttemp 57 | datos ttemp 58 | datos ttemp 59 | datos ttemp 60 | datos ttemp 61 | datos ttemp 62 | -------------------------------------------------------------------------------- /liblsl-Matlab/experiment16-27-34.328.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUNPC/ninjaGUI/9746ca0be4a7519f3f43b6f446786849b7109606/liblsl-Matlab/experiment16-27-34.328.txt -------------------------------------------------------------------------------- /liblsl-Matlab/foo.txt: -------------------------------------------------------------------------------- 1 | 0.12905,0.77984 2 | 0.42056,0.51568 3 | 0.82384,0.39041 4 | 0.27405,0.39333 5 | 0.9346,0.78724 6 | 0.19796,0.75625 7 | 0.28289,0.11584 8 | 0.60164,0.11963 9 | 0.79394,0.29084 10 | 0.48521,0.12459 11 | 0.40385,0.89847 12 | 0.68136,0.31186 13 | 0.41241,0.66903 14 | 0.72071,0.26527 15 | 0.82079,0.47161 16 | 0.083431,0.97136 17 | 0.40593,0.71036 18 | 0.057989,0.97388 19 | 0.24161,0.76729 20 | 0.021387,0.4265 21 | 0.14922,0.50491 22 | 0.67536,0.047922 23 | 0.26362,0.14981 24 | 0.97617,0.81429 25 | 0.37622,0.78981 26 | 0.69077,0.82517 27 | 0.3946,0.27223 28 | 0.28178,0.80937 29 | 0.25337,0.47982 30 | 0.48317,0.27175 31 | 0.58235,0.96662 32 | 0.87032,0.62236 33 | 0.93629,0.27277 34 | 0.22791,0.753 35 | 0.91983,0.7102 36 | 0.44886,0.51376 37 | 0.90051,0.73797 38 | 0.30807,0.41584 39 | 0.99723,0.088278 40 | 0.17945,0.88772 41 | 0.37759,0.55468 42 | 0.30025,0.80664 43 | 0.86521,0.34093 44 | 0.42956,0.022122 45 | 0.30093,0.40986 46 | 0.72686,0.95056 47 | 0.41277,0.76298 48 | 0.026559,0.7779 49 | 0.55893,0.19564 50 | 0.012811,0.069699 51 | 0.76957,0.73915 52 | 0.10202,0.65297 53 | 0.43677,0.075036 54 | 0.24479,0.25648 55 | 0.75948,0.56424 56 | 0.22793,0.49817 57 | 0.38568,0.4992 58 | 0.74717,0.94276 59 | 0.018346,0.74878 60 | 0.90954,0.98879 61 | 0.4452,0.5781 62 | 0.40173,0.17023 63 | 0.1258,0.33142 64 | 0.90337,0.38061 65 | 0.73723,0.37103 66 | 0.2605,0.35115 67 | 0.55227,0.99749 68 | 0.9649,0.28475 69 | 0.56618,0.98304 70 | 0.81669,0.67166 71 | 0.90803,0.34803 72 | 0.87502,0.97941 73 | 0.9115,0.034115 74 | 0.42757,0.87561 75 | 0.24123,0.68014 76 | 0.96099,0.59597 77 | 0.54003,0.16218 78 | 0.1563,0.46346 79 | 0.36125,0.56095 80 | 0.44276,0.83921 81 | 0.56706,0.70612 82 | 0.70305,0.32976 83 | 0.3972,0.14106 84 | 0.27956,0.33193 85 | 0.82381,0.68789 86 | 0.30381,0.27696 87 | 0.24461,0.22315 88 | 0.31908,0.4524 89 | 0.33879,0.26278 90 | 0.010634,0.97505 91 | 0.081917,0.97607 92 | 0.51589,0.15847 93 | 0.79069,0.4095 94 | 0.37735,0.71586 95 | 0.7978,0.10978 96 | 0.29981,0.93293 97 | 0.19559,0.10373 98 | 0.62811,0.93968 99 | 0.12707,0.23645 100 | 0.55872,0.089389 101 | -------------------------------------------------------------------------------- /liblsl-Matlab/liblsl64.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BUNPC/ninjaGUI/9746ca0be4a7519f3f43b6f446786849b7109606/liblsl-Matlab/liblsl64.lib -------------------------------------------------------------------------------- /liblsl-Matlab/lsl_loadlib.m: -------------------------------------------------------------------------------- 1 | function hlib = lsl_loadlib(binarypath,debugging,keep_persistent) 2 | % Load the lab streaming layer library. 3 | % [LibHandle] = lsl_loadlib(BinaryPath,DebugVersion) 4 | % 5 | % This operation loads the library, after which its functions (starting with lsl_) can be used. 6 | % 7 | % In: 8 | % BinaryPath : Optionally the path to the locations of the liblsl bin folder (default: relative 9 | % to this .m file). 10 | % 11 | % DebugVersion : Optionally load the debug version of the library (default: false) 12 | % 13 | % Persistent : keep the library handle around until shutdown (default: true) 14 | % 15 | % Out: 16 | % Handle : handle to the library 17 | % when the handle is deleted, the library will be unloaded 18 | % 19 | % Notes: 20 | % Do not delete this handle while you still have LSL objects (streaminfos, inlets, outlets) 21 | % alive. 22 | % 23 | % Christian Kothe, Swartz Center for Computational Neuroscience, UCSD 24 | % 2012-03-05 25 | 26 | if ~exist('binarypath','var') || isempty(binarypath) 27 | binarypath = [fileparts(mfilename('fullpath')) filesep 'bin']; end 28 | if ~exist('debugging','var') || isempty(debugging) 29 | debugging = false; end 30 | if ~exist('keep_persistent','var') || isempty(keep_persistent) 31 | keep_persistent = true; end 32 | 33 | persistent lib; 34 | if keep_persistent && ~isempty(lib) 35 | hlib = lib; 36 | else 37 | if ispc 38 | ext = '.dll'; 39 | elseif ismac 40 | ext = '.dylib'; 41 | elseif isunix 42 | ext = '.so'; 43 | else 44 | error('Your operating system is not supported by this version of the lab streaming layer API.'); 45 | end 46 | 47 | if strfind(computer,'64') 48 | bitness = '64'; 49 | else 50 | bitness = '32'; 51 | end 52 | 53 | if debugging 54 | debug = '-debug'; 55 | else 56 | debug = ''; 57 | end 58 | 59 | dllpath = [binarypath filesep 'liblsl' bitness debug ext]; 60 | 61 | if ~exist(dllpath,'file') 62 | error(['Apparently the file "' dllpath '" is missing on your computer. Cannot load the lab streaming layer.']); end 63 | 64 | % open the library and make sure that it gets auto-deleted when the handle is erased 65 | hlib = lsl_loadlib_(dllpath); 66 | hlib.on_cleanup = onCleanup(@()lsl_freelib_(hlib)); 67 | 68 | if keep_persistent 69 | lib = hlib; end 70 | end -------------------------------------------------------------------------------- /liblsl-Matlab/lsl_resolve_all.m: -------------------------------------------------------------------------------- 1 | function streaminfos = lsl_resolve_all(lib,timeout) 2 | % [Streaminfos] = lsl_resolve_all(LibHandle,Timeout) 3 | % Resolve all streams on the network. 4 | % 5 | % This function returns all currently available streams from any outlet on the network. 6 | % The network is usually the subnet specified at the local router, but may also include 7 | % a multicast group of machines (given that the network supports it), or list of hostnames. 8 | % These details may optionally be customized by the experimenter in a configuration file 9 | % (see Network Connectivity in the LSL wiki). 10 | % This is the default mechanism used by the browsing programs and the recording program. 11 | % 12 | % In: 13 | % LibHandle : handle to the API library, as obtained via lsl_loadlib(); 14 | % 15 | % Timeout : The timeout for the operation, in seconds. 16 | % 17 | % Out 18 | % Streaminfos : A cell array of stream info objects (excluding their desc field), any of which can 19 | % subsequently be used to open an inlet. The full info can be retrieved from the 20 | % inlet. 21 | 22 | if ~exist('timeout','var') || isempty(timeout) 23 | timeout = 3.0; end 24 | 25 | % first do a raw resolve 26 | tmpresults = lsl_resolve_all_(lib,timeout); 27 | 28 | % create an lsl_streaminfo instance for each result 29 | streaminfos = cell(1,length(tmpresults)); 30 | for r=1:length(tmpresults) 31 | streaminfos{r} = lsl_streaminfo(lib,tmpresults(r)); end 32 | -------------------------------------------------------------------------------- /liblsl-Matlab/lsl_resolve_bypred.m: -------------------------------------------------------------------------------- 1 | function streaminfos = lsl_resolve_bypred(lib,pred,minimum,timeout) 2 | % [Streaminfos] = lsl_resolve_byprop(LibHandle,Predicate,Minimum,Timeout) 3 | % Resolve streams of the network whose contents match a given predicate. 4 | % 5 | % Advanced query that allows to impose more conditions on the retrieved streams; the given string is 6 | % an XPath 1.0 predicate for the node (omitting the surrounding []'s), see also 7 | % http://en.wikipedia.org/w/index.php?title=XPath_1.0&oldid=474981951. 8 | % 9 | % In: 10 | % LibHandle : handle to the API library, as obtained via lsl_loadlib(); 11 | % 12 | % Predicate : The predicate string, e.g. 'name=''BioSemi''' or 13 | % 'type=''EEG'' and starts-with(name,''BioSemi'') and count(info/desc/channel)=32' 14 | % 15 | % Minimum : Return at least this number of results. (default: 1) 16 | % 17 | % Timeout : Optionally a timeout of the operation, in seconds (default: 5s). If the timeout 18 | % expires, less than the desired number of streams (possibly none) will be returned. 19 | % 20 | % Out: 21 | % Streaminfos : A vector of matching stream info objects (excluding their meta-data), any of 22 | % which can subsequently be used to open an inlet. 23 | % 24 | % Notes: 25 | % If you want to wait until a stream shows up it is usually a better idea to call resolve 26 | % in a loop with a few-second timeout than to set the timeout to infinite (since MATLAB would 27 | % otherwise become unresponsive). 28 | 29 | if ~exist('minimum','var') || isempty(minimum) 30 | minimum = 1; end 31 | if ~exist('timeout','var') || isempty(timeout) 32 | timeout = 5; end 33 | 34 | % first do a raw resolve 35 | tmpresults = lsl_resolve_bypred_(lib,pred,minimum,timeout); 36 | 37 | % create an lsl_streaminfo instance for each result 38 | streaminfos = cell(1,length(tmpresults)); 39 | for r=1:length(tmpresults) 40 | streaminfos{r} = lsl_streaminfo(lib,tmpresults(r)); end 41 | -------------------------------------------------------------------------------- /liblsl-Matlab/lsl_resolve_byprop.m: -------------------------------------------------------------------------------- 1 | function streaminfos = lsl_resolve_byprop(lib,prop,value,minimum,timeout) 2 | % [Streaminfos] = lsl_resolve_byprop(LibHandle,PropertyName,PropertyValue,Minimum,Timeout) 3 | % Resolve streams of the network that have a particular value for a given property. 4 | % 5 | % If the goal is to resolve a specific stream, this method is preferred over resolving all streams 6 | % and then selecting the desired one. 7 | % 8 | % In: 9 | % LibHandle : handle to the API library, as obtained via lsl_loadlib(); 10 | % 11 | % PropertyName : The stream_info property that should have a specific value (e.g., 'name', 'type', 12 | % 'source_id', or 'desc/manufaturer'). 13 | % 14 | % PropertyValue : The string value that the property should have (such as 'EEG' if the PropertyName 15 | % was 'type'). 16 | % 17 | % Minimum : Return at least this number of results. (default: 1) 18 | % 19 | % Timeout : Optionally a timeout of the operation, in seconds (default: 5s). If the timeout 20 | % expires, less than the desired number of streams (possibly none) will be returned. 21 | % 22 | % Out: 23 | % Streaminfos : A vector of matching stream info objects (excluding their meta-data), any of 24 | % which can subsequently be used to open an inlet. 25 | % 26 | % Notes: 27 | % If you want to wait until a stream shows up it is usually a better idea to call resolve 28 | % in a loop with a few-second timeout than to set the timeout to infinite (since MATLAB would 29 | % otherwise become unresponsive). 30 | 31 | if ~exist('minimum','var') || isempty(minimum) 32 | minimum = 1; end 33 | if ~exist('timeout','var') || isempty(timeout) 34 | timeout = 5; end 35 | 36 | % first do a raw resolve 37 | tmpresults = lsl_resolve_byprop_(lib,prop,value,minimum,timeout); 38 | 39 | % create an lsl_streaminfo instance for each result 40 | streaminfos = cell(1,length(tmpresults)); 41 | for r=1:length(tmpresults) 42 | streaminfos{r} = lsl_streaminfo(lib,tmpresults(r)); end 43 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/env_compile.m: -------------------------------------------------------------------------------- 1 | % This file is only useful if you're using BCILAB to rebuild the .c files in here. Libraries = 'dl'; -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_append_child.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [DescPtr] = lsl_append_child(LibHandle,DescPtr,Name) */ 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_append_child_t func; 14 | /* input/output variables */ 15 | char str[65536]; 16 | int str_len; 17 | xml_ptr in; 18 | xml_ptr out; 19 | 20 | if (nrhs != 3) 21 | mexErrMsgTxt("3 input argument(s) required."); 22 | if (nlhs != 1) 23 | mexErrMsgTxt("1 output argument(s) required."); 24 | 25 | /* get function handle */ 26 | field = mxGetField(prhs[0],0,"lsl_append_child"); 27 | if (!field) 28 | mexErrMsgTxt("The field does not seem to exist."); 29 | pTmp = (uintptr_t*)mxGetData(field); 30 | if (!pTmp) 31 | mexErrMsgTxt("The field seems to be empty."); 32 | func = (lsl_append_child_t*)*pTmp; 33 | 34 | /* get additional inputs */ 35 | in = (xml_ptr)*(uintptr_t*)mxGetData(prhs[1]); 36 | str_len = mxGetNumberOfElements(prhs[2]); 37 | if (str_len+1 > sizeof(str)/sizeof(str[0])) 38 | mexErrMsgTxt("The given string is too long."); 39 | mxGetString(prhs[2], str, str_len+1); 40 | 41 | /* invoke & return */ 42 | out = func(in,str); 43 | plhs[0] = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(plhs[0]) = (uintptr_t)out; 44 | } 45 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_append_child_value.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [DescPtr] = lsl_append_child_value(LibHandle,DescPtr,Name,Value) */ 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_append_child_value_t func; 14 | /* input/output variables */ 15 | char name[65536], value[65536]; 16 | int name_len, value_len; 17 | xml_ptr in; 18 | xml_ptr out; 19 | 20 | if (nrhs != 4) 21 | mexErrMsgTxt("4 input argument(s) required."); 22 | if (nlhs != 1) 23 | mexErrMsgTxt("1 output argument(s) required."); 24 | 25 | /* get function handle */ 26 | field = mxGetField(prhs[0],0,"lsl_append_child_value"); 27 | if (!field) 28 | mexErrMsgTxt("The field does not seem to exist."); 29 | pTmp = (uintptr_t*)mxGetData(field); 30 | if (!pTmp) 31 | mexErrMsgTxt("The field seems to be append_child_value."); 32 | func = (lsl_append_child_value_t*)*pTmp; 33 | 34 | /* get additional inputs */ 35 | in = (xml_ptr)*(uintptr_t*)mxGetData(prhs[1]); 36 | name_len = mxGetNumberOfElements(prhs[2]); 37 | if (name_len+1 > sizeof(name)/sizeof(name[0])) 38 | mexErrMsgTxt("The given string is too long."); 39 | mxGetString(prhs[2], name, name_len+1); 40 | value_len = mxGetNumberOfElements(prhs[3]); 41 | if (value_len+1 > sizeof(value)/sizeof(value[0])) 42 | mexErrMsgTxt("The given string is too long."); 43 | mxGetString(prhs[3], value, value_len+1); 44 | 45 | /* invoke & return */ 46 | out = func(in,name,value); 47 | plhs[0] = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(plhs[0]) = (uintptr_t)out; 48 | } 49 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_append_copy.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [DescPtr] = lsl_append_copy(LibHandle,DescPtr,Other) */ 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_append_copy_t func; 14 | /* input/output variables */ 15 | xml_ptr in, other; 16 | xml_ptr out; 17 | 18 | if (nrhs != 3) 19 | mexErrMsgTxt("3 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_append_copy"); 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_append_copy_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | in = (xml_ptr)*(uintptr_t*)mxGetData(prhs[1]); 34 | other = (xml_ptr)*(uintptr_t*)mxGetData(prhs[2]); 35 | 36 | /* invoke & return */ 37 | out = func(in,other); 38 | plhs[0] = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(plhs[0]) = (uintptr_t)out; 39 | } 40 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_child.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [DescPtr] = lsl_child(LibHandle,DescPtr,Name) */ 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_child_t func; 14 | /* input/output variables */ 15 | char str[65536]; 16 | int str_len; 17 | xml_ptr in; 18 | xml_ptr out; 19 | 20 | if (nrhs != 3) 21 | mexErrMsgTxt("3 input argument(s) required."); 22 | if (nlhs != 1) 23 | mexErrMsgTxt("1 output argument(s) required."); 24 | 25 | /* get function handle */ 26 | field = mxGetField(prhs[0],0,"lsl_child"); 27 | if (!field) 28 | mexErrMsgTxt("The field does not seem to exist."); 29 | pTmp = (uintptr_t*)mxGetData(field); 30 | if (!pTmp) 31 | mexErrMsgTxt("The field seems to be empty."); 32 | func = (lsl_child_t*)*pTmp; 33 | 34 | /* get additional inputs */ 35 | in = (xml_ptr)*(uintptr_t*)mxGetData(prhs[1]); 36 | str_len = mxGetNumberOfElements(prhs[2]); 37 | if (str_len+1 > sizeof(str)/sizeof(str[0])) 38 | mexErrMsgTxt("The given string is too long."); 39 | mxGetString(prhs[2], str, str_len+1); 40 | 41 | /* invoke & return */ 42 | out = func(in,str); 43 | plhs[0] = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(plhs[0]) = (uintptr_t)out; 44 | } 45 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_child_value.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [ChildValue] = lsl_child_value(LibHandle,DescPtr) */ 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_child_value_t func; 14 | /* input/output variables */ 15 | xml_ptr in; 16 | char *out; 17 | 18 | if (nrhs != 2) 19 | mexErrMsgTxt("2 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_child_value"); 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 child_value."); 30 | func = (lsl_child_value_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | in = (xml_ptr)*(uintptr_t*)mxGetData(prhs[1]); 34 | 35 | /* invoke & return */ 36 | out = func(in); 37 | plhs[0] = mxCreateString(out); 38 | } 39 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_child_value_n.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [ChildValue] = lsl_child_value_n(LibHandle,DescPtr,Name) */ 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_child_value_n_t func; 14 | /* input/output variables */ 15 | char str[65536]; 16 | int str_len; 17 | xml_ptr in; 18 | char *out; 19 | 20 | if (nrhs != 3) 21 | mexErrMsgTxt("3 input argument(s) required."); 22 | if (nlhs != 1) 23 | mexErrMsgTxt("1 output argument(s) required."); 24 | 25 | /* get function handle */ 26 | field = mxGetField(prhs[0],0,"lsl_child_value_n"); 27 | if (!field) 28 | mexErrMsgTxt("The field does not seem to exist."); 29 | pTmp = (uintptr_t*)mxGetData(field); 30 | if (!pTmp) 31 | mexErrMsgTxt("The field seems to be child_value_n."); 32 | func = (lsl_child_value_n_t*)*pTmp; 33 | 34 | /* get additional inputs */ 35 | in = (xml_ptr)*(uintptr_t*)mxGetData(prhs[1]); 36 | str_len = mxGetNumberOfElements(prhs[2]); 37 | if (str_len+1 > sizeof(str)/sizeof(str[0])) 38 | mexErrMsgTxt("The given string is too long."); 39 | mxGetString(prhs[2], str, str_len+1); 40 | 41 | /* invoke & return */ 42 | out = func(in,str); 43 | plhs[0] = mxCreateString(out); 44 | } 45 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_close_stream.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function lsl_close_stream(LibHandle,inlet) */ 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_close_stream_t func; 14 | /* input/output variables */ 15 | uintptr_t out; 16 | 17 | if (nrhs != 2) 18 | mexErrMsgTxt("2 input argument(s) required."); 19 | if (nlhs != 0) 20 | mexErrMsgTxt("0 output argument(s) required."); 21 | 22 | /* get function handle */ 23 | field = mxGetField(prhs[0],0,"lsl_close_stream"); 24 | if (!field) 25 | mexErrMsgTxt("The field does not seem to exist."); 26 | pTmp = (uintptr_t*)mxGetData(field); 27 | if (!pTmp) 28 | mexErrMsgTxt("The field seems to be empty."); 29 | func = (lsl_close_stream_t*)*pTmp; 30 | 31 | /* get additional inputs */ 32 | out = *(uintptr_t*)mxGetData(prhs[1]); 33 | 34 | /* invoke & return */ 35 | func(out); 36 | } 37 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_create_inlet.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [Inlet] = lsl_create_inlet(LibHandle,StreamInfo,MaxBuffered,ChunkSize,Recover) */ 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 | /* mex inputs */ 13 | streaminfo info; 14 | int max_buffered; 15 | int chunk_size; 16 | int recover; 17 | /* function handle */ 18 | lsl_create_inlet_t func; 19 | /* input/output variables */ 20 | inlet result; 21 | 22 | if (nrhs != 5) 23 | mexErrMsgTxt("5 input argument(s) required."); 24 | if (nlhs != 1) 25 | mexErrMsgTxt("1 output argument(s) required."); 26 | 27 | /* get function handle */ 28 | field = mxGetField(prhs[0],0,"lsl_create_inlet"); 29 | if (!field) 30 | mexErrMsgTxt("The field does not seem to exist."); 31 | pTmp = (uintptr_t*)mxGetData(field); 32 | if (!pTmp) 33 | mexErrMsgTxt("The field seems to be empty."); 34 | func = (lsl_create_inlet_t*)*pTmp; 35 | 36 | /* get additional inputs */ 37 | if (mxGetClassID(prhs[1]) != PTR_CLASS) 38 | mexErrMsgTxt("The streaminfo must be a pointer."); 39 | info = (uintptr_t)(*(uintptr_t*)mxGetData(prhs[1])); 40 | 41 | if (mxGetClassID(prhs[2]) != mxDOUBLE_CLASS) 42 | mexErrMsgTxt("The max buffer size must be passed as a double."); 43 | max_buffered = (int)(*(double*)mxGetData(prhs[2])); 44 | 45 | if (mxGetClassID(prhs[3]) != mxDOUBLE_CLASS) 46 | mexErrMsgTxt("The chunk size must be passed as a double."); 47 | chunk_size = (int)(*(double*)mxGetData(prhs[3])); 48 | 49 | if (mxGetClassID(prhs[4]) != mxDOUBLE_CLASS) 50 | mexErrMsgTxt("The recover flag must be passed as a double."); 51 | recover = (int)(*(double*)mxGetData(prhs[4])); 52 | 53 | /* invoke & return */ 54 | result = func(info,max_buffered,chunk_size,recover); 55 | plhs[0] = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *((uintptr_t*)mxGetData(plhs[0])) = (uintptr_t)result; 56 | } 57 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_create_outlet.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [Outlet] = lsl_create_outlet(LibHandle,StreamInfo,ChunkSize,MaxBuffered) */ 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 | /* mex inputs */ 13 | streaminfo info; 14 | int chunk_size; 15 | int max_buffered; 16 | /* function handle */ 17 | lsl_create_outlet_t func; 18 | /* input/output variables */ 19 | outlet result; 20 | 21 | if (nrhs != 4) 22 | mexErrMsgTxt("4 input argument(s) required."); 23 | if (nlhs != 1) 24 | mexErrMsgTxt("1 output argument(s) required."); 25 | 26 | /* get function handle */ 27 | field = mxGetField(prhs[0],0,"lsl_create_outlet"); 28 | if (!field) 29 | mexErrMsgTxt("The field does not seem to exist."); 30 | pTmp = (uintptr_t*)mxGetData(field); 31 | if (!pTmp) 32 | mexErrMsgTxt("The field seems to be empty."); 33 | func = (lsl_create_outlet_t*)*pTmp; 34 | 35 | /* get additional inputs */ 36 | if (mxGetClassID(prhs[1]) != PTR_CLASS) 37 | mexErrMsgTxt("The streaminfo must be a pointer."); 38 | info = (uintptr_t)(*(uintptr_t*)mxGetData(prhs[1])); 39 | 40 | if (mxGetClassID(prhs[2]) != mxDOUBLE_CLASS) 41 | mexErrMsgTxt("The chunk size must be passed as a double."); 42 | chunk_size = (int)(*(double*)mxGetData(prhs[2])); 43 | 44 | if (mxGetClassID(prhs[3]) != mxDOUBLE_CLASS) 45 | mexErrMsgTxt("The max buffer size must be passed as a double."); 46 | max_buffered = (int)(*(double*)mxGetData(prhs[3])); 47 | 48 | /* invoke & return */ 49 | result = func(info,chunk_size,max_buffered); 50 | plhs[0] = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *((uintptr_t*)mxGetData(plhs[0])) = (uintptr_t)result; 51 | } 52 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_create_streaminfo.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [Streaminfo] = lsl_create_streaminfo(LibHandle,Name,Type,ChannelCount,SamplingRate,ChannelFormat,SourceID) */ 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 | /* mex inputs */ 13 | char name[2048], type[2048], source_id[16384]; 14 | int name_len, type_len, source_id_len; 15 | int channel_count; 16 | double nominal_srate; 17 | int channel_format; 18 | /* function handle */ 19 | lsl_create_streaminfo_t func; 20 | /* input/output variables */ 21 | streaminfo result; 22 | if (nrhs != 7) 23 | mexErrMsgTxt("7 input argument(s) required."); 24 | if (nlhs != 1) 25 | mexErrMsgTxt("1 output argument(s) required."); 26 | 27 | /* get function handle */ 28 | field = mxGetField(prhs[0],0,"lsl_create_streaminfo"); 29 | if (!field) 30 | mexErrMsgTxt("The field does not seem to exist."); 31 | pTmp = (uintptr_t*)mxGetData(field); 32 | if (!pTmp) 33 | mexErrMsgTxt("The field seems to be empty."); 34 | func = (lsl_create_streaminfo_t*)*pTmp; 35 | 36 | /* get additional inputs */ 37 | name_len = mxGetNumberOfElements(prhs[1]); 38 | if (name_len+1 > sizeof(name)/sizeof(name[0])) 39 | mexErrMsgTxt("The given stream name is too long."); 40 | mxGetString(prhs[1], name, name_len+1); 41 | 42 | type_len = mxGetNumberOfElements(prhs[2]); 43 | if (type_len+1 > sizeof(type)/sizeof(type[0])) 44 | mexErrMsgTxt("The given stream type is too long."); 45 | mxGetString(prhs[2], type, type_len+1); 46 | 47 | if (mxGetClassID(prhs[3]) != mxDOUBLE_CLASS) 48 | mexErrMsgTxt("The channel count must be passed as a double."); 49 | channel_count = (int)(*(double*)mxGetData(prhs[3])); 50 | 51 | if (mxGetClassID(prhs[4]) != mxDOUBLE_CLASS) 52 | mexErrMsgTxt("The sampling rate must be passed as a double."); 53 | nominal_srate = (*(double*)mxGetData(prhs[4])); 54 | 55 | if (mxGetClassID(prhs[5]) != mxDOUBLE_CLASS) 56 | mexErrMsgTxt("The channel format must be passed as a double."); 57 | channel_format = (*(double*)mxGetData(prhs[5])); 58 | if (!(channel_format>=1 && channel_format <=6)) 59 | mexErrMsgTxt("The given channel format is unsupported."); 60 | 61 | source_id_len = mxGetNumberOfElements(prhs[6]); 62 | if (source_id_len+1 > sizeof(source_id)/sizeof(source_id[0])) 63 | mexErrMsgTxt("The given stream source id is too long."); 64 | mxGetString(prhs[6], source_id, source_id_len+1); 65 | 66 | /* invoke & return */ 67 | result = func(name,type,channel_count,nominal_srate,channel_format,source_id); 68 | plhs[0] = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *((uintptr_t*)mxGetData(plhs[0])) = (uintptr_t)result; 69 | } 70 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_destroy_inlet.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function lsl_destroy_inlet(LibHandle,inlet) */ 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_destroy_inlet_t func; 14 | /* input/output variables */ 15 | uintptr_t out; 16 | 17 | if (nrhs != 2) 18 | mexErrMsgTxt("2 input argument(s) required."); 19 | if (nlhs != 0) 20 | mexErrMsgTxt("0 output argument(s) required."); 21 | 22 | /* get function handle */ 23 | field = mxGetField(prhs[0],0,"lsl_destroy_inlet"); 24 | if (!field) 25 | mexErrMsgTxt("The field does not seem to exist."); 26 | pTmp = (uintptr_t*)mxGetData(field); 27 | if (!pTmp) 28 | mexErrMsgTxt("The field seems to be empty."); 29 | func = (lsl_destroy_inlet_t*)*pTmp; 30 | 31 | /* get additional inputs */ 32 | out = *(uintptr_t*)mxGetData(prhs[1]); 33 | 34 | /* invoke & return */ 35 | func(out); 36 | } 37 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_destroy_outlet.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function lsl_destroy_outlet(LibHandle,Outlet) */ 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_destroy_outlet_t func; 14 | /* input/output variables */ 15 | uintptr_t out; 16 | 17 | if (nrhs != 2) 18 | mexErrMsgTxt("2 input argument(s) required."); 19 | if (nlhs != 0) 20 | mexErrMsgTxt("0 output argument(s) required."); 21 | 22 | /* get function handle */ 23 | field = mxGetField(prhs[0],0,"lsl_destroy_outlet"); 24 | if (!field) 25 | mexErrMsgTxt("The field does not seem to exist."); 26 | pTmp = (uintptr_t*)mxGetData(field); 27 | if (!pTmp) 28 | mexErrMsgTxt("The field seems to be empty."); 29 | func = (lsl_destroy_outlet_t*)*pTmp; 30 | 31 | /* get additional inputs */ 32 | out = *(uintptr_t*)mxGetData(prhs[1]); 33 | 34 | /* invoke & return */ 35 | func(out); 36 | } 37 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_destroy_streaminfo.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function lsl_destroy_streaminfo(LibHandle,StreamInfo) */ 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_destroy_streaminfo_t func; 14 | /* input/output variables */ 15 | uintptr_t info; 16 | 17 | if (nrhs != 2) 18 | mexErrMsgTxt("2 input argument(s) required."); 19 | if (nlhs != 0) 20 | mexErrMsgTxt("0 output argument(s) required."); 21 | 22 | /* get function handle */ 23 | field = mxGetField(prhs[0],0,"lsl_destroy_streaminfo"); 24 | if (!field) 25 | mexErrMsgTxt("The field does not seem to exist."); 26 | pTmp = (uintptr_t*)mxGetData(field); 27 | if (!pTmp) 28 | mexErrMsgTxt("The field seems to be empty."); 29 | func = (lsl_destroy_streaminfo_t*)*pTmp; 30 | 31 | /* get additional inputs */ 32 | info = *(uintptr_t*)mxGetData(prhs[1]); 33 | 34 | /* invoke & return */ 35 | func(info); 36 | } 37 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_empty.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [IsEmpty] = lsl_empty(LibHandle,DescPtr) */ 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_empty_t func; 14 | /* input/output variables */ 15 | xml_ptr in; 16 | int out; 17 | 18 | if (nrhs != 2) 19 | mexErrMsgTxt("2 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_empty"); 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_empty_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | in = (xml_ptr)*(uintptr_t*)mxGetData(prhs[1]); 34 | 35 | /* invoke & return */ 36 | out = func(in); 37 | plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL); *(double*)mxGetData(plhs[0]) = (double)out; 38 | } 39 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_first_child.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [DescPtr] = lsl_first_child(LibHandle,DescPtr) */ 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_first_child_t func; 14 | /* input/output variables */ 15 | xml_ptr in; 16 | xml_ptr out; 17 | 18 | if (nrhs != 2) 19 | mexErrMsgTxt("2 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_first_child"); 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_first_child_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | in = (xml_ptr)*(uintptr_t*)mxGetData(prhs[1]); 34 | 35 | /* invoke & return */ 36 | out = func(in); 37 | plhs[0] = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(plhs[0]) = (uintptr_t)out; 38 | } 39 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_freelib_.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* 4 | * lsl_freelib_(LibHandle); 5 | * Internal function to unload the lab streaming layer library. 6 | * 7 | * Note: as a user you don't have to call this function directly -- lsl_loadlib() ensures that 8 | * it gets called automatically when the last reference to the library handle is deleted.s 9 | * 10 | * In: 11 | * LibHandle : handle to the library, as returned by lsl_loadlib_(). 12 | * 13 | */ 14 | 15 | void mexFunction( int nlhs, mxArray *plhs[], 16 | int nrhs, const mxArray*prhs[] ) 17 | { 18 | mxArray *field; 19 | uintptr_t *pTmp; /* temp pointer */ 20 | void *hlib; /* handle to the library */ 21 | if (nrhs != 1) 22 | mexErrMsgTxt("One input argument required."); 23 | if (mxGetNumberOfElements(prhs[0]) != 1) 24 | mexErrMsgTxt("The input must be a scalar."); 25 | 26 | /* get the library handle */ 27 | field = mxGetField(prhs[0],0,"hlib"); 28 | if (!field) 29 | mexErrMsgTxt("Field does not seem to exist..."); 30 | pTmp = (uintptr_t*)mxGetData(field); 31 | if (!pTmp) 32 | mexErrMsgTxt("Entry does not seem to exist..."); 33 | hlib = (void*)*pTmp; 34 | /* unload the library */ 35 | FREE_LIBRARY(hlib); 36 | } 37 | 38 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_get_channel_count.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [ChannelCount] = lsl_get_channel_count(LibHandle,StreamInfo) */ 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_get_channel_count_t func; 14 | /* input/output variables */ 15 | uintptr_t info; 16 | int channel_count; 17 | 18 | if (nrhs != 2) 19 | mexErrMsgTxt("2 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_get_channel_count"); 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_get_channel_count_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | info = *(uintptr_t*)mxGetData(prhs[1]); 34 | 35 | /* invoke & return */ 36 | channel_count = func(info); 37 | plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL); *(double*)mxGetData(plhs[0]) = (double)channel_count; 38 | } 39 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_get_channel_format.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [ChannelFormat] = lsl_get_channel_format(LibHandle,StreamInfo) */ 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_get_channel_format_t func; 14 | /* input/output variables */ 15 | uintptr_t info; 16 | int channel_format; 17 | 18 | if (nrhs != 2) 19 | mexErrMsgTxt("2 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_get_channel_format"); 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_get_channel_format_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | info = *(uintptr_t*)mxGetData(prhs[1]); 34 | 35 | /* invoke & return */ 36 | channel_format = func(info); 37 | plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL); *(double*)mxGetData(plhs[0]) = (double)channel_format; 38 | } 39 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_get_created_at.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [CreatedAt] = lsl_get_created_at(LibHandle,StreamInfo) */ 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_get_created_at_t func; 14 | /* input/output variables */ 15 | uintptr_t info; 16 | double created_at; 17 | 18 | if (nrhs != 2) 19 | mexErrMsgTxt("2 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_get_created_at"); 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_get_created_at_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | info = *(uintptr_t*)mxGetData(prhs[1]); 34 | 35 | /* invoke & return */ 36 | created_at = func(info); 37 | plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL); *(double*)mxGetData(plhs[0]) = (double)created_at; 38 | } 39 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_get_desc.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [DescPtr] = lsl_get_desc(LibHandle,StreamInfo) */ 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_get_desc_t func; 14 | /* input/output variables */ 15 | uintptr_t info; 16 | xml_ptr desc; 17 | 18 | if (nrhs != 2) 19 | mexErrMsgTxt("2 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_get_desc"); 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_get_desc_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | info = *(uintptr_t*)mxGetData(prhs[1]); 34 | 35 | /* invoke & return */ 36 | desc = func(info); 37 | plhs[0] = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(plhs[0]) = (uintptr_t)desc; 38 | } 39 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_get_fullinfo.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [Streaminfo] = lsl_get_fullinfo(LibHandle,Inlet,Timeout) */ 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_get_fullinfo_t func; 14 | /* input/output variables */ 15 | uintptr_t in; 16 | double timeout; 17 | streaminfo result; 18 | int errcode; 19 | 20 | if (nrhs != 3) 21 | mexErrMsgTxt("3 input argument(s) required."); 22 | if (nlhs != 1) 23 | mexErrMsgTxt("1 output argument(s) required."); 24 | 25 | /* get function handle */ 26 | field = mxGetField(prhs[0],0,"lsl_get_fullinfo"); 27 | if (!field) 28 | mexErrMsgTxt("The field does not seem to exist."); 29 | pTmp = (uintptr_t*)mxGetData(field); 30 | if (!pTmp) 31 | mexErrMsgTxt("The field seems to be empty."); 32 | func = (lsl_get_fullinfo_t*)*pTmp; 33 | 34 | /* get additional inputs */ 35 | in = *(uintptr_t*)mxGetData(prhs[1]); 36 | 37 | if (mxGetClassID(prhs[2]) != mxDOUBLE_CLASS) 38 | mexErrMsgTxt("The timeout argument must be passed as a double."); 39 | timeout = *(double*)mxGetData(prhs[2]); 40 | 41 | /* invoke & return */ 42 | result = func(in,timeout,&errcode); 43 | if (errcode) { 44 | if (errcode == lsl_timeout_error) 45 | mexErrMsgIdAndTxt("lsl:timeout_error","The operation timed out."); 46 | if (errcode == lsl_lost_error) 47 | mexErrMsgIdAndTxt("lsl:lost_error","The stream has been lost."); 48 | if (errcode == lsl_internal_error) 49 | mexErrMsgIdAndTxt("lsl:internal_error","An internal error occurred."); 50 | mexErrMsgIdAndTxt("lsl:unknown_error","An unknown error occurred."); 51 | } 52 | plhs[0] = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(plhs[0]) = (uintptr_t)result; 53 | } 54 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_get_hostname.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [SessionID] = lsl_get_hostname(LibHandle,StreamInfo) */ 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_get_hostname_t func; 14 | /* input/output variables */ 15 | uintptr_t info; 16 | char *session_id; 17 | 18 | if (nrhs != 2) 19 | mexErrMsgTxt("2 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_get_hostname"); 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_get_hostname_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | info = *(uintptr_t*)mxGetData(prhs[1]); 34 | 35 | /* invoke & return */ 36 | session_id = func(info); 37 | plhs[0] = mxCreateString(session_id); 38 | } 39 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_get_info.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [Streaminfo] = lsl_get_info(LibHandle,Outlet) */ 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_get_info_t func; 14 | /* input/output variables */ 15 | uintptr_t out; 16 | streaminfo result; 17 | 18 | if (nrhs != 2) 19 | mexErrMsgTxt("2 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_get_info"); 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_get_info_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | out = *(uintptr_t*)mxGetData(prhs[1]); 34 | 35 | /* invoke & return */ 36 | result = func(out); 37 | plhs[0] = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(plhs[0]) = (uintptr_t)result; 38 | } 39 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_get_name.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [Name] = lsl_get_name(LibHandle,StreamInfo) */ 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_get_name_t func; 14 | /* input/output variables */ 15 | uintptr_t info; 16 | char *name; 17 | 18 | if (nrhs != 2) 19 | mexErrMsgTxt("2 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_get_name"); 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_get_name_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | info = *(uintptr_t*)mxGetData(prhs[1]); 34 | 35 | /* invoke & return */ 36 | name = func(info); 37 | plhs[0] = mxCreateString(name); 38 | } 39 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_get_nominal_srate.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [NominalSrate] = lsl_get_nominal_srate(LibHandle,StreamInfo) */ 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_get_nominal_srate_t func; 14 | /* input/output variables */ 15 | uintptr_t info; 16 | double nominal_srate; 17 | 18 | if (nrhs != 2) 19 | mexErrMsgTxt("2 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_get_nominal_srate"); 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_get_nominal_srate_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | info = *(uintptr_t*)mxGetData(prhs[1]); 34 | 35 | /* invoke & return */ 36 | nominal_srate = func(info); 37 | plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL); *(double*)mxGetData(plhs[0]) = nominal_srate; 38 | } 39 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_get_session_id.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [SessionID] = lsl_get_session_id(LibHandle,StreamInfo) */ 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_get_session_id_t func; 14 | /* input/output variables */ 15 | uintptr_t info; 16 | char *session_id; 17 | 18 | if (nrhs != 2) 19 | mexErrMsgTxt("2 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_get_session_id"); 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_get_session_id_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | info = *(uintptr_t*)mxGetData(prhs[1]); 34 | 35 | /* invoke & return */ 36 | session_id = func(info); 37 | plhs[0] = mxCreateString(session_id); 38 | } 39 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_get_source_id.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [SourceID] = lsl_get_source_id(LibHandle,StreamInfo) */ 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_get_source_id_t func; 14 | /* input/output variables */ 15 | uintptr_t info; 16 | char *source_id; 17 | 18 | if (nrhs != 2) 19 | mexErrMsgTxt("2 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_get_source_id"); 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_get_source_id_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | info = *(uintptr_t*)mxGetData(prhs[1]); 34 | 35 | /* invoke & return */ 36 | source_id = func(info); 37 | plhs[0] = mxCreateString(source_id); 38 | } 39 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_get_type.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [Type] = lsl_get_type(LibHandle,StreamInfo) */ 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_get_type_t func; 14 | /* input/output variables */ 15 | uintptr_t info; 16 | char *type; 17 | 18 | if (nrhs != 2) 19 | mexErrMsgTxt("2 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_get_type"); 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_get_type_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | info = *(uintptr_t*)mxGetData(prhs[1]); 34 | 35 | /* invoke & return */ 36 | type = func(info); 37 | plhs[0] = mxCreateString(type); 38 | } 39 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_get_uid.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [UID] = lsl_get_uid(LibHandle,StreamInfo) */ 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_get_uid_t func; 14 | /* input/output variables */ 15 | uintptr_t info; 16 | char *uid; 17 | 18 | if (nrhs != 2) 19 | mexErrMsgTxt("2 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_get_uid"); 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_get_uid_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | info = *(uintptr_t*)mxGetData(prhs[1]); 34 | 35 | /* invoke & return */ 36 | uid = func(info); 37 | plhs[0] = mxCreateString(uid); 38 | } 39 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_get_version.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [Version] = lsl_get_version(LibHandle,StreamInfo) */ 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_get_version_t func; 14 | /* input/output variables */ 15 | uintptr_t info; 16 | int version; 17 | 18 | if (nrhs != 2) 19 | mexErrMsgTxt("2 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_get_version"); 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_get_version_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | info = *(uintptr_t*)mxGetData(prhs[1]); 34 | 35 | /* invoke & return */ 36 | version = func(info); 37 | plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL); *(double*)mxGetData(plhs[0]) = (double)version; 38 | } 39 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_get_xml.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [XML] = lsl_get_xml(LibHandle,StreamInfo) */ 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_get_xml_t func; 14 | /* input/output variables */ 15 | uintptr_t info; 16 | char *xml; 17 | 18 | if (nrhs != 2) 19 | mexErrMsgTxt("2 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_get_xml"); 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_get_xml_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | info = *(uintptr_t*)mxGetData(prhs[1]); 34 | 35 | /* invoke & return */ 36 | xml = func(info); 37 | plhs[0] = mxCreateString(xml); 38 | } 39 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_have_consumers.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function lsl_have_consumers(LibHandle,Outlet) */ 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_have_consumers_t func; 14 | /* input/output variables */ 15 | uintptr_t out; 16 | int result; 17 | 18 | if (nrhs != 2) 19 | mexErrMsgTxt("2 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_have_consumers"); 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_have_consumers_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | out = *(uintptr_t*)mxGetData(prhs[1]); 34 | 35 | /* invoke & return */ 36 | result = func(out); 37 | plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL); *(double*)mxGetData(plhs[0]) = (double)result; 38 | } 39 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_is_text.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [IsText] = lsl_is_text(LibHandle,DescPtr) */ 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_is_text_t func; 14 | /* input/output variables */ 15 | xml_ptr in; 16 | int out; 17 | 18 | if (nrhs != 2) 19 | mexErrMsgTxt("2 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_is_text"); 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 is_text."); 30 | func = (lsl_is_text_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | in = (xml_ptr)*(uintptr_t*)mxGetData(prhs[1]); 34 | 35 | /* invoke & return */ 36 | out = func(in); 37 | plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL); *(double*)mxGetData(plhs[0]) = (double)out; 38 | } 39 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_last_child.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [DescPtr] = lsl_last_child(LibHandle,DescPtr) */ 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_last_child_t func; 14 | /* input/output variables */ 15 | xml_ptr in; 16 | xml_ptr out; 17 | 18 | if (nrhs != 2) 19 | mexErrMsgTxt("2 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_last_child"); 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_last_child_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | in = (xml_ptr)*(uintptr_t*)mxGetData(prhs[1]); 34 | 35 | /* invoke & return */ 36 | out = func(in); 37 | plhs[0] = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(plhs[0]) = (uintptr_t)out; 38 | } 39 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_library_version.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [LibraryVersion] = lsl_library_version(LibHandle) */ 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_library_version_t func; 14 | /* input/output variables */ 15 | int result; 16 | 17 | if (nrhs != 1) 18 | mexErrMsgTxt("1 input argument(s) required."); 19 | if (nlhs != 1) 20 | mexErrMsgTxt("1 output argument(s) required."); 21 | 22 | /* get function handle */ 23 | field = mxGetField(prhs[0],0,"lsl_library_version"); 24 | if (!field) 25 | mexErrMsgTxt("The field does not seem to exist."); 26 | pTmp = (uintptr_t*)mxGetData(field); 27 | if (!pTmp) 28 | mexErrMsgTxt("The field seems to be empty."); 29 | func = (lsl_library_version_t*)*pTmp; 30 | 31 | /* invoke & return */ 32 | result = func(); 33 | plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); *(int32_T*)mxGetData(plhs[0]) = (int32_T)result; 34 | } 35 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_local_clock.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [LocalClock] = lsl_local_clock(LibHandle) */ 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_local_clock_t func; 14 | /* input/output variables */ 15 | double result; 16 | 17 | if (nrhs != 1) 18 | mexErrMsgTxt("1 input argument(s) required."); 19 | if (nlhs != 1) 20 | mexErrMsgTxt("1 output argument(s) required."); 21 | 22 | /* get function handle */ 23 | field = mxGetField(prhs[0],0,"lsl_local_clock"); 24 | if (!field) 25 | mexErrMsgTxt("The field does not seem to exist."); 26 | pTmp = (uintptr_t*)mxGetData(field); 27 | if (!pTmp) 28 | mexErrMsgTxt("The field seems to be empty."); 29 | func = (lsl_local_clock_t*)*pTmp; 30 | 31 | /* invoke & return */ 32 | result = func(); 33 | plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL); *(double*)mxGetData(plhs[0]) = (double)result; 34 | } 35 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_name.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [Name] = lsl_name(LibHandle,DescPtr) */ 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_name_t func; 14 | /* input/output variables */ 15 | xml_ptr in; 16 | char *out; 17 | 18 | if (nrhs != 2) 19 | mexErrMsgTxt("2 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_name"); 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 name."); 30 | func = (lsl_name_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | in = (xml_ptr)*(uintptr_t*)mxGetData(prhs[1]); 34 | 35 | /* invoke & return */ 36 | out = func(in); 37 | plhs[0] = mxCreateString(out); 38 | } 39 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_next_sibling.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [DescPtr] = lsl_next_sibling(LibHandle,DescPtr) */ 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_next_sibling_t func; 14 | /* input/output variables */ 15 | xml_ptr in; 16 | xml_ptr out; 17 | 18 | if (nrhs != 2) 19 | mexErrMsgTxt("2 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_next_sibling"); 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_next_sibling_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | in = (xml_ptr)*(uintptr_t*)mxGetData(prhs[1]); 34 | 35 | /* invoke & return */ 36 | out = func(in); 37 | plhs[0] = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(plhs[0]) = (uintptr_t)out; 38 | } 39 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_next_sibling_n.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [DescPtr] = lsl_next_sibling_n(LibHandle,DescPtr,Name) */ 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_next_sibling_n_t func; 14 | /* input/output variables */ 15 | char str[65536]; 16 | int str_len; 17 | xml_ptr in; 18 | xml_ptr out; 19 | 20 | if (nrhs != 3) 21 | mexErrMsgTxt("3 input argument(s) required."); 22 | if (nlhs != 1) 23 | mexErrMsgTxt("1 output argument(s) required."); 24 | 25 | /* get function handle */ 26 | field = mxGetField(prhs[0],0,"lsl_next_sibling_n"); 27 | if (!field) 28 | mexErrMsgTxt("The field does not seem to exist."); 29 | pTmp = (uintptr_t*)mxGetData(field); 30 | if (!pTmp) 31 | mexErrMsgTxt("The field seems to be empty."); 32 | func = (lsl_next_sibling_n_t*)*pTmp; 33 | 34 | /* get additional inputs */ 35 | in = (xml_ptr)*(uintptr_t*)mxGetData(prhs[1]); 36 | str_len = mxGetNumberOfElements(prhs[2]); 37 | if (str_len+1 > sizeof(str)/sizeof(str[0])) 38 | mexErrMsgTxt("The given string is too long."); 39 | mxGetString(prhs[2], str, str_len+1); 40 | 41 | /* invoke & return */ 42 | out = func(in,str); 43 | plhs[0] = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(plhs[0]) = (uintptr_t)out; 44 | } 45 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_open_stream.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function lsl_open_stream(LibHandle,Inlet,Timeout) */ 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_open_stream_t func; 14 | /* input/output variables */ 15 | uintptr_t in; 16 | double timeout; 17 | int errcode; 18 | 19 | if (nrhs != 3) 20 | mexErrMsgTxt("3 input argument(s) required."); 21 | if (nlhs != 0) 22 | mexErrMsgTxt("0 output argument(s) required."); 23 | 24 | /* get function handle */ 25 | field = mxGetField(prhs[0],0,"lsl_open_stream"); 26 | if (!field) 27 | mexErrMsgTxt("The field does not seem to exist."); 28 | pTmp = (uintptr_t*)mxGetData(field); 29 | if (!pTmp) 30 | mexErrMsgTxt("The field seems to be empty."); 31 | func = (lsl_open_stream_t*)*pTmp; 32 | 33 | /* get additional inputs */ 34 | in = *(uintptr_t*)mxGetData(prhs[1]); 35 | if (mxGetClassID(prhs[2]) != mxDOUBLE_CLASS) 36 | mexErrMsgTxt("The timeout argument must be passed as a double."); 37 | timeout = *(double*)mxGetData(prhs[2]); 38 | 39 | /* invoke & return */ 40 | func(in,timeout,&errcode); 41 | 42 | if (errcode) { 43 | if (errcode == lsl_timeout_error) 44 | mexErrMsgIdAndTxt("lsl:timeout_error","The operation timed out."); 45 | if (errcode == lsl_lost_error) 46 | mexErrMsgIdAndTxt("lsl:lost_error","The stream has been lost."); 47 | if (errcode == lsl_internal_error) 48 | mexErrMsgIdAndTxt("lsl:internal_error","An internal error occurred."); 49 | mexErrMsgIdAndTxt("lsl:unknown_error","An unknown error occurred."); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_parent.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [DescPtr] = lsl_parent(LibHandle,DescPtr) */ 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_parent_t func; 14 | /* input/output variables */ 15 | xml_ptr in; 16 | xml_ptr out; 17 | 18 | if (nrhs != 2) 19 | mexErrMsgTxt("2 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_parent"); 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_parent_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | in = (xml_ptr)*(uintptr_t*)mxGetData(prhs[1]); 34 | 35 | /* invoke & return */ 36 | out = func(in); 37 | plhs[0] = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(plhs[0]) = (uintptr_t)out; 38 | } 39 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_prepend_child.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [DescPtr] = lsl_prepend_child(LibHandle,DescPtr,Name) */ 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_prepend_child_t func; 14 | /* input/output variables */ 15 | char str[65536]; 16 | int str_len; 17 | xml_ptr in; 18 | xml_ptr out; 19 | 20 | if (nrhs != 3) 21 | mexErrMsgTxt("3 input argument(s) required."); 22 | if (nlhs != 1) 23 | mexErrMsgTxt("1 output argument(s) required."); 24 | 25 | /* get function handle */ 26 | field = mxGetField(prhs[0],0,"lsl_prepend_child"); 27 | if (!field) 28 | mexErrMsgTxt("The field does not seem to exist."); 29 | pTmp = (uintptr_t*)mxGetData(field); 30 | if (!pTmp) 31 | mexErrMsgTxt("The field seems to be empty."); 32 | func = (lsl_prepend_child_t*)*pTmp; 33 | 34 | /* get additional inputs */ 35 | in = (xml_ptr)*(uintptr_t*)mxGetData(prhs[1]); 36 | str_len = mxGetNumberOfElements(prhs[2]); 37 | if (str_len+1 > sizeof(str)/sizeof(str[0])) 38 | mexErrMsgTxt("The given string is too long."); 39 | mxGetString(prhs[2], str, str_len+1); 40 | 41 | /* invoke & return */ 42 | out = func(in,str); 43 | plhs[0] = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(plhs[0]) = (uintptr_t)out; 44 | } 45 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_prepend_child_value.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [DescPtr] = lsl_prepend_child_value(LibHandle,DescPtr,Name,Value) */ 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_prepend_child_value_t func; 14 | /* input/output variables */ 15 | char name[65536], value[65536]; 16 | int name_len, value_len; 17 | xml_ptr in; 18 | xml_ptr out; 19 | 20 | if (nrhs != 4) 21 | mexErrMsgTxt("4 input argument(s) required."); 22 | if (nlhs != 1) 23 | mexErrMsgTxt("1 output argument(s) required."); 24 | 25 | /* get function handle */ 26 | field = mxGetField(prhs[0],0,"lsl_prepend_child_value"); 27 | if (!field) 28 | mexErrMsgTxt("The field does not seem to exist."); 29 | pTmp = (uintptr_t*)mxGetData(field); 30 | if (!pTmp) 31 | mexErrMsgTxt("The field seems to be prepend_child_value."); 32 | func = (lsl_prepend_child_value_t*)*pTmp; 33 | 34 | /* get additional inputs */ 35 | in = (xml_ptr)*(uintptr_t*)mxGetData(prhs[1]); 36 | name_len = mxGetNumberOfElements(prhs[2]); 37 | if (name_len+1 > sizeof(name)/sizeof(name[0])) 38 | mexErrMsgTxt("The given string is too long."); 39 | mxGetString(prhs[2], name, name_len+1); 40 | value_len = mxGetNumberOfElements(prhs[3]); 41 | if (value_len+1 > sizeof(value)/sizeof(value[0])) 42 | mexErrMsgTxt("The given string is too long."); 43 | mxGetString(prhs[3], value, value_len+1); 44 | 45 | /* invoke & return */ 46 | out = func(in,name,value); 47 | plhs[0] = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(plhs[0]) = (uintptr_t)out; 48 | } 49 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_prepend_copy.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [DescPtr] = lsl_prepend_copy(LibHandle,DescPtr,Other) */ 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_prepend_copy_t func; 14 | /* input/output variables */ 15 | xml_ptr in, other; 16 | xml_ptr out; 17 | 18 | if (nrhs != 3) 19 | mexErrMsgTxt("3 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_prepend_copy"); 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_prepend_copy_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | in = (xml_ptr)*(uintptr_t*)mxGetData(prhs[1]); 34 | other = (xml_ptr)*(uintptr_t*)mxGetData(prhs[2]); 35 | 36 | /* invoke & return */ 37 | out = func(in,other); 38 | plhs[0] = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(plhs[0]) = (uintptr_t)out; 39 | } 40 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_previous_sibling.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [DescPtr] = lsl_previous_sibling(LibHandle,DescPtr) */ 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_previous_sibling_t func; 14 | /* input/output variables */ 15 | xml_ptr in; 16 | xml_ptr out; 17 | 18 | if (nrhs != 2) 19 | mexErrMsgTxt("2 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_previous_sibling"); 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_previous_sibling_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | in = (xml_ptr)*(uintptr_t*)mxGetData(prhs[1]); 34 | 35 | /* invoke & return */ 36 | out = func(in); 37 | plhs[0] = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(plhs[0]) = (uintptr_t)out; 38 | } 39 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_previous_sibling_n.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [DescPtr] = lsl_previous_sibling_n(LibHandle,DescPtr,Name) */ 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_previous_sibling_n_t func; 14 | /* input/output variables */ 15 | char str[65536]; 16 | int str_len; 17 | xml_ptr in; 18 | xml_ptr out; 19 | 20 | if (nrhs != 3) 21 | mexErrMsgTxt("3 input argument(s) required."); 22 | if (nlhs != 1) 23 | mexErrMsgTxt("1 output argument(s) required."); 24 | 25 | /* get function handle */ 26 | field = mxGetField(prhs[0],0,"lsl_previous_sibling_n"); 27 | if (!field) 28 | mexErrMsgTxt("The field does not seem to exist."); 29 | pTmp = (uintptr_t*)mxGetData(field); 30 | if (!pTmp) 31 | mexErrMsgTxt("The field seems to be empty."); 32 | func = (lsl_previous_sibling_n_t*)*pTmp; 33 | 34 | /* get additional inputs */ 35 | in = (xml_ptr)*(uintptr_t*)mxGetData(prhs[1]); 36 | str_len = mxGetNumberOfElements(prhs[2]); 37 | if (str_len+1 > sizeof(str)/sizeof(str[0])) 38 | mexErrMsgTxt("The given string is too long."); 39 | mxGetString(prhs[2], str, str_len+1); 40 | 41 | /* invoke & return */ 42 | out = func(in,str); 43 | plhs[0] = mxCreateNumericMatrix(1,1,PTR_CLASS,mxREAL); *(uintptr_t*)mxGetData(plhs[0]) = (uintptr_t)out; 44 | } 45 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_protocol_version.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [ProtocolVersion] = lsl_protocol_version(LibHandle) */ 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_protocol_version_t func; 14 | /* input/output variables */ 15 | int result; 16 | 17 | if (nrhs != 1) 18 | mexErrMsgTxt("1 input argument(s) required."); 19 | if (nlhs != 1) 20 | mexErrMsgTxt("1 output argument(s) required."); 21 | 22 | /* get function handle */ 23 | field = mxGetField(prhs[0],0,"lsl_protocol_version"); 24 | if (!field) 25 | mexErrMsgTxt("The field does not seem to exist."); 26 | pTmp = (uintptr_t*)mxGetData(field); 27 | if (!pTmp) 28 | mexErrMsgTxt("The field seems to be empty."); 29 | func = (lsl_protocol_version_t*)*pTmp; 30 | 31 | /* invoke & return */ 32 | result = func(); 33 | plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); *(int32_T*)mxGetData(plhs[0]) = (int32_T)result; 34 | } 35 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_pull_chunk_d.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [ChunkData,Timestamps] = lsl_pull_chunk_d(LibHandle,Inlet,NumChannels) */ 4 | 5 | /* node in a chain of samples */ 6 | typedef struct { 7 | struct bufnode_t *next; 8 | double *buffer; 9 | double timestamp; 10 | } bufnode_t; 11 | 12 | /* free the entire chain */ 13 | void free_chain(bufnode_t *node) { 14 | free(node->buffer); 15 | if (node->next) 16 | free_chain(node->next); 17 | free(node); 18 | } 19 | 20 | void mexFunction( int nlhs, mxArray *plhs[], 21 | int nrhs, const mxArray*prhs[] ) 22 | { 23 | /* handle of the desired field */ 24 | mxArray *field; 25 | /* temp pointer */ 26 | uintptr_t *pTmp; 27 | /* function handle */ 28 | lsl_pull_sample_d_t func; 29 | 30 | /* input variables */ 31 | uintptr_t in; 32 | int numchannels,k; 33 | double timeout=0.0; 34 | /* output variables */ 35 | int errcode=0, numobtained=0; 36 | /* buffer chain */ 37 | bufnode_t *head=0; /* pointer to the head node */ 38 | bufnode_t **cur=&head; /* pointer to where we want to allocate the next element */ 39 | /* iterates for copying the data */ 40 | double *chunkptr; 41 | double *timestampptr; 42 | 43 | if (nrhs != 3) 44 | mexErrMsgTxt("3 input argument(s) required."); 45 | if (nlhs < 1) 46 | mexErrMsgTxt("At least 1 output argument(s) required."); 47 | if (nlhs > 2) 48 | mexErrMsgTxt("At most 2 output argument(s) required."); 49 | 50 | /* get function handle */ 51 | field = mxGetField(prhs[0],0,"lsl_pull_sample_d"); 52 | if (!field) 53 | mexErrMsgTxt("The field does not seem to exist."); 54 | pTmp = (uintptr_t*)mxGetData(field); 55 | if (!pTmp) 56 | mexErrMsgTxt("The field seems to be empty."); 57 | func = (lsl_pull_sample_d_t*)*pTmp; 58 | 59 | /* get additional inputs */ 60 | in = *(uintptr_t*)mxGetData(prhs[1]); 61 | if (mxGetClassID(prhs[2]) != mxDOUBLE_CLASS) 62 | mexErrMsgTxt("The numchannels argument must be passed as a double."); 63 | numchannels = (int)*(double*)mxGetData(prhs[2]); 64 | 65 | /* pull samples in a loop */ 66 | while (1) { 67 | /* allocate buffer space */ 68 | *cur = malloc(sizeof(bufnode_t)); 69 | (*cur)->buffer = malloc(numchannels*sizeof(double)); 70 | (*cur)->next = 0; 71 | /* retrieve sample */ 72 | (*cur)->timestamp = func(in,(*cur)->buffer,numchannels,timeout,&errcode); 73 | if (errcode) 74 | break; 75 | if ((*cur)->timestamp == 0.0) 76 | break; 77 | cur = &((*cur)->next); 78 | numobtained++; 79 | } 80 | if (errcode) { 81 | /* error: free and throw */ 82 | free_chain(head); 83 | if (errcode == lsl_timeout_error) 84 | mexErrMsgIdAndTxt("lsl:timeout_error", "The operation timed out."); 85 | if (errcode == lsl_lost_error) 86 | mexErrMsgIdAndTxt("lsl:lost_error", "The stream has been lost."); 87 | if (errcode == lsl_internal_error) 88 | mexErrMsgIdAndTxt("lsl:internal_error", "An internal error occurred."); 89 | mexErrMsgIdAndTxt("lsl:unknown_error", "An unknown error occurred."); 90 | } else { 91 | /* no error: first alloc MATLAB arrays */ 92 | plhs[0] = mxCreateNumericMatrix(numchannels,numobtained,mxDOUBLE_CLASS,mxREAL); 93 | plhs[1] = mxCreateNumericMatrix(1,numobtained,mxDOUBLE_CLASS,mxREAL); 94 | /* then copy over all content */ 95 | chunkptr = (double*)mxGetData(plhs[0]); 96 | timestampptr = (double*)mxGetData(plhs[1]); 97 | cur = &head; 98 | for (k=0;kbuffer,sizeof(double)*numchannels); 100 | *timestampptr = (*cur)->timestamp; 101 | cur = &((*cur)->next); 102 | } 103 | /* then free the chain */ 104 | free_chain(head); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_pull_sample_buf.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [SampleData,Timestamp] = lsl_pull_sample_buf(LibHandle,Inlet,NumChannels,Timeout) */ 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_pull_sample_buf_t func; 14 | 15 | /* input/output variables */ 16 | uintptr_t in; 17 | int numchannels,k; 18 | double timeout; 19 | int errcode; 20 | char *buffer[8192]; 21 | unsigned lengths[8192]; 22 | double timestamp; 23 | mwSize length; 24 | mxArray *tmpstr; 25 | 26 | if (nrhs != 4) 27 | mexErrMsgTxt("4 input argument(s) required."); 28 | if (nlhs < 1) 29 | mexErrMsgTxt("At least 1 output argument(s) required."); 30 | if (nlhs > 2) 31 | mexErrMsgTxt("At most 2 output argument(s) required."); 32 | 33 | /* get function handle */ 34 | field = mxGetField(prhs[0],0,"lsl_pull_sample_buf"); 35 | if (!field) 36 | mexErrMsgTxt("The field does not seem to exist."); 37 | pTmp = (uintptr_t*)mxGetData(field); 38 | if (!pTmp) 39 | mexErrMsgTxt("The field seems to be empty."); 40 | func = (lsl_pull_sample_buf_t*)*pTmp; 41 | 42 | /* get additional inputs */ 43 | in = *(uintptr_t*)mxGetData(prhs[1]); 44 | if (mxGetClassID(prhs[2]) != mxDOUBLE_CLASS) 45 | mexErrMsgTxt("The numchannels argument must be passed as a double."); 46 | numchannels = (int)*(double*)mxGetData(prhs[2]); 47 | if (mxGetClassID(prhs[3]) != mxDOUBLE_CLASS) 48 | mexErrMsgTxt("The timeout argument must be passed as a double."); 49 | timeout = *(double*)mxGetData(prhs[3]); 50 | 51 | timestamp = func(in,buffer,lengths,numchannels,timeout,&errcode); 52 | if (errcode) { 53 | if (errcode == lsl_timeout_error) 54 | mexErrMsgIdAndTxt("lsl:timeout_error","The operation timed out."); 55 | if (errcode == lsl_lost_error) 56 | mexErrMsgIdAndTxt("lsl:lost_error","The stream has been lost."); 57 | if (errcode == lsl_internal_error) 58 | mexErrMsgIdAndTxt("lsl:internal_error","An internal error occurred."); 59 | mexErrMsgIdAndTxt("lsl:unknown_error","An unknown error occurred."); 60 | } 61 | if (timestamp) { 62 | /* got a sample */ 63 | plhs[0] = mxCreateCellMatrix(1,numchannels); 64 | /* move data over into the results */ 65 | for (k=0;k 2) 28 | mexErrMsgTxt("At most 2 output argument(s) required."); 29 | 30 | /* get function handle */ 31 | field = mxGetField(prhs[0],0,"lsl_pull_sample_d"); 32 | if (!field) 33 | mexErrMsgTxt("The field does not seem to exist."); 34 | pTmp = (uintptr_t*)mxGetData(field); 35 | if (!pTmp) 36 | mexErrMsgTxt("The field seems to be empty."); 37 | func = (lsl_pull_sample_d_t*)*pTmp; 38 | 39 | /* get additional inputs */ 40 | in = *(uintptr_t*)mxGetData(prhs[1]); 41 | if (mxGetClassID(prhs[2]) != mxDOUBLE_CLASS) 42 | mexErrMsgTxt("The numchannels argument must be passed as a double."); 43 | numchannels = (int)*(double*)mxGetData(prhs[2]); 44 | if (mxGetClassID(prhs[3]) != mxDOUBLE_CLASS) 45 | mexErrMsgTxt("The timeout argument must be passed as a double."); 46 | timeout = *(double*)mxGetData(prhs[3]); 47 | 48 | /* invoke & return */ 49 | timestamp = func(in,buffer,numchannels,timeout,&errcode); 50 | if (errcode) { 51 | if (errcode == lsl_timeout_error) 52 | mexErrMsgIdAndTxt("lsl:timeout_error","The operation timed out."); 53 | if (errcode == lsl_lost_error) 54 | mexErrMsgIdAndTxt("lsl:lost_error","The stream has been lost."); 55 | if (errcode == lsl_internal_error) 56 | mexErrMsgIdAndTxt("lsl:internal_error","An internal error occurred."); 57 | mexErrMsgIdAndTxt("lsl:unknown_error","An unknown error occurred."); 58 | } 59 | if (timestamp) { 60 | /* got a sample */ 61 | plhs[0] = mxCreateNumericMatrix(1,numchannels,mxDOUBLE_CLASS,mxREAL); 62 | /* copy over into the result vector */ 63 | memcpy(mxGetData(plhs[0]),buffer,sizeof(buffer[0])*numchannels); 64 | if (nlhs == 2) { 65 | /* also assign the time stamp */ 66 | plhs[1] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL); 67 | *(double*)mxGetData(plhs[1]) = timestamp; 68 | } 69 | } else { 70 | /* got no sample: return empty arrays */ 71 | plhs[0] = mxCreateNumericMatrix(0,0,mxDOUBLE_CLASS,mxREAL); 72 | if (nlhs == 2) 73 | plhs[1] = mxCreateNumericMatrix(0,0,mxDOUBLE_CLASS,mxREAL); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_pull_sample_str.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [SampleData,Timestamp] = lsl_pull_sample_str(LibHandle,Inlet,NumChannels,Timeout) */ 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_pull_sample_str_t func; 14 | 15 | /* input/output variables */ 16 | uintptr_t in; 17 | int numchannels,k; 18 | double timeout; 19 | int errcode; 20 | char *buffer[8192]; 21 | double timestamp; 22 | 23 | if (nrhs != 4) 24 | mexErrMsgTxt("4 input argument(s) required."); 25 | if (nlhs < 1) 26 | mexErrMsgTxt("At least 1 output argument(s) required."); 27 | if (nlhs > 2) 28 | mexErrMsgTxt("At most 2 output argument(s) required."); 29 | 30 | /* get function handle */ 31 | field = mxGetField(prhs[0],0,"lsl_pull_sample_str"); 32 | if (!field) 33 | mexErrMsgTxt("The field does not seem to exist."); 34 | pTmp = (uintptr_t*)mxGetData(field); 35 | if (!pTmp) 36 | mexErrMsgTxt("The field seems to be empty."); 37 | func = (lsl_pull_sample_str_t*)*pTmp; 38 | 39 | /* get additional inputs */ 40 | in = *(uintptr_t*)mxGetData(prhs[1]); 41 | if (mxGetClassID(prhs[2]) != mxDOUBLE_CLASS) 42 | mexErrMsgTxt("The numchannels argument must be passed as a double."); 43 | numchannels = (int)*(double*)mxGetData(prhs[2]); 44 | if (mxGetClassID(prhs[3]) != mxDOUBLE_CLASS) 45 | mexErrMsgTxt("The timeout argument must be passed as a double."); 46 | timeout = *(double*)mxGetData(prhs[3]); 47 | 48 | /* invoke & return */ 49 | timestamp = func(in,buffer,numchannels,timeout,&errcode); 50 | if (errcode) { 51 | if (errcode == lsl_timeout_error) 52 | mexErrMsgIdAndTxt("lsl:timeout_error","The operation timed out."); 53 | if (errcode == lsl_lost_error) 54 | mexErrMsgIdAndTxt("lsl:lost_error","The stream has been lost."); 55 | if (errcode == lsl_internal_error) 56 | mexErrMsgIdAndTxt("lsl:internal_error","An internal error occurred."); 57 | mexErrMsgIdAndTxt("lsl:unknown_error","An unknown error occurred."); 58 | } 59 | if (timestamp) { 60 | /* got a sample */ 61 | plhs[0] = mxCreateCellMatrix(1,numchannels); 62 | /* move data over into the results */ 63 | for (k=0;k 5) 26 | mexErrMsgTxt("At most 5 input argument(s) required."); 27 | if (nlhs != 0) 28 | mexErrMsgTxt("0 output argument(s) required."); 29 | 30 | /* get function handle */ 31 | field = mxGetField(prhs[0], 0, "lsl_push_sample_dtp"); 32 | if (!field) 33 | mexErrMsgTxt("The field does not seem to exist."); 34 | pTmp = (uintptr_t*)mxGetData(field); 35 | if (!pTmp) 36 | mexErrMsgTxt("The field seems to be empty."); 37 | func_num = (lsl_push_sample_dtp_t*)*pTmp; 38 | 39 | /* get outlet ptr */ 40 | out = *(uintptr_t*)mxGetData(prhs[1]); 41 | 42 | /* get ChunkData ptr & check format */ 43 | if (mxGetClassID(prhs[2]) != mxDOUBLE_CLASS) 44 | mexErrMsgTxt("The ChunkData must be numeric (string-formatted samples must currently be submitted sample-by-sample)."); 45 | chunkdata = (double*)mxGetData(prhs[2]); 46 | if (mxGetNumberOfElements(prhs[2]) == 0) 47 | return; 48 | numchannels = mxGetM(prhs[2]); 49 | numsamples = mxGetN(prhs[2]); 50 | 51 | /* get timestamp pointer */ 52 | if (mxGetClassID(prhs[3]) != mxDOUBLE_CLASS) 53 | mexErrMsgTxt("The timestamp argument must be passed as a double."); 54 | if (mxGetNumberOfElements(prhs[3]) != mxGetN(prhs[2])) 55 | mexErrMsgTxt("The number of timestamps provided must match the number of columns in the chunk data matrix."); 56 | timestamps = (double*)mxGetData(prhs[3]); 57 | 58 | if (nrhs >= 5) { 59 | /* optionally read pushthrough value */ 60 | if (mxGetClassID(prhs[4]) != mxDOUBLE_CLASS) 61 | mexErrMsgTxt("The pushthrough argument must be passed as a double (1 or 0)."); 62 | pushthrough = ((int)*(double*)mxGetData(prhs[4])) != 0; 63 | } 64 | 65 | /* now send the samples (pushthrough is only set for the last sample in the chunk) */ 66 | for (k=0;k 5) 27 | mexErrMsgTxt("At most 5 input argument(s) required."); 28 | if (nlhs != 0) 29 | mexErrMsgTxt("0 output argument(s) required."); 30 | 31 | /* get outlet ptr */ 32 | out = *(uintptr_t*)mxGetData(prhs[1]); 33 | 34 | if (nrhs >= 4) { 35 | /* read timestamp value */ 36 | if (mxGetClassID(prhs[3]) != mxDOUBLE_CLASS) 37 | mexErrMsgTxt("The timestamp argument must be passed as a double."); 38 | timestamp = *(double*)mxGetData(prhs[3]); 39 | } 40 | 41 | if (nrhs >= 5) { 42 | /* read pushthrough value */ 43 | if (mxGetClassID(prhs[4]) != mxDOUBLE_CLASS) 44 | mexErrMsgTxt("The pushthrough argument must be passed as a double (1 or 0)."); 45 | pushthrough = ((int)*(double*)mxGetData(prhs[4])) != 0; 46 | } 47 | 48 | if (mxGetClassID(prhs[2]) == mxDOUBLE_CLASS) { 49 | /* sending numeric data; get function handle */ 50 | field = mxGetField(prhs[0], 0, "lsl_push_sample_dtp"); 51 | if (!field) 52 | mexErrMsgTxt("The field does not seem to exist."); 53 | pTmp = (uintptr_t*)mxGetData(field); 54 | if (!pTmp) 55 | mexErrMsgTxt("The field seems to be empty."); 56 | func_num = (lsl_push_sample_dtp_t*)*pTmp; 57 | /* invoke */ 58 | returncode = func_num(out,(double*)mxGetData(prhs[2]),timestamp,pushthrough); 59 | } else { 60 | if (mxGetClassID(prhs[2]) == mxCELL_CLASS) { 61 | /* string data; get function handle */ 62 | field = mxGetField(prhs[0], 0, "lsl_push_sample_buftp"); 63 | if (!field) 64 | mexErrMsgTxt("The field does not seem to exist."); 65 | pTmp = (uintptr_t*)mxGetData(field); 66 | if (!pTmp) 67 | mexErrMsgTxt("The field seems to be empty."); 68 | func_buf = (lsl_push_sample_buftp_t*)*pTmp; 69 | 70 | /* allocate temporary buffer space */ 71 | numcells = mxGetNumberOfElements(prhs[2]); 72 | buffer = malloc(numcells * sizeof(char*)); 73 | lengths = malloc(numcells * sizeof(unsigned)); 74 | 75 | for (k=0;k sizeof(str)/sizeof(str[0])) 37 | mexErrMsgTxt("The given string is too long."); 38 | mxGetString(prhs[2], str, str_len+1); 39 | 40 | /* invoke & return */ 41 | func(in,str); 42 | } 43 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_resolve_all_.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [StreaminfoArray] = lsl_resolve_all(LibHandle,Timeout) */ 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_resolve_all_t func; 14 | /* input/output variables */ 15 | streaminfo buffer[2048]; 16 | int result,k; 17 | double timeout; 18 | 19 | if (nrhs != 2) 20 | mexErrMsgTxt("2 input argument(s) required."); 21 | if (nlhs != 1) 22 | mexErrMsgTxt("1 output argument(s) required."); 23 | 24 | /* get function handle */ 25 | field = mxGetField(prhs[0],0,"lsl_resolve_all"); 26 | if (!field) 27 | mexErrMsgTxt("The field does not seem to exist."); 28 | pTmp = (uintptr_t*)mxGetData(field); 29 | if (!pTmp) 30 | mexErrMsgTxt("The field seems to be empty."); 31 | func = (lsl_resolve_all_t*)*pTmp; 32 | if (mxGetClassID(prhs[1]) != mxDOUBLE_CLASS) 33 | mexErrMsgTxt("The timeout argument must be passed as a double."); 34 | timeout = *(double*)mxGetData(prhs[1]); 35 | 36 | /* invoke & return */ 37 | result = func(buffer,sizeof(buffer)/sizeof(buffer[0]),timeout); 38 | plhs[0] = mxCreateNumericMatrix(1,result,PTR_CLASS,mxREAL); 39 | for (k=0;k sizeof(pred)/sizeof(pred[0])) 40 | mexErrMsgTxt("The given property name is too long."); 41 | mxGetString(prhs[1], pred, pred_len+1); 42 | if (mxGetClassID(prhs[2]) != mxDOUBLE_CLASS) 43 | mexErrMsgTxt("The minimum argument must be passed as a double."); 44 | minimum = (int)(*(double*)mxGetData(prhs[2])); 45 | if (mxGetClassID(prhs[3]) != mxDOUBLE_CLASS) 46 | mexErrMsgTxt("The timeout argument must be passed as a double."); 47 | timeout = *(double*)mxGetData(prhs[3]); 48 | 49 | /* invoke & return */ 50 | result = func(buffer,sizeof(buffer)/sizeof(buffer[0]),pred,minimum,timeout); 51 | plhs[0] = mxCreateNumericMatrix(1,result,PTR_CLASS,mxREAL); 52 | for (k=0;k sizeof(prop)/sizeof(prop[0])) 40 | mexErrMsgTxt("The given property name is too long."); 41 | mxGetString(prhs[1], prop, prop_len+1); 42 | value_len = mxGetNumberOfElements(prhs[2]); 43 | if (value_len+1 > sizeof(value)/sizeof(value[0])) 44 | mexErrMsgTxt("The given value string is too long."); 45 | mxGetString(prhs[2], value, value_len+1); 46 | if (mxGetClassID(prhs[3]) != mxDOUBLE_CLASS) 47 | mexErrMsgTxt("The minimum argument must be passed as a double."); 48 | minimum = (int)(*(double*)mxGetData(prhs[3])); 49 | if (mxGetClassID(prhs[4]) != mxDOUBLE_CLASS) 50 | mexErrMsgTxt("The timeout argument must be passed as a double."); 51 | timeout = *(double*)mxGetData(prhs[4]); 52 | 53 | /* invoke & return */ 54 | result = func(buffer,sizeof(buffer)/sizeof(buffer[0]),prop,value,minimum,timeout); 55 | plhs[0] = mxCreateNumericMatrix(1,result,PTR_CLASS,mxREAL); 56 | for (k=0;k sizeof(name)/sizeof(name[0])) 38 | mexErrMsgTxt("The given string is too long."); 39 | mxGetString(prhs[2], name, name_len+1); 40 | value_len = mxGetNumberOfElements(prhs[3]); 41 | if (value_len+1 > sizeof(value)/sizeof(value[0])) 42 | mexErrMsgTxt("The given string is too long."); 43 | mxGetString(prhs[3], value, value_len+1); 44 | 45 | /* invoke & return */ 46 | out = func(in,name,value); 47 | plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL); *(double*)mxGetData(plhs[0]) = (double)out; 48 | } 49 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_set_name.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [Success] = lsl_set_name(LibHandle,DescPtr,Name) */ 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_name_t func; 14 | /* input/output variables */ 15 | char str[65536]; 16 | int str_len; 17 | xml_ptr in; 18 | int out; 19 | 20 | if (nrhs != 3) 21 | mexErrMsgTxt("3 input argument(s) required."); 22 | if (nlhs != 1) 23 | mexErrMsgTxt("1 output argument(s) required."); 24 | 25 | /* get function handle */ 26 | field = mxGetField(prhs[0],0,"lsl_set_name"); 27 | if (!field) 28 | mexErrMsgTxt("The field does not seem to exist."); 29 | pTmp = (uintptr_t*)mxGetData(field); 30 | if (!pTmp) 31 | mexErrMsgTxt("The field seems to be set_name."); 32 | func = (lsl_set_name_t*)*pTmp; 33 | 34 | /* get additional inputs */ 35 | in = (xml_ptr)*(uintptr_t*)mxGetData(prhs[1]); 36 | str_len = mxGetNumberOfElements(prhs[2]); 37 | if (str_len+1 > sizeof(str)/sizeof(str[0])) 38 | mexErrMsgTxt("The given string is too long."); 39 | mxGetString(prhs[2], str, str_len+1); 40 | 41 | /* invoke & return */ 42 | out = func(in,str); 43 | plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL); *(double*)mxGetData(plhs[0]) = (double)out; 44 | } 45 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_set_value.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [Success] = lsl_set_value(LibHandle,DescPtr,Value) */ 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_value_t func; 14 | /* input/output variables */ 15 | char str[65536]; 16 | int str_len; 17 | xml_ptr in; 18 | int out; 19 | 20 | if (nrhs != 3) 21 | mexErrMsgTxt("3 input argument(s) required."); 22 | if (nlhs != 1) 23 | mexErrMsgTxt("1 output argument(s) required."); 24 | 25 | /* get function handle */ 26 | field = mxGetField(prhs[0],0,"lsl_set_value"); 27 | if (!field) 28 | mexErrMsgTxt("The field does not seem to exist."); 29 | pTmp = (uintptr_t*)mxGetData(field); 30 | if (!pTmp) 31 | mexErrMsgTxt("The field seems to be set_value."); 32 | func = (lsl_set_value_t*)*pTmp; 33 | 34 | /* get additional inputs */ 35 | in = (xml_ptr)*(uintptr_t*)mxGetData(prhs[1]); 36 | str_len = mxGetNumberOfElements(prhs[2]); 37 | if (str_len+1 > sizeof(str)/sizeof(str[0])) 38 | mexErrMsgTxt("The given string is too long."); 39 | mxGetString(prhs[2], str, str_len+1); 40 | 41 | /* invoke & return */ 42 | out = func(in,str); 43 | plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL); *(double*)mxGetData(plhs[0]) = (double)out; 44 | } 45 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_time_correction.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [TimeCorrection] = lsl_time_correction(LibHandle,Inlet,Timeout) */ 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_time_correction_t func; 14 | /* input/output variables */ 15 | uintptr_t in; 16 | double timeout; 17 | double result; 18 | int errcode; 19 | 20 | if (nrhs != 3) 21 | mexErrMsgTxt("3 input argument(s) required."); 22 | if (nlhs != 1) 23 | mexErrMsgTxt("1 output argument(s) required."); 24 | 25 | /* get function handle */ 26 | field = mxGetField(prhs[0],0,"lsl_time_correction"); 27 | if (!field) 28 | mexErrMsgTxt("The field does not seem to exist."); 29 | pTmp = (uintptr_t*)mxGetData(field); 30 | if (!pTmp) 31 | mexErrMsgTxt("The field seems to be empty."); 32 | func = (lsl_time_correction_t*)*pTmp; 33 | 34 | /* get additional inputs */ 35 | in = *(uintptr_t*)mxGetData(prhs[1]); 36 | 37 | if (mxGetClassID(prhs[2]) != mxDOUBLE_CLASS) 38 | mexErrMsgTxt("The timeout argument must be passed as a double."); 39 | timeout = *(double*)mxGetData(prhs[2]); 40 | 41 | /* invoke & return */ 42 | result = func(in,timeout,&errcode); 43 | if (errcode) { 44 | if (errcode == lsl_timeout_error) 45 | mexErrMsgIdAndTxt("lsl:timeout_error","The operation timed out."); 46 | if (errcode == lsl_lost_error) 47 | mexErrMsgIdAndTxt("lsl:lost_error","The stream has been lost."); 48 | if (errcode == lsl_internal_error) 49 | mexErrMsgIdAndTxt("lsl:internal_error","An internal error occurred."); 50 | mexErrMsgIdAndTxt("lsl:unknown_error","An unknown error occurred."); 51 | } 52 | plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL); *(double*)mxGetData(plhs[0]) = result; 53 | } 54 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_value.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function [Value] = lsl_value(LibHandle,DescPtr) */ 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_value_t func; 14 | /* input/output variables */ 15 | xml_ptr in; 16 | char *out; 17 | 18 | if (nrhs != 2) 19 | mexErrMsgTxt("2 input argument(s) required."); 20 | if (nlhs != 1) 21 | mexErrMsgTxt("1 output argument(s) required."); 22 | 23 | /* get function handle */ 24 | field = mxGetField(prhs[0],0,"lsl_value"); 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 value."); 30 | func = (lsl_value_t*)*pTmp; 31 | 32 | /* get additional inputs */ 33 | in = (xml_ptr)*(uintptr_t*)mxGetData(prhs[1]); 34 | 35 | /* invoke & return */ 36 | out = func(in); 37 | plhs[0] = mxCreateString(out); 38 | } 39 | -------------------------------------------------------------------------------- /liblsl-Matlab/mex/lsl_wait_for_consumers.c: -------------------------------------------------------------------------------- 1 | #include "lsl_common.h" 2 | 3 | /* function Success = lsl_wait_for_consumers(LibHandle,Outlet,Timeout) */ 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_wait_for_consumers_t func; 14 | /* input/output variables */ 15 | uintptr_t out; 16 | double timeout; 17 | int result; 18 | 19 | if (nrhs != 2) 20 | mexErrMsgTxt("2 input argument(s) required."); 21 | if (nlhs != 0) 22 | mexErrMsgTxt("0 output argument(s) required."); 23 | 24 | /* get function handle */ 25 | field = mxGetField(prhs[0],0,"lsl_wait_for_consumers"); 26 | if (!field) 27 | mexErrMsgTxt("The field does not seem to exist."); 28 | pTmp = (uintptr_t*)mxGetData(field); 29 | if (!pTmp) 30 | mexErrMsgTxt("The field seems to be empty."); 31 | func = (lsl_wait_for_consumers_t*)*pTmp; 32 | 33 | /* get additional inputs */ 34 | out = *(uintptr_t*)mxGetData(prhs[1]); 35 | if (mxGetClassID(prhs[2]) != mxDOUBLE_CLASS) 36 | mexErrMsgTxt("The timeout argument must be passed as a double."); 37 | timeout = *(double*)mxGetData(prhs[2]); 38 | 39 | /* invoke */ 40 | result = func(out,timeout); 41 | plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL); *(double*)mxGetData(plhs[0]) = (double)result; 42 | } 43 | -------------------------------------------------------------------------------- /ninjaGUI.m: -------------------------------------------------------------------------------- 1 | function ninjaGUI(fname) 2 | %Routine to check initial configuration of the fNIRS device and launch the 3 | %startup sequence 4 | if nargin==0 5 | [fname,path]=uigetfile({'*.cfg', 'Hardware configuration file (*.cfg)'}); 6 | fname=[path,filesep,fname]; 7 | if ~fname 8 | disp('No file selected, defaulting to fNIRS.cfg') 9 | fname='fNIRS.cfg'; 10 | end 11 | elseif length(fname)<4 12 | fname = strcat(fname,'.cfg'); 13 | elseif ~strcmp(fname(end-3:end),'.cfg') 14 | fname = strcat(fname,'.cfg'); 15 | end 16 | 17 | 18 | %set path to functions 19 | addpath(genpath('device_functions')) 20 | 21 | %% check existence of of cfg 22 | disp(['Looking for ',fname,'...']) 23 | if exist(fname,'file') 24 | disp(['Loading ',fname,'...']) 25 | [devinfo,error]=loadCFG(fname); 26 | if error 27 | disp([filename, ' corrupt, starting configuration dialog']) 28 | okflag=0; 29 | else 30 | okflag=1; 31 | end 32 | else 33 | disp([fname ' not found, starting configuration dialog']) 34 | okflag=0; 35 | end 36 | 37 | if okflag 38 | %call set environment function with devinfo input 39 | disp('Setting environment') 40 | environment=setEnv(devinfo); 41 | disp('Starting NIRS application') 42 | %start main app with environment input 43 | fNIRSapp(devinfo,environment) 44 | %disp('Success') 45 | else 46 | %start configuration dialog 47 | hardwareselect() 48 | end -------------------------------------------------------------------------------- /ninjaGUIinstaller.prj: -------------------------------------------------------------------------------- 1 | 2 | 3 | ninjaGUI 4 | 5 | 6 | 1.90.99 7 | Antonio Ortega 8 | aortegam@bu.edu 9 | Boston University 10 | GUI application to acquire fNIRS signals using the BOAS labs fNIRS hardware (ninjaGUI and NIRS1k) 11 | 12 | 13 | 14 | \Boston University\ninjaGUI\ 15 | option.installpath.programfiles 16 | 17 | 18 | 19 | C:\Users\Antonio\Documents\MATLAB\work\BU\boas lab\rtfNIRS\ninjaGUIdev\ninjaGUIinstaller\for_testing 20 | C:\Users\Antonio\Documents\MATLAB\work\BU\boas lab\rtfNIRS\ninjaGUIdev\ninjaGUIinstaller\for_redistribution_files_only 21 | C:\Users\Antonio\Documents\MATLAB\work\BU\boas lab\rtfNIRS\ninjaGUIdev\ninjaGUIinstaller\for_redistribution 22 | C:\Users\Antonio\Documents\MATLAB\work\BU\boas lab\rtfNIRS\ninjaGUIdev\ninjaGUIinstaller 23 | false 24 | 25 | subtarget.standalone 26 | 27 | true 28 | false 29 | false 30 | ninjaGUIinstall 31 | MyAppInstaller_mcr 32 | MyAppInstaller_app 33 | false 34 | false 35 | 36 | false 37 | false 38 | 39 | Syntax 40 | ninjaGUI -? 41 | ninjaGUI fname 42 | Input Arguments 43 | -? print help on how to use the application 44 | fname input arguments 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | ${PROJECT_ROOT}\ninjaGUI.m 73 | 74 | 75 | ${PROJECT_ROOT}\device_functions 76 | ${PROJECT_ROOT}\liblsl-Matlab 77 | ${PROJECT_ROOT}\snirf 78 | ${PROJECT_ROOT}\snirf\README.md 79 | ${PROJECT_ROOT}\snirf\setpaths.m 80 | 81 | 82 | 83 | ${MATLAB_ROOT}\toolbox\local\userpath.m 84 | ${PROJECT_ROOT}\fNIRSapp.mlapp 85 | ${PROJECT_ROOT}\GetExtinctions.m 86 | ${PROJECT_ROOT}\hardwareselect.mlapp 87 | ${PROJECT_ROOT}\hwcompatlist.txt 88 | 89 | 90 | C:\Users\Antonio\Documents\MATLAB\work\BU\boas lab\rtfNIRS\ninjaGUIdev\ninjaGUIinstaller\for_testing\ninjaGUI.exe 91 | C:\Users\Antonio\Documents\MATLAB\work\BU\boas lab\rtfNIRS\ninjaGUIdev\ninjaGUIinstaller\for_testing\splash.png 92 | C:\Users\Antonio\Documents\MATLAB\work\BU\boas lab\rtfNIRS\ninjaGUIdev\ninjaGUIinstaller\for_testing\readme.txt 93 | 94 | 95 | 96 | C:\Program Files\MATLAB\R2021a 97 | 98 | 99 | 100 | false 101 | false 102 | true 103 | false 104 | false 105 | false 106 | false 107 | false 108 | 10.0 109 | false 110 | true 111 | win64 112 | true 113 | 114 | 115 | -------------------------------------------------------------------------------- /sdfilesetu2nirs1000.m: -------------------------------------------------------------------------------- 1 | % Set up an nSD file for fNIRS1000 example 2 | 3 | nSD.device='fNIRS1000'; 4 | nSD.lambda=[730, 850]; 5 | nSD.nLambdas=2; 6 | nSD.nSrcs=4; 7 | nSD.nDets=4; 8 | nSD.spatialUnit='mm'; 9 | nSD.measList=[]; 10 | nSD.srcPos=[]; %[nSrcs,3] 11 | nSD.detPos=[]; %[nDets,3] 12 | nSD.nStates=1; 13 | nSD.srcFreqMap=[]; %[nSrcs,nWavelengths,nStates] 14 | 15 | d=27.5; 16 | dd=0; 17 | nSD.srcPos=[-dd,0,0;... 18 | d-dd,0,0;... 19 | 2*d-dd,0,0;... 20 | 3*d-dd,0,0;... 21 | ]; 22 | 23 | nSD.detPos=[+dd,-d,0;... 24 | d+dd,-d,0;... 25 | 2*d+dd,-d,0;... 26 | 3*d+dd,-d,0;... 27 | ]; 28 | 29 | 30 | nSD.freqMap=cat(3,[1;3;5;7],[2;4;6;8]); 31 | 32 | 33 | nSD.measList=[1,1,1,1;... 34 | 2,2,1,1;... 35 | 3,2,1,1;... 36 | 3,3,1,1;... 37 | 3,4,1,1;... 38 | 4,4,1,1;... 39 | ]; %[source,detector,state,lambda] 40 | 41 | N=size(nSD.measList,1); 42 | nSD.measList=[nSD.measList;nSD.measList]; 43 | 44 | nSD.measList(N+1:end,4)=2; 45 | 46 | save('mental_math1000.nsd','nSD','-mat') -------------------------------------------------------------------------------- /sdfilesetupexample.m: -------------------------------------------------------------------------------- 1 | % Set up an nSD file 2 | 3 | nSD.device='ninjaNIRS'; 4 | nSD.lambda=[730, 850]; 5 | nSD.nLambdas=2; 6 | nSD.nSrcs=8; 7 | nSD.nDets=8; 8 | nSD.spatialUnit='mm'; 9 | nSD.measList=[]; 10 | nSD.srcPos=[]; %[nSrcs,3] 11 | nSD.detPos=[]; %[nDets,3] 12 | nSD.nStates=1; 13 | nSD.srcFreqMap=[]; %[nSrcs,nWavelengths,nStates] 14 | 15 | d=27.5; 16 | dd=2.5; 17 | nSD.srcPos=[-dd,0,0;... 18 | d-dd,0,0;... 19 | 2*d-dd,0,0;... 20 | 3*d-dd,0,0;... 21 | -dd,-d,0;... 22 | d-dd,-d,0;... 23 | 2*d-dd,-d,0;... 24 | 3*d-dd,-d,0;... 25 | ]; 26 | 27 | nSD.detPos=[dd,0,0;... 28 | d+dd,0,0;... 29 | 2*d+dd,0,0;... 30 | 3*d+dd,0,0;... 31 | +dd,-d,0;... 32 | d+dd,-d,0;... 33 | 2*d+dd,-d,0;... 34 | 3*d+dd,-d,0;... 35 | ]; 36 | 37 | nSD.freqMap=cat(3,[1;3;5;1;-5;0;0;0],[2;4;6;2;-6;0;0;0]); 38 | 39 | nSD.freqMap=cat(3,[1;3;0;5;-5;0;0;0],[2;4;0;6;-6;0;0;0]); 40 | 41 | nSD.freqMap=cat(3,[1;3;5;1;-5;0;0;0],[2;4;6;2;-6;0;0;0]); 42 | 43 | 44 | nSD.measList=[1,1,1,1;... 45 | 2,2,1,1;... 46 | 3,3,1,1;... 47 | 4,4,1,1;... 48 | 5,1,1,1;... 49 | 1,2,1,1;... 50 | 1,1,1,2;... 51 | 2,2,1,2;... 52 | 3,3,1,2;... 53 | 4,4,1,2;... 54 | 5,1,1,2;... 55 | 1,2,1,2;... 56 | ]; %[source,detector,state,lambda] 57 | 58 | nSD.measList=[1,5,1,1;... 59 | 1,6,1,1;... 60 | 2,6,1,1;... 61 | 3,7,1,1;... 62 | 4,8,1,1;... 63 | 5,5,1,1;... 64 | ]; %[source,detector,state,lambda] 65 | 66 | nSD.measList=[1,5,1,1;... 67 | 2,6,1,1;... 68 | 3,7,1,1;... 69 | 4,8,1,1;... 70 | 5,5,1,1;... 71 | ]; %[source,detector,state,lambda] 72 | 73 | N=size(nSD.measList,1); 74 | nSD.measList=[nSD.measList;nSD.measList]; 75 | 76 | nSD.measList(N+1:end,4)=2; 77 | 78 | % %the following two associate each source and detector with an optode 79 | % nSD.Source2Optode=[1,2,3,4,5]'; 80 | % nSD.Detector2Optode=[5,6,7,8]'; 81 | 82 | % so, for example Detector2Optode(MeasList(n,2)) tells us what optode is 83 | % receiving channel n. abs(freqMap(Source2Optode(MeasList(n,1)),s,m)) tells us 84 | % the frequency for that channel at state 1 for wavelength m 85 | save('mental_math.nsd','nSD','-mat') -------------------------------------------------------------------------------- /snirf/README.md: -------------------------------------------------------------------------------- 1 | 2 | NOTE: This documentation is a work in progress. More detailed documentation will be added in the coming months. 3 | 4 | 5 | Introduction: 6 | ============= 7 | SNIRF is a HDF5-based file format for storing and sharing NIRS data independently of any platform-specific file format such as Matlab. Snirf_homer3 is a standalone implementation in Matlab of a SNIRF reader/writer application that is used by the Homer3. 8 | 9 | 10 | Downloading snirf_homer3: 11 | ============================== 12 | First download the snirf_homer3 package. Go online to https://github.com/fNIRS/snirf_homer3 and click the green "Clone or download" button on right. Then click "Download ZIP" right below the green button. Once you have downloaded the zip file, unzip it. 13 | 14 | 15 | Installing snirf_homer3 16 | ============================== 17 | 18 | 1. Open Matlab and in the command window, change the current folder to the snirf_homer3 root folder that you downloaded. In the command window, type 19 | 20 | >> setpaths 21 | 22 | This will set all the required matlab search paths for snirf_homer3. Note: this step should be done every time a new Matlab session is started. 23 | 24 | At this point you should be ready to start snirf_homer3 from the Matlab command window. 25 | 26 | 2. Running the SNIRF demo: 27 | 28 | Run the demos demo_snirf.m and demo_snirf_readfile.m (which should be available on the Matlab command line after running setpaths). They demonstrate how to use SnirfClass reader/writer to save, load and read SNIRF files. Make sure to run demo_snirf before demo_snirf_readfile.m since it expects the snirf files generated by demo_snirf to be present (otherwise it displays a message box stating this if it doesn't find them). The snirf_homer3 project includes sample .nirs files (DataTree/AcquiredData/Snirf/Examples) which the demo converts to .snirf files and then shows how to load them back into memory. 29 | 30 | 3. Example 1: 31 | 32 | * Save .nirs file in SNIRF format 33 | 34 | nirs = load('neuro_run01.nirs','-mat'); 35 | snirf1 = SnirfClass(nirs); 36 | snirf1.Save('neuro_run01.snirf'); 37 | snirf1.Info(); 38 | 39 | * Check that the file was saved correctly by looking at snirf2 contents and comparing with snirf1 contents 40 | 41 | snirf2 = SnirfClass(); 42 | snirf2.Load('neuro_run01.snirf'); 43 | snirf2.Info(); 44 | 45 | -------------------------------------------------------------------------------- /snirf/Snirf/DataTypeLabelValues.m: -------------------------------------------------------------------------------- 1 | function dataTypeLabelValues = DataTypeLabelValues() 2 | dataTypeLabelValues = struct(... 3 | 'dOD','dOD', ... % Change in optical density 4 | 'mua','mua', ... % Absorption coefficient 5 | 'musp','musp', ... % Scattering coefficient 6 | 'HbO','HbO', ... % Oxygenated hemoglobin (oxyhemoglobin) concentration 7 | 'HbR','HbR', ... % Deoxygenated hemoglobin (deoxyhemoglobin) concentration 8 | 'HbT','HbT', ... % Total hemoglobin concentration 9 | 'HRF_HbO','HRF HbO', ... % Hemodynamic response function for oxyhemoglobin concentration 10 | 'HRF_HbR','HRF HbR', ... % Hemodynamic response function for deoxyhemoglobin concentration 11 | 'HRF_HbT','HRF HbT', ... % Hemodynamic response function for total hemoglobin concentration 12 | 'H2O','H2O', ... % Water content 13 | 'Lipid','Lipid', ... % Lipid concentration 14 | 'BFi','BFi', ... % Hemodynamic response function for blood flow index (BFi) 15 | 'HRF_BFi','HRF BFi' ... % Hemodynamic response function for blood flow index (BFi) 16 | ); -------------------------------------------------------------------------------- /snirf/Snirf/DataTypeValues.m: -------------------------------------------------------------------------------- 1 | function valsDataType = DataTypeValues() 2 | valsDataType = struct(... 3 | 'Raw', struct(... 4 | 'CW',struct(... 5 | 'Amplitude',1, ... 6 | 'FluorescenceAmplitude',51 ... 7 | ), ... 8 | 'FD',struct(... 9 | 'ACAmplitude',101, ... 10 | 'Phase',102, ... 11 | 'FluorescenceAmplitude',151, ... 12 | 'FluorescencePhase',152 ... 13 | ), ... 14 | 'TDGated',struct(... 15 | 'Amplitude',201, ... 16 | 'FluorescenceAmplitude',251 ... 17 | ), ... 18 | 'TDMoments',struct(... 19 | 'Amplitude',301, ... 20 | 'FluorescenceAmplitude',351 ... 21 | ), ... 22 | 'DCS',struct(... 23 | 'g2',401, ... 24 | 'BFi',410 ... 25 | ) ... 26 | ), ... 27 | 'Processed', 99999 ... 28 | ); 29 | end 30 | -------------------------------------------------------------------------------- /snirf/Snirf/Examples/demo_snirf.m: -------------------------------------------------------------------------------- 1 | function demo_snirf() 2 | 3 | % Syntax: 4 | % demo_snirf() 5 | % 6 | % Description: 7 | % Convert sample .nirs files included in the Homer3 project to SNIRF files (*.snirf) and 8 | % compare the saved and loaded SnirfClass objects for each coberted file to make sure 9 | % saving and loading of the .snirf is working correctly. 10 | % 11 | 12 | % Find the Homer3 Examples folder and cd to it 13 | examplesDir = findexamplesdir(); 14 | 15 | % Delete any previously generated .snirf files to make sure to start from scratch 16 | delete([examplesDir, '*.snirf']); 17 | 18 | % Start with .nirs files 19 | nirsfiles = dir([examplesDir, '*.nirs']); 20 | 21 | fprintf('\n') 22 | 23 | % Go through all the sample .nirs files 24 | for ii=1:length(nirsfiles) 25 | 26 | % Convert sample .nirs file to SNIRF file (*.snirf) 27 | [pname,fname,ext] = fileparts([examplesDir, nirsfiles(ii).name]); 28 | fprintf('Converting %s to %s\n', [pname, '/', fname, ext], [pname, '/', fname, '.snirf']); 29 | [snirf_saved, snirf_loaded] = snirf_load_save([pname, '/', nirsfiles(ii).name]); 30 | 31 | % Compare the saved and loaded SnirfClass objects, using overloaded == operator 32 | if snirf_saved == snirf_loaded 33 | fprintf('Saved and loaded SnirfClass objects for %s are equal\n', [fname,'.snirf']); 34 | else 35 | fprintf('ERROR: Saved and loaded SnirfClass objects for %s are NOT equal\n', [fname,'.snirf']); 36 | end 37 | fprintf('\n'); 38 | 39 | end 40 | 41 | 42 | -------------------------------------------------------------------------------- /snirf/Snirf/Examples/demo_snirf_readfile.m: -------------------------------------------------------------------------------- 1 | function snirf = demo_snirf_readfile(fname) 2 | 3 | % Syntax: 4 | % 5 | % snirf = demo_snirf_readfile() 6 | % 7 | % Description: 8 | % 9 | % Demo of how to read individual SNIRF fields using SnirfClass methods. 10 | % 11 | % Examples: 12 | % 13 | % In each example, make sure the standard Examples .snirf files are there 14 | % by first running demo_snirf (only once), then call this function. 15 | % 16 | % demo_snirf 17 | % 18 | % 1. Read and print data from default .snirf file 19 | % 20 | % snirf = demo_snirf_readfile(); 21 | % 22 | % 2. Read and print data from named files 23 | % 24 | % snirf = demo_snirf_readfile('Simple_Probe.snirf'); 25 | % snirf = demo_snirf_readfile('FingerTapping_run3_tdmlproc.snirf'); 26 | % snirf = demo_snirf_readfile('neuro_run01.snirf'); 27 | % 28 | % 29 | 30 | REPLACE_CODE_WITH_SNIRF_INFO_METHOD = true; 31 | 32 | if nargin==0 33 | fname = 'neuro_run01.snirf'; 34 | end 35 | rootdirexamples = findexamplesdir(); 36 | fnamefullpath = findfile(rootdirexamples, fname); 37 | if isempty(fnamefullpath) 38 | return; 39 | end 40 | 41 | %%%%% This is the actual demo showing how to read a .snirf file on the command line 42 | 43 | % Create empty snirf object 44 | snirf = SnirfClass(); 45 | 46 | % Use the SnirfClass LoadYYYY method to load whichever field you want 47 | fprintf('This is a demo of how to load data from a SNIRF file and convert it to .nirs style data.\n'); 48 | fprintf('========================================================================================\n'); 49 | fprintf('Displaying data from %s\n\n', fnamefullpath); 50 | 51 | 52 | % Load the SNIRF fields into empty snirf class object, one at a time 53 | snirf.LoadMetaDataTags(fnamefullpath); 54 | snirf.LoadData(fnamefullpath); 55 | snirf.LoadProbe(fnamefullpath); 56 | snirf.LoadStim(fnamefullpath); 57 | snirf.LoadAux(fnamefullpath); 58 | 59 | % The SnirfClass.Info() method replaces the code in the else statement below. It is essentially 60 | % the same code adapted to work from within the class. We keep the else statement around for 61 | % easy viewing of code showing how to load, extract and display SnirfClass data 62 | if REPLACE_CODE_WITH_SNIRF_INFO_METHOD 63 | 64 | snirf.Info(); 65 | 66 | else 67 | 68 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 69 | % Load meta data tags from file and extract the tag names and values for display 70 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 71 | fprintf(' MetaDataTags:\n'); 72 | tags = snirf.GetMetaDataTags(); 73 | for ii=1:length(tags) 74 | fprintf(' Meta data tag #%d: {''%s'', ''%s''}\n', ii, tags(ii).key, tags(ii).value); 75 | end 76 | fprintf('\n'); 77 | 78 | 79 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 80 | % Load data from file and extract .nirs-style d and ml matrices for display 81 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 82 | fprintf(' Data (.nirs-style display):\n'); 83 | for ii=1:length(snirf.data) 84 | 85 | % Display data matrix dimensions and data type 86 | d = snirf.data(ii).GetDataTimeSeries(); 87 | pretty_print_struct(d, 8, 1); 88 | 89 | % Display meas list dimensions and data type 90 | ml = snirf.data(ii).GetMeasList(); 91 | pretty_print_struct(ml, 8, 1); 92 | 93 | end 94 | fprintf('\n'); 95 | 96 | 97 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 98 | % Load probe and extract .nirs-style SD structure 99 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 100 | fprintf(' Probe (.nirs-style display):\n'); 101 | SD = snirf.GetSDG(); 102 | pretty_print_struct(SD, 8, 1); 103 | fprintf('\n'); 104 | 105 | 106 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 107 | % Load stim from file and extract it for display 108 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 109 | fprintf(' Stim (.snirf-style display):\n'); 110 | for ii=1:length(snirf.stim) 111 | fprintf(' stim(%d): {name = ''%s'', data = [', ii, snirf.stim(ii).name); 112 | for jj=1:size(snirf.stim(ii).data,1) 113 | if jj==size(snirf.stim(ii).data,1) 114 | fprintf('%0.1f', snirf.stim(ii).data(jj,1)); 115 | else 116 | fprintf('%0.1f, ', snirf.stim(ii).data(jj,1)); 117 | end 118 | end 119 | fprintf(']}\n'); 120 | end 121 | fprintf('\n'); 122 | 123 | 124 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 125 | % Load aux from file and extract nirs-style data for display 126 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 127 | fprintf(' Aux (.nirs-style display):\n'); 128 | aux = snirf.GetAuxiliary(); 129 | pretty_print_struct(aux, 8, 1); 130 | 131 | end 132 | 133 | 134 | 135 | % --------------------------------------------------- 136 | function fnamefullpath = findfile(rootdirexamples, fname) 137 | fnamefullpath = [rootdirexamples, fname]; 138 | if ~exist(fnamefullpath, 'file') 139 | msg = sprintf('%s does not exist. You first have to generate it by running demo_snirf\n', fnamefullpath); 140 | MenuBox(msg, 'OK'); 141 | fnamefullpath = ''; 142 | return; 143 | end 144 | -------------------------------------------------------------------------------- /snirf/Snirf/Examples/findexamplesdir.m: -------------------------------------------------------------------------------- 1 | function rootdirexamples = findexamplesdir() 2 | 3 | rootdir = fileparts(which('SnirfClass.m')); 4 | rootdirexamples = [rootdir, '/Examples/']; 5 | rootdirexamples(rootdirexamples=='\') = '/'; -------------------------------------------------------------------------------- /snirf/Snirf/Examples/snirf_load_save.m: -------------------------------------------------------------------------------- 1 | function [snirf_saved, snirf_loaded, nirs] = snirf_load_save(infile) 2 | 3 | % 4 | % Syntax: 5 | % 6 | % [snirf_saved, snirf_loaded, nirs] = snirf_load_save(infile) 7 | % 8 | % Description: 9 | % 10 | % Verify that the SnirfClass saver/loaded work correctly to convert .nirs data 11 | % to snirf. Function loads .nirs data, converts to SnirfClass object, saves in 12 | % HDF5 file and loads back into empty SnirfClass object. 13 | % 14 | % Usage examples: 15 | % 16 | % [snirf_saved, snirf_loaded, nirs] = snirf_load_save('./Simple_Probe1.nirs'); 17 | % [snirf_saved, snirf_loaded, nirs] = snirf_load_save('./FingerTapping_run3_tdmlproc.nirs'); 18 | % 19 | 20 | snirf_saved = []; 21 | snirf_loaded = []; 22 | nirs = []; 23 | 24 | % Error check 25 | if nargin == 0 26 | return; 27 | end 28 | 29 | % Get the input and output file names 30 | [pname, fname] = fileparts(infile); 31 | outfile = [pname, '/', fname, '.snirf']; 32 | 33 | % Load .nirs file 34 | nirs = load(infile,'-mat'); 35 | 36 | % Save SNIRF: Convert .nirs format data to SnirfClass object, save it to .snirf file (HDF5) 37 | fprintf('Saving %s ...\n', outfile); 38 | snirf_saved = SnirfClass(nirs); 39 | tic; snirf_saved.Save(outfile); toc 40 | 41 | % Load SNIRF: Create another SnirfClass object, load SNIRF data from the .snirf file (HDF5) 42 | fprintf('Loading %s ...\n', outfile); 43 | tic; snirf_loaded = SnirfClass(outfile); toc 44 | 45 | % NOTE: the SnirfClass constructor uses the Load() method which complements the Save() 46 | % method. If one wanted to be consistent with the Save operation above you could do 47 | % the loading this way: 48 | % 49 | % fprintf('Loading %s ...\n', outfile); 50 | % snirf_loaded = SnirfClass(); 51 | % tic; snirf_loaded.Load(outfile); toc 52 | % 53 | % However in the actual code that loads .snirf files, it is much clearer and more concise 54 | % to use the constructor the way it's done in this function. 55 | % 56 | -------------------------------------------------------------------------------- /snirf/Utils/CopyHandles.m: -------------------------------------------------------------------------------- 1 | function objnew = CopyHandles(varargin) 2 | % Syntax: 3 | % objnew = CopyHandles(obj) 4 | % objnew = CopyHandles(obj, objnew) 5 | % 6 | % Generate copy of array of handle objects from obj to objnew 7 | % 8 | % 9 | 10 | if nargin==1 11 | obj = varargin{1}; 12 | elseif nargin==2 13 | obj = varargin{1}; 14 | objnew = varargin{2}; 15 | end 16 | 17 | if isempty(obj) 18 | objnew = obj; 19 | return 20 | end 21 | 22 | if isa(obj, 'handle') 23 | % Generate class instance with shallow copy 24 | objnew = obj(1).copy; 25 | for ii=2:length(obj) 26 | objnew(ii) = obj(ii).copy; 27 | end 28 | else 29 | objnew = obj; 30 | end 31 | 32 | props = properties(obj(1)); 33 | 34 | % Deep copy properties from obj to objnew 35 | for ii=1:length(obj) 36 | for iProp=1:length(props) 37 | if isa( eval( sprintf('obj(ii).%s', props{iProp}) ), 'handle') 38 | for kk=1:eval( sprintf('length(obj(ii).%s)', props{iProp}) ) 39 | eval( sprintf('objnew(ii).%s(kk) = CopyHandles(obj(ii).%s(kk));', props{iProp}, props{iProp}) ); 40 | end 41 | else 42 | % Non-handle object assignment does copy-by-value which is deep copy by definition 43 | eval( sprintf('objnew(ii).%s = obj(ii).%s;', props{iProp}, props{iProp}) ); 44 | end 45 | end 46 | end 47 | 48 | -------------------------------------------------------------------------------- /snirf/Utils/Hdf5/HDF5_DatasetLoad.m: -------------------------------------------------------------------------------- 1 | function val = HDF5_DatasetLoad(gid, name, val0, options) 2 | 3 | if ~exist('val0','var') 4 | val0 = []; 5 | end 6 | if ~exist('options','var') 7 | options = ''; 8 | end 9 | 10 | try 11 | dsetid = H5D.open(gid, name); 12 | 13 | % NOTE: HDF5 stores contiguous muti-dimensional arrays in row-major order. 14 | % Matlab stores them in row-major order. We want to transpose the loaded data 15 | % it back to Matlab's column-major storage order and thus get back the 16 | % original array. 17 | val = H5D.read(dsetid); 18 | val = HDF5_PostProcessing(val, val0, options); 19 | 20 | % val = H5D.read(dsetid); 21 | H5D.close(dsetid); 22 | catch 23 | switch(class(val0)) 24 | case 'char' 25 | val = ''; 26 | case 'cell' 27 | val = {}; 28 | otherwise 29 | val = []; 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /snirf/Utils/Hdf5/HDF5_DatasetWrite.m: -------------------------------------------------------------------------------- 1 | function err = HDF5_DatasetWrite(fname, location, data) 2 | 3 | if exist(fname,'file') 4 | fid = H5F.open(fname, 'H5F_ACC_RDWR', 'H5P_DEFAULT'); 5 | else 6 | fid = H5F.create(fname, 'H5F_ACC_TRUNC', 'H5P_DEFAULT', 'H5P_DEFAULT'); 7 | end 8 | if fid<0 9 | err = -1; 10 | return; 11 | end 12 | 13 | % Create group where dataset is located 14 | group = fileparts(location); 15 | group(group=='\') = '/'; 16 | gid = CreateGroup(fid, group); 17 | if gid < 0 18 | err = -1; 19 | return; 20 | end 21 | 22 | % Update dataset 23 | err = WriteDataset(fid, location, data); 24 | 25 | 26 | 27 | 28 | % ---------------------------------------------------------------- 29 | function gid = CreateGroup(fid, group) 30 | if group == '/' 31 | gid = H5G.open(fid, '/'); 32 | return; 33 | end 34 | 35 | try 36 | gid = H5G.open(fid, group); 37 | catch 38 | [rootgroup, group] = fileparts(group); 39 | rootgroup(rootgroup=='\') = '/'; 40 | gid = CreateGroup(fid, rootgroup); 41 | gid = H5G.create(gid, group, 'H5P_DEFAULT','H5P_DEFAULT','H5P_DEFAULT'); 42 | end 43 | 44 | 45 | 46 | % -------------------------------------------------------------- 47 | function err = WriteDataset(fid, location, data) 48 | 49 | err = 0; 50 | 51 | % data = HDF5_Transpose(data); 52 | dims = size(data); 53 | h5_dims = fliplr(dims); 54 | unlimited = H5ML.get_constant_value('H5S_UNLIMITED'); 55 | h5_maxdims = [unlimited, unlimited]; 56 | 57 | if isnumeric(data) 58 | type_id = H5T.copy('H5T_NATIVE_DOUBLE'); 59 | elseif ischar(data) 60 | type_id = H5T.copy('H5T_C_S1'); 61 | else 62 | err = -1; 63 | return; 64 | end 65 | 66 | space_id = H5S.create_simple(2, h5_dims, h5_maxdims); 67 | proplist_id = H5P.create('H5P_DATASET_CREATE'); 68 | 69 | % Open or create dataset 70 | try 71 | dset_id = H5D.open(fid, location); 72 | H5D.set_extent(dset_id, h5_dims); 73 | catch 74 | H5P.set_chunk(proplist_id, h5_dims); 75 | dset_id = H5D.create(fid, location, type_id, space_id, proplist_id); 76 | end 77 | file_space_id = H5D.get_space(dset_id); 78 | 79 | % Write dataset 80 | % H5D.write(dset_id, type_id, space_id, file_space_id, proplist_id, data); 81 | H5D.write(dset_id, type_id, space_id, file_space_id, 'H5P_DEFAULT', data); 82 | 83 | % Close space, type, dataset and file 84 | H5S.close(space_id); 85 | H5T.close(type_id); 86 | H5D.close(dset_id); 87 | H5F.close(fid); 88 | 89 | 90 | 91 | % ---------------------------------------------------------------- 92 | function [dset_id, type_id, space_id, proplist_id] = CreateDataset(fid, location, h5_dims) 93 | 94 | h5_maxdims = h5_dims; 95 | 96 | type_id = H5T.copy('H5T_NATIVE_DOUBLE'); 97 | space_id = H5S.create_simple(2, h5_dims, h5_maxdims); 98 | proplist_id = H5P.create('H5P_DATASET_CREATE'); 99 | H5P.set_chunk(proplist_id, [h5_dims(1), h5_dims(2)]); 100 | 101 | dset_id = H5D.create(fid, location, type_id, space_id, proplist_id); 102 | 103 | 104 | -------------------------------------------------------------------------------- /snirf/Utils/Hdf5/HDF5_DatasetWriteStrings.m: -------------------------------------------------------------------------------- 1 | function HDF5_DatasetWriteStrings(fname, location, data) 2 | 3 | if ~exist(fname, 'file') 4 | fid = H5F.create(fname, 'H5F_ACC_TRUNC', 'H5P_DEFAULT', 'H5P_DEFAULT'); 5 | else 6 | fid = H5F.open(fname,'H5F_ACC_RDWR','H5P_DEFAULT'); 7 | end 8 | data = cell2str_new(data); 9 | 10 | filetype = H5T.copy('H5T_FORTRAN_S1'); 11 | H5T.set_size(filetype, size(data,2)); 12 | memtype = H5T.copy('H5T_C_S1'); 13 | H5T.set_size(memtype, size(data,2)); 14 | 15 | % Create dataspace. Setting maximum size to [] sets the maximum 16 | % size to be the current size. 17 | space = H5S.create_simple(1, size(data,1), []); 18 | 19 | % Create the dataset and write the string data to it. 20 | dset = H5D.create(fid, location, filetype, space, 'H5P_DEFAULT'); 21 | 22 | % Transpose the data to match the layout in the H5 file to match C 23 | % generated H5 file. 24 | H5D.write(dset, memtype, 'H5S_ALL', 'H5S_ALL', 'H5P_DEFAULT', data'); 25 | 26 | % Close and release resources. 27 | H5D.close(dset); 28 | H5S.close(space); 29 | H5T.close(filetype); 30 | H5T.close(memtype); 31 | H5F.close(fid); 32 | 33 | 34 | -------------------------------------------------------------------------------- /snirf/Utils/Hdf5/HDF5_GroupClose.m: -------------------------------------------------------------------------------- 1 | function HDF5_GroupClose(fileobj, gid, fid) 2 | 3 | H5G.close(gid); 4 | if ischar(fileobj) 5 | H5F.close(fid); 6 | end 7 | -------------------------------------------------------------------------------- /snirf/Utils/Hdf5/HDF5_GroupOpen.m: -------------------------------------------------------------------------------- 1 | function [gid, fid] = HDF5_GroupOpen(fileobj, location) 2 | 3 | % Find data location 4 | if ischar(fileobj) 5 | fid = H5F.open(fileobj); 6 | else 7 | fid = fileobj; 8 | end 9 | try 10 | gid = H5G.open(fid, location); 11 | catch 12 | gid.double = -1; 13 | end 14 | 15 | 16 | -------------------------------------------------------------------------------- /snirf/Utils/Hdf5/HDF5_PostProcessing.m: -------------------------------------------------------------------------------- 1 | function val = HDF5_PostProcessing(val, val0, options) 2 | 3 | if ~exist('val0','var') 4 | val0 = []; 5 | end 6 | if ~exist('options','var') 7 | options = ''; 8 | end 9 | val = HDF5_Transpose(val, options); 10 | 11 | % Convert muti-row char array to cell string array 12 | if ischar(val) && ~iscell(val0) 13 | val = convertHDF5StrToMatlabStr(val); 14 | elseif ischar(val) 15 | val = convertHDF5StrToMatlabStr(val, 'cell'); 16 | end 17 | -------------------------------------------------------------------------------- /snirf/Utils/Hdf5/HDF5_Transpose.m: -------------------------------------------------------------------------------- 1 | function val = HDF5_Transpose(val, options) 2 | 3 | if ~exist('options','var') 4 | options = ''; 5 | end 6 | 7 | % Matlab stores contiguous muti-dimensional arrays in column-major order. 8 | % HDF5 stores them in row-major order. We want to transpose the data to agree 9 | % with the file format's storage order. 10 | if ~isrow(val) && ~iscolumn(val) % Matrices 11 | val = permute(val, ndims(val):-1:1); 12 | elseif ischar(val) % 1D char strings 13 | val = permute(val, ndims(val):-1:1); 14 | elseif ~isempty(findstr('multidim', options)) % Force multi-dimensional even if vector 15 | val = permute(val, ndims(val):-1:1); 16 | elseif ~isempty(findstr('2D', options)) % Force 2D even if vector 17 | val = permute(val, ndims(val):-1:1); 18 | end 19 | -------------------------------------------------------------------------------- /snirf/Utils/Hdf5/convertHDF5StrToMatlabStr.m: -------------------------------------------------------------------------------- 1 | function snew = convertHDF5StrToMatlabStr(s, type) 2 | snew = ''; 3 | 4 | if ~exist('type', 'var') || isempty(type) 5 | type = 'char'; 6 | end 7 | 8 | % Convert muti-row char array to cell string array 9 | if size(s,1)==1 && strcmp(type,'char') 10 | snew = strtrim_improve(s); 11 | else 12 | snew = cell(size(s,1),1); 13 | for ii = 1:size(s,1) 14 | snew{ii} = strtrim_improve(s(ii,:)); 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /snirf/Utils/Hdf5/h5loadgroup.m: -------------------------------------------------------------------------------- 1 | function data = h5loadgroup(loc) 2 | 3 | data = struct(); 4 | 5 | num_objs = H5G.get_num_objs(loc); 6 | 7 | % 8 | % Load groups and datasets 9 | % 10 | for j_item = 0:num_objs-1 11 | objtype = H5G.get_objtype_by_idx(loc, j_item); 12 | objname = H5G.get_objname_by_idx(loc, j_item); 13 | 14 | if objtype == 0 15 | % Group 16 | name = regexprep(objname, '.*/', ''); 17 | 18 | if ~isempty(regexp(name,'^[a-zA-Z].*')) 19 | group_loc = H5G.open(loc, name); 20 | try 21 | sub_data = h5loadgroup(group_loc); 22 | H5G.close(group_loc); 23 | catch exc 24 | H5G.close(group_loc); 25 | rethrow(exc); 26 | end 27 | if isempty(path_parts) 28 | data = setfield(data, name, sub_data); 29 | else 30 | data = sub_data; 31 | return 32 | end 33 | end 34 | 35 | elseif objtype == 1 36 | % Dataset 37 | name = regexprep(objname, '.*/', ''); 38 | if ~isempty(regexp(name,'^[a-zA-Z].*')) 39 | dataset_loc = H5D.open(loc, name); 40 | try 41 | % NOTE: HDF5 stores contiguous muti-dimensional arrays in row-major order. 42 | % Matlab stores them in row-major order. We want to transpose the loaded data 43 | % it back to Matlab's column-major storage order and thus get back the 44 | % original array. 45 | sub_data = H5D.read(dataset_loc, 'H5ML_DEFAULT', 'H5S_ALL','H5S_ALL','H5P_DEFAULT'); 46 | sub_data = HDF5_PostProcessing(sub_data); 47 | 48 | H5D.close(dataset_loc); 49 | catch exc 50 | H5D.close(dataset_loc); 51 | rethrow(exc); 52 | end 53 | 54 | sub_data = fix_data(sub_data); 55 | 56 | data = setfield(data, name, sub_data); 57 | end 58 | end 59 | 60 | end 61 | 62 | 63 | % --------------------------------------------------------------------- 64 | function data = fix_data(data) 65 | % Fix some common types of data to more friendly form. 66 | 67 | if isstruct(data) 68 | fields = fieldnames(data); 69 | if length(fields) == 2 & strcmp(fields{1}, 'r') & strcmp(fields{2}, 'i') 70 | if isnumeric(data.r) & isnumeric(data.i) 71 | data = data.r + 1j*data.i; 72 | end 73 | end 74 | end 75 | 76 | if isnumeric(data) & ndims(data) > 1 77 | % permute dimensions 78 | data = permute(data, fliplr(1:ndims(data))); 79 | end 80 | 81 | -------------------------------------------------------------------------------- /snirf/Utils/Hdf5/hdf5write_safe.m: -------------------------------------------------------------------------------- 1 | function err = hdf5write_safe(fname, name, val, options) 2 | 3 | err = -1; 4 | if isempty(val) 5 | return; 6 | end 7 | if ~exist('options','var') 8 | options = ''; 9 | end 10 | 11 | if iscell(val) 12 | HDF5_DatasetWriteStrings(fname, name, val) 13 | else 14 | val = HDF5_Transpose(val, options); 15 | try 16 | if ~isempty(findstr('rw', options)) 17 | HDF5_DatasetWrite(fname, name, val); 18 | else 19 | hdf5write(fname, name, val, 'WriteMode','append'); 20 | end 21 | catch 22 | return; 23 | end 24 | end 25 | err = 0; -------------------------------------------------------------------------------- /snirf/Utils/cell2str_new.m: -------------------------------------------------------------------------------- 1 | function s = cell2str_new(c) 2 | s = c; 3 | if iscell(c) 4 | maxlen = 0; 5 | for ii = 1:length(c) 6 | if length(c{ii}) > maxlen 7 | maxlen = length(c{ii}); 8 | end 9 | end 10 | s = char(zeros(length(c), maxlen)); 11 | for ii = 1:length(c) 12 | s(ii,1:length(c{ii})) = c{ii}; 13 | end 14 | end 15 | 16 | -------------------------------------------------------------------------------- /snirf/Utils/isproperty.m: -------------------------------------------------------------------------------- 1 | function b = isproperty(obj, propname) 2 | 3 | if isstruct(obj) 4 | b = isfield(obj, propname); 5 | elseif isobject(obj) 6 | b = all(isprop(obj, propname)); 7 | else 8 | b = false; 9 | end 10 | -------------------------------------------------------------------------------- /snirf/Utils/iswholenum.m: -------------------------------------------------------------------------------- 1 | function b = iswholenum(x) 2 | % Reason for this function is that isinteger() looks at the class of the number 3 | % rather it's actual value. So isinteger(4) will return true but integer(4.0) will 4 | % be false even though 4.0 = 4. This is a problem. 5 | b = false; 6 | if ~ismember(class(x), {'double','single','int8','uint8','int16','uint16','int32','uint32'}); 7 | return; 8 | end 9 | b = (x == floor(x)); 10 | 11 | -------------------------------------------------------------------------------- /snirf/Utils/pretty_print_struct.m: -------------------------------------------------------------------------------- 1 | function pretty_print_struct(st, indent, option, logger) 2 | spaces = ''; 3 | 4 | if ~exist('st','var') || isempty(st) 5 | return; 6 | end 7 | if ~exist('indent','var') || isempty(indent) 8 | indent = 0; 9 | end 10 | if ~exist('option','var') || isempty(option) 11 | option = 1; 12 | end 13 | if ~exist('logger','var') 14 | logger = []; 15 | end 16 | logger = InitLogger(logger); 17 | 18 | if iswholenum(indent) 19 | spaces = blanks(indent); 20 | elseif ischar(indent) 21 | spaces = blanks(length(indent)); 22 | end 23 | 24 | if isstruct(st) || isobject(st) 25 | s = evalc('disp(st)'); 26 | c = str2cell_fast(s, char(10)); 27 | for ii=1:length(c) 28 | if option==1 29 | logger.Write(sprintf('%s%s\n', spaces, strtrim_improve(c{ii}))); 30 | elseif option==2 31 | logger.Write(sprintf('%s%s\n', spaces, c{ii})); 32 | end 33 | end 34 | else 35 | str = ''; 36 | for jj=1:ndims(st) 37 | if jj==1 38 | str = num2str(size(st,jj)); 39 | else 40 | str = sprintf('%sx%s', str, num2str(size(st,jj))); 41 | end 42 | end 43 | logger.Write(sprintf(' %s: [%s %s]\n', inputname(1), str, class(st))); 44 | end 45 | 46 | -------------------------------------------------------------------------------- /snirf/Utils/propnames.m: -------------------------------------------------------------------------------- 1 | function props = propnames(s) 2 | 3 | if isstruct(s) 4 | props = fieldnames(s); 5 | else 6 | props = properties(s); 7 | end -------------------------------------------------------------------------------- /snirf/Utils/strtrim_improve.m: -------------------------------------------------------------------------------- 1 | function s = strtrim_improve(s0) 2 | % 3 | % strtrim handles only a limited number of whitespace types. 4 | % But does NOT handle 0 for example. This function turns all 5 | % whitespaces including 0 to plain old spaces which strtrim 6 | % does handle. 7 | % 8 | % 9 | s = s0; 10 | s(s<33) = ' '; % Replace all non-printable chracters with spaces 11 | 12 | % Feed the digestable new string to strtrim. 13 | s = strtrim(s); 14 | 15 | 16 | -------------------------------------------------------------------------------- /snirf/setpaths.m: -------------------------------------------------------------------------------- 1 | function setpaths(option) 2 | 3 | % 4 | % USAGE: 5 | % 6 | % setpaths 7 | % setpaths(1) 8 | % setpaths(0) 9 | % 10 | 11 | if ~exist('option','var') 12 | option = 1; 13 | end 14 | setpathsPath = which('setpaths'); 15 | rootdir = fileparts(setpathsPath); 16 | p = { 17 | 'Snirf'; 18 | 'Snirf/Examples'; 19 | 'Utils'; 20 | 'Utils/Hdf5'; 21 | }; 22 | 23 | for ii = 1:length(p) 24 | pname = [rootdir, '/', p{ii}]; 25 | if option 26 | addpath(pname, '-end'); 27 | else 28 | rmpath(pname); 29 | end 30 | end 31 | 32 | 33 | --------------------------------------------------------------------------------