Expand description

Definition of the Intermediate Representation for the JIT compiler.

This is a quick guide of the intermediate language you can pass into the JIT compiler in form of an crate::ASTNode tree.

For a reference of the AST itself I recommend looking at crate::ASTNode and crate::ASTBinOp. They are pretty self explanatory.

Make sure to visit crate::ast::build too, it is an easy way to build an AST data structure.

Global Variables

There are multiple different kinds of variables you can access:

  • Predefined crate::DSPFunction Parameters (available in every function):
    • in1 - First channel input
    • in2 - Second channel input
    • alpha - Alpha parameter input
    • beta - Beta parameter input
    • delta - Delta parameter input
    • gamma - Gamma parameter input
    • &sig1 - Writeable signal channel 1 output
    • &sig2 - Writeable signal channel 2 output
  • Global Constants
    • PI - 3.14159…
    • TAU - 2*PI
    • E - Eulers number
    • 1PI - 1/PI
    • 2PI - 2/PI
    • PI2 - PI/2
    • PI3 - PI/3
    • PI4 - PI/4
    • PI6 - PI/6
    • PI8 - PI/8
    • 1SQRT2 - 1/sqrt(2)
    • 1SQRT_PI - 1/sqrt(PI)
    • LN2 - Ln(2)
    • LN10 - Ln(10)
  • Global Variables / Auxilary Variables:
    • $srate - The current sample rate in Hz
    • $israte - The current sample rate in 1.0 / Hz
    • $reset - Is 1.0 directly after the very first initialization and after an explicit call to crate::DSPFunction::reset. Otherwise it’s 0.0.
  • Persistent Variables (persistent across multiple calls, until a reset):
    • *... - Any variable that starts with a * is stored across multiple calls.
    • Note: If you need more (longer) persistent variables, across resets too, use the atomw/atomr nodes!
  • Multiple Return Value Accessors
    • First return value does not exist as variable, it just is the result of the AST node itself, or the result of the node function.
    • %1 - Second return value
    • %2 - Third return value
    • %3 - Fourth return value
    • %4 - Fifth return value
    • %5 - Sixth return value

DSP Nodes

I heavily recommend checking out HexoSynth if you plan to use synfx-dsp-jit, it offers a graphical environment for trying out all the following nodes in real time in a visual programming language (called WBlockDSP):

DSPNodeType nameInputsOutputsDescription
accuminput, resetsumAccumulator, sums up the input
phasefrequency, resetphasePhase oscillator
sinradianssineSine function
/%a, bdiv, remComputes the float division and remainder of a and b
atomrindexvalueReads an atomic float from a shared buffer at the given index
atomr~indexvalueReads a linear interpolated atomic float from a shared buffer at the given index
atomwindex, valuevalueWrites an atomic float into a shared buffer at the given index
s&hinput, setvalueA sample & hold node that samples it’s input on a rising edge at ‘set’.
s&h~input, setvalueA sample & hold node that continously samples it’s input if ‘set’ is set.

Buffers and Tables

You can pass a configuration to crate::DSPNodeContext::new which lets you define the number of possible buffers and a set of tables. Double precision buffers have to be declared by the JIT AST itself using crate::ASTNode::BufDeclare.

Tables are vectors of single precision floats, which are provided by the caller/user of crate::DSPNodeContext at creation time. You can however swap out the tables at runtime later with others. Either directly by accessing crate::DSPFunction::with_dsp_state or via the crate::engine::CodeEngine::send_table method.

Structs

Functions

Creates a crate::context::DSPNodeTypeLibrary that contains a bunch of standard components as seem fit by the synfx-dsp-jit crate developer.