aboutsummaryrefslogtreecommitdiff
path: root/externals/extra/loop~
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2011-01-10 06:03:02 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2011-01-10 06:03:02 +0000
commit5af7081222ef801b23857fb904c78d0798f5d0df (patch)
tree68ac177c010b99c8eb837ea323c69cb541497148 /externals/extra/loop~
parentb77e38f5d194fb2ed72563d8ed20815d02a88efc (diff)
build Pd's extra as a libdir
svn path=/trunk/; revision=14694
Diffstat (limited to 'externals/extra/loop~')
-rw-r--r--externals/extra/loop~/loop~-help.pd74
-rw-r--r--externals/extra/loop~/loop~.c164
-rw-r--r--externals/extra/loop~/test-loop~.pd58
3 files changed, 296 insertions, 0 deletions
diff --git a/externals/extra/loop~/loop~-help.pd b/externals/extra/loop~/loop~-help.pd
new file mode 100644
index 00000000..a445b805
--- /dev/null
+++ b/externals/extra/loop~/loop~-help.pd
@@ -0,0 +1,74 @@
+#N canvas 33 0 647 662 12;
+#X floatatom 41 204 0 0 0 0 - - -;
+#X obj 254 382 print~;
+#X msg 254 347 bang;
+#X obj 41 338 loop~;
+#X floatatom 66 279 0 0 0 0 - - -;
+#X msg 55 252 bang;
+#X obj 183 382 print~;
+#X msg 183 347 bang;
+#N canvas 0 0 450 300 graph1 0;
+#X array array2 150000 float 0;
+#X coords 0 1 150000 -1 200 150 1;
+#X restore 393 464 graph;
+#X msg 393 622 \; array2 resize 150000;
+#X obj 25 613 soundfiler;
+#X obj 16 453 tabread4~ array2;
+#X obj 16 407 *~;
+#X obj 16 522 dac~;
+#X obj 16 499 hip~ 5;
+#X obj 62 411 samphold~;
+#X obj 16 430 +~;
+#X floatatom 96 303 0 0 0 0 - - -;
+#X obj 96 326 *~ 1000;
+#X msg 43 568 read ../doc/sound/bell.aiff array2;
+#X msg 43 591 read ../doc/sound/vocal.aiff array2;
+#X msg 47 229 set 0.5;
+#X text 95 196 left signal input is transposition (1 is normal \, 2
+is up an octave \, etc);
+#X text 82 4 loop~ - phase generator for looping samplers;
+#X text 116 228 set phase (0 to 1);
+#X text 104 253 reset phase to 0;
+#X text 104 278 right signal input is window size in samples;
+#X text 134 302 here's how to handle onsets;
+#X obj 16 476 *~;
+#X floatatom 167 432 0 0 0 0 - - -;
+#X obj 167 501 line~;
+#X obj 167 455 dbtorms;
+#X obj 167 478 pack 0 50;
+#X text 201 431 output level 0-100;
+#X text 187 326 print outputs;
+#X text 33 32 loop~ takes input signals to set a window size and transposition
+\, and outputs a phase and a sampled window size. The window size only
+changes at phase zero crossings and the phase output is adjusted so
+that changing window size doesn't change the transposition.;
+#X text 33 112 You can send "bang" or "set" message to force the phase
+to zero--you should mute the output before doing so. This may be desirable
+if you've set a large window size but then want to decrease it without
+waiting for the next phase crossing.;
+#X connect 0 0 3 0;
+#X connect 2 0 1 0;
+#X connect 3 0 6 0;
+#X connect 3 0 12 0;
+#X connect 3 0 15 1;
+#X connect 3 1 1 0;
+#X connect 3 1 12 1;
+#X connect 4 0 3 1;
+#X connect 5 0 3 0;
+#X connect 7 0 6 0;
+#X connect 11 0 28 0;
+#X connect 12 0 16 0;
+#X connect 14 0 13 0;
+#X connect 14 0 13 1;
+#X connect 15 0 16 1;
+#X connect 16 0 11 0;
+#X connect 17 0 18 0;
+#X connect 18 0 15 0;
+#X connect 19 0 10 0;
+#X connect 20 0 10 0;
+#X connect 21 0 3 0;
+#X connect 28 0 14 0;
+#X connect 29 0 31 0;
+#X connect 30 0 28 1;
+#X connect 31 0 32 0;
+#X connect 32 0 30 0;
diff --git a/externals/extra/loop~/loop~.c b/externals/extra/loop~/loop~.c
new file mode 100644
index 00000000..2f440030
--- /dev/null
+++ b/externals/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/externals/extra/loop~/test-loop~.pd b/externals/extra/loop~/test-loop~.pd
new file mode 100644
index 00000000..9966483d
--- /dev/null
+++ b/externals/extra/loop~/test-loop~.pd
@@ -0,0 +1,58 @@
+#N canvas 33 0 680 609 12;
+#X floatatom 52 262 0 0 0 0 - - -;
+#X obj 261 346 print~;
+#X msg 47 373 bang;
+#X msg 274 313 bang;
+#X obj 52 306 loop~;
+#X floatatom 102 245 0 0 0 0 - - -;
+#N canvas 0 0 450 300 graph1 0;
+#X array array1 44100 float 0;
+#X coords 0 10 44100 0 200 150 1;
+#X restore 65 17 graph;
+#X msg 43 204 \; array1 resize 44100;
+#X obj 25 401 tabwrite~ array1;
+#X msg 208 371 bang;
+#X obj 176 402 tabwrite~ array1;
+#X msg 194 261 bang;
+#X obj 204 347 print~;
+#X msg 217 314 bang;
+#N canvas 0 0 450 300 graph1 0;
+#X array array2 150000 float 0;
+#X coords 0 1 150000 -1 200 150 1;
+#X restore 332 398 graph;
+#X msg 326 274 \; array2 resize 150000;
+#X obj 103 529 tabread4~ array2;
+#X obj 64 481 *~;
+#X obj 107 581 dac~;
+#X obj 105 552 hip~ 5;
+#X obj 123 482 samphold~;
+#X obj 102 506 +~;
+#X floatatom 106 430 0 0 0 0 - - -;
+#X obj 108 453 *~ 1000;
+#X obj 312 215 soundfiler;
+#X msg 330 170 read ../doc/sound/bell.aiff array2;
+#X msg 330 193 read ../doc/sound/vocal.aiff 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 17 0;
+#X connect 4 0 8 0;
+#X connect 4 0 20 1;
+#X connect 4 1 10 0;
+#X connect 4 1 1 0;
+#X connect 4 1 17 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 16 0 19 0;
+#X connect 17 0 21 0;
+#X connect 19 0 18 0;
+#X connect 19 0 18 1;
+#X connect 20 0 21 1;
+#X connect 21 0 16 0;
+#X connect 22 0 23 0;
+#X connect 23 0 20 0;
+#X connect 25 0 24 0;
+#X connect 26 0 24 0;