|
arduino-audio-tools
|
Software "pseudo-float": a real number represented as a signed 16-bit mantissa plus a 16-bit exponent (value = mantissa * 2^exponent), computed with integer multiply/shift/compare only – no hardware floating-point instructions. This generalizes speexdsp's classic fixed-point trick of tracking a handful of wide-dynamic-range control variables as a normalized mantissa+exponent pair into a full, operator-overloaded numeric type usable as a drop-in replacement for float (see MDFFixedPoint in MDFEchoCancellation.h, which uses this class as the element type for the MDF echo canceller's sample/spectrum arrays and internal state, so the whole algorithm runs without native float arithmetic).
More...
#include <soft_float_t.h>
Public Member Functions | |
| constexpr | soft_float_t ()=default |
| soft_float_t (double d) | |
| soft_float_t (float f) | |
| soft_float_t (int i) | |
| constexpr | soft_float_t (int16_t mantissa, int16_t exponent) |
| int16_t | exponent () const |
| int16_t | mantissa () const |
| operator float () const | |
| operator int () const | |
| truncates toward zero, like (int)someFloat | |
| bool | operator!= (double o) const |
| bool | operator!= (float o) const |
| bool | operator!= (int o) const |
| bool | operator!= (soft_float_t o) const |
| soft_float_t | operator* (double o) const |
| soft_float_t | operator* (float o) const |
| soft_float_t | operator* (int o) const |
| soft_float_t | operator* (soft_float_t o) const |
| soft_float_t & | operator*= (soft_float_t o) |
| soft_float_t | operator+ (double o) const |
| soft_float_t | operator+ (float o) const |
| soft_float_t | operator+ (int o) const |
| soft_float_t | operator+ (soft_float_t o) const |
| soft_float_t & | operator+= (soft_float_t o) |
| soft_float_t | operator- () const |
| soft_float_t | operator- (double o) const |
| soft_float_t | operator- (float o) const |
| soft_float_t | operator- (int o) const |
| soft_float_t | operator- (soft_float_t o) const |
| soft_float_t & | operator-= (soft_float_t o) |
| soft_float_t | operator/ (double o) const |
| soft_float_t | operator/ (float o) const |
| soft_float_t | operator/ (int o) const |
| soft_float_t | operator/ (soft_float_t o) const |
| soft_float_t & | operator/= (soft_float_t o) |
| bool | operator< (double o) const |
| bool | operator< (float o) const |
| bool | operator< (int o) const |
| bool | operator< (soft_float_t o) const |
| bool | operator<= (double o) const |
| bool | operator<= (float o) const |
| bool | operator<= (int o) const |
| bool | operator<= (soft_float_t o) const |
| bool | operator== (double o) const |
| bool | operator== (float o) const |
| bool | operator== (int o) const |
| bool | operator== (soft_float_t o) const |
| bool | operator> (double o) const |
| bool | operator> (float o) const |
| bool | operator> (int o) const |
| bool | operator> (soft_float_t o) const |
| bool | operator>= (double o) const |
| bool | operator>= (float o) const |
| bool | operator>= (int o) const |
| bool | operator>= (soft_float_t o) const |
| int16_t | scale (int16_t sample) const |
| scales a 16-bit PCM sample by this factor | |
| int24_t | scale (int24_t sample) const |
| scales a 24-bit PCM sample by this factor | |
| int32_t | scale (int32_t sample) const |
| scales a 32-bit PCM sample by this factor | |
| int16_t | toInt16 () const |
| converts to a 16-bit PCM sample (-32768..32767) | |
| int24_t | toInt24 () const |
| converts to a 24-bit PCM sample (-8388608..8388607) | |
| int32_t | toInt32 () const |
| converts to a 32-bit PCM sample (-2147483648..2147483647) | |
Static Public Member Functions | |
| static soft_float_t | fromInt16 (int16_t sample) |
| builds a soft_float_t from a 16-bit PCM sample (-32768..32767) | |
| static soft_float_t | fromInt24 (int24_t sample) |
| builds a soft_float_t from a 24-bit PCM sample (-8388608..8388607) | |
| static soft_float_t | fromInt32 (int32_t sample) |
| builds a soft_float_t from a 32-bit PCM sample (-2147483648..2147483647) | |
Software "pseudo-float": a real number represented as a signed 16-bit mantissa plus a 16-bit exponent (value = mantissa * 2^exponent), computed with integer multiply/shift/compare only – no hardware floating-point instructions. This generalizes speexdsp's classic fixed-point trick of tracking a handful of wide-dynamic-range control variables as a normalized mantissa+exponent pair into a full, operator-overloaded numeric type usable as a drop-in replacement for float (see MDFFixedPoint in MDFEchoCancellation.h, which uses this class as the element type for the MDF echo canceller's sample/spectrum arrays and internal state, so the whole algorithm runs without native float arithmetic).
Unlike a plain fixed Q-format (a fixed number of fractional bits, which only covers a fixed range/precision trade-off and would over/underflow badly across this algorithm's actual value range – audio samples, FFT magnitudes in the thousands, and adaptation-rate fractions near zero, all flowing through the same arrays), this type renormalizes on every operation, so it tolerates the same wide dynamic range as float, at roughly the precision of a 16-bit mantissa (a relative error on the order of 2^-15, i.e. about 4-5 significant decimal digits – comparable to a compressed/half-precision float).
<, >, etc.) convert both sides to float and compare natively – they're scalar, infrequent control-flow checks, not the per-element array math this class exists to keep off the FPU, so trading a little purity there for simpler, more obviously correct code is a reasonable trade. Arithmetic that mixes a soft_float_t with a plain float/double literal (e.g. 0.7f * pseudoFloatValue) also still executes that specific operation using native float arithmetic via the implicit conversions below – avoiding all native float instructions everywhere would require rewriting every numeric literal in the algorithm as a soft_float_t, which isn't done here. What this class does guarantee is that soft_float_t-to-soft_float_t arithmetic – the tight inner loops over whole arrays (FFT bins, filter weights, correlations) that dominate the algorithm's cost – runs on integer mantissa/exponent math throughout.
|
constexprdefault |
|
inlineconstexpr |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlinestatic |
builds a soft_float_t from a 16-bit PCM sample (-32768..32767)
|
inlinestatic |
builds a soft_float_t from a 24-bit PCM sample (-8388608..8388607)
|
inlinestatic |
builds a soft_float_t from a 32-bit PCM sample (-2147483648..2147483647)
|
inline |
|
inline |
|
inlineexplicit |
truncates toward zero, like (int)someFloat
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
scales a 16-bit PCM sample by this factor
|
inline |
scales a 32-bit PCM sample by this factor
|
inline |
converts to a 16-bit PCM sample (-32768..32767)
|
inline |
converts to a 24-bit PCM sample (-8388608..8388607)
|
inline |
converts to a 32-bit PCM sample (-2147483648..2147483647)