aboutsummaryrefslogtreecommitdiff
path: root/aenv~
diff options
context:
space:
mode:
Diffstat (limited to 'aenv~')
-rw-r--r--aenv~/Makefile75
-rwxr-xr-xaenv~/aenv~-help.pd76
-rw-r--r--aenv~/aenv~.c165
3 files changed, 316 insertions, 0 deletions
diff --git a/aenv~/Makefile b/aenv~/Makefile
new file mode 100644
index 0000000..90a1668
--- /dev/null
+++ b/aenv~/Makefile
@@ -0,0 +1,75 @@
+current:
+ echo make pd_linux, pd_nt, pd_irix5, or pd_irix6
+
+clean: ; rm -f *.pd_linux *.o
+
+# ----------------------- NT -----------------------
+
+pd_nt: aenv~.dll
+
+.SUFFIXES: .dll
+
+PDNTCFLAGS = /W3 /WX /DNT /DPD /nologo
+VC="C:\Program Files\Microsoft Visual Studio\Vc98"
+
+PDNTINCLUDE = /I. /I\tcl\include /I\ftp\pd\src /I$(VC)\include
+
+PDNTLDIR = $(VC)\lib
+PDNTLIB = $(PDNTLDIR)\libc.lib \
+ $(PDNTLDIR)\oldnames.lib \
+ $(PDNTLDIR)\kernel32.lib \
+ \ftp\pd\bin\pd.lib
+
+.c.dll:
+ cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c $*.c
+ link /dll /export:$*_setup $*.obj $(PDNTLIB)
+
+# ----------------------- IRIX 5.x -----------------------
+
+pd_irix5: aenv~.pd_irix5
+
+.SUFFIXES: .pd_irix5
+
+SGICFLAGS5 = -o32 -DPD -DUNIX -DIRIX -O2
+
+
+SGIINCLUDE = -I../../src/
+
+.c.pd_irix5:
+ cc $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c
+ ld -elf -shared -rdata_shared -o $*.pd_irix5 $*.o
+ rm $*.o
+
+# ----------------------- IRIX 6.x -----------------------
+
+pd_irix6: aenv~.pd_irix6
+
+.SUFFIXES: .pd_irix6
+
+SGICFLAGS6 = -n32 -DPD -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \
+ -OPT:roundoff=3 -OPT:IEEE_arithmetic=3 -OPT:cray_ivdep=true \
+ -Ofast=ip32
+
+.c.pd_irix6:
+ cc $(SGICFLAGS6) $(SGIINCLUDE) -o $*.o -c $*.c
+ ld -IPA -n32 -shared -rdata_shared -o $*.pd_irix6 $*.o
+ rm $*.o
+
+# ----------------------- LINUX i386 -----------------------
+
+pd_linux: aenv~.pd_linux
+
+.SUFFIXES: .pd_linux
+
+LINUXCFLAGS = -DPD -O2 -funroll-loops -fomit-frame-pointer \
+ -Wall -W -Wshadow -Wstrict-prototypes -Werror \
+ -Wno-unused -Wno-parentheses -Wno-switch
+
+LINUXINCLUDE = -I/usr/local/lib/pd/include
+
+.c.pd_linux:
+ cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c
+ ld -export_dynamic -shared -o $*.pd_linux $*.o -lc -lm
+ strip --strip-unneeded $*.pd_linux
+ rm $*.o
+
diff --git a/aenv~/aenv~-help.pd b/aenv~/aenv~-help.pd
new file mode 100755
index 0000000..a888cb0
--- /dev/null
+++ b/aenv~/aenv~-help.pd
@@ -0,0 +1,76 @@
+#N canvas 10 20 762 475 10;
+#X floatatom 238 150 5 0 0;
+#X floatatom 281 150 5 0 0;
+#X floatatom 324 150 5 0 0;
+#X floatatom 367 150 5 0 0;
+#X msg 8 115 1;
+#X msg 50 115 0;
+#N canvas 0 0 450 300 graph1 0;
+#X array env 88200 float 0;
+#X coords 0 1 88199 0 300 140 1;
+#X restore 455 327 graph;
+#X msg 20 250 bang;
+#X obj 142 353 tabwrite~ env;
+#X obj 291 335 *~;
+#X obj 312 444 dac~;
+#X obj 318 410 *~;
+#X obj 364 395 vsl 8 64 0 1 0 1 empty empty empty 0 -8 0 8 -262144
+-1 -1 4900 1;
+#X obj 170 211 aenv~ 100 200 0.6 500;
+#X obj 430 222 phasor~ 100;
+#X obj 430 266 lop~ 1000;
+#X obj 430 244 -~ 0.5;
+#X obj 238 75 vsl 8 64 10 2000 0 1 empty empty attack 0 -8 0 8 -262144
+-1 -1 600 1;
+#X obj 281 75 vsl 8 64 10 2000 0 1 empty empty decay 0 -8 0 8 -262144
+-1 -1 800 1;
+#X obj 367 75 vsl 8 64 10 2000 0 1 empty empty release 0 -8 0 8 -262144
+-1 -1 2600 1;
+#X obj 324 75 vsl 8 64 0 1 0 1 empty empty sustain 0 -8 0 8 -262144
+-1 -1 4400 1;
+#X obj 430 146 notein 1;
+#X obj 430 196 mtof;
+#X text 42 206 nonzero -> attack;
+#X text 484 81 Ben Saylor <bsaylor@macalester.edu>;
+#X text 500 97 http://www.macalester.edu/~bsaylor;
+#X obj 8 20 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1
+;
+#X text 27 17 <- click here;
+#X obj 20 70 del 800;
+#X text 452 6 aenv~: asymptotic ADSR envelope generator;
+#X msg 198 73 lina;
+#X msg 198 104 loga;
+#X text 104 73 linear attack;
+#X text 120 105 log attack;
+#X msg 198 133 zero;
+#X text 77 219 0 -> release;
+#X connect 0 0 13 1;
+#X connect 1 0 13 2;
+#X connect 2 0 13 3;
+#X connect 3 0 13 4;
+#X connect 4 0 7 0;
+#X connect 4 0 13 0;
+#X connect 5 0 13 0;
+#X connect 7 0 8 0;
+#X connect 9 0 11 0;
+#X connect 11 0 10 0;
+#X connect 11 0 10 1;
+#X connect 12 0 11 1;
+#X connect 13 0 8 0;
+#X connect 13 0 9 0;
+#X connect 14 0 16 0;
+#X connect 15 0 9 1;
+#X connect 16 0 15 0;
+#X connect 17 0 0 0;
+#X connect 18 0 1 0;
+#X connect 19 0 3 0;
+#X connect 20 0 2 0;
+#X connect 21 0 22 0;
+#X connect 21 1 13 0;
+#X connect 22 0 14 0;
+#X connect 26 0 4 0;
+#X connect 26 0 28 0;
+#X connect 28 0 5 0;
+#X connect 30 0 13 0;
+#X connect 31 0 13 0;
+#X connect 34 0 13 0;
diff --git a/aenv~/aenv~.c b/aenv~/aenv~.c
new file mode 100644
index 0000000..1fb476c
--- /dev/null
+++ b/aenv~/aenv~.c
@@ -0,0 +1,165 @@
+/* Copyright 2002 Benjamin R. Saylor
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "m_pd.h"
+
+#ifdef _MSC_VER
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+enum { ATTACK, DECAY, RELEASE, LINEAR, LOGARITHMIC };
+#define THRESHOLD 0.99
+#define SCALE 4600.0
+#define CLIP(x) ((x < 0.1) ? 0.1 : x)
+#define IS_DENORMAL(f) (((*(unsigned int *)&(f))&0x7f800000) == 0)
+
+static t_class *aenv_class;
+
+typedef struct _aenv {
+ t_object x_obj;
+ t_float srate;
+ t_float a;
+ t_float d;
+ t_float s;
+ t_float r;
+ t_float lastval;
+ int stage;
+ int attacktype;
+} t_aenv;
+
+static t_int *aenv_perform(t_int *w)
+{
+ t_aenv *x = (t_aenv *)(w[1]);
+ t_float *out = (t_float *)(w[2]);
+ int n = (int)(w[3]);
+
+ t_float lastval = x->lastval;
+ t_float a, d, s, r;
+
+ switch (x->stage) {
+ case ATTACK:
+ if (x->attacktype == LINEAR) {
+ a = 1000 / (x->a * x->srate);
+ while (n--) {
+ *out = lastval + a;
+ lastval = *(out++);
+ if (lastval > THRESHOLD) {
+ x->stage = DECAY;
+ break;
+ }
+ }
+ } else {
+ a = SCALE / (CLIP(x->a) * x->srate);
+ while (n--) {
+ *out = lastval + a * (1 - lastval);
+ lastval = *(out++);
+ if (lastval > THRESHOLD) {
+ x->stage = DECAY;
+ break;
+ }
+ }
+ }
+ case DECAY:
+ d = SCALE / (CLIP(x->d) * x->srate);
+ s = x->s;
+ while (n-- > 0) {
+ *out = lastval - d * (lastval - s);
+ if (IS_DENORMAL(*out)) *out = 0.0;
+ lastval = *(out++);
+ }
+ break;
+ case RELEASE:
+ r = SCALE / (CLIP(x->r) * x->srate);
+ while (n--) {
+ *out = lastval - r * lastval;
+ if (IS_DENORMAL(*out)) *out = 0.0;
+ lastval = *(out++);
+ }
+ }
+
+ x->lastval = lastval;
+
+ return (w+4);
+}
+
+static void aenv_dsp(t_aenv *x, t_signal **sp)
+{
+ dsp_add(aenv_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
+}
+
+static void aenv_float(t_aenv *x, t_float f)
+{
+ if (f == 0)
+ x->stage = RELEASE;
+ else
+ x->stage = ATTACK;
+}
+
+static void *aenv_new(t_symbol *s, int argc, t_atom *argv)
+{
+ t_aenv *x = (t_aenv *)pd_new(aenv_class);
+ floatinlet_new(&x->x_obj, &x->a);
+ floatinlet_new(&x->x_obj, &x->d);
+ floatinlet_new(&x->x_obj, &x->s);
+ floatinlet_new(&x->x_obj, &x->r);
+ outlet_new(&x->x_obj, gensym("signal"));
+
+ x->srate = sys_getsr();
+ x->a = 500;
+ x->d = 500;
+ x->s = 0.5;
+ x->r = 500;
+ x->lastval = 0;
+ x->stage = RELEASE;
+ x->attacktype = LOGARITHMIC;
+
+ if (argc == 4) {
+ x->a = atom_getfloat(argv);
+ x->d = atom_getfloat(argv+1);
+ x->s = atom_getfloat(argv+2);
+ x->r = atom_getfloat(argv+3);
+ }
+
+ return (x);
+}
+
+static void aenv_lina(t_aenv *x)
+{
+ x->attacktype = LINEAR;
+}
+
+static void aenv_loga(t_aenv *x)
+{
+ x->attacktype = LOGARITHMIC;
+}
+
+static void aenv_zero(t_aenv *x)
+{
+ x->stage = RELEASE;
+ x->lastval = 0.0;
+}
+
+void aenv_tilde_setup(void)
+{
+ aenv_class = class_new(gensym("aenv~"), (t_newmethod)aenv_new, 0, sizeof(t_aenv), 0, A_GIMME, 0);
+ class_addmethod(aenv_class, (t_method)aenv_dsp, gensym("dsp"), 0);
+ class_addfloat(aenv_class, (t_method)aenv_float);
+ class_addmethod(aenv_class, (t_method)aenv_lina, gensym("lina"), 0);
+ class_addmethod(aenv_class, (t_method)aenv_loga, gensym("loga"), 0);
+ class_addmethod(aenv_class, (t_method)aenv_zero, gensym("zero"), 0);
+}