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 (BseMusicalTuningType musical_tuning);
382 double bse_transpose_factor (BseMusicalTuningType musical_tuning,
399 static inline double bse_cent_tune_fast (
int fine_tune ) G_GNUC_CONST;
402 static inline double G_GNUC_CONST
403 bse_approx_atan1 (
register double x)
407 register double numerator, denominator = -1.0;
409 denominator += x * 0.81901156857081841441890603235599;
410 numerator = x * 0.41156875521951602506487246309908;
412 numerator += -1.0091272542790025586079663559158;
413 denominator += 1.0091272542790025586079663559158;
415 return -1.0 - numerator / denominator;
419 register double numerator, denominator = 1.0;
421 denominator += x * 0.81901156857081841441890603235599;
422 numerator = x * -0.41156875521951602506487246309908;
424 numerator += -1.0091272542790025586079663559158;
425 denominator += 1.0091272542790025586079663559158;
427 return 1.0 + numerator / denominator;
434 static inline double G_GNUC_CONST
435 bse_approx_qcircle1 (
register double x)
437 double numerator = 1.20460124790369468987715633298929 * x - 1.20460124790369468987715633298929;
438 double denominator = x - 1.20460124790369468987715633298929;
440 return numerator / denominator;
443 static inline double G_GNUC_CONST
444 bse_approx_qcircle2 (
register double x)
446 double numerator = 1.20460124790369468987715633298929*x;
447 double denominator = x + 0.20460124790369468987715633298929;
449 return numerator / denominator;
452 static inline double G_GNUC_CONST
453 bse_approx_qcircle3 (
register double x)
455 double numerator = 0.20460124790369468987715633298929 - 0.20460124790369468987715633298929 * x;
456 double denominator = x + 0.20460124790369468987715633298929;
458 return numerator / denominator;
461 static inline double G_GNUC_CONST
462 bse_approx_qcircle4 (
register double x)
464 double numerator = -0.20460124790369468987715633298929 * x;
465 double denominator = x - 1.20460124790369468987715633298929;
467 return numerator / denominator;
470 static inline double G_GNUC_CONST
471 bse_approx2_exp2 (
float ex)
474 register int i = bse_ftoi (ex);
475 fp.mpn.biased_exponent = BSE_FLOAT_BIAS + i;
476 register double x = ex - i;
477 return fp.v_float * (1.0 + x * (0.69314718055994530941723212145818 +
478 x * (0.24022650695910071233355126316333)));
481 static inline double G_GNUC_CONST
482 bse_approx3_exp2 (
float ex)
485 register int i = bse_ftoi (ex);
486 fp.mpn.biased_exponent = BSE_FLOAT_BIAS + i;
487 register double x = ex - i;
488 return fp.v_float * (1.0 + x * (0.69314718055994530941723212145818 +
489 x * (0.24022650695910071233355126316333 +
490 x * (0.055504108664821579953142263768622))));
496 static inline double G_GNUC_CONST
497 bse_approx4_exp2 (
float ex)
500 register int i = bse_ftoi (ex);
501 fp.mpn.biased_exponent = BSE_FLOAT_BIAS + i;
502 register double x = ex - i;
503 return fp.v_float * (1.0 + x * (0.69314718055994530941723212145818 +
504 x * (0.24022650695910071233355126316333 +
505 x * (0.055504108664821579953142263768622 +
506 x * (0.0096181291076284771619790715736589)))));
513 static inline double G_GNUC_CONST
514 bse_approx5_exp2 (
float ex)
517 register int i = bse_ftoi (ex);
518 fp.mpn.biased_exponent = BSE_FLOAT_BIAS + i;
519 register double x = ex - i;
520 return fp.v_float * (1.0 + x * (0.69314718055994530941723212145818 +
521 x * (0.24022650695910071233355126316333 +
522 x * (0.055504108664821579953142263768622 +
523 x * (0.0096181291076284771619790715736589 +
524 x * (0.0013333558146428443423412221987996))))));
527 static inline double G_GNUC_CONST
528 bse_approx6_exp2 (
float ex)
531 register int i = bse_ftoi (ex);
532 fp.mpn.biased_exponent = BSE_FLOAT_BIAS + i;
533 register double x = ex - i;
534 return fp.v_float * (1.0 + x * (0.69314718055994530941723212145818 +
535 x * (0.24022650695910071233355126316333 +
536 x * (0.055504108664821579953142263768622 +
537 x * (0.0096181291076284771619790715736589 +
538 x * (0.0013333558146428443423412221987996 +
539 x * (0.00015403530393381609954437097332742)))))));
542 static inline double G_GNUC_CONST
543 bse_approx7_exp2 (
float ex)
546 register int i = bse_ftoi (ex);
547 fp.mpn.biased_exponent = BSE_FLOAT_BIAS + i;
548 register double x = ex - i;
549 return fp.v_float * (1.0 + x * (0.69314718055994530941723212145818 +
550 x * (0.24022650695910071233355126316333 +
551 x * (0.055504108664821579953142263768622 +
552 x * (0.0096181291076284771619790715736589 +
553 x * (0.0013333558146428443423412221987996 +
554 x * (0.00015403530393381609954437097332742 +
555 x * (0.00001525273380405984028002543901201))))))));
558 static inline double G_GNUC_CONST
559 bse_approx8_exp2 (
float ex)
562 register int i = bse_ftoi (ex);
563 fp.mpn.biased_exponent = BSE_FLOAT_BIAS + i;
564 register double x = ex - i;
565 return fp.v_float * (1.0 + x * (0.69314718055994530941723212145818 +
566 x * (0.24022650695910071233355126316333 +
567 x * (0.055504108664821579953142263768622 +
568 x * (0.0096181291076284771619790715736589 +
569 x * (0.0013333558146428443423412221987996 +
570 x * (0.00015403530393381609954437097332742 +
571 x * (0.00001525273380405984028002543901201 +
572 x * (0.0000013215486790144309488403758228288)))))))));
575 static inline double G_GNUC_CONST
576 bse_approx9_exp2 (
float ex)
579 register int i = bse_ftoi (ex);
580 fp.mpn.biased_exponent = BSE_FLOAT_BIAS + i;
581 register double x = ex - i;
582 return fp.v_float * (1.0 + x * (0.69314718055994530941723212145818 +
583 x * (0.24022650695910071233355126316333 +
584 x * (0.055504108664821579953142263768622 +
585 x * (0.0096181291076284771619790715736589 +
586 x * (0.0013333558146428443423412221987996 +
587 x * (0.00015403530393381609954437097332742 +
588 x * (0.00001525273380405984028002543901201 +
589 x * (0.0000013215486790144309488403758228288 +
590 x * 0.00000010178086009239699727490007597745)))))))));
593 static inline double G_GNUC_CONST
594 bse_approx2_tanh (
float x)
596 if (G_UNLIKELY (x < -20))
598 if (G_UNLIKELY (x > 20))
600 register double bpot = bse_approx2_exp2 (x * BSE_2_DIV_LN2);
601 return (bpot - 1) / (bpot + 1);
604 static inline double G_GNUC_CONST
605 bse_approx3_tanh (
float x)
607 if (G_UNLIKELY (x < -20))
609 if (G_UNLIKELY (x > 20))
611 register double bpot = bse_approx3_exp2 (x * BSE_2_DIV_LN2);
612 return (bpot - 1) / (bpot + 1);
615 static inline double G_GNUC_CONST
616 bse_approx4_tanh (
float x)
618 if (G_UNLIKELY (x < -20))
620 if (G_UNLIKELY (x > 20))
622 register double bpot = bse_approx4_exp2 (x * BSE_2_DIV_LN2);
623 return (bpot - 1) / (bpot + 1);
627 static inline double G_GNUC_CONST
628 bse_approx5_tanh (
float x)
630 if (G_UNLIKELY (x < -20))
632 if (G_UNLIKELY (x > 20))
634 register double bpot = bse_approx5_exp2 (x * BSE_2_DIV_LN2);
635 return (bpot - 1) / (bpot + 1);
638 static inline double G_GNUC_CONST
639 bse_approx6_tanh (
float x)
641 if (G_UNLIKELY (x < -20))
643 if (G_UNLIKELY (x > 20))
645 register double bpot = bse_approx6_exp2 (x * BSE_2_DIV_LN2);
646 return (bpot - 1) / (bpot + 1);
649 static inline double G_GNUC_CONST
650 bse_approx7_tanh (
float x)
652 if (G_UNLIKELY (x < -20))
654 if (G_UNLIKELY (x > 20))
656 register double bpot = bse_approx7_exp2 (x * BSE_2_DIV_LN2);
657 return (bpot - 1) / (bpot + 1);
660 static inline double G_GNUC_CONST
661 bse_approx8_tanh (
float x)
663 if (G_UNLIKELY (x < -20))
665 if (G_UNLIKELY (x > 20))
667 register double bpot = bse_approx8_exp2 (x * BSE_2_DIV_LN2);
668 return (bpot - 1) / (bpot + 1);
671 static inline double G_GNUC_CONST
672 bse_approx9_tanh (
float x)
674 if (G_UNLIKELY (x < -20))
676 if (G_UNLIKELY (x > 20))
678 register double bpot = bse_approx9_exp2 (x * BSE_2_DIV_LN2);
679 return (bpot - 1) / (bpot + 1);
682 static inline double G_GNUC_CONST
683 bse_saturate_hard (
double value,
686 register double v1 =
fabsf (value + limit);
687 register double v2 =
fabsf (value - limit);
688 return 0.5 * (v1 - v2);
691 static inline double G_GNUC_CONST
692 bse_saturate_branching (
double value,
695 if (G_UNLIKELY (value >= limit))
697 if (G_UNLIKELY (value <= limit))
702 void _bse_init_signal (
void);
704 extern const double *
const bse_cent_table;
706 static inline double G_GNUC_CONST
707 bse_cent_tune_fast (
int fine_tune)
709 return bse_cent_table[CLAMP (fine_tune, -100, 100)];
double bse_approx_atan1_prescale(double boost_amount)
Definition: bsemathsignal.cc:650
Definition: bseieee754.hh:129
double bse_cent_tune(double fine_tune)
Definition: bsemathsignal.cc:210
Definition: bsemathsignal.hh:74