The Physics of the Punch: Impulses vs. Envelopes
The Physics of the Punch: Impulses vs. Envelopes
If your audio visualizer feels like it's "breathing" underwater rather than dancing to the music, you are likely driving your math with envelopes instead of impulses.
The Mathematical Trap of the EMA
Most standard audio analysis outputs a smoothed envelope using an Exponential Moving Average (EMA) to prevent visual flickering. The math looks like this:
Where:
- is the envelope at time
- is the raw magnitude of the frequency band
- is the smoothing coefficient (attack/release)
The problem: By the time reaches its peak, the actual drum hit in the audio has already passed. If you map directly to the scale of an object, the object will swell and deflate sluggishly.
The Solution: Spring-Damper with Transient Injection
To make geometry feel kinetic, we separate the resting state from the kinetic energy. We use the envelope () to define the resting state, but we inject raw, unsmoothed transients (, or spectral flux) directly into the velocity of a simulated spring.
A standard damped spring-mass system is defined as:
The Reactive Hack: Instead of just setting the target , we forcefully inject energy into the velocity whenever a transient crosses a threshold.
This causes the geometry to snap outward instantly on a snare or kick, and then gracefully ring out using the spring physics, settling back to the slow-moving baseline of the EMA.