Search guides and the APICtrl K
  1. API reference
  2. DSP

polynomial.h

A polynomial as a value: evaluate it, add it, multiply it.

#include <sonore/polynomial.h>
On this page

Design notes

The polynomials that run per sample in this SDK are written inline where they are used -- the sine in fast_math.h, the BLEP residual, the Lagrange weights -- and each is tested against the function it approximates. That stays: a fixed polynomial is fastest as a fixed expression.

This is for the other job, where the polynomial is BUILT: multiplying out (s - p1)(s - p2)... from a filter's poles, the transfer function of a cascade as one numerator and one denominator, a waveshaper curve fitted at prepare(), a Chebyshev polynomial for harmonic shaping. Doing that by hand is a nested loop with an off-by-one in it, which is what this replaces.

Coefficients are in ASCENDING order -- c[0] + c[1] x + c[2] x^2 ... -- the order the reference uses, and the one where coefficient i is the power i, so nobody has to remember which end is which.

The coefficients live in a std::vector, so CONSTRUCTING one allocates, and so do the operations that return a new polynomial. EVALUATING does not: build at prepare(), evaluate on the audio thread.

Types 1

template <typename T> class Polynomial

A polynomial held as its coefficients, lowest power first, as the reference's dsp::Polynomial orders them: evaluate it, add, multiply, differentiate and integrate it.

A value type that owns a std::vector and is never empty (the zero polynomial has one coefficient, 0). Building one, and every operation that returns a new one, allocates: do that in prepare() or on a message thread. Evaluating with operator() does not, and is what the audio thread calls. Nothing trims trailing zeros, so getOrder() is the storage's order.

↑↓ to move↵ to openEvery public name in the headers, and every guide