xdf library

XDF (Extensible Data Format), the file format of LabRecorder and the Lab Streaming Layer.

  • loadXdf reads a whole file into memory, like pyxdf's load_xdf (clock synchronisation, clock reset handling and jitter removal with pyxdf's algorithms and defaults).
  • readChunks and readSamples give the raw chunks.

Pure Dart; works on all platforms, including the web.

Classes

LSLChannel
One channel, as a stream's metadata describes it (desc/channels/channel).
XdfBytesWriter
Writes little-endian values.
XdfChunk
One chunk of an XDF file: its tag and content (after the tag), which starts at offset in the file.
XdfClockOffset
A clock offset measurement: at time on the stream's own clock, that clock was value seconds behind the recorder's (add it to the stream's time stamps to get the recorder's time).
XdfEvents
Samples of an irregular stream (e.g. markers), in memory.
XdfFile
Random access to a large XDF recording without loading it into memory.
XdfFileOptions
Settings for XdfFile.
XdfIndexer
Indexes an XDF file in one sequential pass, for XdfFile: stream headers, clock offsets, footers, a summary pyramid per regular stream and where each samples chunk is; irregular streams are kept in memory.
XdfReader
Reads little-endian values from bytes, from position on.
XdfRecording
A loaded XDF file.
XdfRecordingSource
An XDF recording being indexed, here (XdfFile) or in a background isolate (XdfFile.openInBackground).
XdfSampleChunk
A samples chunk of a regular stream, decodable on its own.
XdfSamples
The samples of one samples chunk.
XdfStream
One stream of a loaded XDF file.
XdfStreamFooter
A stream's footer, written when recording stops.
XdfStreamIndex
One stream of an XdfFile: its header, and how its samples map to time.
XdfStreamInfo
A stream's header: what LSL says about the stream (its info XML).
XdfStreamView
What a viewer needs of one stream of an indexed XDF recording.
XdfSyncOptions
How loadXdf (and XdfFile) process time stamps. The defaults are pyxdf's.
XdfWriter
Writes an XDF file to sink as data comes in, like LabRecorder: the file header first, then stream headers, samples, clock offsets and boundaries in any order, and each stream's footer on close.

Enums

LSLChannelFormat
The stream info channel formats.
XdfTag
Kinds of XDF chunks.

Constants

xdfBoundaryUuid → const List<int>
The boundary chunk's content: a fixed UUID that lets a reader find the next chunk in a damaged file.
xdfMagic → const List<int>
The four bytes every XDF file starts with.

Functions

canDropSamples(XdfStreamInfo info) → bool
Whether a stream's header says it can drop samples (desc/synchronization/can_drop_samples), e.g. video.
clockFits(List<double> times, List<double> values, List<XdfRange> ranges, XdfSyncOptions o) → List<XdfClockFit>
The clock correction of each range of times and values (from detectClockResets).
detectClockResets(List<double> times, List<double> values, XdfSyncOptions o) → List<XdfRange>
Ranges of clock offsets between clock resets.
fillTimestamps(Float64List ts, double previous, double nominalRate) → double
Fill the time stamps that samples leave out (NaN): the previous one plus 1 / nominalRate (the previous chunk's last is previous). Returns the last time stamp.
isXdf(List<int> bytes) → bool
Whether bytes start like an XDF file.
loadXdf(Uint8List bytes, {XdfSyncOptions options = const XdfSyncOptions(), Set<int>? streamIds}) → XdfRecording
Load a whole XDF file from bytes, like pyxdf's load_xdf: clock synchronisation and jitter removal as options say (pyxdf's defaults). Samples of streams not in streamIds (when given) are skipped.
readChunkHeader(Uint8List bytes, int position) → XdfChunkHeader?
Parse the chunk header at position of bytes, or null if bytes end before it does (at most 11 bytes are needed).
readChunks(Uint8List bytes) → Iterable<XdfChunk>
The chunks of a whole XDF file in memory. A truncated last chunk (a recording that was cut off) is left out.
readSamples(Uint8List content, LSLChannelFormat format, int channels, {bool values = true, bool exact = false, void onInexact()?}) → XdfSamples
Decode a samples chunk's content for a stream of format with channels channels. With values false, numeric values are skipped (time stamps only). With exact, they come in the stream's own format (XdfSamples.typed) instead of as doubles. onInexact is called if an int64 value could not be held exactly (beyond 2^53 on the web, or as a double).
removeJitter(Float64List ts, double nominalRate, XdfSyncOptions o, {bool canDropSamples = false}) → XdfJitterResult
Replace the time stamps ts of a stream at nominalRate (in place) by a least-squares line per segment between breaks, and measure the effective rate. Irregular streams (rate 0) are left alone. With canDropSamples (e.g. video), time stamps are kept as they are.
robustFit(List<double> x, List<double> y, {double rho = 1, int iters = 1000}) → (double, double)
Robust linear regression y ≈ a + b·x with the Huber loss, solved by ADMM (pyxdf's _robust_fit). Returns (a, b).
segmentsBetween(List<bool> breaks) → List<XdfRange>
Segments of consecutive indices between breaks: breaks has one entry per pair of neighbours (length n - 1).
synchronizeClock(Float64List ts, List<double> times, List<double> values, XdfSyncOptions o) → List<XdfRange>
Map time stamps ts (in place) onto the recorder's clock with the clock offsets times and values. Returns the clock segments: the ranges of ts each correction applies to.

Typedefs

XdfChannel = LSLChannel
One channel as a stream header describes it (desc/channels/channel).
XdfChunkHeader = ({int contentLength, int contentOffset, int tag})
Where a chunk's header says its content is: contentOffset and contentLength (after the tag), with the tag.
XdfClockFit = (double, double)
A linear clock correction: add a + b·t to a time stamp t.
XdfFormat = LSLChannelFormat
How the values of a stream are stored: the LSL channel format.
XdfJitterResult = ({double effectiveRate, List<XdfRange> segments})
The result of removeJitter.
XdfRange = (int, int)
An inclusive range of indices.