/usr/include/bse/bsemathsignal.h is in libbse-dev 0.7.4-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 | /* BSE - Better Sound Engine
* Copyright (C) 1997-2004 Tim Janik
* Copyright (C) 2001 Stefan Westerfeld
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* A copy of the GNU Lesser General Public License should ship along
* with this library; if not, see http://www.gnu.org/copyleft/.
*/
#ifndef __BSE_SIGNAL_H__
#define __BSE_SIGNAL_H__
#include <bse/bsemath.h>
#include <bse/bseglobals.h>
#include <bse/bsetype.h> // for BseMusicalTuningType
G_BEGIN_DECLS
/**
* smallest value of a signal sample, greater than zero
*/
#define BSE_SIGNAL_EPSILON (1.15e-14) /* 1.16415321826934814453125e-9 ~= 1/2^33 */
/**
* maximum value of a signal sample
*/
#define BSE_SIGNAL_KAPPA (1.5)
/**
* Catch edges in sync signals.
* sync signals should be constant, do comparing against
* an epsilon just hurts speed in the common case.
*/
#define BSE_SIGNAL_RAISING_EDGE(v1,v2) ((v1) < (v2))
/**
* Inverse variant of BSE_SIGNAL_RAISING_EDGE().
*/
#define BSE_SIGNAL_FALLING_EDGE(v1,v2) ((v1) > (v2))
/**
* Value changes in signals which represent frequencies.
*/
#define BSE_SIGNAL_FREQ_CHANGED(v1,v2) (fabs ((v1) - (v2)) > 1e-7)
/**
* Inverse variant of BSE_SIGNAL_FREQ_CHANGED().
*/
#define BSE_SIGNAL_FREQ_EQUALS(v1,v2) (!BSE_SIGNAL_FREQ_CHANGED (v1, v2))
/**
* Value changes in signals which represent modulation.
*/
#define BSE_SIGNAL_MOD_CHANGED(v1,v2) (fabs ((v1) - (v2)) > 1e-8)
/**
* Value changes in signals which represent dB ranges.
*/
#define BSE_SIGNAL_GAIN_CHANGED(v1,v2) (fabs ((v1) - (v2)) > 1e-8)
/**
* Convert between literal frequencies and signal values.
*/
#define BSE_SIGNAL_TO_FREQ_FACTOR (BSE_MAX_FREQUENCY)
#define BSE_SIGNAL_FROM_FREQ_FACTOR (1.0 / BSE_MAX_FREQUENCY)
#define BSE_SIGNAL_TO_FREQ(value) (BSE_FREQ_FROM_VALUE (value))
#define BSE_SIGNAL_FROM_FREQ(freq) (BSE_VALUE_FROM_FREQ (freq))
#define BSE_SIGNAL_CLIP(v) bse_signal_value_clip (v)
static inline double bse_signal_value_clip (register double x) G_GNUC_CONST;
static inline double G_GNUC_CONST
bse_signal_value_clip (register double x)
{
if (G_UNLIKELY (x > 1.0))
return 1.0;
if (G_UNLIKELY (x < -1.0))
return -1.0;
return x;
}
/* --- frequency modulation --- */
typedef struct {
gfloat fm_strength; /* linear: 0..1, exponential: n_octaves */
guint exponential_fm : 1;
gfloat signal_freq; /* for ifreq == NULL (as BSE_SIGNAL_FROM_FREQ) */
gint fine_tune; /* -100..+100 */
} BseFrequencyModulator;
void bse_frequency_modulator (const BseFrequencyModulator *fm,
guint n_values,
const gfloat *ifreq,
const gfloat *ifmod,
gfloat *fm_buffer);
/* --- windows --- */
double bse_window_bartlett (double x); /* narrowest */
double bse_window_blackman (double x);
double bse_window_cos (double x);
double bse_window_hamming (double x);
double bse_window_sinc (double x);
double bse_window_rect (double x); /* widest */
/* --- function approximations --- */
/**
* @param x x as in atan(x)
*
* Fast atan(x)/(PI/2) approximation, with maximum error < 0.01 and
* bse_approx_atan1(0)==0, according to the formula:
* n1 = -0.41156875521951602506487246309908;
* n2 = -1.0091272542790025586079663559158;
* d1 = 0.81901156857081841441890603235599;
* d2 = 1.0091272542790025586079663559158;
* positive_atan1(x) = 1 + (n1 * x + n2) / ((1 + d1 * x) * x + d2);
*/
static inline double bse_approx_atan1 (register double x) G_GNUC_CONST;
/**
* @param boost_amount boost amount between [0..1]
* @return prescale factor for bse_approx_atan1()
*
* Calculate the prescale factor for bse_approx_atan1(x*prescale) from
* a linear boost factor, where 0.5 amounts to prescale=1.0, 1.0 results
* in maximum boost and 0.0 results in maximum attenuation.
*/
double bse_approx_atan1_prescale (double boost_amount);
/**
* @param x x within [0..1]
* @return y for circle approximation within [0..1]
*
* Fast approximation of the upper right quadrant of a circle.
* Errors at x=0 and x=1 are zero, for the rest of the curve, the error
* wasn't minimized, but distributed to best fit the curverture of a
* quarter circle. The maximum error is below 0.092.
*/
static inline double bse_approx_qcircle1 (register double x) G_GNUC_CONST;
/**
* @param x x within [0..1]
* @return y for circle approximation within [0..1]
*
* Fast approximation of the upper left quadrant of a circle.
* Errors at x=0 and x=1 are zero, for the rest of the curve, the error
* wasn't minimized, but distributed to best fit the curverture of a
* quarter circle. The maximum error is below 0.092.
*/
static inline double bse_approx_qcircle2 (register double x) G_GNUC_CONST;
/**
* @param x x within [0..1]
* @return y for circle approximation within [0..1]
*
* Fast approximation of the lower left quadrant of a circle.
* Errors at x=0 and x=1 are zero, for the rest of the curve, the error
* wasn't minimized, but distributed to best fit the curverture of a
* quarter circle. The maximum error is below 0.092.
*/
static inline double bse_approx_qcircle3 (register double x) G_GNUC_CONST;
/**
* @param x x within [0..1]
* @return y for circle approximation within [0..1]
*
* Fast approximation of the lower right quadrant of a circle.
* Errors at x=0 and x=1 are zero, for the rest of the curve, the error
* wasn't minimized, but distributed to best fit the curverture of a
* quarter circle. The maximum error is below 0.092.
*/
static inline double bse_approx_qcircle4 (register double x) G_GNUC_CONST;
/**
* @param ex exponent within [-127..+127]
* @return y approximating 2^ex
*
* Fast approximation of 2 raised to the power of ex.
* Within -1..+1, the error stays below 0.01275 which corresponds to a sample
* precision of 6.2 bit, the average error amounts to 0.001914.
* For integer values of @a ex (i.e. @a ex - floor (@a ex) -> 0), the error
* approaches zero. On a 2GHz machine, execution takes roughly 12.81 ns.
*/
static inline double bse_approx2_exp2 (float ex) G_GNUC_CONST;
/**
* @param ex exponent within [-127..+127]
* @return y approximating 2^ex
*
* Fast approximation of 2 raised to the power of ex.
* Within -1..+1, the error stays below 0.001123415 which corresponds to a sample
* precision of 9.7 bit, the average error amounts to 0.000133.
* For integer values of @a ex (i.e. @a ex - floor (@a ex) -> 0), the error
* approaches zero. On a 2GHz machine, execution takes roughly 13.74 ns.
*/
static inline double bse_approx3_exp2 (float ex) G_GNUC_CONST;
/**
* @param ex exponent within [-127..+127]
* @return y approximating 2^ex
*
* Fast approximation of 2 raised to the power of ex.
* Within -1..+1, the error stays below 7.876055e-05 which corresponds to a sample
* precision of 13.6 bit, the average error amounts to 7.7012792e-06.
* For integer values of @a ex (i.e. @a ex - floor (@a ex) -> 0), the error
* approaches zero. On a 2GHz machine, execution takes roughly 16.46 ns.
*/
static inline double bse_approx4_exp2 (float ex) G_GNUC_CONST;
/**
* @param ex exponent within [-127..+127]
* @return y approximating 2^ex
*
* Fast approximation of 2 raised to the power of ex.
* Within -1..+1, the error stays below 4.60807023e-06 which corresponds to a sample
* precision of 17.7 bit, the average error amounts to 3.842199e-07.
* For integer values of @a ex (i.e. @a ex - floor (@a ex) -> 0), the error
* approaches zero. On a 2GHz machine, execution takes roughly 18.51 ns.
*/
static inline double bse_approx5_exp2 (float ex) G_GNUC_CONST;
/**
* @param ex exponent within [-127..+127]
* @return y approximating 2^ex
*
* Fast approximation of 2 raised to the power of ex.
* Within -1..+1, the error stays below 2.5505813e-07 which corresponds to a sample
* precision of 21.9 bit, the average error amounts to 2.1028377e-08.
* For integer values of @a ex (i.e. @a ex - floor (@a ex) -> 0), the error
* approaches zero. On a 2GHz machine, execution takes roughly 21.84 ns.
*/
static inline double bse_approx6_exp2 (float ex) G_GNUC_CONST;
/**
* @param ex exponent within [-127..+127]
* @return y approximating 2^ex
*
* Fast approximation of 2 raised to the power of ex.
* Within -1..+1, the error stays below 4.1074325e-08 which corresponds to a sample
* precision of 24.5 bit, the average error amounts to 7.7448985e-09.
* For integer values of @a ex (i.e. @a ex - floor (@a ex) -> 0), the error
* approaches zero. On a 2GHz machine, execution takes roughly 23.79 ns.
*/
static inline double bse_approx7_exp2 (float ex) G_GNUC_CONST;
/**
* @param ex exponent within [-127..+127]
* @return y approximating 2^ex
*
* Fast approximation of 2 raised to the power of ex.
* Within -1..+1, the error stays below 4.1074325e-08 which corresponds to a sample
* precision of 24.5 bit, the average error amounts to 7.6776048e-09.
* Note that there is no significant precision increment over bse_approx7_exp2().
* For integer values of @a ex (i.e. @a ex - floor (@a ex) -> 0), the error
* approaches zero. On a 2GHz machine, execution takes roughly 26.59 ns.
*/
static inline double bse_approx8_exp2 (float ex) G_GNUC_CONST;
/**
* @param ex exponent within [-127..+127]
* @return y approximating 2^ex
*
* Fast approximation of 2 raised to the power of ex.
* Within -1..+1, the error stays below 4.1074325e-08 which corresponds to a sample
* precision of 24.5 bit, the average error amounts to 7.677515903e-09.
* Note that there is no significant precision increment over bse_approx7_exp2().
* For integer values of @a ex (i.e. @a ex - floor (@a ex) -> 0), the error
* approaches zero. On a 2GHz machine, execution takes roughly 29.40 ns.
*/
static inline double bse_approx9_exp2 (float ex) G_GNUC_CONST;
/**
* @param x exponent within [-127..+127]
* @return y approximating tanh(x)
*
* Fast approximation of the hyperbolic tangent of x.
* Within -1..+1, the error stays below 0.00436 which corresponds to a sample
* precision of 7.8 bit, the average error amounts to 0.00069220.
* On a 2GHz machine, execution takes roughly 24.48 ns.
*/
static inline double bse_approx2_tanh (float x) G_GNUC_CONST;
/**
* @param x exponent within [-127..+127]
* @return y approximating tanh(x)
*
* Fast approximation of the hyperbolic tangent of x.
* Within -1..+1, the error stays below 0.0003857 which corresponds to a sample
* precision of 7.8 bit, the average error amounts to 0.00004827.
* On a 2GHz machine, execution takes roughly 25.78 ns.
*/
static inline double bse_approx3_tanh (float x) G_GNUC_CONST;
/**
* @param x exponent within [-127..+127]
* @return y approximating tanh(x)
*
* Fast approximation of the hyperbolic tangent of x.
* Within -1..+1, the error stays below 2.7017507e-05 which corresponds to a sample
* precision of 15.1 bit, the average error amounts to 2.799594e-06.
* On a 2GHz machine, execution takes roughly 28.41 ns.
*/
static inline double bse_approx4_tanh (float x) G_GNUC_CONST;
/**
* @param x exponent within [-127..+127]
* @return y approximating tanh(x)
*
* Fast approximation of the hyperbolic tangent of x.
* Within -1..+1, the error stays below 1.582042006e-06 which corresponds to a sample
* precision of 19.2 bit, the average error amounts to 1.42780810e-07.
* On a 2GHz machine, execution takes roughly 30.35 ns.
*/
static inline double bse_approx5_tanh (float x) G_GNUC_CONST;
/**
* @param x exponent within [-127..+127]
* @return y approximating tanh(x)
*
* Fast approximation of the hyperbolic tangent of x.
* Within -1..+1, the error stays below 9.7878796e-08 which corresponds to a sample
* precision of 23.2 bit, the average error amounts to 1.3016999e-08.
* On a 2GHz machine, execution takes roughly 34.29 ns.
*/
static inline double bse_approx6_tanh (float x) G_GNUC_CONST;
/**
* @param x exponent within [-127..+127]
* @return y approximating tanh(x)
*
* Fast approximation of the hyperbolic tangent of x.
* Within -1..+1, the error stays below 4.4375671e-08 which corresponds to a sample
* precision of 24.4 bit, the average error amounts to 9.5028421e-09.
* On a 2GHz machine, execution takes roughly 36.86 ns.
*/
static inline double bse_approx7_tanh (float x) G_GNUC_CONST;
/**
* @param x exponent within [-127..+127]
* @return y approximating tanh(x)
*
* Fast approximation of the hyperbolic tangent of x.
* Within -1..+1, the error stays below 4.4375671e-08 which corresponds to a sample
* precision of 24.4 bit, the average error amounts to 9.49155722e-09.
* Note that there is no significant precision increment over bse_approx7_tanh().
* On a 2GHz machine, execution takes roughly 42.03 ns.
*/
static inline double bse_approx8_tanh (float x) G_GNUC_CONST;
/**
* @param x exponent within [-127..+127]
* @return y approximating tanh(x)
*
* Fast approximation of the hyperbolic tangent of x.
* Within -1..+1, the error stays below 4.4375671e-08 which corresponds to a sample
* precision of 24.4 bit, the average error amounts to 9.49141881e-09.
* Note that there is no significant precision increment over bse_approx7_tanh().
* On a 2GHz machine, execution takes roughly 43.83 ns.
*/
static inline double bse_approx9_tanh (float x) G_GNUC_CONST;
/**
* @param value value to saturate
* @param limit limit not to be exceeded by value
* @return @a value bounded by -limit and @a limit
*
* Clamp @a value within -limit and +limit. Limiting is performed
* by floating point operations only, thus executing faster than
* condition based branching code on most modern architectures.
* On a 2GHz machine, execution takes roughly 6.86 ns.
*/
static inline double bse_saturate_hard (double value,
double limit) G_GNUC_CONST;
/**
* @param value value to saturate
* @param limit limit not to be exceeded by value
* @return @a value bounded by -limit and @a limit
*
* Clamp @a value within -limit and +limit. Limiting is performed
* by executing conditions and branches, so it will probably run
* slower than bse_saturate_hard() on many machines.
* On a 2GHz machine, execution takes roughly 8.29 ns.
*/
static inline double bse_saturate_branching (double value,
double limit) G_GNUC_CONST;
/* --- semitone factors (for +-11 octaves) --- */
const double* bse_semitone_table_from_tuning (BseMusicalTuningType musical_tuning); /* returns [-132..+132] */
double bse_transpose_factor (BseMusicalTuningType musical_tuning,
int index /* [-132..+132] */);
/* --- cents (1/100th of a semitone) --- */
double bse_cent_tune (double fine_tune);
/**
* @param fine_tune fine tuning in cent between -100 and 100
* @return a factor corresponding to this
*
* This function computes a factor which corresponds to a given fine tuning in
* cent. The result can be used as factor for the frequency or the play speed.
* It is a faster alternative to bse_cent_tune(), and can only deal with
* integer values between -100 and 100. The input is always CLAMPed to ensure
* that it lies in this range.
*/
static inline double bse_cent_tune_fast (int fine_tune /* -100..+100 */) G_GNUC_CONST;
/* --- implementation details --- */
static inline double G_GNUC_CONST
bse_approx_atan1 (register double x)
{
if (x < 0) /* make use of -atan(-x)==atan(x) */
{
register double numerator, denominator = -1.0;
denominator += x * 0.81901156857081841441890603235599; /* d1 */
numerator = x * 0.41156875521951602506487246309908; /* -n1 */
denominator *= x;
numerator += -1.0091272542790025586079663559158; /* n2 */
denominator += 1.0091272542790025586079663559158; /* d2 */
return -1.0 - numerator / denominator;
}
else
{
register double numerator, denominator = 1.0;
denominator += x * 0.81901156857081841441890603235599; /* d1 */
numerator = x * -0.41156875521951602506487246309908; /* n1 */
denominator *= x;
numerator += -1.0091272542790025586079663559158; /* n2 */
denominator += 1.0091272542790025586079663559158; /* d2 */
return 1.0 + numerator / denominator;
}
/* atan1_positive(x)=1+(x*-0.411568755219516-1.009127254279)/((1+x*0.81901156857)*x+1.009127254279)
* atan1(x)=x<0 ? -atan1_positive(-x) : atan1_positive(x)
*/
}
static inline double G_GNUC_CONST
bse_approx_qcircle1 (register double x)
{
double numerator = 1.20460124790369468987715633298929 * x - 1.20460124790369468987715633298929;
double denominator = x - 1.20460124790369468987715633298929;
/* R1(x)=(1.2046012479036946898771563 * x - 1.2046012479036946898771563) / (x - 1.2046012479036946898771563) */
return numerator / denominator;
}
static inline double G_GNUC_CONST
bse_approx_qcircle2 (register double x)
{
double numerator = 1.20460124790369468987715633298929*x;
double denominator = x + 0.20460124790369468987715633298929;
/* R2(x)=1.2046012479036946898771563*x/(x + 0.2046012479036946898771563) */
return numerator / denominator;
}
static inline double G_GNUC_CONST
bse_approx_qcircle3 (register double x)
{
double numerator = 0.20460124790369468987715633298929 - 0.20460124790369468987715633298929 * x;
double denominator = x + 0.20460124790369468987715633298929;
/* R3(x)=(0.2046012479036946898771563 - 0.2046012479036946898771563 * x) / (x + 0.2046012479036946898771563) */
return numerator / denominator;
}
static inline double G_GNUC_CONST
bse_approx_qcircle4 (register double x)
{
double numerator = -0.20460124790369468987715633298929 * x;
double denominator = x - 1.20460124790369468987715633298929;
/* R4(x)=-0.2046012479036946898771563 * x / (x - 1.2046012479036946898771563) */
return numerator / denominator;
}
static inline double G_GNUC_CONST
bse_approx2_exp2 (float ex)
{
register BseFloatIEEE754 fp = { 0, };
register int i = bse_ftoi (ex);
fp.mpn.biased_exponent = BSE_FLOAT_BIAS + i;
register double x = ex - i;
return fp.v_float * (1.0 + x * (0.69314718055994530941723212145818 +
x * (0.24022650695910071233355126316333)));
}
static inline double G_GNUC_CONST
bse_approx3_exp2 (float ex)
{
register BseFloatIEEE754 fp = { 0, };
register int i = bse_ftoi (ex);
fp.mpn.biased_exponent = BSE_FLOAT_BIAS + i;
register double x = ex - i;
return fp.v_float * (1.0 + x * (0.69314718055994530941723212145818 +
x * (0.24022650695910071233355126316333 +
x * (0.055504108664821579953142263768622))));
/* exp2frac(x)=x-ftoi(x)
* exp2a3(x)=2**ftoi(x)*(1+exp2frac(x)*(0.6931471805599453+exp2frac(x)*(0.2402265069591+exp2frac(x)*0.0555041086648)))
*/
}
static inline double G_GNUC_CONST
bse_approx4_exp2 (float ex)
{
register BseFloatIEEE754 fp = { 0, };
register int i = bse_ftoi (ex);
fp.mpn.biased_exponent = BSE_FLOAT_BIAS + i;
register double x = ex - i;
return fp.v_float * (1.0 + x * (0.69314718055994530941723212145818 +
x * (0.24022650695910071233355126316333 +
x * (0.055504108664821579953142263768622 +
x * (0.0096181291076284771619790715736589)))));
/* ftoi(x)=int(x<-0.0 ? x - 0.5 : x + 0.5)
* exp2frac(x)=x-ftoi(x)
* exp2a4(x)=2**ftoi(x)*(1+exp2frac(x)*(0.6931471805599453+exp2frac(x)*(0.2402265069591+exp2frac(x)*(0.0555041086648+exp2frac(x)*0.009618129107628477))))
*/
}
static inline double G_GNUC_CONST
bse_approx5_exp2 (float ex)
{
register BseFloatIEEE754 fp = { 0, };
register int i = bse_ftoi (ex);
fp.mpn.biased_exponent = BSE_FLOAT_BIAS + i;
register double x = ex - i;
return fp.v_float * (1.0 + x * (0.69314718055994530941723212145818 +
x * (0.24022650695910071233355126316333 +
x * (0.055504108664821579953142263768622 +
x * (0.0096181291076284771619790715736589 +
x * (0.0013333558146428443423412221987996))))));
}
static inline double G_GNUC_CONST
bse_approx6_exp2 (float ex)
{
register BseFloatIEEE754 fp = { 0, };
register int i = bse_ftoi (ex);
fp.mpn.biased_exponent = BSE_FLOAT_BIAS + i;
register double x = ex - i;
return fp.v_float * (1.0 + x * (0.69314718055994530941723212145818 +
x * (0.24022650695910071233355126316333 +
x * (0.055504108664821579953142263768622 +
x * (0.0096181291076284771619790715736589 +
x * (0.0013333558146428443423412221987996 +
x * (0.00015403530393381609954437097332742)))))));
}
static inline double G_GNUC_CONST
bse_approx7_exp2 (float ex)
{
register BseFloatIEEE754 fp = { 0, };
register int i = bse_ftoi (ex);
fp.mpn.biased_exponent = BSE_FLOAT_BIAS + i;
register double x = ex - i;
return fp.v_float * (1.0 + x * (0.69314718055994530941723212145818 +
x * (0.24022650695910071233355126316333 +
x * (0.055504108664821579953142263768622 +
x * (0.0096181291076284771619790715736589 +
x * (0.0013333558146428443423412221987996 +
x * (0.00015403530393381609954437097332742 +
x * (0.00001525273380405984028002543901201))))))));
}
static inline double G_GNUC_CONST
bse_approx8_exp2 (float ex)
{
register BseFloatIEEE754 fp = { 0, };
register int i = bse_ftoi (ex);
fp.mpn.biased_exponent = BSE_FLOAT_BIAS + i;
register double x = ex - i;
return fp.v_float * (1.0 + x * (0.69314718055994530941723212145818 +
x * (0.24022650695910071233355126316333 +
x * (0.055504108664821579953142263768622 +
x * (0.0096181291076284771619790715736589 +
x * (0.0013333558146428443423412221987996 +
x * (0.00015403530393381609954437097332742 +
x * (0.00001525273380405984028002543901201 +
x * (0.0000013215486790144309488403758228288)))))))));
}
static inline double G_GNUC_CONST
bse_approx9_exp2 (float ex)
{
register BseFloatIEEE754 fp = { 0, };
register int i = bse_ftoi (ex);
fp.mpn.biased_exponent = BSE_FLOAT_BIAS + i;
register double x = ex - i;
return fp.v_float * (1.0 + x * (0.69314718055994530941723212145818 +
x * (0.24022650695910071233355126316333 +
x * (0.055504108664821579953142263768622 +
x * (0.0096181291076284771619790715736589 +
x * (0.0013333558146428443423412221987996 +
x * (0.00015403530393381609954437097332742 +
x * (0.00001525273380405984028002543901201 +
x * (0.0000013215486790144309488403758228288 +
x * 0.00000010178086009239699727490007597745)))))))));
}
static inline double G_GNUC_CONST
bse_approx2_tanh (float x)
{
if (G_UNLIKELY (x < -20))
return -1;
if (G_UNLIKELY (x > 20))
return 1;
register double bpot = bse_approx2_exp2 (x * BSE_2_DIV_LN2);
return (bpot - 1) / (bpot + 1);
}
static inline double G_GNUC_CONST
bse_approx3_tanh (float x)
{
if (G_UNLIKELY (x < -20))
return -1;
if (G_UNLIKELY (x > 20))
return 1;
register double bpot = bse_approx3_exp2 (x * BSE_2_DIV_LN2);
return (bpot - 1) / (bpot + 1);
}
static inline double G_GNUC_CONST
bse_approx4_tanh (float x)
{
if (G_UNLIKELY (x < -20))
return -1;
if (G_UNLIKELY (x > 20))
return 1;
register double bpot = bse_approx4_exp2 (x * BSE_2_DIV_LN2);
return (bpot - 1) / (bpot + 1);
/* tanha4(x)=x<-20 ? -1 : x>20 ? 1 : (exp2a4(x*2.885390081777926814719849362)-1) / (exp2a4(x*2.885390081777926814719849362)+1) */
}
static inline double G_GNUC_CONST
bse_approx5_tanh (float x)
{
if (G_UNLIKELY (x < -20))
return -1;
if (G_UNLIKELY (x > 20))
return 1;
register double bpot = bse_approx5_exp2 (x * BSE_2_DIV_LN2);
return (bpot - 1) / (bpot + 1);
}
static inline double G_GNUC_CONST
bse_approx6_tanh (float x)
{
if (G_UNLIKELY (x < -20))
return -1;
if (G_UNLIKELY (x > 20))
return 1;
register double bpot = bse_approx6_exp2 (x * BSE_2_DIV_LN2);
return (bpot - 1) / (bpot + 1);
}
static inline double G_GNUC_CONST
bse_approx7_tanh (float x)
{
if (G_UNLIKELY (x < -20))
return -1;
if (G_UNLIKELY (x > 20))
return 1;
register double bpot = bse_approx7_exp2 (x * BSE_2_DIV_LN2);
return (bpot - 1) / (bpot + 1);
}
static inline double G_GNUC_CONST
bse_approx8_tanh (float x)
{
if (G_UNLIKELY (x < -20))
return -1;
if (G_UNLIKELY (x > 20))
return 1;
register double bpot = bse_approx8_exp2 (x * BSE_2_DIV_LN2);
return (bpot - 1) / (bpot + 1);
}
static inline double G_GNUC_CONST
bse_approx9_tanh (float x)
{
if (G_UNLIKELY (x < -20))
return -1;
if (G_UNLIKELY (x > 20))
return 1;
register double bpot = bse_approx9_exp2 (x * BSE_2_DIV_LN2);
return (bpot - 1) / (bpot + 1);
}
static inline double G_GNUC_CONST
bse_saturate_hard (double value,
double limit)
{
register double v1 = fabsf (value + limit);
register double v2 = fabsf (value - limit);
return 0.5 * (v1 - v2); /* CLAMP() without branching */
}
static inline double G_GNUC_CONST
bse_saturate_branching (double value,
double limit)
{
if (G_UNLIKELY (value >= limit))
return limit;
if (G_UNLIKELY (value <= limit))
return -limit;
return value;
}
void _bse_init_signal (void);
static inline double G_GNUC_CONST
bse_cent_tune_fast (int fine_tune)
{
extern const double * const bse_cent_table;
return bse_cent_table[CLAMP (fine_tune, -100, 100)];
}
G_END_DECLS
#endif /* __BSE_SIGNAL_H__ */
|