Debian Codegraph @

compressor~.c

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /* Copyright (c) 2002 Yves Degoyon. */
2 /* For information on usage and redistribution, and for a DISCLAIMER OF ALL */
3 /* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
4 /* */
5 /* compressor~ -- compresses audio signal according to a factor */
6 /* */
7 /* This program is free software; you can redistribute it and/or */
8 /* modify it under the terms of the GNU General Public License */
9 /* as published by the Free Software Foundation; either version 2 */
10 /* of the License, or (at your option) any later version. */
11 /* */
12 /* See file LICENSE for further informations on licensing terms. */
13 /* */
14 /* This program is distributed in the hope that it will be useful, */
15 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
16 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
17 /* GNU General Public License for more details. */
18 /* */
19 /* You should have received a copy of the GNU General Public License */
20 /* along with this program; if not, write to the Free Software */
21 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 /* */
23 /* Based on PureData by Miller Puckette and others. */
24 /* */
25 /* Made while listening to : */
26 /* */
27 /* "I can't get you out of my head" */
28 /* "Na, na, na, na, na, na, na, na, na, ...." */
29 /* Kylie Minogue ( without Nick Cave ) */
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 }