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.

90 lines
1.7KB

  1. #ifndef GVERBDSP_H
  2. #define GVERBDSP_H
  3. #include "ladspa-util.h"
  4. namespace rack_plugin_rcm {
  5. typedef struct {
  6. int size;
  7. int idx;
  8. float *buf;
  9. } ty_fixeddelay;
  10. typedef struct {
  11. int size;
  12. float coeff;
  13. int idx;
  14. float *buf;
  15. } ty_diffuser;
  16. typedef struct {
  17. float damping;
  18. float delay;
  19. } ty_damper;
  20. ty_diffuser *diffuser_make(int, float);
  21. void diffuser_free(ty_diffuser *);
  22. void diffuser_flush(ty_diffuser *);
  23. //float diffuser_do(ty_diffuser *, float);
  24. ty_damper *damper_make(float);
  25. void damper_free(ty_damper *);
  26. void damper_flush(ty_damper *);
  27. //void damper_set(ty_damper *, float);
  28. //float damper_do(ty_damper *, float);
  29. ty_fixeddelay *fixeddelay_make(int);
  30. void fixeddelay_free(ty_fixeddelay *);
  31. void fixeddelay_flush(ty_fixeddelay *);
  32. //float fixeddelay_read(ty_fixeddelay *, int);
  33. //void fixeddelay_write(ty_fixeddelay *, float);
  34. int isprime(int);
  35. int nearest_prime(int, float);
  36. static __inline float diffuser_do(ty_diffuser *p, float x)
  37. {
  38. float y,w;
  39. w = x - p->buf[p->idx]*p->coeff;
  40. w = flush_to_zero(w);
  41. y = p->buf[p->idx] + w*p->coeff;
  42. p->buf[p->idx] = w;
  43. p->idx = (p->idx + 1) % p->size;
  44. return(y);
  45. }
  46. static __inline float fixeddelay_read(ty_fixeddelay *p, int n)
  47. {
  48. int i;
  49. i = (p->idx - n + p->size) % p->size;
  50. return(p->buf[i]);
  51. }
  52. static __inline void fixeddelay_write(ty_fixeddelay *p, float x)
  53. {
  54. p->buf[p->idx] = x;
  55. p->idx = (p->idx + 1) % p->size;
  56. }
  57. static __inline void damper_set(ty_damper *p, float damping)
  58. {
  59. p->damping = damping;
  60. }
  61. static __inline float damper_do(ty_damper *p, float x)
  62. {
  63. float y;
  64. y = x*(1.0-p->damping) + p->delay*p->damping;
  65. p->delay = y;
  66. return(y);
  67. }
  68. } // namespace rack_plugin_rcm
  69. #endif