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_osc_api_platform
 Current platform.
 
const uint32_t k_osc_api_version
 Current API version.
 
uint32_t _osc_mcu_hash (void)
 Get MCU hash. More...
 
__fast_inline uint32_t osc_mcu_hash (void)
 
#define k_samplerate   (48000)
 
#define k_samplerate_recipf   (2.08333333333333e-005f)
 

Note to frequency conversion table

const float midi_to_hz_lut_f [k_midi_to_hz_size]
 
__fast_inline float osc_notehzf (uint8_t note)
 Get Hertz value for note. More...
 
__fast_inline float osc_w0f_for_note (uint8_t note, uint8_t mod)
 Get floating point phase increment for given note and fine modulation. More...
 
#define k_midi_to_hz_size   (152)
 
#define k_note_mod_fscale   (0.00392156862745098f)
 
#define k_note_max_hz   (23679.643054f)
 

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 osc_sinf (float x)
 Lookup value of sin(2*pi*x). More...
 
__fast_inline float osc_cosf (float 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)
 

Band-limited sawtooth half-waves

Note
Wrap interpolation towards zero for 0.5, negate and reverse phase for >= 0.5
const uint8_t wt_saw_notes [k_wt_saw_notes_cnt]
 
const float wt_saw_lut_f [k_wt_saw_lut_tsize]
 
__fast_inline float osc_sawf (float x)
 Sawtooth wave lookup. More...
 
__fast_inline float osc_bl_sawf (float x, uint8_t idx)
 Band-limited sawtooth wave lookup. More...
 
__fast_inline float osc_bl2_sawf (float x, float idx)
 Band-limited sawtooth wave lookup. More...
 
float _osc_bl_saw_idx (float note)
 Get band-limited sawtooth wave index for note. More...
 
__fast_inline float osc_bl_saw_idx (float note)
 
#define k_wt_saw_size_exp   (7)
 
#define k_wt_saw_size   (1U<<k_wt_saw_size_exp)
 
#define k_wt_saw_u32shift   (24)
 
#define k_wt_saw_frrecip   (5.96046447753906e-008f)
 
#define k_wt_saw_mask   (k_wt_saw_size-1)
 
#define k_wt_saw_lut_size   (k_wt_saw_size+1)
 
#define k_wt_saw_notes_cnt   (7)
 
#define k_wt_saw_lut_tsize   (k_wt_saw_notes_cnt * k_wt_saw_lut_size)
 

Band-limited square half-waves

Note
Wrap interpolation to zero for 0.5, negate and reverse phase for >= 0.5
const uint8_t wt_sqr_notes [k_wt_sqr_notes_cnt]
 
const float wt_sqr_lut_f [k_wt_sqr_lut_tsize]
 
__fast_inline float osc_sqrf (float x)
 Square wave lookup. More...
 
__fast_inline float osc_bl_sqrf (float x, uint8_t idx)
 Band-limited square wave lookup. More...
 
__fast_inline float osc_bl2_sqrf (float x, float idx)
 Band-limited square wave lookup. More...
 
float _osc_bl_sqr_idx (float note)
 Get band-limited square wave index for note. More...
 
__fast_inline float osc_bl_sqr_idx (float note)
 
#define k_wt_sqr_size_exp   7
 
#define k_wt_sqr_size   (1U<<k_wt_sqr_size_exp)
 
#define k_wt_sqr_u32shift   (24)
 
#define k_wt_sqr_frrecip   (5.96046447753906e-008f)
 
#define k_wt_sqr_mask   (k_wt_sqr_size-1)
 
#define k_wt_sqr_lut_size   (k_wt_sqr_size+1)
 
#define k_wt_sqr_notes_cnt   7
 
#define k_wt_sqr_lut_tsize   (k_wt_sqr_notes_cnt * k_wt_sqr_lut_size)
 

Band-limited parabolic half-waves.

Note
Wrap interpolation to zero for 0.5, negate and reverse phase for >= 0.5. Careful to negate index 0 when wrapping.
const uint8_t wt_par_notes [k_wt_par_notes_cnt]
 
const float wt_par_lut_f [k_wt_par_lut_tsize]
 
__fast_inline float osc_parf (float x)
 Parabolic wave lookup. More...
 
__fast_inline float osc_bl_parf (float x, uint8_t idx)
 Band-limited parabolic wave lookup. More...
 
__fast_inline float osc_bl2_parf (float x, float idx)
 Band-limited parabolic wave lookup. More...
 
float _osc_bl_par_idx (float note)
 Get band-limited parabolic wave index for note. More...
 
__fast_inline float osc_bl_par_idx (float note)
 
#define k_wt_par_size_exp   7
 
#define k_wt_par_size   (1U<<k_wt_par_size_exp)
 
#define k_wt_par_u32shift   (24)
 
#define k_wt_par_frrecip   (5.96046447753906e-008f)
 
#define k_wt_par_mask   (k_wt_par_size-1)
 
#define k_wt_par_lut_size   (k_wt_par_size+1)
 
#define k_wt_par_notes_cnt   7
 
#define k_wt_par_lut_tsize   (k_wt_par_notes_cnt * k_wt_par_lut_size)
 

Wave banks.

Banks are organized in categories from A to F in order of increasing harmonic components.

const float *const wavesA [k_waves_a_cnt]
 
const float *const wavesB [k_waves_b_cnt]
 
const float *const wavesC [k_waves_c_cnt]
 
const float *const wavesD [k_waves_d_cnt]
 
const float *const wavesE [k_waves_e_cnt]
 
const float *const wavesF [k_waves_f_cnt]
 
static float osc_wave_scanf (const float *w, float x)
 
static float osc_wave_scanuf (const float *w, uint32_t x)
 
#define k_waves_size_exp   (7)
 
#define k_waves_size   (1U<<k_waves_size_exp)
 
#define k_waves_u32shift   (24)
 
#define k_waves_frrecip   (5.96046447753906e-008f)
 
#define k_waves_mask   (k_waves_size-1)
 
#define k_waves_lut_size   (k_waves_size+1)
 
#define k_waves_a_cnt   16
 
#define k_waves_b_cnt   16
 
#define k_waves_c_cnt   14
 
#define k_waves_d_cnt   13
 
#define k_waves_e_cnt   15
 
#define k_waves_f_cnt   16
 

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]
 
__fast_inline float osc_logf (float x)
 Lookup value of log(x) in [0.00001, 1.0] range. More...
 
__fast_inline float osc_tanpif (float x)
 Lookup value of tan(pi*x) in [0.0001, 0.49] range. More...
 
__fast_inline float osc_sqrtm2logf (float x)
 Lookup value of sqrt(-2*log(x)) in [0.005, 1.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)
 

Clipping and Saturation.

const float cubicsat_lut_f [k_cubicsat_lut_size]
 
const float schetzen_lut_f [k_schetzen_lut_size]
 
__fast_inline float osc_softclipf (const float c, float x)
 Soft clip. More...
 
__fast_inline float osc_sat_cubicf (float x)
 Cubic saturation. More...
 
__fast_inline float osc_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 osc_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 _osc_rand (void)
 Random integer. More...
 
__fast_inline uint32_t osc_rand (void)
 
float _osc_white (void)
 Gaussian white noise. More...
 
__fast_inline float osc_white (void)
 

Detailed Description

Function Documentation

◆ _osc_bl_par_idx()

float _osc_bl_par_idx ( float  note)

Get band-limited parabolic wave index for note.

Parameters
noteFractional note in [0-151] range.
Returns
Corresponding band-limited wave fractional index in [0-6].

◆ _osc_bl_saw_idx()

float _osc_bl_saw_idx ( float  note)

Get band-limited sawtooth wave index for note.

Parameters
noteFractional note in [0-151] range.
Returns
Corresponding band-limited wave fractional index in [0-6].

◆ _osc_bl_sqr_idx()

float _osc_bl_sqr_idx ( float  note)

Get band-limited square wave index for note.

Parameters
noteFractional note in [0-151] range.
Returns
Corresponding band-limited wave fractional index in [0-6].

◆ _osc_mcu_hash()

uint32_t _osc_mcu_hash ( void  )

Get MCU hash.

Returns
A MCU specific "unique" hash.

◆ _osc_rand()

uint32_t _osc_rand ( void  )

Random integer.

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

◆ _osc_white()

float _osc_white ( void  )

Gaussian white noise.

Returns
Value in [-1.0, 1.0].

◆ osc_bitresf()

__fast_inline float osc_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 741 of file osc_api.h.

741  {
742  const float xf = x * k_bitres_size;
743  const uint32_t xi = (uint32_t)xf;
744  const float y0 = bitres_lut_f[xi];
745  const float y1 = bitres_lut_f[xi+1];
746  return linintf(xf - xi, y0, y1);
747  }

◆ osc_bl2_parf()

__fast_inline float osc_bl2_parf ( float  x,
float  idx 
)

Band-limited parabolic wave lookup.

(interpolated version)

Parameters
xPhase in [0, 1.0].
idxFractional wave index in [0,6].
Returns
Wave sample.
Note
Not checking input, caller responsible for bounding x and idx.

Definition at line 478 of file osc_api.h.

478  {
479  const float p = x - (uint32_t)x;
480 
481  const float x0f = 2.f * p * k_wt_par_size;
482  const uint32_t x0p = (uint32_t)x0f;
483 
484  uint32_t x0 = (x0p<=k_wt_par_size) ? x0p : (k_wt_par_size - (x0p & k_wt_par_mask));
485  uint32_t x1 = (x0p<(k_wt_par_size-1)) ? (x0 + 1) & k_wt_par_mask : (x0p >= k_wt_par_size) ? (x0 - 1) & k_wt_par_mask : (x0 + 1);
486 
487  const float *wt = &wt_par_lut_f[(uint16_t)idx*k_wt_par_lut_size];
488  const float fr = x0f - x0p;
489  const float y0 = linintf(fr, wt[x0], wt[x1]);
490 
491  wt += k_wt_par_lut_size;
492 
493  const float y1 = linintf(fr, wt[x0], wt[x1]);
494 
495  return linintf((idx - (uint8_t)idx), y0, y1);
496  }

◆ osc_bl2_sawf()

__fast_inline float osc_bl2_sawf ( float  x,
float  idx 
)

Band-limited sawtooth wave lookup.

(interpolated version)

Parameters
xPhase in [0, 1.0].
idxFractional wave index in [0,6].
Returns
Wave sample.

Definition at line 258 of file osc_api.h.

258  {
259  const float p = x - (uint32_t)x;
260 
261  const float x0f = 2.f * p * k_wt_saw_size;
262  const uint32_t x0p = (uint32_t)x0f;
263 
264  uint32_t x0 = x0p, x1 = x0p+1;
265  float sign = 1.f;
266  if (x0p >= k_wt_saw_size) {
267  x0 = k_wt_saw_size - (x0p & k_wt_saw_mask);
268  x1 = x0 - 1;
269  sign = -1.f;
270  }
271  const float *wt = &wt_saw_lut_f[(uint16_t)idx*k_wt_saw_lut_size];
272  const float fr = x0f - x0p;
273  const float y0 = sign * linintf(fr, wt[x0], wt[x1]);
274 
275  wt += k_wt_saw_lut_size;
276  const float y1 = sign * linintf(fr, wt[x0], wt[x1]);
277 
278  return linintf((idx - (uint8_t)idx), y0, y1);
279  }

◆ osc_bl2_sqrf()

__fast_inline float osc_bl2_sqrf ( float  x,
float  idx 
)

Band-limited square wave lookup.

(interpolated version).

Parameters
xPhase in [0, 1.0].
idxFractional wave index in [0,6].
Returns
Wave sample.
Note
Not checking input, caller responsible for bounding x and idx.

Definition at line 373 of file osc_api.h.

373  {
374  const float p = x - (uint32_t)x;
375 
376  const float x0f = 2.f * p * k_wt_sqr_size;
377  const uint32_t x0p = (uint32_t)x0f;
378 
379  uint32_t x0 = x0p, x1 = x0p+1;
380  float sign = 1.f;
381  if (x0p >= k_wt_sqr_size) {
382  x0 = k_wt_sqr_size - (x0p & k_wt_sqr_mask);
383  x1 = x0 - 1;
384  sign = -1.f;
385  }
386  const float *wt = &wt_sqr_lut_f[(uint16_t)idx*k_wt_sqr_lut_size];
387  const float fr = x0f - x0p;
388  const float y0 = sign * linintf(fr, wt[x0], wt[x1]);
389 
390  wt += k_wt_sqr_lut_size;
391  const float y1 = sign * linintf(fr, wt[x0], wt[x1]);
392 
393  return linintf((idx - (uint8_t)idx), y0, y1);
394  }

◆ osc_bl_parf()

__fast_inline float osc_bl_parf ( float  x,
uint8_t  idx 
)

Band-limited parabolic wave lookup.

Parameters
xPhase in [0, 1.0].
idxWave index in [0,6].
Returns
Wave sample.
Note
Not checking input, caller responsible for bounding x and idx.

Definition at line 456 of file osc_api.h.

456  {
457  const float p = x - (uint32_t)x;
458 
459  const float x0f = 2.f * p * k_wt_par_size;
460  const uint32_t x0p = (uint32_t)x0f;
461 
462  const uint32_t x0 = (x0p<=k_wt_par_size) ? x0p : (k_wt_par_size - (x0p & k_wt_par_mask));
463  const uint32_t x1 = (x0p<(k_wt_par_size-1)) ? (x0 + 1) & k_wt_par_mask : (x0p >= k_wt_par_size) ? (x0 - 1) & k_wt_par_mask : (x0 + 1);
464 
465  const float *wt = &wt_par_lut_f[idx*k_wt_par_lut_size];
466  const float y0 = linintf(x0f - x0p, wt[x0], wt[x1]);
467  return y0;
468  }

◆ osc_bl_sawf()

__fast_inline float osc_bl_sawf ( float  x,
uint8_t  idx 
)

Band-limited sawtooth wave lookup.

Parameters
xPhase in [0, 1.0].
idxWave index in [0,6].
Returns
Wave sample.

Definition at line 233 of file osc_api.h.

233  {
234  const float p = x - (uint32_t)x;
235 
236  const float x0f = 2.f * p * k_wt_saw_size;
237  const uint32_t x0p = (uint32_t)x0f;
238 
239  uint32_t x0 = x0p, x1 = x0p+1;
240  float sign = 1.f;
241  if (x0p >= k_wt_saw_size) {
242  x0 = k_wt_saw_size - (x0p & k_wt_saw_mask);
243  x1 = x0 - 1;
244  sign = -1.f;
245  }
246  const float *wt = &wt_saw_lut_f[idx*k_wt_saw_lut_size];
247  const float y0 = linintf(x0f - x0p, wt[x0], wt[x1]);
248  return sign*y0;
249  }

◆ osc_bl_sqrf()

__fast_inline float osc_bl_sqrf ( float  x,
uint8_t  idx 
)

Band-limited square wave lookup.

Parameters
xPhase in [0, 1.0].
idxWave index in [0,6].
Returns
Wave sample.
Note
Not checking input, caller responsible for bounding x and idx.

Definition at line 347 of file osc_api.h.

347  {
348  const float p = x - (uint32_t)x;
349 
350  const float x0f = 2.f * p * k_wt_sqr_size;
351  const uint32_t x0p = (uint32_t)x0f;
352 
353  uint32_t x0 = x0p, x1 = x0p+1;
354  float sign = 1.f;
355  if (x0p >= k_wt_sqr_size) {
356  x0 = k_wt_sqr_size - (x0p & k_wt_sqr_mask);
357  x1 = x0 - 1;
358  sign = -1.f;
359  }
360  const float *wt = &wt_sqr_lut_f[idx*k_wt_sqr_lut_size];
361  const float y0 = linintf(x0f - x0p, wt[x0], wt[x1]);
362  return sign*y0;
363  }

◆ osc_cosf()

__fast_inline float osc_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 176 of file osc_api.h.

176  {
177  return osc_sinf(x+0.25f);
178  }

◆ osc_logf()

__fast_inline float osc_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 597 of file osc_api.h.

597  {
598  const float idxf = x * k_log_size;
599  const uint32_t idx = (uint32_t)idxf;
600  const float y0 = log_lut_f[idx];
601  const float y1 = log_lut_f[idx+1];
602  return linintf(idxf - idx, y0, y1);
603  }

◆ osc_notehzf()

__fast_inline float osc_notehzf ( uint8_t  note)

Get Hertz value for note.

Parameters
noteNote in [0-151] range.
Returns
Corresponding Hertz value.

Definition at line 114 of file osc_api.h.

114  {
115  return midi_to_hz_lut_f[clipmaxu32(note,k_midi_to_hz_size-1)];
116  }

◆ osc_parf()

__fast_inline float osc_parf ( float  x)

Parabolic wave lookup.

Parameters
xPhase in [0, 1.0].
Returns
Wave sample.
Note
Not checking input, caller responsible for bounding x.

Definition at line 436 of file osc_api.h.

436  {
437  const float p = x - (uint32_t)x;
438 
439  const float x0f = 2.f * p * k_wt_par_size;
440  const uint32_t x0p = (uint32_t)x0f;
441 
442  const uint32_t x0 = (x0p<=k_wt_par_size) ? x0p : (k_wt_par_size - (x0p & k_wt_par_mask));
443  const uint32_t x1 = (x0p<(k_wt_par_size-1)) ? (x0 + 1) & k_wt_par_mask : (x0p >= k_wt_par_size) ? (x0 - 1) & k_wt_par_mask : (x0 + 1);
444  const float y0 = linintf(x0f - x0p, wt_par_lut_f[x0], wt_par_lut_f[x1]);
445  return y0;
446  }

◆ osc_sat_cubicf()

__fast_inline float osc_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 690 of file osc_api.h.

690  {
691  const float xf = si_fabsf(clip1f(x)) * k_cubicsat_size;
692  const uint32_t xi = (uint32_t)x;
693  const float y0 = cubicsat_lut_f[xi];
694  const float y1 = cubicsat_lut_f[xi+1];
695  return si_copysignf(linintf(xf - xi, y0, y1), x);
696  }

◆ osc_sat_schetzenf()

__fast_inline float osc_sat_schetzenf ( float  x)

Schetzen saturation.

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

Definition at line 711 of file osc_api.h.

711  {
712  const float xf = si_fabsf(clip1f(x)) * k_schetzen_size;
713  const uint32_t xi = (uint32_t)x;
714  const float y0 = schetzen_lut_f[xi];
715  const float y1 = schetzen_lut_f[xi+1];
716  return si_copysignf(linintf(xf - xi, y0, y1), x);
717  }

◆ osc_sawf()

__fast_inline float osc_sawf ( float  x)

Sawtooth wave lookup.

Parameters
xPhase in [0, 1.0].
Returns
Wave sample.

Definition at line 208 of file osc_api.h.

208  {
209  const float p = x - (uint32_t)x;
210 
211  const float x0f = 2.f * p * k_wt_saw_size;
212  const uint32_t x0p = (uint32_t)x0f;
213 
214  uint32_t x0 = x0p, x1 = x0p+1;
215  float sign = 1.f;
216  if (x0p >= k_wt_saw_size) {
217  x0 = k_wt_saw_size - (x0p & k_wt_saw_mask);
218  x1 = x0 - 1;
219  sign = -1.f;
220  }
221 
222  const float y0 = linintf(x0f - x0p, wt_saw_lut_f[x0], wt_saw_lut_f[x1]);
223  return sign*y0;
224  }

◆ osc_sinf()

__fast_inline float osc_sinf ( float  x)

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

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

Definition at line 156 of file osc_api.h.

156  {
157  const float p = x - (uint32_t)x;
158 
159  // half period stored -- wrap around and invert
160  const float x0f = 2.f * p * k_wt_sine_size;
161  const uint32_t x0p = (uint32_t)x0f;
162 
163  const uint32_t x0 = x0p & k_wt_sine_mask;
164  const uint32_t x1 = (x0 + 1) & k_wt_sine_mask;
165 
166  const float y0 = linintf(x0f - x0p, wt_sine_lut_f[x0], wt_sine_lut_f[x1]);
167  return (x0p < k_wt_sine_size)?y0:-y0;
168  }

◆ osc_softclipf()

__fast_inline float osc_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 671 of file osc_api.h.

672  {
673  x = clip1m1f(x);
674  return x - c * (x*x*x);
675  }

◆ osc_sqrf()

__fast_inline float osc_sqrf ( float  x)

Square wave lookup.

Parameters
xPhase in [0, 1.0].
Returns
Wave sample.
Note
Not checking input, caller responsible for bounding x.

Definition at line 321 of file osc_api.h.

321  {
322  const float p = x - (uint32_t)x;
323 
324  const float x0f = 2.f * p * k_wt_sqr_size;
325  const uint32_t x0p = (uint32_t)x0f;
326 
327  uint32_t x0 = x0p, x1 = x0p+1;
328  float sign = 1.f;
329  if (x0p >= k_wt_sqr_size) {
330  x0 = k_wt_sqr_size - (x0p & k_wt_sqr_mask);
331  x1 = x0 - 1;
332  sign = -1.f;
333  }
334 
335  const float y0 = linintf(x0f - x0p, wt_sqr_lut_f[x0], wt_sqr_lut_f[x1]);
336  return sign*y0;
337  }

◆ osc_sqrtm2logf()

__fast_inline float osc_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 644 of file osc_api.h.

644  {
645  const float idxf = (x-k_sqrtm2log_base) * k_sqrtm2log_range_recip * k_sqrtm2log_size;
646  const uint32_t idx = (uint32_t)idxf;
647  const float y0 = sqrtm2log_lut_f[idx];
648  const float y1 = sqrtm2log_lut_f[idx+1];
649  return linintf(idxf - idx, y0, y1);
650  }

◆ osc_tanpif()

__fast_inline float osc_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 620 of file osc_api.h.

620  {
621  const float idxf = x * k_tanpi_range_recip * k_tanpi_size;
622  const uint32_t idx = (uint32_t)idxf;
623  const float y0 = tanpi_lut_f[idx];
624  const float y1 = tanpi_lut_f[idx+1];
625  return linintf(idxf - idx, y0, y1);
626  }

◆ osc_w0f_for_note()

__fast_inline float osc_w0f_for_note ( uint8_t  note,
uint8_t  mod 
)

Get floating point phase increment for given note and fine modulation.

Parameters
noteNote in [0-151] range, mod in [0-255] range.
Returns
Corresponding 0-1 phase increment in floating point.

Definition at line 124 of file osc_api.h.

124  {
125  const float f0 = osc_notehzf(note);
126  const float f1 = osc_notehzf(note+1);
127 
128  const float f = clipmaxf(linintf(mod * k_note_mod_fscale, f0, f1), k_note_max_hz);
129 
130  return f * k_samplerate_recipf;
131  }
clipmaxu32
static uint32_t clipmaxu32(const uint32_t x, const uint32_t m)
Clip upper bound of unsigned integer x to m (inclusive)
Definition: int_math.h:84
clipmaxf
static float clipmaxf(const float x, const float m)
Clip upper bound of x to m (inclusive)
Definition: float_math.h:389
si_copysignf
static float si_copysignf(const float x, const float y)
Return x with sign of y applied.
Definition: float_math.h:270
osc_notehzf
__fast_inline float osc_notehzf(uint8_t note)
Get Hertz value for note.
Definition: osc_api.h:114
osc_sinf
__fast_inline float osc_sinf(float x)
Lookup value of sin(2*pi*x).
Definition: osc_api.h:156
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