Fixed-Rate Source

class gpype.backend.sources.base.fixed_rate_source.FixedRateSource[source]

Bases: Source

Fixed-rate source for continuous data generation at sampling rate.

Generates data at fixed sampling rate using background thread with precise timing control and drift compensation.

The pacing thread runs one cycle per sample, not per frame. A subclass whose step() returns frame_size samples per call must therefore set decimation_factor=frame_size, so that step() runs on every frame_size-th cycle and the stream leaves at its declared rate. A subclass that omits this emits frame_size times too much data, and nothing reports it: the frames are individually well-formed, the declared sampling rate is unchanged, and only wall-clock measurement reveals it. Measured on a reader before this was applied: 1.01x at frame_size 1, 5.02x at 5, 24.98x at 25, 50.03x at 50.

Every subclass here does this – Generator, CsvReader and RecordingReader – and a fourth must too. Two exemptions, both real:

  • Batch mode. A batch reader starts no pacing thread; the driver calls cycle() once for the whole recording. A decimation factor there would make that single cycle emit nothing.

  • Externally driven sources. An amplifier is clocked by its own device callback rather than by this thread, so it emits one frame per callback and needs a factor of one. Those extend Source directly.

class Configuration[source]

Bases: Configuration

Configuration class for FixedRateSource parameters.

class Keys[source]

Bases: Keys

Configuration keys for fixed-rate source settings.

SAMPLING_RATE = 'sampling_rate'

Configuration key for sampling rate in Hz

__init__(sampling_rate, **kwargs)[source]

Initialize configuration with sampling rate validation.

Parameters:
  • sampling_rate (float) – Sampling rate in Hz. Must be positive.

  • **kwargs – Additional configuration parameters.

Raises:

ValueError – If sampling_rate is not positive.

__init__(sampling_rate, output_ports=None, **kwargs)[source]

Initialize fixed-rate source with sampling configuration.

Parameters:
  • sampling_rate (float) – Sampling rate in Hz for data generation.

  • output_ports (Optional[list[Configuration]]) – List of output port configurations. Defaults to default port configuration if None.

  • **kwargs – Additional arguments for parent Source class.

start()[source]

Start fixed-rate source and begin data generation.

Initializes parent source and starts background thread for continuous data generation at specified sampling rate.

stop()[source]

Stop fixed-rate source and terminate data generation.

Signals background thread to stop and waits for completion.

master_candidacy()[source]

Claim as a counted stream.

Contiguous by construction and with a declared rate, so it is a valid timeline – but not a loss-aware one, since a source that reports no counter cannot say what it dropped. A numbered device therefore outranks it.

Returns:

(rate, COUNTED), or None if no usable rate is set.

setup(data, port_context_in)[source]

Setup output port contexts with sampling rate information.

Parameters:
  • data (dict[str, ndarray]) – Input data arrays (empty for source nodes).

  • port_context_in (dict[str, dict]) – Input port contexts (empty for source nodes).

Return type:

dict[str, dict]

Returns:

Dictionary of output port contexts with sampling_rate information.