2 #ifndef __BSE_SIGNAL_H__
3 #define __BSE_SIGNAL_H__
14 #define BSE_SIGNAL_EPSILON (1.15e-14)
19 #define BSE_SIGNAL_KAPPA (1.5)
26 #define BSE_SIGNAL_RAISING_EDGE(v1,v2) ((v1) < (v2))
30 #define BSE_SIGNAL_FALLING_EDGE(v1,v2) ((v1) > (v2))
35 #define BSE_SIGNAL_FREQ_CHANGED(v1,v2) (fabs ((v1) - (v2)) > 1e-7)
39 #define BSE_SIGNAL_FREQ_EQUALS(v1,v2) (!BSE_SIGNAL_FREQ_CHANGED (v1, v2))
44 #define BSE_SIGNAL_MOD_CHANGED(v1,v2) (fabs ((v1) - (v2)) > 1e-8)
49 #define BSE_SIGNAL_GAIN_CHANGED(v1,v2) (fabs ((v1) - (v2)) > 1e-8)
54 #define BSE_SIGNAL_TO_FREQ_FACTOR (BSE_MAX_FREQUENCY)
55 #define BSE_SIGNAL_FROM_FREQ_FACTOR (1.0 / BSE_MAX_FREQUENCY)
56 #define BSE_SIGNAL_TO_FREQ(value) (BSE_FREQ_FROM_VALUE (value))
57 #define BSE_SIGNAL_FROM_FREQ(freq) (BSE_VALUE_FROM_FREQ (freq))
59 #define BSE_SIGNAL_CLIP(v) bse_signal_value_clip (v)
61 static inline double bse_signal_value_clip (
register double x) G_GNUC_CONST;
62 static inline double G_GNUC_CONST
63 bse_signal_value_clip (
register double x)
65 if (G_UNLIKELY (x > 1.0))
67 if (G_UNLIKELY (x < -1.0))
76 guint exponential_fm : 1;
89 double bse_window_bartlett (
double x);
90 double bse_window_blackman (
double x);
91 double bse_window_cos (
double x);
92 double bse_window_hamming (
double x);
93 double bse_window_sinc (
double x);
94 double bse_window_rect (
double x);
110 static inline double bse_approx_atan1 (
register double x) G_GNUC_CONST;
131 static inline double bse_approx_qcircle1 (
register double x) G_GNUC_CONST;
142 static inline double bse_approx_qcircle2 (
register double x) G_GNUC_CONST;
153 static inline double bse_approx_qcircle3 (
register double x) G_GNUC_CONST;
164 static inline double bse_approx_qcircle4 (
register double x) G_GNUC_CONST;
176 static inline double bse_approx2_exp2 (
float ex) G_GNUC_CONST;
188 static inline double bse_approx3_exp2 (
float ex) G_GNUC_CONST;
200 static inline double bse_approx4_exp2 (
float ex) G_GNUC_CONST;
212 static inline double bse_approx5_exp2 (
float ex) G_GNUC_CONST;
224 static inline double bse_approx6_exp2 (
float ex) G_GNUC_CONST;
236 static inline double bse_approx7_exp2 (
float ex) G_GNUC_CONST;
249 static inline double bse_approx8_exp2 (
float ex) G_GNUC_CONST;
262 static inline double bse_approx9_exp2 (
float ex) G_GNUC_CONST;
273 static inline double bse_approx2_tanh (
float x) G_GNUC_CONST;
284 static inline double bse_approx3_tanh (
float x) G_GNUC_CONST;
295 static inline double bse_approx4_tanh (
float x) G_GNUC_CONST;
306 static inline double bse_approx5_tanh (
float x) G_GNUC_CONST;
317 static inline double bse_approx6_tanh (
float x) G_GNUC_CONST;
328 static inline double bse_approx7_tanh (
float x) G_GNUC_CONST;
340 static inline double bse_approx8_tanh (
float x) G_GNUC_CONST;
352 static inline double bse_approx9_tanh (
float x) G_GNUC_CONST;
364 static inline double bse_saturate_hard (
double value,
365 double limit) G_GNUC_CONST;
377 static inline double bse_saturate_branching (
double value,
378 double limit) G_GNUC_CONST;
381 const double* bse_semitone_table_from_tuning (Bse::MusicalTuning musical_tuning);
382 double bse_transpose_factor (Bse::MusicalTuning musical_tuning,
int index );
398 static inline double bse_cent_tune_fast (
int fine_tune ) G_GNUC_CONST;
401 static inline double G_GNUC_CONST
402 bse_approx_atan1 (
register double x)
406 register double numerator, denominator = -1.0;
408 denominator += x * 0.81901156857081841441890603235599;
409 numerator = x * 0.41156875521951602506487246309908;
411 numerator += -1.0091272542790025586079663559158;
412 denominator += 1.0091272542790025586079663559158;
414 return -1.0 - numerator / denominator;
418 register double numerator, denominator = 1.0;
420 denominator += x * 0.81901156857081841441890603235599;
421 numerator = x * -0.41156875521951602506487246309908;
423 numerator += -1.0091272542790025586079663559158;
424 denominator += 1.0091272542790025586079663559158;
426 return 1.0 + numerator / denominator;
433 static inline double G_GNUC_CONST
434 bse_approx_qcircle1 (
register double x)
436 double numerator = 1.20460124790369468987715633298929 * x - 1.20460124790369468987715633298929;
437 double denominator = x - 1.20460124790369468987715633298929;
439 return numerator / denominator;
442 static inline double G_GNUC_CONST
443 bse_approx_qcircle2 (
register double x)
445 double numerator = 1.20460124790369468987715633298929*x;
446 double denominator = x + 0.20460124790369468987715633298929;
448 return numerator / denominator;
451 static inline double G_GNUC_CONST
452 bse_approx_qcircle3 (
register double x)
454 double numerator = 0.20460124790369468987715633298929 - 0.20460124790369468987715633298929 * x;
455 double denominator = x + 0.20460124790369468987715633298929;
457 return numerator / denominator;
460 static inline double G_GNUC_CONST
461 bse_approx_qcircle4 (
register double x)
463 double numerator = -0.20460124790369468987715633298929 * x;
464 double denominator = x - 1.20460124790369468987715633298929;
466 return numerator / denominator;
469 static inline double G_GNUC_CONST
470 bse_approx2_exp2 (
float ex)
473 register int i = bse_ftoi (ex);
474 fp.mpn.biased_exponent = BSE_FLOAT_BIAS + i;
475 register double x = ex - i;
476 return fp.v_float * (1.0 + x * (0.69314718055994530941723212145818 +
477 x * (0.24022650695910071233355126316333)));
480 static inline double G_GNUC_CONST
481 bse_approx3_exp2 (
float ex)
484 register int i = bse_ftoi (ex);
485 fp.mpn.biased_exponent = BSE_FLOAT_BIAS + i;
486 register double x = ex - i;
487 return fp.v_float * (1.0 + x * (0.69314718055994530941723212145818 +
488 x * (0.24022650695910071233355126316333 +
489 x * (0.055504108664821579953142263768622))));
495 static inline double G_GNUC_CONST
496 bse_approx4_exp2 (
float ex)
499 register int i = bse_ftoi (ex);
500 fp.mpn.biased_exponent = BSE_FLOAT_BIAS + i;
501 register double x = ex - i;
502 return fp.v_float * (1.0 + x * (0.69314718055994530941723212145818 +
503 x * (0.24022650695910071233355126316333 +
504 x * (0.055504108664821579953142263768622 +
505 x * (0.0096181291076284771619790715736589)))));
512 static inline double G_GNUC_CONST
513 bse_approx5_exp2 (
float ex)
516 register int i = bse_ftoi (ex);
517 fp.mpn.biased_exponent = BSE_FLOAT_BIAS + i;
518 register double x = ex - i;
519 return fp.v_float * (1.0 + x * (0.69314718055994530941723212145818 +
520 x * (0.24022650695910071233355126316333 +
521 x * (0.055504108664821579953142263768622 +
522 x * (0.0096181291076284771619790715736589 +
523 x * (0.0013333558146428443423412221987996))))));
526 static inline double G_GNUC_CONST
527 bse_approx6_exp2 (
float ex)
530 register int i = bse_ftoi (ex);
531 fp.mpn.biased_exponent = BSE_FLOAT_BIAS + i;
532 register double x = ex - i;
533 return fp.v_float * (1.0 + x * (0.69314718055994530941723212145818 +
534 x * (0.24022650695910071233355126316333 +
535 x * (0.055504108664821579953142263768622 +
536 x * (0.0096181291076284771619790715736589 +
537 x * (0.0013333558146428443423412221987996 +
538 x * (0.00015403530393381609954437097332742)))))));
541 static inline double G_GNUC_CONST
542 bse_approx7_exp2 (
float ex)
545 register int i = bse_ftoi (ex);
546 fp.mpn.biased_exponent = BSE_FLOAT_BIAS + i;
547 register double x = ex - i;
548 return fp.v_float * (1.0 + x * (0.69314718055994530941723212145818 +
549 x * (0.24022650695910071233355126316333 +
550 x * (0.055504108664821579953142263768622 +
551 x * (0.0096181291076284771619790715736589 +
552 x * (0.0013333558146428443423412221987996 +
553 x * (0.00015403530393381609954437097332742 +
554 x * (0.00001525273380405984028002543901201))))))));
557 static inline double G_GNUC_CONST
558 bse_approx8_exp2 (
float ex)
561 register int i = bse_ftoi (ex);
562 fp.mpn.biased_exponent = BSE_FLOAT_BIAS + i;
563 register double x = ex - i;
564 return fp.v_float * (1.0 + x * (0.69314718055994530941723212145818 +
565 x * (0.24022650695910071233355126316333 +
566 x * (0.055504108664821579953142263768622 +
567 x * (0.0096181291076284771619790715736589 +
568 x * (0.0013333558146428443423412221987996 +
569 x * (0.00015403530393381609954437097332742 +
570 x * (0.00001525273380405984028002543901201 +
571 x * (0.0000013215486790144309488403758228288)))))))));
574 static inline double G_GNUC_CONST
575 bse_approx9_exp2 (
float ex)
578 register int i = bse_ftoi (ex);
579 fp.mpn.biased_exponent = BSE_FLOAT_BIAS + i;
580 register double x = ex - i;
581 return fp.v_float * (1.0 + x * (0.69314718055994530941723212145818 +
582 x * (0.24022650695910071233355126316333 +
583 x * (0.055504108664821579953142263768622 +
584 x * (0.0096181291076284771619790715736589 +
585 x * (0.0013333558146428443423412221987996 +
586 x * (0.00015403530393381609954437097332742 +
587 x * (0.00001525273380405984028002543901201 +
588 x * (0.0000013215486790144309488403758228288 +
589 x * 0.00000010178086009239699727490007597745)))))))));
592 static inline double G_GNUC_CONST
593 bse_approx2_tanh (
float x)
595 if (G_UNLIKELY (x < -20))
597 if (G_UNLIKELY (x > 20))
599 register double bpot = bse_approx2_exp2 (x * BSE_2_DIV_LN2);
600 return (bpot - 1) / (bpot + 1);
603 static inline double G_GNUC_CONST
604 bse_approx3_tanh (
float x)
606 if (G_UNLIKELY (x < -20))
608 if (G_UNLIKELY (x > 20))
610 register double bpot = bse_approx3_exp2 (x * BSE_2_DIV_LN2);
611 return (bpot - 1) / (bpot + 1);
614 static inline double G_GNUC_CONST
615 bse_approx4_tanh (
float x)
617 if (G_UNLIKELY (x < -20))
619 if (G_UNLIKELY (x > 20))
621 register double bpot = bse_approx4_exp2 (x * BSE_2_DIV_LN2);
622 return (bpot - 1) / (bpot + 1);
626 static inline double G_GNUC_CONST
627 bse_approx5_tanh (
float x)
629 if (G_UNLIKELY (x < -20))
631 if (G_UNLIKELY (x > 20))
633 register double bpot = bse_approx5_exp2 (x * BSE_2_DIV_LN2);
634 return (bpot - 1) / (bpot + 1);
637 static inline double G_GNUC_CONST
638 bse_approx6_tanh (
float x)
640 if (G_UNLIKELY (x < -20))
642 if (G_UNLIKELY (x > 20))
644 register double bpot = bse_approx6_exp2 (x * BSE_2_DIV_LN2);
645 return (bpot - 1) / (bpot + 1);
648 static inline double G_GNUC_CONST
649 bse_approx7_tanh (
float x)
651 if (G_UNLIKELY (x < -20))
653 if (G_UNLIKELY (x > 20))
655 register double bpot = bse_approx7_exp2 (x * BSE_2_DIV_LN2);
656 return (bpot - 1) / (bpot + 1);
659 static inline double G_GNUC_CONST
660 bse_approx8_tanh (
float x)
662 if (G_UNLIKELY (x < -20))
664 if (G_UNLIKELY (x > 20))
666 register double bpot = bse_approx8_exp2 (x * BSE_2_DIV_LN2);
667 return (bpot - 1) / (bpot + 1);
670 static inline double G_GNUC_CONST
671 bse_approx9_tanh (
float x)
673 if (G_UNLIKELY (x < -20))
675 if (G_UNLIKELY (x > 20))
677 register double bpot = bse_approx9_exp2 (x * BSE_2_DIV_LN2);
678 return (bpot - 1) / (bpot + 1);
681 static inline double G_GNUC_CONST
682 bse_saturate_hard (
double value,
685 register double v1 =
fabsf (value + limit);
686 register double v2 =
fabsf (value - limit);
687 return 0.5 * (v1 - v2);
690 static inline double G_GNUC_CONST
691 bse_saturate_branching (
double value,
694 if (G_UNLIKELY (value >= limit))
696 if (G_UNLIKELY (value <= limit))
701 void _bse_init_signal (
void);
703 extern const double *
const bse_cent_table;
705 static inline double G_GNUC_CONST
706 bse_cent_tune_fast (
int fine_tune)
708 return bse_cent_table[CLAMP (fine_tune, -100, 100)];
double bse_approx_atan1_prescale(double boost_amount)
Definition: bsemathsignal.cc:649
Definition: bseieee754.hh:129
double bse_cent_tune(double fine_tune)
Definition: bsemathsignal.cc:210
Definition: bsemathsignal.hh:74