Skip to content

FreqSawsEffect

Source: FreqSawsEffect.h

FreqSawsEffect

class FreqSawsEffect
src/light/effects/FreqSawsEffect.h:31

Inherits: EffectBase

Audio-reactive effect: sawtooth bands driven by the frequency spectrum.

FreqSawsEffect card FreqSawsEffect controls Author: @TroyHacks (MoonLight / WLED MoonModules), https://github.com/ewowi/MoonLight/blob/main/src/MoonLight/Nodes/Effects/E_MoonLight.h

One vertical saw per band, each running at a rate its own loudness drives. A band's speed rises instantly to a loud hit and decays slowly once the sound stops. So a struck band keeps sawing for a while, and a quiet one winds down.

Prior art: MoonLight's FreqSaws, whose physics and three position methods this reproduces.

Public Attributes

uint8_t fade = 4 : The per-frame fade, which is the motion trail.

uint8_t increaser = 211 : How much a band's loudness gains into its target speed.

uint8_t decreaser = 18 : How fast a silent band decays, where 0 leaves it running.

uint8_t bpmMax = 198 : The top rate a fully sped band reaches.

bool invert = false : Mirror every other column, for a woven look.

bool keepOn = false : Keep drawing a band whose speed has decayed to nothing.

uint8_t method = 2 : Which of the three position methods places the saw.

Public Methods

virtual inline const char * tags() const override : Catalog tags: MoonLight origin, audio-reactive.

virtual inline Dim dimensions() const override : Writes the z=0 slice, which extrude fills through a volume.

virtual inline void defineControls() override : Publish the trail, the band physics and the position method.

virtual inline void prepare() override : Start every band from rest, since the state is per band rather than per light.

virtual inline void tick() override : Advance all sixteen bands once, then draw each column from its band's cached position.

More info

Three ways to place the saw

Chaos reads the position straight off the beat, so the saw teleports as the rate changes. Chaos fix carries a per-band offset, so a rate change continues from where the saw already was. BandPhases integrates a per-band accumulator each frame, so it advances with no jump at all.

The physics run once a tick

The band loop caches each band's position, and the column loop only reads that cache. So a band spanning many columns integrates once a frame rather than once a column. invert mirrors every other column for a woven look, and keepOn keeps a decayed band drawn.