aboutsummaryrefslogtreecommitdiff
path: root/susloop~
diff options
context:
space:
mode:
Diffstat (limited to 'susloop~')
-rw-r--r--susloop~/Makefile75
-rw-r--r--susloop~/mtosr.pd11
-rw-r--r--susloop~/susloop~.c149
-rw-r--r--susloop~/susloop~.pd102
4 files changed, 337 insertions, 0 deletions
diff --git a/susloop~/Makefile b/susloop~/Makefile
new file mode 100644
index 0000000..3234d6d
--- /dev/null
+++ b/susloop~/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: susloop~.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: susloop~.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: susloop~.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: susloop~.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/susloop~/mtosr.pd b/susloop~/mtosr.pd
new file mode 100644
index 0000000..0807e69
--- /dev/null
+++ b/susloop~/mtosr.pd
@@ -0,0 +1,11 @@
+#N canvas 0 0 450 300 10;
+#X obj 38 57 mtof;
+#X obj 38 33 inlet;
+#X obj 38 82 expr \$1 / 261.626 * $f1;
+#X obj 38 106 outlet;
+#X text 74 249 creation argument: samplerate at middle C.;
+#X text 25 190 takes midi note value and converts to a samplerate for
+sample playback.;
+#X connect 0 0 2 0;
+#X connect 1 0 0 0;
+#X connect 2 0 3 0;
diff --git a/susloop~/susloop~.c b/susloop~/susloop~.c
new file mode 100644
index 0000000..bdde314
--- /dev/null
+++ b/susloop~/susloop~.c
@@ -0,0 +1,149 @@
+/* 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"
+
+static t_class *susloop_class;
+
+static t_float pdsr; /* pd's sample rate */
+
+typedef struct _susloop {
+ t_object x_obj;
+ t_float a; /* beginning of loop */
+ t_float b; /* end of loop */
+ t_float startpos; /* start offset */
+ t_float pos; /* position in sample */
+ t_float direction; /* for pingpong loops */
+ t_float f; /* dummy for when input is float instead of signal */
+ void (*susloop_func)(t_int *x, t_float *in, t_float *out, int n); /* can be forward or pingpong */
+} t_susloop;
+
+static void susloop_forward(t_int *x, t_float *in, t_float *out, int n)
+{
+ t_float sr;
+ t_float p = ((t_susloop *)x)->pos;
+ t_float a = ((t_susloop *)x)->a;
+ t_float b = ((t_susloop *)x)->b;
+
+ while (n--) {
+ sr = *in;
+ if (p > b) {
+ p = a + (p - b);
+ }
+ *out = p;
+ p += sr/pdsr;
+ in++;
+ out++;
+ }
+
+ ((t_susloop *)x)->pos = p;
+}
+
+static void susloop_pingpong(t_int *x, t_float *in, t_float *out, int n)
+{
+ t_float sr;
+ t_float p = ((t_susloop *)x)->pos;
+ t_float a = ((t_susloop *)x)->a;
+ t_float b = ((t_susloop *)x)->b;
+ t_float d = ((t_susloop *)x)->direction;
+
+ while (n--) {
+ sr = *in;
+ if (p > b) {
+ p = b - (p - b);
+ d = -1;
+ } else if (p < a && d < 0) {
+ p = a + (a - p);
+ d = 1;
+ }
+ *out = p;
+ p += d*(sr/pdsr);
+ in++;
+ out++;
+ }
+
+ ((t_susloop *)x)->pos = p;
+ ((t_susloop *)x)->direction = d;
+}
+
+static t_int *susloop_perform(t_int *w)
+{
+ ((t_susloop *)w[1])->susloop_func((t_int *)w[1], (t_float *)(w[2]), (t_float *)(w[3]), (int)(w[4]));
+ return (w+5);
+}
+
+static void susloop_dsp(t_susloop *x, t_signal **sp)
+{
+ dsp_add(susloop_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
+}
+
+static void *susloop_new(t_symbol *s, int argc, t_atom *argv)
+{
+ t_susloop *x = (t_susloop *)pd_new(susloop_class);
+ int looptype = 0;
+ x->a = x->b = x->startpos = 0;
+ x->direction = 1;
+ x->susloop_func = susloop_forward;
+
+ switch (argc) {
+ case 4:
+ x->startpos = atom_getfloat(argv+3);
+ case 3:
+ looptype = atom_getint(argv+2);
+ if (looptype == 0)
+ x->susloop_func = susloop_forward;
+ else
+ x->susloop_func = susloop_pingpong;
+ case 2:
+ x->a = atom_getfloat(argv);
+ x->b = atom_getfloat(argv+1);
+ }
+
+ floatinlet_new(&x->x_obj, &x->a);
+ floatinlet_new(&x->x_obj, &x->b);
+ floatinlet_new(&x->x_obj, &x->startpos);
+ outlet_new(&x->x_obj, gensym("signal"));
+ return (x);
+}
+
+static void susloop_bang(t_susloop *x)
+{
+ x->pos = x->startpos;
+ x->direction = 1;
+}
+
+static void susloop_setfunc(t_susloop *x, t_floatarg type)
+{
+ if (type == 1) {
+ x->direction = 1;
+ x->susloop_func = susloop_pingpong;
+ } else
+ x->susloop_func = susloop_forward;
+}
+
+void susloop_tilde_setup(void)
+{
+ pdsr = sys_getsr();
+ susloop_class = class_new(gensym("susloop~"), (t_newmethod)susloop_new, 0, sizeof(t_susloop), 0, A_GIMME, 0);
+ class_addbang(susloop_class, susloop_bang);
+ /*
+ class_addmethod(susloop_class, nullfn, gensym("signal"), 0);
+ */
+ CLASS_MAINSIGNALIN(susloop_class, t_susloop, f);
+ class_addmethod(susloop_class, (t_method)susloop_dsp, gensym("dsp"), 0);
+ class_addmethod(susloop_class, (t_method)susloop_setfunc, gensym("type"), A_DEFFLOAT, 0);
+}
diff --git a/susloop~/susloop~.pd b/susloop~/susloop~.pd
new file mode 100644
index 0000000..bce3791
--- /dev/null
+++ b/susloop~/susloop~.pd
@@ -0,0 +1,102 @@
+#N canvas 236 83 735 643 10;
+#N canvas 0 0 450 300 graph1 0;
+#X array sample 86754 float 0;
+#X coords 0 1 86753 -1 200 64 1;
+#X restore 441 412 graph;
+#X obj 480 341 soundfiler;
+#X msg 480 315 read -resize \$1 sample;
+#X obj 480 289 openpanel;
+#X obj 480 267 bng 15 250 50 0 empty empty empty 20 8 0 8 -262144 -1
+-1;
+#X obj 8 513 dac~;
+#X floatatom 69 489 5 0 0;
+#X obj 69 513 / 100;
+#X obj 8 450 tabread4~ sample;
+#X obj 8 481 *~;
+#X floatatom 127 272 5 0 0;
+#X obj 127 310 mtosr 44100;
+#X msg 17 271 type 0;
+#X msg 17 299 type 1;
+#X msg 176 272 44100;
+#X floatatom 322 380 5 0 0;
+#X floatatom 179 380 6 0 0;
+#X floatatom 245 380 6 0 0;
+#X obj 88 271 bng 15 250 50 0 empty empty empty 20 8 0 8 -262144 -1
+-1;
+#X text 514 265 <- load a sample;
+#X text 421 230 Ben Saylor - bsaylor@macalester.edu;
+#X msg 124 489 70;
+#X obj 156 489 loadbang;
+#X text 54 45 optional creation args:;
+#X text 239 45 [loopstart loopend [looptype [startpos]]];
+#X text 172 336 loopstart;
+#X text 242 337 loopend;
+#X text 319 338 startpos;
+#X text 38 154 <looptype> is 0 for a forward loop (default) and 1 for
+a pingpong loop.;
+#X text 40 193 Playback speed is in samples/sec - send a float or signal
+to the left inlet.;
+#X text 10 7 susloop~ - another phase generator for sample looping
+;
+#X obj 127 414 susloop~ 4000 12000;
+#X text 37 94 When the left inlet gets a bang \, the phase output will
+start at <startpos> (defaults to 0) \, continue until it reaches <loopend>
+\, and then start looping between <loopstart> and <loopend>.;
+#X floatatom 480 366 5 0 0;
+#X obj 442 480 hsl 200 15 0 1 0 0 empty empty loop_start 10 8 0 8 -195568
+-33289 -33289 13700 0;
+#X obj 442 499 hsl 200 15 0 1 0 0 empty empty loop_end 10 8 0 8 -233017
+-1 -1 16900 0;
+#X obj 250 565 *;
+#X obj 293 565 *;
+#X obj 293 589 int;
+#X obj 250 589 int;
+#X obj 531 366 s filesize;
+#X obj 266 501 r filesize;
+#X obj 229 616 s lstart;
+#X obj 293 615 s lend;
+#X obj 245 356 r lend;
+#X obj 179 358 r lstart;
+#X obj 442 516 hsl 200 15 0 1 0 0 empty empty start 10 8 0 8 -262144
+-1 -1 0 0;
+#X obj 346 567 *;
+#X obj 346 591 int;
+#X obj 346 616 s start;
+#X obj 322 356 r start;
+#X connect 1 0 33 0;
+#X connect 1 0 40 0;
+#X connect 2 0 1 0;
+#X connect 3 0 2 0;
+#X connect 4 0 3 0;
+#X connect 6 0 7 0;
+#X connect 7 0 9 1;
+#X connect 8 0 9 0;
+#X connect 9 0 5 0;
+#X connect 9 0 5 1;
+#X connect 10 0 11 0;
+#X connect 11 0 31 0;
+#X connect 12 0 31 0;
+#X connect 13 0 31 0;
+#X connect 14 0 31 0;
+#X connect 15 0 31 3;
+#X connect 16 0 31 1;
+#X connect 17 0 31 2;
+#X connect 18 0 31 0;
+#X connect 21 0 7 0;
+#X connect 22 0 21 0;
+#X connect 31 0 8 0;
+#X connect 34 0 36 0;
+#X connect 35 0 37 0;
+#X connect 36 0 39 0;
+#X connect 37 0 38 0;
+#X connect 38 0 43 0;
+#X connect 39 0 42 0;
+#X connect 41 0 36 1;
+#X connect 41 0 37 1;
+#X connect 41 0 47 1;
+#X connect 44 0 17 0;
+#X connect 45 0 16 0;
+#X connect 46 0 47 0;
+#X connect 47 0 48 0;
+#X connect 48 0 49 0;
+#X connect 50 0 15 0;