Delay
- class gpype.backend.timing.delay.Delay[source]
Bases:
IONodeDelays the input stream by an exact number of samples.
num_samplescounts samples and is independent of frame_size. The first num_samples samples of output areinitial_value, every emitted frame keeps the input’s shape andConstants.DATA_TYPE, and num_samples=0 is a pass-through.Declaring both
channel_countandsampling_rateturns the node into a feedback-loop breaker: it asserts its own output context instead of deriving it from an input that does not exist yet, pushes one priming frame ofinitial_valueinstart(), and reportsBREAKS_CYCLESTrue – which is what letsgpype.Pipelineaccept a cyclic pipeline at all. The loop delay is then exactly num_samples samples, and must be at least frame_size because a node pushes a whole frame at a time.setup()re-verifies the declaration against what comes back round the loop, and refuses a channel with theindexrole on that edge.- Parameters:
num_samples (
int) – Samples to delay the stream by. Non-negative, and at least frame_size when a context is declared.initial_value (
float) – Value every warm-up sample holds, and what the rest of a loop sees as its “sample -1”.channel_count (
Optional[int]) – Channels the declared edge carries. Declaring form only; None derives it from the input.sampling_rate (
Optional[float]) – Sampling rate of the declared edge, in Hz. Declaring form only; None derives it from the input.frame_size (
Optional[int]) – Samples per pushed frame on the declared edge. Declaring form only, where it defaults to 1; must be None otherwise, since a deriving Delay takes it from its input.**kwargs – Additional arguments for parent IONode.
- Raises:
ValueError – If num_samples is negative; if exactly one of channel_count and sampling_rate is given; if frame_size is given without them; if a declared channel_count, sampling_rate or frame_size is not positive; or if a declared num_samples is smaller than frame_size.
- __init__(num_samples, initial_value=0.0, channel_count=None, sampling_rate=None, frame_size=None, **kwargs)[source]
Initialize the delay and, optionally, declare its own context.
- Parameters:
num_samples (
int) – Number of samples to delay the signal by.initial_value (
float) – Fill value for the warm-up samples.channel_count (
Optional[int]) – Channels on the declared edge, or None.sampling_rate (
Optional[float]) – Sampling rate of the declared edge, or None.frame_size (
Optional[int]) – Frame size of the declared edge, or None.**kwargs – Additional arguments for parent IONode.
- Raises:
ValueError – See the class docstring.
- BREAKS_CYCLES = False
Duck-typed marker read by Pipeline’s cycle detector so it can recognise a loop breaker without importing a concrete node class from a family it otherwise stays agnostic to – the same reason a source is found by a TIME_BASE attribute rather than an isinstance check.
False here and set per instance in __init__, because only the declaring form breaks anything: a Delay that derives its context from its input cannot break the context cycle, and accepting one as a breaker would let the detector pass a pipeline that then stalls silently at Healthy with an unbounded queue – the exact failure the check exists to prevent.
- start()[source]
Start the node and, if it declares a context, prime the loop.
The priming push runs after
super().start(): it sets the output port’s context directly, which only makes sense once that port exists. Safe to call again after a stop() – see stop().- Return type:
- stop()[source]
Stop the node and forget that it has primed a loop.
Without this, a second start() would see
_primedalready True and push no fresh token. Pipeline.start() clears every input queue before any node starts, so with no new token nothing would ever again reach the other side of the junction the loop closes at – the loop would go silent, not error.- Return type:
- setup(data, port_context_in)[source]
Publish the output context and size the sample-domain ring.
In the deriving form this is the ordinary IONode merge. In the declaring form
super().setup()is deliberately not called: the output context was asserted at construction, not derived from the input the way an ordinary IONode’s is, so the generic multi-port merge would be answering a question already answered – and the arriving context is re-verified against the declaration instead.- Parameters:
- Return type:
- Returns:
Output port contexts – the parent’s merge, or the declaration.
- Raises:
ValueError – If channel count is not provided in context (or, via the parent’s own check below, frame size isn’t); or, in the declaring form, if the arriving context disagrees with the declaration.
- step(data)[source]
Process one step of delay.
- Parameters:
data (
dict[str,ndarray]) – Input data dictionary containing signal to delay.- Return type:
- Returns:
Dictionary with the delayed signal, one frame_size-shaped frame per call, filled with initial_value while still in the warm-up period. A pass-through when this node buffers nothing: num_samples=0 in the deriving form, or num_samples == frame_size in the declaring form, where the whole delay is the frame pushed in start().