Programming Reference:GenericSignal Class

From BCI2000 Wiki
Jump to navigation Jump to search

Location

src/shared/types

Synopsis

When being handed down through the filter chain from one GenericFilter instance to the next, signal data is transported inside GenericSignal objects. Signals are associated with a data type, which is one of int16, float24, float32 or int32. This is used whenever signals are written to a file or into a network connection, internally however, signal data is always represented as double.

GenericSignal transparently handles memory allocation, lazy assignment, and data storage inside shared memory regions in order to improve the overally efficiency of real-time data transport between filters and modules.

Methods

GenericSignal()

Instantiates a new, empty signal.

GenericSignal(uint channels, uint elements, SignalType=float32)

Instantiates a new signal with channels channels, elements elements and a signal data type, which is one of int16, float24, float32 or int32. Values are initialized to zeros.

GenericSignal(SignalProperties, double value=0)

Instantiates a new signal from a SignalProperties object, initializing all values to the given value argument.

GenericSignal(GenericSignal)

Instantiates a new signal which is a shallow copy of an existing signal. Whenever the copy is updated, the shallow copy is replaced with a deep copy before applying changes.

AssignValues(GenericSignal), operator=(GenericSignal)

Lazy assignment from another signal. A shallow copy is applied first. Whenever the signal is written to, the shallow copy is replaced with a deep one first.

bool Empty()

Returns true if the signal has no channels and no elements.

double Value(uint channel, uint element), operator()(uint channel, uint element)

Returns the value at the given channel and element index.

SetValue(uint channel, uint element, double value)

Sets the value at the given channel and element index.

SetAllValues(double value)

Sets all signal values to the value given as argument.

EnsureDeepCopy()

If the signal contains a shallow copy of another signal, replace it with a deep copy.

bool ShareAcrossModules()

If data is not contained in shared memory already, this function moves signal data into a newly assigned shared memory block. Serialize() will output a short reference to that shared memory block rather than the signal's data content. Returns true if data was newly moved into shared memory, false otherwise.

ostream InsertInto(ostream)

Writes the signal's content to the given stream in human readable format.

istream ExtractFrom(istream)

Reads the signal's content as written by InsertInto().

WriteValueBinary(ostream, uint channel, uint element)

Writes a single value into the given stream in binary form.

ReadValueBinary(istream, uint channel, uint element)

Reads a single value from the given stream in binary form.

Serialize(ostream)

Writes the entire signal into the given stream in binary form. If ShareAcrossModules has been called, a reference to shared memory is written rather than signal data.

Unserialize(istream)

Reads the entire signal from the given stream in binary form. If the stream contains a reference to shared memory, the signal is linked to that shared memory block and behaves as if ShareAcrossModules had been called.

Properties

SignalProperties Properties (rw)

Signal properties such as the number of channels and elements, data type, and channel and element labels contained in a SignalProperties object.

int Channels (r)

The number of channels in the signal.

int Elements (r)

The number of elements (or samples) in the signal.

SignalType Type (r)

The signal's data type, one of int16, float24, float32 or int32.

See also

Programming Reference:GenericFilter Class, Technical Reference:Visualization Properties, Programming Tutorial:Implementing a Signal Processing Filter, Programming Reference:SignalSharingDemo Signal Processing