aboutsummaryrefslogtreecommitdiff
path: root/pd/extra/loop~
diff options
context:
space:
mode:
Diffstat (limited to 'pd/extra/loop~')
-rw-r--r--pd/extra/loop~/loop~.c164
-rw-r--r--pd/extra/loop~/makefile97
-rw-r--r--pd/extra/loop~/test-loop~.pd56
3 files changed, 317 insertions, 0 deletions
diff --git a/pd/extra/loop~/loop~.c b/pd/extra/loop~/loop~.c
new file mode 100644
index 00000000..85588ba8
--- /dev/null
+++ b/pd/extra/loop~/loop~.c
@@ -0,0 +1,164 @@
+/* loop~ -- loop generator for sampling */
+
+/* Copyright 1997-1999 Miller Puckette.
+Permission is granted to use this software for any purpose provided you
+keep this copyright notice intact.
+
+THE AUTHOR AND HIS EMPLOYERS MAKE NO WARRANTY, EXPRESS OR IMPLIED,
+IN CONNECTION WITH THIS SOFTWARE.
+
+This file is downloadable from http://www.crca.ucsd.edu/~msp .
+
+*/
+
+#ifdef PD
+#include "m_pd.h"
+#endif
+
+typedef struct _loopctl
+{
+ double l_phase;
+ float l_invwindow;
+ float l_window;
+ int l_resync;
+} t_loopctl;
+
+static void loopctl_run(t_loopctl *x, float *transposein,
+ float *windowin, float *rawout, float *windowout, int n)
+{
+ float window, invwindow;
+ double phase = x->l_phase;
+ if (x->l_resync)
+ {
+ window = *windowin;
+ if (window < 0)
+ {
+ if (window > -1)
+ window = -1;
+ invwindow = -1/window;
+ }
+ else
+ {
+ if (window < 1)
+ window = 1;
+ invwindow = 1/window;
+ }
+ x->l_resync = 0;
+ }
+ else
+ {
+ window = x->l_window;
+ phase = x->l_phase;
+ invwindow = x->l_invwindow;
+ }
+ while (n--)
+ {
+ double phaseinc = invwindow * *transposein++;
+ double newphase;
+ float nwind = *windowin++;
+ if (phaseinc >= 1 || phaseinc < 0)
+ phaseinc = 0;
+ newphase = phase + phaseinc;
+ if (newphase >= 1)
+ {
+ window = nwind;
+ if (window < 0)
+ {
+ if (window > -1)
+ window = -1;
+ invwindow = -1/window;
+ }
+ else
+ {
+ if (window < 1)
+ window = 1;
+ invwindow = 1/window;
+ }
+ newphase -= 1.;
+ }
+ phase = newphase;
+ *rawout++ = (float)phase;
+ *windowout++ = window;
+ }
+ x->l_invwindow = invwindow;
+ x->l_window = window;
+ x->l_phase = phase;
+}
+
+static void loopctl_init(t_loopctl *x)
+{
+ x->l_window = 1;
+ x->l_invwindow = 1;
+ x->l_phase = 0;
+}
+
+static void loopctl_set(t_loopctl *x, float val)
+{
+ if (val < 0 || val > 1)
+ val = 0;
+ x->l_phase = val;
+ x->l_resync = 1;
+}
+
+#ifdef PD
+
+typedef struct _loop
+{
+ t_object x_obj;
+ t_float x_f;
+ t_loopctl x_loopctl;
+} t_loop;
+
+static t_class *loop_class;
+
+static void *loop_new(void)
+{
+ t_loop *x = (t_loop *)pd_new(loop_class);
+ loopctl_init(&x->x_loopctl);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
+ outlet_new(&x->x_obj, gensym("signal"));
+ outlet_new(&x->x_obj, gensym("signal"));
+ return (x);
+}
+
+static t_int *loop_perform(t_int *w)
+{
+ t_loopctl *ctl = (t_loopctl *)(w[1]);
+ t_float *in1 = (t_float *)(w[2]);
+ t_float *in2 = (t_float *)(w[3]);
+ t_float *out1 = (t_float *)(w[4]);
+ t_float *out2 = (t_float *)(w[5]);
+ int n = (int)(w[6]);
+ loopctl_run(ctl, in1, in2, out1, out2, n);
+ return (w+7);
+}
+
+static void loop_dsp(t_loop *x, t_signal **sp)
+{
+ dsp_add(loop_perform, 6,
+ &x->x_loopctl, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec,
+ sp[0]->s_n);
+}
+
+static void loop_set(t_loop *x, t_floatarg val)
+{
+ loopctl_set(&x->x_loopctl, val);
+}
+
+static void loop_bang(t_loop *x)
+{
+ loopctl_set(&x->x_loopctl, 0);
+}
+
+void loop_tilde_setup(void)
+{
+ loop_class = class_new(gensym("loop~"), (t_newmethod)loop_new, 0,
+ sizeof(t_loop), 0, 0);
+ class_addmethod(loop_class, (t_method)loop_dsp, gensym("dsp"), A_CANT, 0);
+ CLASS_MAINSIGNALIN(loop_class, t_loop, x_f);
+ class_addmethod(loop_class, (t_method)loop_set, gensym("set"),
+ A_DEFFLOAT, 0);
+ class_addbang(loop_class, loop_bang);
+}
+
+#endif /* PD */
diff --git a/pd/extra/loop~/makefile b/pd/extra/loop~/makefile
new file mode 100644
index 00000000..7adffbd6
--- /dev/null
+++ b/pd/extra/loop~/makefile
@@ -0,0 +1,97 @@
+NAME=loop~
+CSYM=loop_tilde
+
+current: pd_linux
+
+# ----------------------- NT -----------------------
+
+pd_nt: $(NAME).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:$(CSYM)_setup $*.obj $(PDNTLIB)
+
+# ----------------------- IRIX 5.x -----------------------
+
+pd_irix5: $(NAME).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 -f $*.o ../$*.pd_linux
+ ln -s $*.pd_linux ..
+
+# ----------------------- IRIX 6.x -----------------------
+
+pd_irix6: $(NAME).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 -n32 -IPA -shared -rdata_shared -o $*.pd_irix6 $*.o
+ rm $*.o
+
+# ----------------------- LINUX i386 -----------------------
+
+pd_linux: $(NAME).pd_linux
+
+.SUFFIXES: .pd_linux
+
+LINUXCFLAGS = -fPIC -DPD -O2 -funroll-loops -fomit-frame-pointer \
+ -Wall -W -Wshadow -Wstrict-prototypes -Werror \
+ -Wno-unused -Wno-parentheses -Wno-switch
+
+LINUXINCLUDE = -I../../src
+
+LSTRIP = strip --strip-unneeded -R .note -R .comment
+
+.c.pd_linux:
+ cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c
+ cc -Wl,-export_dynamic --shared -o $*.pd_linux $*.o -lm
+ $(LSTRIP) $*.pd_linux
+ rm -f $*.o ../$*.pd_linux
+ ln -s $*/$*.pd_linux ..
+
+# ----------------------- Mac OSX -----------------------
+
+pd_darwin: $(NAME).pd_darwin
+
+.SUFFIXES: .pd_darwin
+
+DARWINCFLAGS = -DPD -O2 -Wall -W -Wshadow -Wstrict-prototypes \
+ -Wno-unused -Wno-parentheses -Wno-switch
+
+.c.pd_darwin:
+ cc $(DARWINCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c
+ cc -bundle -undefined suppress -flat_namespace -o $*.pd_darwin $*.o
+ rm -f $*.o ../$*.pd_darwin
+ ln -s $*/$*.pd_darwin ..
+
+# ----------------------------------------------------------
+
+clean:
+ rm -f *.o *.pd_* so_locations
diff --git a/pd/extra/loop~/test-loop~.pd b/pd/extra/loop~/test-loop~.pd
new file mode 100644
index 00000000..9f454109
--- /dev/null
+++ b/pd/extra/loop~/test-loop~.pd
@@ -0,0 +1,56 @@
+#N canvas 33 0 498 586 12;
+#X floatatom 52 262;
+#X obj 261 346 print~;
+#X msg 57 370 bang;
+#X msg 274 313 bang;
+#X obj 52 306 loop~;
+#X floatatom 102 245;
+#X graph graph1 0 0 44100 10 120 186 320 36;
+#X array array1 44100 float;
+#X pop;
+#X msg 43 204 \; array1 resize 44100;
+#X obj 25 401 tabwrite~ array1;
+#X msg 180 376 bang;
+#X obj 148 407 tabwrite~ array1;
+#X msg 194 261 bang;
+#X obj 204 347 print~;
+#X msg 217 314 bang;
+#X graph graph1 0 -1 150000 1 273 543 473 393;
+#X array array2 150000 float;
+#X pop;
+#X msg 326 274 \; array2 resize 150000;
+#X obj 235 234 soundfiler;
+#X msg 215 199 read ../../../ham/Hamburger.wav array2;
+#X obj 103 529 tabread4~ array2;
+#X obj 64 496 *~;
+#X obj 107 581 dac~;
+#X obj 105 552 hip~ 5;
+#X obj 123 482 samphold~;
+#X obj 102 506 +~;
+#X floatatom 106 430;
+#X obj 108 453 *~ 1000;
+#X msg 222 169 read ../../../ham/Wrong.wav array2;
+#X connect 0 0 4 0;
+#X connect 2 0 8 0;
+#X connect 3 0 1 0;
+#X connect 4 0 12 0;
+#X connect 4 0 19 0;
+#X connect 4 0 8 0;
+#X connect 4 0 22 1;
+#X connect 4 1 10 0;
+#X connect 4 1 1 0;
+#X connect 4 1 19 1;
+#X connect 5 0 4 1;
+#X connect 9 0 10 0;
+#X connect 11 0 4 0;
+#X connect 13 0 12 0;
+#X connect 17 0 16 0;
+#X connect 18 0 21 0;
+#X connect 19 0 23 0;
+#X connect 21 0 20 0;
+#X connect 21 0 20 1;
+#X connect 22 0 23 1;
+#X connect 23 0 18 0;
+#X connect 24 0 25 0;
+#X connect 25 0 22 0;
+#X connect 26 0 16 0;