pub struct DSPFunction { /* private fields */ }
Expand description

This is the result of the JIT compiled crate::ast::ASTNode tree. You can send this structure to the audio backend thread and execute it using DSPFunction::exec.

To execute this DSPFunction properly, you have to call DSPFunction::init once the newly allocated structure is received by the DSP executing thread.

If the sample rate changes or the stateful DSP stuff must be resetted, you should call DSPFunction::reset or DSPFunction::set_sample_rate. Of course also only on the DSP executing thread.

Implementations

This function must be called before DSPFunction::exec! otherwise your states might not be properly initialized or preserved.

If you recompiled a function, pass the old one on the audio thread to the previous_function parameter here. It will take care of preserving state, such as persistent variables (those that start with “*”: crate::build::var("*abc")).

Swaps out the buffer at the given index with the new buffer. The contents of the Vec will be swapped with the current contents of the buffer, unless you specify preserve_old_samples which will try to preserve as many samples from the previous buffer as possible.

Swaps out the table at the given index with the new table.

If the audio thread changes the sampling rate, call this function, it will update the DSPState and reset all [DSPNodeState]s.

If the DSP state needs to be resetted, call this on the audio thread.

Use this to retrieve a pointer to the DSPState to access it between calls to DSPFunction::exec.

Use this to access the DSPState pointer between calls to DSPFunction::exec.

Safety

You must not create multiple aliasing references from that DSP state!

Use this to access the state of a specific DSP node state pointer between calls to DSPFunction::exec.

The node_state_uid and the type you pass here must match! It’s your responsibility to make sure this works!

Safety

You absolutely must know which ID has which DSPNodeType, otherwise this will badly go wrong!

 use synfx_dsp_jit::*;
 use synfx_dsp_jit::build::*;
 use synfx_dsp_jit::stdlib::AccumNodeState;

 let (ctx, mut fun) = instant_compile_ast(call("accum", 21, &[var("in1"), literal(0.0)])).unwrap();

 fun.init(44100.0, None);
 // Accumulate 42.0 here:
 fun.exec_2in_2out(21.0, 0.0);
 fun.exec_2in_2out(21.0, 0.0);

 unsafe {
     // Check 42.0 and set 99.0
     fun.with_node_state(21, |state: *mut AccumNodeState| {
         assert!(((*state).value - 42.0).abs() < 0.0001);
         (*state).value = 99.0;
     })
 };

 // Accumulate up to 100.0 here:
 let (_, _, ret) = fun.exec_2in_2out(1.0, 0.0);
 assert!((ret - 100.0).abs() < 0.0001);

 ctx.borrow_mut().free();

Retrieves the DSP node state pointer for a certain unique node state id.

Safety

You are responsible afterwards for knowing what type the actual pointer is of.

Helper function, it lets you specify only the contents of the parameters "in1" and "in2". It also returns you the values for "&sig1" and "&sig2" after execution. The third value is the return value of the compiled expression.

Executes the machine code and provides the following parameters in order: "in1", "in2", "alpha", "beta", "delta", "gamma", "&sig1", "&sig2"

It returns the return value of the computation. For addition outputs you can write to "&sig1" or "&sig2" with for instance: assign(var("&sig1"), literal(10.0)).

Gives you access to the persistent variables. To get the index of the persistent variable you must use DSPNodeContext::get_persistent_variable_index_by_name.

Checks if the DSP function actually has the state for a certain unique DSP node state ID.

Trait Implementations

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.