Skip to content
Back to top

# Signal Chain Stages

Signal chain Stages allow for the control of signal flow through the pipeline. This includes stages for combining and splitting signals, basic gain components, and delays.

## Bypass

class audio_dsp.stages.Bypass(**kwargs)

  Stage which does not modify its inputs. Useful if data needs to flow through a thread which is not being processed on to keep pipeline lengths aligned.

  process(in_channels)

    Return a copy of the inputs.

### Bypass Control

The Bypass Stage has no runtime controllable parameters.

## Fork

class audio_dsp.stages.Fork(count=2, **kwargs)

  Fork the signal.

  Use if the same data needs to be sent to multiple data paths:

      a = t.stage(Example, ...)
      f = t.stage(Fork, a, count=2)  # count optional, default is 2
      b = t.stage(Example, f.forks[0])
      c = t.stage(Example, f.forks[1])

  Attributes:
    forks list[list[StageOutput]]

      For convenience, each forked output will be available in this list each entry contains a set of outputs which will contain the same data as the input.

  class ForkOutputList(
    edges: list[StageOutput | None] | None = None,
  )

    Custom StageOutputList that is created by Fork.

    This allows convenient access to each fork output.

    Attributes:
      forks: list[StageOutputList]

        Fork duplicates its inputs, each entry in the forks list is a single copy of the input edges.

  get_frequency_response(nfft=32768)

    Fork has no sensible frequency response, not implemented.

  process(in_channels)

    Duplicate the inputs to the outputs based on this fork’s configuration.

### Fork Control

The Fork Stage has no runtime controllable parameters.

## Mixer

class audio_dsp.stages.Mixer(**kwargs)

  Mixes the input signals together. The mixer can be used to add signals together, or to attenuate the input signals.

  Attributes:
    dsp_block `audio_dsp.dsp.signal_chain.mixer`

      The DSP block class; see Mixer for implementation details

  set_gain(gain_db)

    Set the gain of the mixer in dB.

    Parameters:
      gain_db float

        The gain of the mixer in dB.

  set_parameters(parameters: MixerParameters)

    Update the parameters of the Mixer stage.

pydantic model audio_dsp.models.signal_chain.MixerParameters

  Parameters for Mixer Stage.

  field gain_db: float = -6

    Gain of the stage in dB.

    Constraints:

      - ge = -162.55619765854985

      - le = 24.082399717833418

### Mixer Control

The following runtime command ids are available for the Mixer Stage. For details on reading and writing these commands, see the Run-Time Control User Guide.

Control parameter | Payload length
--- | ---
CMD_MIXER_GAIN | `sizeof(int32_t)`
The current gain in Q_GAIN format. To convert a value in decibels to this format, the function `adsp_dB_to_gain()` in `control/signal_chain.h` can be used. |

## Adder

class audio_dsp.stages.Adder(**kwargs)

  Add the input signals together. The adder can be used to add signals together.

  Attributes:
    dsp_block `audio_dsp.dsp.signal_chain.adder`

      The DSP block class; see Adder for implementation details.

### Adder Control

The Adder Stage has no runtime controllable parameters.

## Subtractor

class audio_dsp.stages.Subtractor(**kwargs)

  Subtract the second input from the first. The subtractor can be used to subtract signals from each other. It must only have 2 inputs.

  Attributes:
    dsp_block `audio_dsp.dsp.signal_chain.subtractor`

      The DSP block class; see Subtractor for implementation details.

### Subtractor Control

The Subtractor Stage has no runtime controllable parameters.

## FixedGain

class audio_dsp.stages.FixedGain(gain_db=0, **kwargs)

  This stage implements a fixed gain. The input signal is multiplied by a gain. If the gain is changed at runtime, pops and clicks may occur.

  If the gain needs to be changed at runtime, use a `VolumeControl` stage instead.

  Parameters:
    gain_db float, optional

      The gain of the mixer in dB.

  Attributes:
    dsp_block `audio_dsp.dsp.signal_chain.fixed_gain`

      The DSP block class; see Fixed Gain for implementation details.

  set_gain(gain_db)

    Set the gain of the fixed gain in dB.

    Parameters:
      gain_db float

        The gain of the fixed gain in dB.

  set_parameters(
    parameters: FixedGainParameters,
  )

    Update the parameters of the FixedGain stage.

pydantic model audio_dsp.models.signal_chain.FixedGainParameters

  Parameters for FixedGain Stage.

  field gain_db: float = 0.0

    Gain of the stage in dB.

    Constraints:

      - ge = -162.55619765854985

      - le = 24.082399717833418

### FixedGain Control

The following runtime command ids are available for the FixedGain Stage. For details on reading and writing these commands, see the Run-Time Control User Guide.

Control parameter | Payload length
--- | ---
CMD_FIXED_GAIN_GAIN | `sizeof(int32_t)`
The gain value in Q_GAIN format. To convert a value in decibels to this format, the function `adsp_dB_to_gain()` in `control/signal_chain.h` can be used. |

## VolumeControl

class audio_dsp.stages.VolumeControl(gain_dB=0, mute_state=0, **kwargs)

  This stage implements a volume control. The input signal is multiplied by a gain. The gain can be changed at runtime. To avoid pops and clicks during gain changes, a slew is applied to the gain update. The stage can be muted and unmuted at runtime.

  Parameters:
    gain_db float, optional

      The gain of the Volume Control in dB.

    mute_state int, optional

      The mute state of the Volume Control: 0: unmuted, 1: muted.

  Attributes:
    dsp_block `audio_dsp.dsp.signal_chain.volume_control`

      The DSP block class; see Volume Control for implementation details.

  make_volume_control(gain_dB, slew_shift, mute_state, Q_sig=27)

    Update the settings of this volume control.

    Parameters:
      gain_dB

        Target gain of this volume control.

      slew_shift

        The shift value used in the exponential slew.

      mute_state

        The mute state of the Volume Control: 0: unmuted, 1: muted.

  set_gain(gain_dB)

    Set the gain of the volume control in dB.

    Parameters:
      gain_db float

        The gain of the volume control in dB.

  set_mute_state(mute_state)

    Set the mute state of the volume control.

    Parameters:
      mute_state bool

        The mute state of the volume control.

  set_parameters(
    parameters: VolumeControlParameters,
  )

    Update the parameters of the VolumeControl stage.

pydantic model audio_dsp.models.signal_chain.VolumeControlParameters

  Parameters for VolumeControl Stage.

  field gain_db: float = 0.0

    Gain of the stage in dB.

    Constraints:

      - ge = -162.55619765854985

      - le = 24.082399717833418

  field mute_state: int = 0

    The mute state of the VolumeControl: 0: unmuted, 1: muted.

    Constraints:

      - ge = 0

      - le = 1

### VolumeControl Control

The following runtime command ids are available for the VolumeControl Stage. For details on reading and writing these commands, see the Run-Time Control User Guide.

Control parameter | Payload length
--- | ---
CMD_VOLUME_CONTROL_TARGET_GAIN | `sizeof(int32_t)`
The target gain of the volume control in Q_GAIN format. To convert a value in decibels to this format, the function `adsp_dB_to_gain()` in `control/signal_chain.h` can be used. |
CMD_VOLUME_CONTROL_GAIN | `sizeof(int32_t)`
The current applied gain of the volume control in Q_GAIN format. The volume control will slew the applied gain towards the target gain. This command is read only. When sending a write control command, it will be ignored. |
CMD_VOLUME_CONTROL_SLEW_SHIFT | `sizeof(int32_t)`
The shift value used to set the slew rate. See the volume control documentation for conversions between slew_shift and time constant. |
CMD_VOLUME_CONTROL_MUTE_STATE | `sizeof(uint8_t)`
Sets the mute state. 1 is muted and 0 is unmuted. |

## Switch

class audio_dsp.stages.Switch(index=0, **kwargs)

  Switch the output to one of the inputs. The switch can be used to select between different signals.

  Parameters:
    index int

      The position to which to move the switch. This changes the output signal to the input[index]

  move_switch(position)

    Move the switch to the specified position.

    Parameters:
      position int

        The position to which to move the switch. This changes the output signal to the input[position]

  set_parameters(
    parameters: SwitchParameters,
  )

    Update the parameters of the Switch stage.

pydantic model audio_dsp.models.signal_chain.SwitchParameters

  Parameters for Switch Stage.

  field position: int = 0

    Switch position. This changes the output signal to the input[index]

    Constraints:

      - ge = 0

### Switch Control

The following runtime command ids are available for the Switch Stage. For details on reading and writing these commands, see the Run-Time Control User Guide.

Control parameter | Payload length
--- | ---
CMD_SWITCH_POSITION | `sizeof(int32_t)`
The current switch position. |

## SwitchSlew

class audio_dsp.stages.SwitchSlew(index=0, **kwargs)

  Switch the output to one of the inputs. The switch can be used to select between different signals. When the switch is move, a cosine slew is used to avoid clicks. This supports up to 16 inputs.

  Parameters:
    index int

      The position to which to move the switch. This changes the output signal to the input[index]

  Attributes:
    dsp_block `audio_dsp.dsp.signal_chain.switch_slew`

      The DSP block class; see Switch with slew for implementation details.

  move_switch(position)

    Move the switch to the specified position.

    Parameters:
      position int

        The position to which to move the switch. This changes the output signal to the input[position]

  set_parameters(
    parameters: SwitchParameters,
  )

    Update the parameters of the Switch stage.

pydantic model audio_dsp.models.signal_chain.SwitchParameters

  Parameters for Switch Stage.

  field position: int = 0

    Switch position. This changes the output signal to the input[index]

    Constraints:

      - ge = 0

### SwitchSlew Control

The following runtime command ids are available for the SwitchSlew Stage. For details on reading and writing these commands, see the Run-Time Control User Guide.

Control parameter | Payload length
--- | ---
CMD_SWITCH_SLEW_POSITION | `sizeof(int32_t)`
The current switch position. |

## SwitchStereo

class audio_dsp.stages.SwitchStereo(index=0, **kwargs)

  Switch the input to one of the stereo pairs of outputs. The switch can be used to select between different stereo signal pairs. The inputs should be passed in pairs, e.g. `[0_L, 0_R, 1_L, 1_R, ...]`. Setting the switch position will output the nth pair.

  Parameters:
    index int

      The position to which to move the switch. This changes the output signal to the [input[2*index], input[:2*index + 1]]

  move_switch(position)

    Move the switch to the specified position.

    Parameters:
      position int

        The position to which to move the switch. This changes the output signal to the [input[2*position], input[:2*position + 1]]

  set_parameters(
    parameters: SwitchParameters,
  )

    Update the parameters of the SwitchStereo stage.

pydantic model audio_dsp.models.signal_chain.SwitchParameters

  Parameters for Switch Stage.

  field position: int = 0

    Switch position. This changes the output signal to the input[index]

    Constraints:

      - ge = 0

### SwitchStereo Control

The following runtime command ids are available for the SwitchStereo Stage. For details on reading and writing these commands, see the Run-Time Control User Guide.

Control parameter | Payload length
--- | ---
CMD_SWITCH_STEREO_POSITION | `sizeof(int32_t)`
The current switch position. |

## Delay

class audio_dsp.stages.Delay(

  max_delay: float = 1024,
  starting_delay: float = 0,
  units: str = 'samples',
  **kwargs,

)

  Delay the input signal by a specified amount.

  The maximum delay is set at compile time, and the runtime delay can be set between 0 and `max_delay`.

  Parameters:
    max_delay float

      The maximum delay in specified units. This can only be set at compile time.

    starting_delay float

      The starting delay in specified units.

    units str, optional

      The units of the delay, can be ‘samples’, ‘ms’ or ‘s’. Default is ‘samples’.

  Attributes:
    dsp_block `audio_dsp.dsp.signal_chain.delay`

      The DSP block class; see Delay for implementation details.

  set_delay(delay, units='samples')

    Set the length of the delay line, will saturate at max_delay.

    Parameters:
      delay float

        The delay in specified units.

      units str

        The units of the delay, can be ‘samples’, ‘ms’ or ‘s’. Default is ‘samples’.

  set_parameters(parameters: DelayParameters)

    Update the parameters of the Delay stage.

pydantic model audio_dsp.models.signal_chain.DelayParameters

  Parameters for delay stage.

  field delay: float = 0

    Current delay length in the configured units

    Constraints:

      - ge = 0

### Delay Control

The following runtime command ids are available for the Delay Stage. For details on reading and writing these commands, see the Run-Time Control User Guide.

Control parameter | Payload length
--- | ---
CMD_DELAY_MAX_DELAY | `sizeof(uint32_t)`
The maximum delay value in samples. This is only configurable at compile time. This command is read only. When sending a write control command, it will be ignored. |
CMD_DELAY_DELAY | `sizeof(uint32_t)`
The current delay value in samples. To convert a value in other units of time to samples, use `time_to_samples()` in `control/signal_chain.h`. Note the minimum delay provided by this stage is 1 sample. Setting the delay to 0 will still yield a 1 sample delay. |

## Crossfader

class audio_dsp.stages.Crossfader(mix=0.5, **kwargs)

  The crossfader mixes between two inputs. The mix control sets the respective levels of each input. When the mix is changed, the gain is updated with a slew.

  Parameters:
    mix float

      The mix of the crossfader between 0 and 1.

  Attributes:
    dsp_block `audio_dsp.dsp.signal_chain.crossfader`

      The DSP block class; see Crossfader for implementation details.

  set_mix(mix)

    Set the mix of the crossfader.

    When the mix is set to 0, only the first signal will be output. When the mix is set to 0.5, each channel has a gain of -4.5 dB. When the mix is set to 1, only they second signal will be output.

    Parameters:
      mix float

        The mix of the crossfader between 0 and 1.

  set_parameters(
    parameters: CrossfaderParameters,
  )

    Update the parameters of the Crossfader stage.

pydantic model audio_dsp.models.signal_chain.CrossfaderParameters

  Parameters for crossfader stage.

  field mix: float = 0.5

    Set the mix of the crossfader

    Constraints:

      - ge = 0

      - le = 1

### Crossfader Control

The following runtime command ids are available for the Crossfader Stage. For details on reading and writing these commands, see the Run-Time Control User Guide.

Control parameter | Payload length
--- | ---
CMD_CROSSFADER_GAINS | `sizeof(int32_t)*[2]`
The gains of each input to the crossfader in Q0.31 format. A mix between 0 and 1 can be converted to gains by using the helper function :c:func`adsp_crossfader_mix` in `control/signal_chain.h`. |

## CrossfaderStereo

class audio_dsp.stages.CrossfaderStereo(mix=0.5, **kwargs)

  The stereo crossfader mixes between two stereo inputs. The mix control sets the respective levels of each input pair. When the mix is changed, the gain is updated with a slew. The inputs should be passed in pairs, e.g. `[0_L, 0_R, 1_L, 1_R]`.

  Attributes:
    dsp_block `audio_dsp.dsp.signal_chain.crossfader`

      The DSP block class; see Crossfader for implementation details.

  set_mix(mix)

    Set the mix of the crossfader.

    When the mix is set to 0, only the first signal will be output. When the mix is set to 0.5, each channel has a gain of -4.5 dB. When the mix is set to 1, only they second signal will be output.

    Parameters:
      mix float

        The mix of the crossfader between 0 and 1.

  set_parameters(
    parameters: CrossfaderParameters,
  )

    Update the parameters of the Crossfader stage.

pydantic model audio_dsp.models.signal_chain.CrossfaderParameters

  Parameters for crossfader stage.

  field mix: float = 0.5

    Set the mix of the crossfader

    Constraints:

      - ge = 0

      - le = 1

### CrossfaderStereo Control

The following runtime command ids are available for the CrossfaderStereo Stage. For details on reading and writing these commands, see the Run-Time Control User Guide.

Control parameter | Payload length
--- | ---
CMD_CROSSFADER_STEREO_GAINS | `sizeof(int32_t)*[2]`
The gains of each input to the crossfader in Q0.31 format. A mix between 0 and 1 can be converted to gains by using the helper function :c:func`adsp_crossfader_mix` in `control/signal_chain.h`. |

## Router4to1

class audio_dsp.stages.Router4to1(channel_states=[True, False, False, False], **kwargs)

  The 4:1 Router combines functionality of both switch and mixer. It takes up to 4 inputs and can select any combination of them to be mixed to a single output.

  Parameters:
    channel_states list[bool]

      A list of 4 boolean values indicating which channels should be active (True) or inactive (False).

  Attributes:
    dsp_block `audio_dsp.dsp.signal_chain.router_4to1`

      The DSP block class that combines switching and mixing functionality.

  set_channel_states(channel_states)

    Set which channels are active or inactive in the router.

    Parameters:
      channel_states list[bool]

        A list of 4 boolean values indicating which channels should be active (True) or inactive (False).

  set_parameters(
    parameters: Router4to1Parameters,
  )

    Update the parameters of the Router4to1 stage.

pydantic model audio_dsp.models.signal_chain.Router4to1Parameters

  Parameters for 4:1 router stage.

  Attributes:
    channel_states: [bool, bool, bool, bool]

      List of 4 boolean values indicating which channels are active.

  field channel_states: Annotated[list[Annotated[bool, FieldInfo(annotation=NoneType, required=True, description='Channel state', metadata=[Ge(ge=0), Le(le=1)])]], Len(min_length=4, max_length=None)] [Optional]
    Constraints:

      - min_length = 4

### Router4to1 Control

The following runtime command ids are available for the Router4to1 Stage. For details on reading and writing these commands, see the Run-Time Control User Guide.

Control parameter | Payload length
--- | ---
CMD_ROUTER_4TO1_CHANNEL_STATES | `sizeof(int32_t)*[4]`
States of the 4 input channels (1 = active, 0 = inactive). Active channels are mixed together to produce the output signal. |