script

package
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package script builds dsp.Effect implementations from Lua descriptions.

A script declares a parameter set and a node graph once at load time. The Go kernel builds that graph into a flat execution plan, and only the plan runs per sample: Effect.Process takes no lock, allocates nothing, and never calls into the interpreter.

A script may also register a control callback that recomputes node state per block. It runs on a control goroutine, publishes its result atomically, and a watchdog silences it if it overruns its budget.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(path string) (dsp.Factory, error)

Load reads one Lua file and returns the factory that builds its effect. The front end is a binder, not an evaluator: it runs the script once, walks the graph description the build function produced, and hands the result to the Go compiler. It never runs on the audio thread and is never called again for a Tier 1 script.

Every failure is an error: a bad script never panics and never registers a half-built effect.

func LoadDir

func LoadDir(dir string) ([]dsp.Factory, error)

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

func Register(f dsp.Factory) error

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. It wraps a compiled plan behind the same dsp.Effect interface a built-in implements, so the registry, the chain, the preset loader and the UI never know a script is involved.

func (*Effect) Bypassed

func (e *Effect) Bypassed() bool

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: a host must ask for recovery explicitly, and until it does the effect stays bypassed.

func (*Effect) Close

func (e *Effect) Close() error

Close stops the control goroutine and releases the instance's interpreter. A Tier 2 effect owns a goroutine and a Lua state, which the engine's dsp.Effect contract cannot 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) Get

func (e *Effect) Get(key string) (any, error)

Get returns the current value of a parameter.

func (*Effect) Latency

func (e *Effect) Latency() time.Duration

Latency reports how far the effect delays its output, so the chain can add it to the reported position. It runs on the control side, so reading the store's mutex is fine. A negative or zero resolved value clamps to zero: a script cannot claim a latency that would advance the position.

func (*Effect) Meters

func (e *Effect) Meters() map[string]float32

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) Name

func (e *Effect) Name() string

Name identifies the instance in a chain.

func (*Effect) Process

func (e *Effect) Process(buf []float32, frames int) error

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

func (e *Effect) Readings() []dsp.Reading

Readings describes every meter node's key, so a UI knows how to draw it. It is a copy, so the caller cannot mutate the effect's declaration. An effect with no meter nodes returns an empty slice, never nil, so it marshals as [].

func (*Effect) Reset

func (e *Effect) Reset() error

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) Schema

func (e *Effect) Schema() []dsp.Param

Schema returns the parameter set, standard parameters included.

func (*Effect) Set

func (e *Effect) Set(key string, value any) error

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.

func (*Effect) Visuals

func (e *Effect) Visuals() []dsp.Visual

Visuals returns the plots the script declared, in declaration order, or an empty slice when it declared none. The slices are copied so a caller cannot reach into the effect's declaration, and every list is non-nil so it marshals as [] rather than null.

func (*Effect) Watchdog

func (e *Effect) Watchdog() string

Watchdog returns the fault reason, empty when the callback is healthy. It exists so a host can surface why an effect went quiet instead of guessing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL