| 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 |
#include "m_pd.h" |
| 33 |
#include <stdlib.h> |
| 34 |
#include <math.h> |
| 35 |
|
| 36 |
static char *compressor_version = "compressor~: an audio compressor, version 0.1 ([email protected])"; |
| 37 |
|
| 38 |
typedef struct _compressor |
| 39 |
{ |
| 40 |
t_object x_obj; |
| 41 |
t_float x_strength; |
| 42 |
t_float x_pifactor; |
| 43 |
t_float x_f; |
| 44 |
} t_compressor; |
| 45 |
|
| 46 |
static t_class *compressor_class; |
| 47 |
|
| 48 |
static void compressor_strength(t_compressor *x, t_floatarg fstrength ) |
| 49 |
{ |
| 50 |
if (fstrength < -1.0) |
| 51 |
{ |
| 52 |
x->x_strength = -1.0; |
| 53 |
} |
| 54 |
else if (fstrength > 5) |
| 55 |
{ |
| 56 |
x->x_strength = 5; |
| 57 |
} |
| 58 |
else |
| 59 |
{ |
| 60 |
x->x_strength = fstrength; |
| 61 |
} |
| 62 |
x->x_pifactor = pow( M_PI, x->x_strength ); |
| 63 |
} |
| 64 |
|
| 65 |
static void *compressor_new(void) |
| 66 |
{ |
| 67 |
t_compressor *x = (t_compressor *)pd_new(compressor_class); |
| 68 |
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("strength")); |
| 69 |
x->x_strength = 0.; |
| 70 |
x->x_pifactor = pow( M_PI, x->x_strength ); |
| 71 |
outlet_new(&x->x_obj, &s_signal); |
| 72 |
return (x); |
| 73 |
} |
| 74 |
|
| 75 |
static t_int *compressor_perform(t_int *w) |
| 76 |
{ |
| 77 |
t_float *in = (t_float *)(w[1]); |
| 78 |
t_float *out = (t_float *)(w[2]); |
| 79 |
int n = (int)(w[3]); |
| 80 |
t_compressor *x = (t_compressor*)(w[4]); |
| 81 |
t_float isample_fact = x->x_pifactor; |
| 82 |
t_float osample_fact = 2.0 / M_PI; |
| 83 |
|
| 84 |
while (n--) |
| 85 |
{ |
| 86 |
*out = atan (*in * isample_fact) * osample_fact; |
| 87 |
out++; |
| 88 |
in++; |
| 89 |
} |
| 90 |
return (w+5); |
| 91 |
} |
| 92 |
|
| 93 |
static void compressor_dsp(t_compressor *x, t_signal **sp) |
| 94 |
{ |
| 95 |
dsp_add(compressor_perform, 4, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n, x ); |
| 96 |
} |
| 97 |
|
| 98 |
void compressor_tilde_setup(void) |
| 99 |
{ |
| •100 |
logpost(NULL, 4, "%s", compressor_version ); |
| 101 |
compressor_class = class_new(gensym("compressor~"), (t_newmethod)compressor_new, 0, |
| 102 |
sizeof(t_compressor), 0, 0); |
| 103 |
CLASS_MAINSIGNALIN( compressor_class, t_compressor, x_f ); |
| 104 |
class_addmethod(compressor_class, (t_method)compressor_dsp, gensym("dsp"), 0); |
| 105 |
class_addmethod(compressor_class, (t_method)compressor_strength, gensym("strength"), A_FLOAT, 0); |
| 106 |
} |