55 #define __fast_inline static inline __attribute__((always_inline, optimize("Ofast")))
83 __fast_inline uint32_t osc_mcu_hash(
void) {
87 #define k_samplerate (48000)
88 #define k_samplerate_recipf (2.08333333333333e-005f)
101 #define k_midi_to_hz_size (152)
103 extern const float midi_to_hz_lut_f[k_midi_to_hz_size];
105 #define k_note_mod_fscale (0.00392156862745098f)
106 #define k_note_max_hz (23679.643054f)
115 return midi_to_hz_lut_f[
clipmaxu32(note,k_midi_to_hz_size-1)];
128 const float f =
clipmaxf(
linintf(mod * k_note_mod_fscale, f0, f1), k_note_max_hz);
130 return f * k_samplerate_recipf;
141 #define k_wt_sine_size_exp (7)
142 #define k_wt_sine_size (1U<<k_wt_sine_size_exp)
143 #define k_wt_sine_u32shift (24)
144 #define k_wt_sine_frrecip (5.96046447753906e-008f) // 1/(1<<24)
145 #define k_wt_sine_mask (k_wt_sine_size-1)
146 #define k_wt_sine_lut_size (k_wt_sine_size+1)
148 extern const float wt_sine_lut_f[k_wt_sine_lut_size];
157 const float p = x - (uint32_t)x;
160 const float x0f = 2.f * p * k_wt_sine_size;
161 const uint32_t x0p = (uint32_t)x0f;
163 const uint32_t x0 = x0p & k_wt_sine_mask;
164 const uint32_t x1 = (x0 + 1) & k_wt_sine_mask;
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;
188 #define k_wt_saw_size_exp (7)
189 #define k_wt_saw_size (1U<<k_wt_saw_size_exp)
190 #define k_wt_saw_u32shift (24)
191 #define k_wt_saw_frrecip (5.96046447753906e-008f) // 1/(1<<24)
192 #define k_wt_saw_mask (k_wt_saw_size-1)
193 #define k_wt_saw_lut_size (k_wt_saw_size+1)
194 #define k_wt_saw_notes_cnt (7)
195 #define k_wt_saw_lut_tsize (k_wt_saw_notes_cnt * k_wt_saw_lut_size)
197 extern const uint8_t wt_saw_notes[k_wt_saw_notes_cnt];
198 extern const float wt_saw_lut_f[k_wt_saw_lut_tsize];
209 const float p = x - (uint32_t)x;
211 const float x0f = 2.f * p * k_wt_saw_size;
212 const uint32_t x0p = (uint32_t)x0f;
214 uint32_t x0 = x0p, x1 = x0p+1;
216 if (x0p >= k_wt_saw_size) {
217 x0 = k_wt_saw_size - (x0p & k_wt_saw_mask);
222 const float y0 =
linintf(x0f - x0p, wt_saw_lut_f[x0], wt_saw_lut_f[x1]);
234 const float p = x - (uint32_t)x;
236 const float x0f = 2.f * p * k_wt_saw_size;
237 const uint32_t x0p = (uint32_t)x0f;
239 uint32_t x0 = x0p, x1 = x0p+1;
241 if (x0p >= k_wt_saw_size) {
242 x0 = k_wt_saw_size - (x0p & k_wt_saw_mask);
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]);
259 const float p = x - (uint32_t)x;
261 const float x0f = 2.f * p * k_wt_saw_size;
262 const uint32_t x0p = (uint32_t)x0f;
264 uint32_t x0 = x0p, x1 = x0p+1;
266 if (x0p >= k_wt_saw_size) {
267 x0 = k_wt_saw_size - (x0p & k_wt_saw_mask);
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]);
275 wt += k_wt_saw_lut_size;
276 const float y1 = sign *
linintf(fr, wt[x0], wt[x1]);
278 return linintf((idx - (uint8_t)idx), y0, y1);
289 __fast_inline
float osc_bl_saw_idx(
float note) {
302 #define k_wt_sqr_size_exp 7
303 #define k_wt_sqr_size (1U<<k_wt_sqr_size_exp)
304 #define k_wt_sqr_u32shift (24)
305 #define k_wt_sqr_frrecip (5.96046447753906e-008f) // 1/(1<<24)
306 #define k_wt_sqr_mask (k_wt_sqr_size-1)
307 #define k_wt_sqr_lut_size (k_wt_sqr_size+1)
308 #define k_wt_sqr_notes_cnt 7
309 #define k_wt_sqr_lut_tsize (k_wt_sqr_notes_cnt * k_wt_sqr_lut_size)
311 extern const uint8_t wt_sqr_notes[k_wt_sqr_notes_cnt];
312 extern const float wt_sqr_lut_f[k_wt_sqr_lut_tsize];
322 const float p = x - (uint32_t)x;
324 const float x0f = 2.f * p * k_wt_sqr_size;
325 const uint32_t x0p = (uint32_t)x0f;
327 uint32_t x0 = x0p, x1 = x0p+1;
329 if (x0p >= k_wt_sqr_size) {
330 x0 = k_wt_sqr_size - (x0p & k_wt_sqr_mask);
335 const float y0 =
linintf(x0f - x0p, wt_sqr_lut_f[x0], wt_sqr_lut_f[x1]);
348 const float p = x - (uint32_t)x;
350 const float x0f = 2.f * p * k_wt_sqr_size;
351 const uint32_t x0p = (uint32_t)x0f;
353 uint32_t x0 = x0p, x1 = x0p+1;
355 if (x0p >= k_wt_sqr_size) {
356 x0 = k_wt_sqr_size - (x0p & k_wt_sqr_mask);
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]);
374 const float p = x - (uint32_t)x;
376 const float x0f = 2.f * p * k_wt_sqr_size;
377 const uint32_t x0p = (uint32_t)x0f;
379 uint32_t x0 = x0p, x1 = x0p+1;
381 if (x0p >= k_wt_sqr_size) {
382 x0 = k_wt_sqr_size - (x0p & k_wt_sqr_mask);
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]);
390 wt += k_wt_sqr_lut_size;
391 const float y1 = sign *
linintf(fr, wt[x0], wt[x1]);
393 return linintf((idx - (uint8_t)idx), y0, y1);
404 __fast_inline
float osc_bl_sqr_idx(
float note) {
417 #define k_wt_par_size_exp 7
418 #define k_wt_par_size (1U<<k_wt_par_size_exp)
419 #define k_wt_par_u32shift (24)
420 #define k_wt_par_frrecip (5.96046447753906e-008f) // 1/(1<<24)
421 #define k_wt_par_mask (k_wt_par_size-1)
422 #define k_wt_par_lut_size (k_wt_par_size+1)
423 #define k_wt_par_notes_cnt 7
424 #define k_wt_par_lut_tsize (k_wt_par_notes_cnt * k_wt_par_lut_size)
426 extern const uint8_t wt_par_notes[k_wt_par_notes_cnt];
427 extern const float wt_par_lut_f[k_wt_par_lut_tsize];
437 const float p = x - (uint32_t)x;
439 const float x0f = 2.f * p * k_wt_par_size;
440 const uint32_t x0p = (uint32_t)x0f;
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]);
457 const float p = x - (uint32_t)x;
459 const float x0f = 2.f * p * k_wt_par_size;
460 const uint32_t x0p = (uint32_t)x0f;
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);
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]);
479 const float p = x - (uint32_t)x;
481 const float x0f = 2.f * p * k_wt_par_size;
482 const uint32_t x0p = (uint32_t)x0f;
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);
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]);
491 wt += k_wt_par_lut_size;
493 const float y1 =
linintf(fr, wt[x0], wt[x1]);
495 return linintf((idx - (uint8_t)idx), y0, y1);
506 __fast_inline
float osc_bl_par_idx(
float note) {
522 #define k_waves_size_exp (7)
523 #define k_waves_size (1U<<k_waves_size_exp)
524 #define k_waves_u32shift (24)
525 #define k_waves_frrecip (5.96046447753906e-008f) // 1/(1<<24)
526 #define k_waves_mask (k_waves_size-1)
527 #define k_waves_lut_size (k_waves_size+1)
531 #define k_waves_a_cnt 16
533 extern const float *
const wavesA[k_waves_a_cnt];
535 #define k_waves_b_cnt 16
537 extern const float *
const wavesB[k_waves_b_cnt];
539 #define k_waves_c_cnt 14
541 extern const float *
const wavesC[k_waves_c_cnt];
543 #define k_waves_d_cnt 13
545 extern const float *
const wavesD[k_waves_d_cnt];
547 #define k_waves_e_cnt 15
549 extern const float *
const wavesE[k_waves_e_cnt];
551 #define k_waves_f_cnt 16
553 extern const float *
const wavesF[k_waves_f_cnt];
555 static inline __attribute__((always_inline, optimize(
"Ofast")))
556 float osc_wave_scanf(const
float *w,
float x) {
557 const float p = x - (uint32_t)x;
558 const float x0f = p * k_waves_size;
559 const uint32_t x0 = ((uint32_t)x0f) & k_waves_mask;
560 const uint32_t x1 = (x0 + 1) & k_waves_mask;
561 return linintf(x0f - (uint32_t)x0f, w[x0], w[x1]);
564 static inline __attribute__((always_inline, optimize(
"Ofast")))
565 float osc_wave_scanuf(const
float *w, uint32_t x) {
566 const uint32_t x0 = (x>>k_waves_u32shift);
567 const uint32_t x1 = (x0 + 1) & k_waves_mask;
568 const float fr = k_waves_frrecip * (float)(x & ((1U<<k_waves_u32shift)-1));
569 return linintf(fr, w[x0], w[x1]);
584 #define k_log_size_exp (8)
585 #define k_log_size (1U<<k_log_size_exp)
586 #define k_log_mask (k_log_size-1)
587 #define k_log_lut_size (k_log_size+1)
589 extern const float log_lut_f[k_log_lut_size];
599 const float idxf = x * k_log_size;
600 const uint32_t idx = (uint32_t)idxf;
601 const float y0 = log_lut_f[idx];
602 const float y1 = log_lut_f[idx+1];
603 return linintf(idxf - idx, y0, y1);
606 #define k_tanpi_size_exp (8)
607 #define k_tanpi_size (1U<<k_tanpi_size_exp)
608 #define k_tanpi_mask (k_tanpi_size-1)
609 #define k_tanpi_range_recip (2.04081632653061f) // 1/0.49
610 #define k_tanpi_lut_size (k_tanpi_size+1)
612 extern const float tanpi_lut_f[k_log_lut_size];
622 const float idxf = x * k_tanpi_range_recip * k_tanpi_size;
623 const uint32_t idx = (uint32_t)idxf;
624 const float y0 = tanpi_lut_f[idx];
625 const float y1 = tanpi_lut_f[idx+1];
626 return linintf(idxf - idx, y0, y1);
629 #define k_sqrtm2log_size_exp (8)
630 #define k_sqrtm2log_size (1U<<k_sqrtm2log_size_exp)
631 #define k_sqrtm2log_mask (k_sqrtm2log_size-1)
632 #define k_sqrtm2log_base (0.005f)
633 #define k_sqrtm2log_range_recip (1.00502512562814f) // 1/0.995
634 #define k_sqrtm2log_lut_size (k_sqrtm2log_size+1)
636 extern const float sqrtm2log_lut_f[k_sqrtm2log_lut_size];
646 const float idxf = (x-k_sqrtm2log_base) * k_sqrtm2log_range_recip * k_sqrtm2log_size;
647 const uint32_t idx = (uint32_t)idxf;
648 const float y0 = sqrtm2log_lut_f[idx];
649 const float y1 = sqrtm2log_lut_f[idx+1];
650 return linintf(idxf - idx, y0, y1);
675 return x - c * (x*x*x);
678 #define k_cubicsat_size_exp (7)
679 #define k_cubicsat_size (1U<<k_cubicsat_size_exp)
680 #define k_cubicsat_mask (k_cubicsat_size-1)
681 #define k_cubicsat_lut_size (k_cubicsat_size+1)
683 extern const float cubicsat_lut_f[k_cubicsat_lut_size];
693 const uint32_t xi = (uint32_t)x;
694 const float y0 = cubicsat_lut_f[xi];
695 const float y1 = cubicsat_lut_f[xi+1];
699 #define k_schetzen_size_exp (7)
700 #define k_schetzen_size (1U<<k_schetzen_size_exp)
701 #define k_schetzen_mask (k_schetzen_size-1)
702 #define k_schetzen_lut_size (k_schetzen_size+1)
704 extern const float schetzen_lut_f[k_schetzen_lut_size];
714 const uint32_t xi = (uint32_t)x;
715 const float y0 = schetzen_lut_f[xi];
716 const float y1 = schetzen_lut_f[xi+1];
728 #define k_bitres_size_exp (7)
729 #define k_bitres_size (1U<<k_bitres_size_exp)
730 #define k_bitres_mask (k_bitres_size-1)
731 #define k_bitres_lut_size (k_bitres_size+1)
733 extern const float bitres_lut_f[k_bitres_lut_size];
743 const float xf = x * k_bitres_size;
744 const uint32_t xi = (uint32_t)xf;
745 const float y0 = bitres_lut_f[xi];
746 const float y1 = bitres_lut_f[xi+1];
747 return linintf(xf - xi, y0, y1);
769 __fast_inline uint32_t osc_rand(
void) {
780 __fast_inline
float osc_white(
void) {
793 #endif // __osc_api_h