libxdf: C:/Users/Yida Lin/Documents/GitHub/libxdf/libxdf/xdf.h Source File

libxdf 0.92 A static C++ library for loading XDF files

xdf.h
Go to the documentation of this file.
1 //libxdf is a static C++ library to load XDF files
2 //Copyright (C) 2017 Yida Lin
3
4 //This program is free software: you can redistribute it and/or modify
5 //it under the terms of the GNU General Public License as published by
6 //the Free Software Foundation, either version 3 of the License, or
7 //(at your option) any later version.
8
9 //This program is distributed in the hope that it will be useful,
10 //but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 //GNU General Public License for more details.
13
14 //You should have received a copy of the GNU General Public License
15 //along with this program. If not, see <http://www.gnu.org/licenses/>.
16 //If you have questions, contact author at ITAL_FAZIOLI@hotmail.com
17
22 #ifndef XDF_H
23 #define XDF_H
24
25 #include <string>
26 #include <vector>
27 #include <map>
28 #include <set>
29
37 class Xdf
38 {
39 public:
41 Xdf();
42
43 //subclass for single streams
53 struct Stream
54 {
56 std::vector<std::vector<float> > time_series;
57 std::vector<float> time_stamps;
58 std::string streamHeader;
59 std::string streamFooter;
61 struct
62 {
63 int channel_count;
64 double nominal_srate;
65 std::string name;
66 std::string type;
67 std::string channel_format;
69 std::vector<std::map<std::string, std::string> > channels;
71 std::vector<std::pair<double, double> > clock_offsets;
73 double first_timestamp;
74 double last_timestamp;
75 int sample_count;
76 double measured_srate;
77 double effective_sample_rate;
78 } info;
80 float last_timestamp{ 0 };
81 float sampling_interval;
82 std::vector<double> clock_times;
83 std::vector<double> clock_values;
84 };
85
86 //XDF properties=================================================================================
87
88 std::vector<Stream> streams;
89 float version;
91 uint64_t totalLen = 0;
94 float minTS = 0;
95 float maxTS = 0;
96 size_t totalCh = 0;
97 int majSR = 0;
98 int maxSR = 0;
99 std::vector<int> streamMap;
107 typedef std::string eventName;
113 typedef float eventTimeStamp;
114
115 std::vector<std::pair<std::pair<eventName, eventTimeStamp>, int> > eventMap;
117 std::vector<std::string> dictionary;
118 std::vector<uint16_t> eventType;
119 std::vector<std::string> labels;
120 std::set<double> sampleRateMap;
121 std::vector<float> offsets;
123 std::string fileHeader;
124 int userAddedStream { 0 };
127 std::vector<std::pair<std::string, double> > userCreatedEvents;
129 //Public Functions==============================================================================================
130
142 void adjustTotalLength();
143
154 void calcTotalLength(int sampleRate);
155
160 void createLabels();
161
174 void detrend();
175
186 void freeUpTimeStamps();
187
193 int load_xdf(std::string filename);
194
200 void resample(int userSrate);
201
208 int writeEventsToXDF(std::string file_path);
209
210 //Private Functions: Not intended to be used by external programs======================================
211
212 private:
213
217 void calcEffectiveSrate();
218
229 void calcTotalChannel();
230
251 void findMajSR();
252
259 void findMinMax();
260
267 void getHighestSampleRate();
268
274 void loadDictionary();
275
281 void loadSampleRateMap();
282
292 uint64_t readLength(std::ifstream &file);
293 };
294
295 #endif // XDF_H
Xdf::eventName
std::string eventName
Used as std::vector<std::pair<std::pair<eventName, eventTimeStamp>, int> > in eventMap.
Definition: xdf.h:107
Xdf::Stream::measured_srate
double measured_srate
Definition: xdf.h:76
Xdf::dictionary
std::vector< std::string > dictionary
Definition: xdf.h:117
Xdf::Stream::last_timestamp
double last_timestamp
Definition: xdf.h:74
Xdf::Stream::clock_values
std::vector< double > clock_values
Definition: xdf.h:83
Xdf::freeUpTimeStamps
void freeUpTimeStamps()
Delete the time stamps vectors when no longer needed to release some memory.
Definition: xdf.cpp:760
Xdf::userCreatedEvents
std::vector< std::pair< std::string, double > > userCreatedEvents
Definition: xdf.h:127
Xdf::userAddedStream
int userAddedStream
Definition: xdf.h:124
Xdf::majSR
int majSR
Definition: xdf.h:97
Xdf::totalCh
size_t totalCh
Definition: xdf.h:96
Xdf::minTS
float minTS
Definition: xdf.h:94
Xdf::Stream::streamFooter
std::string streamFooter
Definition: xdf.h:59
Xdf::eventType
std::vector< uint16_t > eventType
Definition: xdf.h:118
Xdf::Stream::clock_times
std::vector< double > clock_times
Definition: xdf.h:82
Xdf::Stream
Definition: xdf.h:53
Xdf::maxTS
float maxTS
Definition: xdf.h:95
Xdf::detrend
void detrend()
Subtract the entire channel by its mean.
Definition: xdf.cpp:803
Xdf::Stream::time_series
std::vector< std::vector< float > > time_series
A 2D vector which stores the time series of a stream. Each row represents a channel.
Definition: xdf.h:56
Xdf::Stream::type
std::string type
Definition: xdf.h:66
Xdf::streams
std::vector< Stream > streams
Definition: xdf.h:88
Xdf::adjustTotalLength
void adjustTotalLength()
Adjust totalLen to avoid possible deviation.
Definition: xdf.cpp:776
Xdf::Stream::name
std::string name
Definition: xdf.h:65
Xdf::writeEventsToXDF
int writeEventsToXDF(std::string file_path)
writeEventsToXDF
Definition: xdf.cpp:851
Xdf::eventMap
std::vector< std::pair< std::pair< eventName, eventTimeStamp >, int > > eventMap
Definition: xdf.h:115
Xdf::eventTimeStamp
float eventTimeStamp
Used as std::vector<std::pair<std::pair<eventName, eventTimeStamp>, int> > in eventMap.
Definition: xdf.h:113
Xdf
Definition: xdf.h:37
Xdf::createLabels
void createLabels()
Create labels for each channel and store them in labels vector.
Definition: xdf.cpp:940
Xdf::resample
void resample(int userSrate)
Resample all streams and channel to a chosen sample rate.
Definition: xdf.cpp:537
Xdf::Stream::channel_count
int channel_count
Definition: xdf.h:63
Xdf::Xdf
Xdf()
Default constructor with no parameter.
Definition: xdf.cpp:30
Xdf::labels
std::vector< std::string > labels
Definition: xdf.h:119
Xdf::maxSR
int maxSR
Definition: xdf.h:98
Xdf::Stream::channel_format
std::string channel_format
Definition: xdf.h:67
Xdf::Stream::first_timestamp
double first_timestamp
Definition: xdf.h:73
Xdf::Stream::info
struct Xdf::Stream::@0 info
Xdf::sampleRateMap
std::set< double > sampleRateMap
Definition: xdf.h:120
Xdf::streamMap
std::vector< int > streamMap
Definition: xdf.h:99
Xdf::Stream::sampling_interval
float sampling_interval
Definition: xdf.h:81
Xdf::version
float version
Definition: xdf.h:89
Xdf::offsets
std::vector< float > offsets
Definition: xdf.h:121
Xdf::Stream::effective_sample_rate
double effective_sample_rate
Definition: xdf.h:77
Xdf::totalLen
uint64_t totalLen
Definition: xdf.h:91
Xdf::calcTotalLength
void calcTotalLength(int sampleRate)
Calculate the globle length (in samples).
Definition: xdf.cpp:755
Xdf::load_xdf
int load_xdf(std::string filename)
The main function of loading an XDF file.
Definition: xdf.cpp:34
Xdf::Stream::sample_count
int sample_count
Definition: xdf.h:75
Xdf::fileHeader
std::string fileHeader
Definition: xdf.h:123
Xdf::Stream::clock_offsets
std::vector< std::pair< double, double > > clock_offsets
Definition: xdf.h:71
Xdf::Stream::streamHeader
std::string streamHeader
Definition: xdf.h:58
Xdf::Stream::channels
std::vector< std::map< std::string, std::string > > channels
Definition: xdf.h:69
Xdf::Stream::time_stamps
std::vector< float > time_stamps
Definition: xdf.h:57
Xdf::Stream::nominal_srate
double nominal_srate
Definition: xdf.h:64