Documentation
¶
Overview ¶
Package script builds dsp.Effect implementations from Lua descriptions.
The split keeps Lua off the audio thread: Lua declares a parameter set and a node graph once at load time, the Go kernel here builds that graph into a flat execution plan, and only the Go plan runs per sample. Lua never runs on the audio thread and never runs per sample, so the real-time contract that every other dsp stage obeys holds unchanged: Process takes no lock, allocates nothing, and never calls back into the interpreter.
Tier 2 scripts may register a control callback that recomputes node state per block. That callback runs on a control goroutine and publishes its result atomically, and a watchdog silences it if it ever overruns its budget.
Index ¶
- func Load(path string) (dsp.Factory, error)
- func LoadDir(dir string) ([]dsp.Factory, error)
- func Register(f dsp.Factory) error
- type Effect
- func (e *Effect) Bypassed() bool
- func (e *Effect) ClearFault()
- func (e *Effect) Close() error
- func (e *Effect) Configure(in core.FrameFormat) (core.FrameFormat, error)
- func (e *Effect) Get(key string) (any, error)
- func (e *Effect) Latency() time.Duration
- func (e *Effect) Meters() map[string]float32
- func (e *Effect) Name() string
- func (e *Effect) Process(buf []float32, frames int) error
- func (e *Effect) Readings() []dsp.Reading
- func (e *Effect) Reset() error
- func (e *Effect) Schema() []dsp.Param
- func (e *Effect) Set(key string, value any) error
- func (e *Effect) Visuals() []dsp.Visual
- func (e *Effect) Watchdog() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Load ¶
Load reads one Lua file and returns the factory that builds its effect. Every failure is an error: a bad script never panics and never registers a half-built effect.
func LoadDir ¶
LoadDir reads every .lua file in dir, in name order, and returns one factory per script. A bad script fails the whole load with the file named, which is what a registration path wants: a half-loaded directory is harder to reason about than a failed one. Two scripts with the same effect name are rejected here: dsp's registry keeps only the last of a duplicate (kind, impl), so a silent collision would hide one effect behind the other.
func Register ¶
Register adds a script factory to dsp's default registry. It is the script equivalent of dsp.Register with the one check the registry does not do: two scripts that share an effect name would collide on the (kind, impl) pair, so the second registration is refused instead of shadowing the first.
Types ¶
type Effect ¶
type Effect struct {
// contains filtered or unexported fields
}
Effect is a scripted effect instance.
func (*Effect) Bypassed ¶
Bypassed reports the bypass parameter or a watchdog fault, so the chain can skip the effect entirely and contribute no latency.
func (*Effect) ClearFault ¶
func (e *Effect) ClearFault()
ClearFault clears a watchdog verdict so the effect can run again after a transient overrun. The fault is fail-closed by default: a host must ask for recovery explicitly, and until it does the effect stays bypassed. This is the documented way out of that state.
func (*Effect) Close ¶
Close stops the control goroutine and releases the instance's interpreter. A Tier 2 effect owns a goroutine and a Lua state, neither of which the engine's Effect contract knows how to free, so a host that discards an effect should call this. It is safe on a Tier 1 effect and safe to call twice.
func (*Effect) Configure ¶
func (e *Effect) Configure(in core.FrameFormat) (core.FrameFormat, error)
Configure negotiates the format and builds the audio state for it. It is the only place the plan is compiled, so the plan always belongs to the rate and channel count Process will use.
func (*Effect) Latency ¶
Latency reports how far the effect delays its output; the chain sums it into the reported position. It is only called on the control side, so reading the store's mutex here is fine. A negative resolved value clamps to zero: a script cannot claim a latency that would advance the position.
func (*Effect) Meters ¶
Meters reports the input and output peaks in dBFS under the standard keys, plus one entry per meter node the script declared. The meter values are block samples the audio thread published; this only reads atomics, so it is safe from the control goroutine.
func (*Effect) Process ¶
Process runs the plan in place. It loads the state once, so a Set during the call cannot make one buffer run on two configurations. It allocates nothing and takes no lock.
func (*Effect) Readings ¶
Readings describes every meter node's key, so a UI knows how to draw it. It is a copy: the effect's declaration is not the caller's to mutate. An effect with no meter nodes returns an empty slice, never nil, so it always marshals as [] rather than null.
func (*Effect) Reset ¶
Reset clears every node's state and the meters, so a seek cannot carry a tail across it. It builds a fresh plan and publishes it whole, the same way Set does, so a concurrent Process reads either the old plan or the new one and never the plan being cleared.
func (*Effect) Set ¶
Set validates a value, stores it and republishes the audio state. It is the only method a control goroutine calls while audio is running.
A parameter change must not reset node state: moving a delay time or a filter cutoff would otherwise wipe the line and click. So Set does not recompile; it recomputes the resolved parameter values and swaps in a snapshot that reuses the same plan, which keeps every delay buffer and filter memory intact.