summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/intern/phasor~.c
diff options
context:
space:
mode:
authorPeter D'Hoye <peter.dhoye@gmail.com>2009-05-22 21:58:48 +0000
committerPeter D'Hoye <peter.dhoye@gmail.com>2009-05-22 21:58:48 +0000
commit513389b4c1bc8afe4b2dc9947c534bfeb105e3da (patch)
tree10e673b35651ac567fed2eda0c679c7ade64cbc6 /apps/plugins/pdbox/PDa/intern/phasor~.c
parent95fa7f6a2ef466444fbe3fe87efc6d5db6b77b36 (diff)
downloadrockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.zip
rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.tar.gz
rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.tar.bz2
rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.tar.xz
Add FS #10214. Initial commit of the original PDa code for the GSoC Pure Data plugin project of Wincent Balin. Stripped some non-sourcefiles and added a rockbox readme that needs a bit more info from Wincent. Is added to CATEGORIES and viewers, but not yet to SUBDIRS (ie doesn't build yet)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21044 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pdbox/PDa/intern/phasor~.c')
-rw-r--r--apps/plugins/pdbox/PDa/intern/phasor~.c138
1 files changed, 138 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/intern/phasor~.c b/apps/plugins/pdbox/PDa/intern/phasor~.c
new file mode 100644
index 0000000..b823286
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/intern/phasor~.c
@@ -0,0 +1,138 @@
+
+#include <m_pd.h>
+#include <m_fixed.h>
+
+/* -------------------------- phasor~ ------------------------------ */
+static t_class *phasor_class;
+
+typedef struct _phasor
+{
+ t_object x_obj;
+ unsigned int x_phase;
+ t_sample x_conv;
+ t_sample x_f; /* scalar frequency */
+} t_phasor;
+
+static void *phasor_new(t_floatarg f)
+{
+ t_phasor *x = (t_phasor *)pd_new(phasor_class);
+ x->x_f = ftofix(f);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1"));
+ x->x_phase = 0;
+ x->x_conv = 0;
+ outlet_new(&x->x_obj, gensym("signal"));
+ return (x);
+}
+
+static t_int *phasor_perform(t_int *w)
+{
+ t_phasor *x = (t_phasor *)(w[1]);
+ t_sample *in = (t_sample *)(w[2]);
+ t_sample *out = (t_sample *)(w[3]);
+ int n = (int)(w[4]);
+ unsigned int phase = x->x_phase;
+ int conv = x->x_conv;
+
+ while (n--) {
+ phase+= mult(conv , (*in++));
+ phase &= (itofix(1) - 1);
+ *out++ = phase;
+ }
+ x->x_phase = phase;
+
+ return (w+5);
+}
+
+static void phasor_dsp(t_phasor *x, t_signal **sp)
+{
+ x->x_conv = ftofix(1000.)/sp[0]->s_sr;
+ x->x_conv = mult(x->x_conv + 500,ftofix(0.001));
+ dsp_add(phasor_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
+}
+
+
+static void phasor_ft1(t_phasor *x, t_float f)
+{
+ x->x_phase = ftofix(f);
+}
+
+void phasor_tilde_setup(void)
+{
+ phasor_class = class_new(gensym("phasor~"), (t_newmethod)phasor_new, 0,
+ sizeof(t_phasor), 0, A_DEFFLOAT, 0);
+ CLASS_MAINSIGNALIN(phasor_class, t_phasor, x_f);
+ class_addmethod(phasor_class, (t_method)phasor_dsp, gensym("dsp"), 0);
+ class_addmethod(phasor_class, (t_method)phasor_ft1,
+ gensym("ft1"), A_FLOAT, 0);
+ class_sethelpsymbol(phasor_class, gensym("osc~-help.pd"));
+}
+
+
+#include <m_pd.h>
+#include <m_fixed.h>
+
+/* -------------------------- phasor~ ------------------------------ */
+static t_class *phasor_class;
+
+typedef struct _phasor
+{
+ t_object x_obj;
+ unsigned int x_phase;
+ t_sample x_conv;
+ t_sample x_f; /* scalar frequency */
+} t_phasor;
+
+static void *phasor_new(t_floatarg f)
+{
+ t_phasor *x = (t_phasor *)pd_new(phasor_class);
+ x->x_f = ftofix(f);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1"));
+ x->x_phase = 0;
+ x->x_conv = 0;
+ outlet_new(&x->x_obj, gensym("signal"));
+ return (x);
+}
+
+static t_int *phasor_perform(t_int *w)
+{
+ t_phasor *x = (t_phasor *)(w[1]);
+ t_sample *in = (t_sample *)(w[2]);
+ t_sample *out = (t_sample *)(w[3]);
+ int n = (int)(w[4]);
+ unsigned int phase = x->x_phase;
+ int conv = x->x_conv;
+
+ while (n--) {
+ phase+= mult(conv , (*in++));
+ phase &= (itofix(1) - 1);
+ *out++ = phase;
+ }
+ x->x_phase = phase;
+
+ return (w+5);
+}
+
+static void phasor_dsp(t_phasor *x, t_signal **sp)
+{
+ x->x_conv = ftofix(1000.)/sp[0]->s_sr;
+ x->x_conv = mult(x->x_conv + 500,ftofix(0.001));
+ dsp_add(phasor_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
+}
+
+
+static void phasor_ft1(t_phasor *x, t_float f)
+{
+ x->x_phase = ftofix(f);
+}
+
+void phasor_tilde_setup(void)
+{
+ phasor_class = class_new(gensym("phasor~"), (t_newmethod)phasor_new, 0,
+ sizeof(t_phasor), 0, A_DEFFLOAT, 0);
+ CLASS_MAINSIGNALIN(phasor_class, t_phasor, x_f);
+ class_addmethod(phasor_class, (t_method)phasor_dsp, gensym("dsp"), 0);
+ class_addmethod(phasor_class, (t_method)phasor_ft1,
+ gensym("ft1"), A_FLOAT, 0);
+ class_sethelpsymbol(phasor_class, gensym("osc~-help.pd"));
+}
+