Spectral Flux
Overview
spectral_flux is the level of the part of a signal above a cutoff frequency. It is a High Pass Filter followed by a Peak Envelope Follower: the level jumps at once and releases over a window.
A pick or a pluck puts broadband energy into that band, and a string ringing on keeps little of it, so the band’s level jumps at an attack and falls away as the note sustains. Compared with its own recent past by a delta_gate, that jump marks an attack from the spectrum of the signal. The block gives the level only; the threshold, and what counts as an attack, are the user’s.
The high-pass is a second-order Butterworth biquad (Q 0.707), 12 dB per octave. The follower’s window is its release: an SMA-equivalent span, about two time constants, as for the Peak Envelope Follower.
Declaration
struct spectral_flux
{
using follower = peak_envelope_follower;
spectral_flux(
frequency cutoff, duration window, float sps);
float operator()(float s);
float operator()() const;
};
Expressions
Notation
sf,a,b-
Objects of type
spectral_flux. f-
Object of type
frequency, the cutoff. w-
Object of type
duration, the follower’s release. sps-
Floating point value representing samples per second.
s-
Floating point value for the input sample.
Constructors and Assignment
| Expression | Semantics |
|---|---|
|
Construct a |
|
Copy construct a |
|
Assign |
| C++ brace initialization may also be used. |
Function Call
| Expression | Semantics | Return Type |
|---|---|---|
|
Process the input sample |
|
|
Get the latest level. |
|
Type Definitions
| Expression | Semantics | Type |
|---|---|---|
|
Get the envelope follower type. |
|
Example
Detect a pick in the input samples in, at sps samples per second, by the
band above 3 kHz rising 12 dB against about 20 ms ago. The monostable and the
edge make one event per pick, as on the Delta Gate page:
#include <q/fx/delta_gate.hpp> // For delta_gate
#include <q/fx/monostable.hpp> // For monostable
#include <q/fx/edge.hpp> // For rising_edge
namespace q = cycfi::q;
using namespace q::literals;
auto flux = q::spectral_flux{3_kHz, 50_ms, sps}; (1)
auto rise = q::delta_gate{12_dB, 20_ms, sps};
auto hold = q::monostable{100_ms, sps};
auto edge = q::rising_edge{};
for (auto s : in)
{
bool pick = edge(hold(rise(flux(s)))); (2)
}
| 1 | Construct a spectral_flux on the band above 3 kHz, with a 50 ms
release. |
| 2 | Process the sample, and pass the level of the band to the delta gate.
pick is true once per pick. |