Go to the documentation of this file.
56 #define __fast_inline static inline __attribute__((always_inline, optimize("Ofast")))
84 __fast_inline uint32_t fx_mcu_hash(
void) {
95 __fast_inline uint16_t fx_get_bpm(
void) {
106 __fast_inline
float fx_get_bpmf(
void) {
123 #define k_wt_sine_size_exp (7)
124 #define k_wt_sine_size (1U<<k_wt_sine_size_exp)
125 #define k_wt_sine_u32shift (24)
126 #define k_wt_sine_frrecip (5.96046447753906e-008f) // 1/(1<<24)
127 #define k_wt_sine_mask (k_wt_sine_size-1)
128 #define k_wt_sine_lut_size (k_wt_sine_size+1)
130 extern const float wt_sine_lut_f[k_wt_sine_lut_size];
139 const float p = x - (uint32_t)x;
142 const float x0f = 2.f * p * k_wt_sine_size;
143 const uint32_t x0p = (uint32_t)x0f;
145 const uint32_t x0 = x0p & k_wt_sine_mask;
146 const uint32_t x1 = (x0 + 1) & k_wt_sine_mask;
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;
181 return fx_sinuf(x+((k_wt_sine_size>>2)<<k_wt_sine_u32shift));
196 #define k_log_size_exp (8)
197 #define k_log_size (1U<<k_log_size_exp)
198 #define k_log_mask (k_log_size-1)
199 #define k_log_lut_size (k_log_size+1)
201 extern const float log_lut_f[k_log_lut_size];
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);
218 #define k_tanpi_size_exp (8)
219 #define k_tanpi_size (1U<<k_tanpi_size_exp)
220 #define k_tanpi_mask (k_tanpi_size-1)
221 #define k_tanpi_range_recip (2.04081632653061f) // 1/0.49
222 #define k_tanpi_lut_size (k_tanpi_size+1)
224 extern const float tanpi_lut_f[k_log_lut_size];
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);
241 #define k_sqrtm2log_size_exp (8)
242 #define k_sqrtm2log_size (1U<<k_sqrtm2log_size_exp)
243 #define k_sqrtm2log_mask (k_sqrtm2log_size-1)
244 #define k_sqrtm2log_base (0.005f)
245 #define k_sqrtm2log_range_recip (1.00502512562814f) // 1/0.995
246 #define k_sqrtm2log_lut_size (k_sqrtm2log_size+1)
248 extern const float sqrtm2log_lut_f[k_sqrtm2log_lut_size];
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);
265 #define k_pow2_size_exp (8)
266 #define k_pow2_size (1U<<k_pow2_size_exp)
267 #define k_pow2_scale (85.3333333333333f) // 256 / 3
268 #define k_pow2_mask (k_pow2_size-1)
269 #define k_pow2_lut_size (k_pow2_size+1)
271 extern const float pow2_lut_f[k_pow2_lut_size];
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);
310 return x - c * (x*x*x);
313 #define k_cubicsat_size_exp (7)
314 #define k_cubicsat_size (1U<<k_cubicsat_size_exp)
315 #define k_cubicsat_mask (k_cubicsat_size-1)
316 #define k_cubicsat_lut_size (k_cubicsat_size+1)
318 extern const float cubicsat_lut_f[k_cubicsat_lut_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];
334 #define k_schetzen_size_exp (7)
335 #define k_schetzen_size (1U<<k_schetzen_size_exp)
336 #define k_schetzen_mask (k_schetzen_size-1)
337 #define k_schetzen_lut_size (k_schetzen_size+1)
339 extern const float schetzen_lut_f[k_schetzen_lut_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];
363 #define k_bitres_size_exp (7)
364 #define k_bitres_size (1U<<k_bitres_size_exp)
365 #define k_bitres_mask (k_bitres_size-1)
366 #define k_bitres_lut_size (k_bitres_size+1)
368 extern const float bitres_lut_f[k_bitres_lut_size];
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);
404 __fast_inline uint32_t fx_rand(
void) {
415 __fast_inline
float fx_white(
void) {
const uint32_t k_fx_api_platform
Current platform.
__fast_inline float fx_cosf(float x)
Lookup value of cos(2*pi*x) in [0, 1.0] range.
uint32_t _fx_rand(void)
Random integer.
__fast_inline float fx_sinf(float x)
Lookup value of sin(2*pi*x).
__fast_inline float fx_sqrtm2logf(float x)
Lookup value of sqrt(-2*log(x)) in [0.005, 1.0] range.
Fixed Point Math Utilities.
__fast_inline float fx_cosuf(uint32_t x)
Lookup value of cos(2*pi*x) in [0, 1.0] range.
__fast_inline float fx_sat_schetzenf(float x)
Schetzen saturation.
uint16_t _fx_get_bpm(void)
Get current tempo as beats per minute as integer.
Floating Point Math Utilities.
const uint32_t k_fx_api_version
Current API version.
__fast_inline float fx_sinuf(uint32_t x)
Lookup value of sin(2*pi*x) in [0, 1.0] range.
uint32_t _fx_mcu_hash(void)
Get MCU hash.
static float si_copysignf(const float x, const float y)
Return x with sign of y applied.
float _fx_get_bpmf(void)
Get current tempo as beats per minute as floating point.
__fast_inline float fx_logf(float x)
Lookup value of log(x) in [0.00001, 1.0] range.
__fast_inline float fx_sat_cubicf(float x)
Cubic saturation.
float _fx_white(void)
Gaussian white noise.
__fast_inline float fx_tanpif(float x)
Lookup value of tan(pi*x) in [0.0001, 0.49] range.
__fast_inline float fx_bitresf(float x)
Bit depth scaling table.
static float clip1f(const float x)
Clip upper bound of x to 1.f (inclusive)
__fast_inline float fx_pow2f(float x)
Lookup value of 2^k for k in [0, 3.0] range.
static float clip1m1f(const float x)
Clip x to [-1.f, 1.f] (inclusive)
static float linintf(const float fr, const float x0, const float x1)
Linear interpolation.
__fast_inline float fx_softclipf(const float c, float x)
Soft clip.
static float si_fabsf(float x)
Absolute value.