diff options
author | IOhannes m zmölnig <zmoelnig@iem.at> | 2015-10-14 15:14:38 +0200 |
---|---|---|
committer | IOhannes m zmölnig <zmoelnig@iem.at> | 2015-10-14 15:14:38 +0200 |
commit | 28b7e464fd119b8c848753a1f41070422c463c41 (patch) | |
tree | 07449abdf85d8f1fd4068839b974242b429720ca /block_delay~/block_delay~.c | |
parent | 90c6018a9401e38859f733b3521c919e042322b7 (diff) | |
parent | 6932ee2d22511226378218992b0005cb01eb235e (diff) |
Merge branchesHEADsvn2git-headmaster
- abstractions/tb
- externals/tb
Diffstat (limited to 'block_delay~/block_delay~.c')
-rw-r--r-- | block_delay~/block_delay~.c | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/block_delay~/block_delay~.c b/block_delay~/block_delay~.c new file mode 100644 index 0000000..f5cfa4c --- /dev/null +++ b/block_delay~/block_delay~.c @@ -0,0 +1,99 @@ +/* this external is based on nop~ which was part of zexy-1.x, see the copyright notice below: + + * ZEXY is published under the GNU GeneralPublicLicense, that must be shipped with ZEXY. + * if you are using Debian GNU/linux, the GNU-GPL can be found under /usr/share/common-licenses/GPL + * if you still haven't found a copy of the GNU-GPL, have a look at http://www.gnu.org + * + * "pure data" has it's own license, that comes shipped with "pure data". + * + * there are ABSOLUTELY NO WARRANTIES for anything + + it does absolutely the same as z~ 64, but since it uses simd instructions, it's faster. +*/ + + + +/* ------------------------ block_delay~ ----------------------------- */ +/* this will pass trough the signal unchanged except for a delay of 1 block */ + +#include "m_pd.h" + +static t_class *block_delay_tilde_class; + +typedef struct _block_delay +{ + t_object x_obj; + t_float *buf; + int n; + int toggle; +} t_block_delay; + + +static t_int *block_delay_tilde_perfsimd(t_int *w) +{ + t_float *in = (t_float *)w[1]; + t_float *out = (t_float *)w[2]; + t_block_delay *x = (t_block_delay *)w[3]; + int n = x->n; + t_float *rp = x->buf + n * x->toggle, *wp = x->buf + n * (x->toggle ^= 1); + + copyvec_simd(wp, in, n); + copyvec_simd(out, rp, n); + + return (w+4); +} + +static t_int *block_delay_tilde_perform(t_int *w) +{ + t_float *in = (t_float *)w[1]; + t_float *out = (t_float *)w[2]; + t_block_delay *x = (t_block_delay *)w[3]; + int n = x->n; + t_float *rp = x->buf + n * x->toggle, *wp = x->buf + n * (x->toggle ^= 1); + + while (n--) { + *wp++ = *in++; + *out++ = *rp++; + } + + return (w+4); +} + +static void block_delay_tilde_dsp(t_block_delay *x, t_signal **sp) +{ + if (x->n != sp[0]->s_n) + { + if (x->n) + freealignedbytes(x->buf, x->n * 2 * sizeof(t_float)); + x->buf = (t_float *)getalignedbytes(sizeof(t_float) * 2 * (x->n = sp[0]->s_n)); + } + if (simd_check2(sp[0]->s_n, sp[0]->s_vec, sp[1]->s_vec)) + dsp_add(block_delay_tilde_perfsimd, 3, sp[0]->s_vec, sp[1]->s_vec, x); + else + dsp_add(block_delay_tilde_perform, 3, sp[0]->s_vec, sp[1]->s_vec, x); +} + +static void block_delay_tilde_free(t_block_delay *x) +{ + if (x->buf) + freealignedbytes(x->buf, x->n * sizeof(t_float)); +} + + +static void *block_delay_tilde_new(void) +{ + t_block_delay *x = (t_block_delay *)pd_new(block_delay_tilde_class); + outlet_new(&x->x_obj, gensym("signal")); + x->toggle = 0; + x->n = 0; + + return (x); +} + +void block_delay_tilde_setup(void) +{ + block_delay_tilde_class = class_new(gensym("block_delay~"), (t_newmethod)block_delay_tilde_new, (t_method)block_delay_tilde_free, + sizeof(t_block_delay), 0, A_DEFFLOAT, 0); + class_addmethod(block_delay_tilde_class, nullfn, gensym("signal"), 0); + class_addmethod(block_delay_tilde_class, (t_method)block_delay_tilde_dsp, gensym("dsp"), 0); +} |