Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

wdf.h 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. wdf.h
  3. Copyright (C) 2013 Damien Zammit
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  15. */
  16. #ifndef __WDF_H__
  17. #define __WDF_H__
  18. #include <math.h>
  19. #define ONEPORT 0
  20. #define PASSTHROUGH 1
  21. #define THREEPORT 2
  22. #define max(x,y) (( (x) > (y) ) ? x : y )
  23. #define min(x,y) (( (x) < (y) ) ? x : y )
  24. #define sign(x) ( (x) >= 0.0 ? 1.0 : -1.0 )
  25. #define BIG 1e12
  26. #define SMALL 1e-14
  27. #define EPSILON 1e-9
  28. #define ITER 50
  29. #define SWAP_PP(x,y) {T tmp=y; y=x; x=tmp;}
  30. #define SWAP_PN(x,y) {T tmp=y; y=-x; x=tmp;}
  31. #define SWAP_NP(x,y) {T tmp=y; y=x; x=-tmp;}
  32. #define SWAP_NN(x,y) {T tmp=y; y=-x; x=-tmp;}
  33. #if 0
  34. #include <stdio.h>
  35. #define DUMP(x) x
  36. #else
  37. #define DUMP(x)
  38. #endif
  39. typedef double T;
  40. class WDF {
  41. public:
  42. T WD;
  43. T WU;
  44. T PortRes;
  45. WDF();
  46. T Voltage();
  47. T Current();
  48. T state;
  49. char type;
  50. virtual T waveUp() { return 0.0; }
  51. virtual void setWD(T waveparent);
  52. };
  53. class OnePort : public WDF {
  54. public:
  55. void setWD(T waveparent);
  56. };
  57. class Triode {
  58. public:
  59. WDF G, K, P;
  60. T vg, vk, vp;
  61. T g, mu, gamma, c, gg, e, cg, ig0;
  62. T g1, mu1, gamma1, c1, gg1, e1, cg1, ig01;
  63. T g2, mu2, gamma2, c2, gg2, e2, cg2, ig02;
  64. T ffg(T VG);
  65. T fgdash(T VG);
  66. T ffp(T VP);
  67. T fpdash(T VP);
  68. T ffk();
  69. T secantfg(T *i1, T *i2);
  70. T newtonfg(T *i1);
  71. T secantfp(T *i1, T *i2);
  72. T newtonfp(T *i1);
  73. Triode();
  74. //Brent's method
  75. T r8_abs ( T x );
  76. T r8_epsilon;
  77. T r8_max ( T x, T y );
  78. T r8_sign ( T x );
  79. T zeroffp ( T a, T b, T t );
  80. T zeroffg ( T a, T b, T t );
  81. };
  82. class Adaptor : public OnePort {
  83. public:
  84. WDF *left;
  85. WDF *right;
  86. Adaptor(int flag);
  87. };
  88. class R : public Adaptor {
  89. public:
  90. R(T res);
  91. T waveUp();
  92. };
  93. class C : public Adaptor {
  94. public:
  95. C(T c, T fs);
  96. T waveUp();
  97. };
  98. class V : public Adaptor {
  99. public:
  100. T e;
  101. V(T ee, T r);
  102. T waveUp();
  103. };
  104. class inv;
  105. class ser;
  106. class par;
  107. #include "inv.h"
  108. #include "ser.h"
  109. #include "par.h"
  110. #else
  111. #endif