minilogue xd 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
Todo:
Replace by full period wave and simplify scan code
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 377 of file fx_api.h.

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

◆ 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 170 of file fx_api.h.

170  {
171  return fx_sinf(x+0.25f);
172  }

◆ 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 180 of file fx_api.h.

180  {
181  return fx_sinuf(x+((k_wt_sine_size>>2)<<k_wt_sine_u32shift));
182  }

◆ 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 210 of file fx_api.h.

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

◆ 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 280 of file fx_api.h.

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

◆ 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 326 of file fx_api.h.

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

◆ 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 347 of file fx_api.h.

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

◆ 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 138 of file fx_api.h.

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

◆ 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 158 of file fx_api.h.

158  {
159  //TODO
160  (void)x;
161  return 0.f;
162  }

◆ 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 307 of file fx_api.h.

308  {
309  x = clip1m1f(x);
310  return x - c * (x*x*x);
311  }

◆ 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 257 of file fx_api.h.

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

◆ 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 233 of file fx_api.h.

233  {
234  const float idxf = x * k_tanpi_range_recip * k_tanpi_size;
235  const uint32_t idx = (uint32_t)idxf;
236  const float y0 = tanpi_lut_f[idx];
237  const float y1 = tanpi_lut_f[idx+1];
238  return linintf(idxf - idx, y0, y1);
239  }
fx_sinf
__fast_inline float fx_sinf(float x)
Lookup value of sin(2*pi*x).
Definition: fx_api.h:138
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:158
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