Phasic← Overview

XDF

Reads:      .xdf (XDF 1.0)
Writes:     .xdf — single stream, multi-stream session, and live recording
Requires:   (no feature flag for reading; live recording needs `lsl`)
Applies to: all channel kinds

XDF is the format the Lab Streaming Layer ecosystem records to. A single file holds any number of streams — each with its own sample rate, channel set and device — recorded against a shared session clock.

Phasic treats an XDF file as several independent recordings on one timeline, not as one merged recording. Opening a file presents a stream picker; each stream you open becomes its own document, and they stay aligned because they share the session clock.

Listing the streams does not decode any samples, so even a very large file opens its picker immediately.

Streams and markers

A stream carries markers if its channel format is string — and that is the only thing that decides it. A string stream declaring a sample rate of 1000 Hz is still a marker stream. Everything else is a signal stream.

Marker streams behave differently from signal streams in three ways:

  • They are always decoded, whichever streams you chose to open
  • They cannot be opened as a document of their own
  • They belong to the session, not to any single stream, and are shown against whichever recording you are viewing

A marker sample spanning several channels is joined into one annotation text separated by spaces. XDF markers are instants — they carry no duration, and are always presented with a duration of zero.

The rate Phasic reports is measured, not declared

A stream’s header declares a nominal sample rate. Phasic does not use it when the timestamps disagree: the rate shown is derived from the timestamps themselves, with the declared rate used only as a fallback.

This is deliberate and occasionally surprising. One of the format ecosystem’s own reference files declares 100 Hz and actually runs at roughly 92.93 Hz, and Phasic reports the latter. The nominal rate is a claim; the timestamps are the measurement.

Streams that declare no rate at all still open, measured from their timestamps. Several real devices declare zero on every stream, so refusing them would reject working recordings.

Clock handling

Timestamps are corrected before anything else uses them.

Clock offsets recorded in the file are applied per stream. Clock resets — a discontinuity of more than one second in the offset series — are detected, and each side of the reset is fitted separately rather than being averaged into one wrong line.

Session time zero accounts for markers. The origin is the earliest point across both stream data and marker events, so a cue that precedes the first data sample does not land at a negative time.

Gaps are segmented on the same thresholds the ecosystem’s Python implementation uses: a break of more than one second, or more than 500 nominal sample periods, whichever is larger.

A known limitation

The reference Python implementation fits clock offsets with a robust regression that tolerates outliers. Phasic uses ordinary least squares. Clock resets are handled and obvious placeholder values are discarded, so what remains unguarded is a clock range containing extreme but non-placeholder outliers, which would tilt that range’s fit.

A miscorrected timeline is not necessarily obvious: the total span of a recording can look entirely plausible while local spacing is wrong.

Streams that cannot be opened

A stream may be listed but unavailable, with the reason shown rather than the stream silently disappearing:

Reason Meaning
stream declares no channels The header declares a channel count of zero
stream contains no samples The stream was declared but never carried data
could not determine a sample rate — the stream declares none and its timestamps do not advance No declared rate, and the timestamps give nothing to measure

Sample data belonging to a stream that was never declared is skipped.

Files that are refused

Condition Message
Missing or wrong magic bytes not an XDF file: expected magic "XDF:", found …
Declares no streams at all this XDF file declares no streams
Corrupt chunk length corrupt XDF: chunk at offset … declares length …, minimum is 2
Chunk claims more bytes than remain corrupt XDF: … claims N bytes at offset X, only M remain
Unsupported channel format unknown XDF channel_format …
Bad timestamp width bad XDF timestamp width …: expected 0 or 8

Supported channel formats are int8, int16, int32, int64, float32, double64 and string.

A malformed chunk stops the read rather than attempting to resynchronise, because every subsequent offset would be guesswork. The reader is written against untrusted input and is covered by tests asserting that a truncated or corrupt file produces an error rather than a crash.

Not supported

  • Compressed .xdfz files. There is no gzip handling
  • Version checking. Phasic targets XDF 1.0, the only version in circulation, but does not verify the file’s declared version — a future 1.1 file would be parsed as 1.0
  • Stream footers as a synchronisation source. Footers are parsed but their clock information is not used; the clock-offset chunks are authoritative

Device quirks that are accommodated

Some recorders deviate from the specification in ways that would otherwise lose data, and these are handled deliberately:

  • A sample rate given in the stream description rather than the standard field is used when the standard field is zero
  • A channel label given as <name> rather than <label> is accepted, since otherwise every channel name would be lost
  • A missing or short channel list is padded with generated names
  • A stream with no name is presented as Stream <id>

Recording XDF

Phasic writes XDF in three ways: exporting a single document, exporting a whole multi-stream session, and spooling a live recording to disk.

A live recording writes one file per session, not per stream. Streams may start and stop independently while the file continues, and the file is complete the moment the last write lands — no finalisation step is needed, so an interrupted recording is still readable.

Two properties of what Phasic writes are worth knowing:

Samples are always stored as 32-bit floats, never as integers. There is no quantisation grid, so the value stored is the value received.

Files Phasic writes contain no clock-offset chunks, deliberately. Its live inputs are already corrected onto the shared clock as they arrive, so recording offsets as well would cause its own reader to correct them a second time. Timestamps in a Phasic-written file are already right.

This differs from what other recorders produce, and is correct for round-tripping through Phasic. A file written by Phasic and read by another tool is still valid XDF.