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