Nu:Tekt NTS-1 digital SDK  v1.1-0
Macros
Runtime API

Macros

#define __fast_inline   static inline __attribute__((always_inline, optimize("Ofast")))
 

Runtime Environment

const uint32_t k_fx_api_platform
 Current platform.
 
const uint32_t k_fx_api_version
 Current API version.
 
uint32_t _fx_mcu_hash (void)
 Get MCU hash. More...
 
__fast_inline uint32_t fx_mcu_hash (void)
 
uint16_t _fx_get_bpm (void)
 Get current tempo as beats per minute as integer. More...
 
__fast_inline uint16_t fx_get_bpm (void)
 
float _fx_get_bpmf (void)
 Get current tempo as beats per minute as floating point. More...
 
__fast_inline float fx_get_bpmf (void)
 

Sine half-wave

Note
Wrap and negate for phase >= 0.5
const float wt_sine_lut_f [k_wt_sine_lut_size]
 
__fast_inline float fx_sinf (float x)
 Lookup value of sin(2*pi*x). More...
 
__fast_inline float fx_sinuf (uint32_t x)
 Lookup value of sin(2*pi*x) in [0, 1.0] range. More...
 
__fast_inline float fx_cosf (float x)
 Lookup value of cos(2*pi*x) in [0, 1.0] range. More...
 
__fast_inline float fx_cosuf (uint32_t x)
 Lookup value of cos(2*pi*x) in [0, 1.0] range. More...
 
#define k_wt_sine_size_exp   (7)
 
#define k_wt_sine_size   (1U<<k_wt_sine_size_exp)
 
#define k_wt_sine_u32shift   (24)
 
#define k_wt_sine_frrecip   (5.96046447753906e-008f)
 
#define k_wt_sine_mask   (k_wt_sine_size-1)
 
#define k_wt_sine_lut_size   (k_wt_sine_size+1)
 

Various function lookups

const float log_lut_f [k_log_lut_size]
 
const float tanpi_lut_f [k_log_lut_size]
 
const float sqrtm2log_lut_f [k_sqrtm2log_lut_size]
 
const float pow2_lut_f [k_pow2_lut_size]
 
__fast_inline float fx_logf (float x)
 Lookup value of log(x) in [0.00001, 1.0] range. More...
 
__fast_inline float fx_tanpif (float x)
 Lookup value of tan(pi*x) in [0.0001, 0.49] range. More...
 
__fast_inline float fx_sqrtm2logf (float x)
 Lookup value of sqrt(-2*log(x)) in [0.005, 1.0] range. More...
 
__fast_inline float fx_pow2f (float x)
 Lookup value of 2^k for k in [0, 3.0] range. More...
 
#define k_log_size_exp   (8)
 
#define k_log_size   (1U<<k_log_size_exp)
 
#define k_log_mask   (k_log_size-1)
 
#define k_log_lut_size   (k_log_size+1)
 
#define k_tanpi_size_exp   (8)
 
#define k_tanpi_size   (1U<<k_tanpi_size_exp)
 
#define k_tanpi_mask   (k_tanpi_size-1)
 
#define k_tanpi_range_recip   (2.04081632653061f)
 
#define k_tanpi_lut_size   (k_tanpi_size+1)
 
#define k_sqrtm2log_size_exp   (8)
 
#define k_sqrtm2log_size   (1U<<k_sqrtm2log_size_exp)
 
#define k_sqrtm2log_mask   (k_sqrtm2log_size-1)
 
#define k_sqrtm2log_base   (0.005f)
 
#define k_sqrtm2log_range_recip   (1.00502512562814f)
 
#define k_sqrtm2log_lut_size   (k_sqrtm2log_size+1)
 
#define k_pow2_size_exp   (8)
 
#define k_pow2_size   (1U<<k_pow2_size_exp)
 
#define k_pow2_scale   (85.3333333333333f)
 
#define k_pow2_mask   (k_pow2_size-1)
 
#define k_pow2_lut_size   (k_pow2_size+1)
 

Clipping and Saturation.

const float cubicsat_lut_f [k_cubicsat_lut_size]
 
const float schetzen_lut_f [k_schetzen_lut_size]
 
__fast_inline float fx_softclipf (const float c, float x)
 Soft clip. More...
 
__fast_inline float fx_sat_cubicf (float x)
 Cubic saturation. More...
 
__fast_inline float fx_sat_schetzenf (float x)
 Schetzen saturation. More...
 
#define k_cubicsat_size_exp   (7)
 
#define k_cubicsat_size   (1U<<k_cubicsat_size_exp)
 
#define k_cubicsat_mask   (k_cubicsat_size-1)
 
#define k_cubicsat_lut_size   (k_cubicsat_size+1)
 
#define k_schetzen_size_exp   (7)
 
#define k_schetzen_size   (1U<<k_schetzen_size_exp)
 
#define k_schetzen_mask   (k_schetzen_size-1)
 
#define k_schetzen_lut_size   (k_schetzen_size+1)
 

Bit reduction.

const float bitres_lut_f [k_bitres_lut_size]
 
__fast_inline float fx_bitresf (float x)
 Bit depth scaling table. More...
 
#define k_bitres_size_exp   (7)
 
#define k_bitres_size   (1U<<k_bitres_size_exp)
 
#define k_bitres_mask   (k_bitres_size-1)
 
#define k_bitres_lut_size   (k_bitres_size+1)
 

Noise source

uint32_t _fx_rand (void)
 Random integer. More...
 
__fast_inline uint32_t fx_rand (void)
 
float _fx_white (void)
 Gaussian white noise. More...
 
__fast_inline float fx_white (void)
 

Detailed Description

Function Documentation

◆ _fx_get_bpm()

uint16_t _fx_get_bpm ( void  )

Get current tempo as beats per minute as integer.

Returns
Current integer BPM, multiplied by 10 to allow 1 decimal precision

◆ _fx_get_bpmf()

float _fx_get_bpmf ( void  )

Get current tempo as beats per minute as floating point.

Returns
Current floating point BPM

◆ _fx_mcu_hash()

uint32_t _fx_mcu_hash ( void  )

Get MCU hash.

Returns
A MCU specific "unique" hash.

◆ _fx_rand()

uint32_t _fx_rand ( void  )

Random integer.

Returns
Value in [0, UINT_MAX].
Note
Generated with Park-Miller-Carta

◆ _fx_white()

float _fx_white ( void  )

Gaussian white noise.

Returns
Value in [-1.0, 1.0].

◆ fx_bitresf()

__fast_inline float fx_bitresf ( float  x)

Bit depth scaling table.

Parameters
xValue in [0, 1.0].
Returns
Quantization scaling factor.
Note
Fractional bit depth, exponentially mapped, 1 to 24 bits.

Definition at line 375 of file fx_api.h.

375  {
376  const float xf = x * k_bitres_size;
377  const uint32_t xi = (uint32_t)xf;
378  const float y0 = bitres_lut_f[xi];
379  const float y1 = bitres_lut_f[xi+1];
380  return linintf(xf - xi, y0, y1);
381  }

◆ fx_cosf()

__fast_inline float fx_cosf ( float  x)

Lookup value of cos(2*pi*x) in [0, 1.0] range.

Parameters
xValue in [0, 1.0].
Returns
Result of cos(2*pi*x).

Definition at line 168 of file fx_api.h.

168  {
169  return fx_sinf(x+0.25f);
170  }

◆ fx_cosuf()

__fast_inline float fx_cosuf ( uint32_t  x)

Lookup value of cos(2*pi*x) in [0, 1.0] range.

Parameters
xPhase ratio.
Returns
Result of sin(2*pi*x).

Definition at line 178 of file fx_api.h.

178  {
179  return fx_sinuf(x+((k_wt_sine_size>>2)<<k_wt_sine_u32shift));
180  }

◆ fx_logf()

__fast_inline float fx_logf ( float  x)

Lookup value of log(x) in [0.00001, 1.0] range.

Parameters
xValue in [0.00001, 1.0].
Returns
Result of log(x).
Note
Not checking input, caller responsible for bounding x.

Definition at line 208 of file fx_api.h.

208  {
209  const float idxf = x * k_log_size;
210  const uint32_t idx = (uint32_t)idxf;
211  const float y0 = log_lut_f[idx];
212  const float y1 = log_lut_f[idx+1];
213  return linintf(idxf - idx, y0, y1);
214  }

◆ fx_pow2f()

__fast_inline float fx_pow2f ( float  x)

Lookup value of 2^k for k in [0, 3.0] range.

Parameters
xValue in [0, 3.0].
Returns
Result of 2^k.
Note
Not checking input, caller responsible for bounding x.

Definition at line 278 of file fx_api.h.

278  {
279  const float idxf = x * k_pow2_scale;
280  const uint32_t idx = (uint32_t)idxf;
281  const float y0 = pow2_lut_f[idx];
282  const float y1 = pow2_lut_f[idx+1];
283  return linintf(idxf - idx, y0, y1);
284  }

◆ fx_sat_cubicf()

__fast_inline float fx_sat_cubicf ( float  x)

Cubic saturation.

Parameters
xValue in [-1.0, 1.0].
Returns
Cubic curve above 0.42264973081, gain: 1.2383127573

Definition at line 324 of file fx_api.h.

324  {
325  const float xf = si_fabsf(clip1f(x)) * k_cubicsat_size;
326  const uint32_t xi = (uint32_t)x;
327  const float y0 = cubicsat_lut_f[xi];
328  const float y1 = cubicsat_lut_f[xi+1];
329  return si_copysignf(linintf(xf - xi, y0, y1), x);
330  }

◆ fx_sat_schetzenf()

__fast_inline float fx_sat_schetzenf ( float  x)

Schetzen saturation.

Parameters
xValue in [-1.0, 1.0].
Returns
Saturated value.

Definition at line 345 of file fx_api.h.

345  {
346  const float xf = si_fabsf(clip1f(x)) * k_schetzen_size;
347  const uint32_t xi = (uint32_t)x;
348  const float y0 = schetzen_lut_f[xi];
349  const float y1 = schetzen_lut_f[xi+1];
350  return si_copysignf(linintf(xf - xi, y0, y1), x);
351  }

◆ fx_sinf()

__fast_inline float fx_sinf ( float  x)

Lookup value of sin(2*pi*x).

Parameters
xPhase ratio
Returns
Result of sin(2*pi*x).

Definition at line 137 of file fx_api.h.

137  {
138  const float p = x - (uint32_t)x;
139 
140  // half period stored -- wrap around and invert
141  const float x0f = 2.f * p * k_wt_sine_size;
142  const uint32_t x0p = (uint32_t)x0f;
143 
144  const uint32_t x0 = x0p & k_wt_sine_mask;
145  const uint32_t x1 = (x0 + 1) & k_wt_sine_mask;
146 
147  const float y0 = linintf(x0f - x0p, wt_sine_lut_f[x0], wt_sine_lut_f[x1]);
148  return (x0p < k_wt_sine_size)?y0:-y0;
149  }

◆ fx_sinuf()

__fast_inline float fx_sinuf ( uint32_t  x)

Lookup value of sin(2*pi*x) in [0, 1.0] range.

Parameters
xPhase ratio.
Returns
Result of sin(2*pi*x).

Definition at line 157 of file fx_api.h.

157  {
158  (void)x;
159  return 0.f;
160  }

◆ fx_softclipf()

__fast_inline float fx_softclipf ( const float  c,
float  x 
)

Soft clip.

Parameters
cCoefficient in [0, 1/3].
xValue in (-inf, +inf).
Returns
Clipped value in [-(1-c), (1-c)].

Definition at line 305 of file fx_api.h.

306  {
307  x = clip1m1f(x);
308  return x - c * (x*x*x);
309  }

◆ fx_sqrtm2logf()

__fast_inline float fx_sqrtm2logf ( float  x)

Lookup value of sqrt(-2*log(x)) in [0.005, 1.0] range.

Parameters
xValue in [0.005, 1.0].
Returns
Result of sqrt(-2*log(x)).
Note
Not checking input, caller responsible for bounding x.

Definition at line 255 of file fx_api.h.

255  {
256  const float idxf = (x-k_sqrtm2log_base) * k_sqrtm2log_range_recip * k_sqrtm2log_size;
257  const uint32_t idx = (uint32_t)idxf;
258  const float y0 = sqrtm2log_lut_f[idx];
259  const float y1 = sqrtm2log_lut_f[idx+1];
260  return linintf(idxf - idx, y0, y1);
261  }

◆ fx_tanpif()

__fast_inline float fx_tanpif ( float  x)

Lookup value of tan(pi*x) in [0.0001, 0.49] range.

Parameters
xValue in [0.0001, 0.49].
Returns
Result of tan(pi*x).
Note
Not checking input, caller responsible for bounding x.

Definition at line 231 of file fx_api.h.

231  {
232  const float idxf = x * k_tanpi_range_recip * k_tanpi_size;
233  const uint32_t idx = (uint32_t)idxf;
234  const float y0 = tanpi_lut_f[idx];
235  const float y1 = tanpi_lut_f[idx+1];
236  return linintf(idxf - idx, y0, y1);
237  }
fx_sinf
__fast_inline float fx_sinf(float x)
Lookup value of sin(2*pi*x).
Definition: fx_api.h:137
fx_sinuf
__fast_inline float fx_sinuf(uint32_t x)
Lookup value of sin(2*pi*x) in [0, 1.0] range.
Definition: fx_api.h:157
si_copysignf
static float si_copysignf(const float x, const float y)
Return x with sign of y applied.
Definition: float_math.h:270
clip1f
static float clip1f(const float x)
Clip upper bound of x to 1.f (inclusive)
Definition: float_math.h:413
clip1m1f
static float clip1m1f(const float x)
Clip x to [-1.f, 1.f] (inclusive)
Definition: float_math.h:431
linintf
static float linintf(const float fr, const float x0, const float x1)
Linear interpolation.
Definition: float_math.h:824
si_fabsf
static float si_fabsf(float x)
Absolute value.
Definition: float_math.h:284