Skip to content

Commit

Permalink
slew~
Browse files Browse the repository at this point in the history
  • Loading branch information
porres committed Aug 4, 2023
1 parent fd54de4 commit 8e2ef63
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 41 deletions.
26 changes: 17 additions & 9 deletions Code_source/Compiled/signal/glide~.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,17 @@ static float glide_get_step(t_glide *x, t_floatarg delta){
static t_int *glide_perform(t_int *w){
t_glide *x = (t_glide *)(w[1]);
int n = (int)(w[2]);
t_float *in1 = (t_float *)(w[3]);
t_float *in2 = (t_float *)(w[4]);
t_float *out = (t_float *)(w[5]);
int ch2 = (int)(w[3]);
t_float *in1 = (t_float *)(w[4]);
t_float *in2 = (t_float *)(w[5]);
t_float *out = (t_float *)(w[6]);
float *last_in = x->x_last_in;
float *last_out = x->x_last_out;
float *start = x->x_start;
for(int j = 0; j < x->x_nchans; j++){
for(int i = 0; i < n; i++){
t_float in = in1[j*n + i];
t_float ms = in2[i];
t_float ms = ch2 == 1 ? in2[i] : in2[j*n + i];
if(ms <= 0)
ms = 0;
x->x_n = (int)roundf(ms * x->x_sr_khz) + 1; // n samples
Expand All @@ -68,9 +69,11 @@ static t_int *glide_perform(t_int *w){
else{
float delta = (in - last_out[j]);
if(x->x_reset){ // reset
x->x_nleft = 0;
x->x_reset = 0;
out[j*n + i] = last_out[j] = last_in[j] = in;
if(j == (x->x_nchans - 1)){
x->x_reset = 0;
x->x_nleft = 0;
}
}
else if(in != last_in[j]){ // input change, update
start[j] = last_out[j];
Expand All @@ -94,12 +97,12 @@ static t_int *glide_perform(t_int *w){
x->x_start = start;
x->x_last_in = last_in;
x->x_last_out = last_out;
return(w+6);
return(w+7);
}

static void glide_dsp(t_glide *x, t_signal **sp){
x->x_sr_khz = sp[0]->s_sr * 0.001;
int chs = sp[0]->s_nchans, n = sp[0]->s_n;
int chs = sp[0]->s_nchans, ch2 = sp[1]->s_nchans, n = sp[0]->s_n;
signal_setmultiout(&sp[2], chs);
if(x->x_nchans != chs){
x->x_last_in = (t_float *)resizebytes(x->x_last_in,
Expand All @@ -110,7 +113,12 @@ static void glide_dsp(t_glide *x, t_signal **sp){
x->x_nchans * sizeof(t_float), chs * sizeof(t_float));
x->x_nchans = chs;
}
dsp_add(glide_perform, 5, x, n, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec);
if(ch2 > 1 && ch2 != x->x_nchans){
dsp_add_zero(sp[2]->s_vec, chs*n);
pd_error(x, "[glide~]: channel sizes mismatch");
}
else
dsp_add(glide_perform, 6, x, n, ch2, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec);
}

static void *glide_free(t_glide *x){
Expand Down
74 changes: 49 additions & 25 deletions Code_source/Compiled/signal/lag~.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,63 +9,87 @@ typedef struct _lag{
t_object x_obj;
t_float x_in;
t_inlet *x_inlet_ms;
t_outlet *x_out;
t_float x_sr_khz;
double x_ynm1;
double *x_last_out;
int x_reset;
int x_nchans;
}t_lag;

static t_class *lag_class;

static t_int *lag_perform(t_int *w){
t_lag *x = (t_lag *)(w[1]);
int n = (int)(w[2]);
t_float *in1 = (t_float *)(w[3]);
t_float *in2 = (t_float *)(w[4]);
t_float *out = (t_float *)(w[5]);
int ch2 = (int)(w[3]);
t_float *in1 = (t_float *)(w[4]);
t_float *in2 = (t_float *)(w[5]);
t_float *out = (t_float *)(w[6]);
t_float sr_khz = x->x_sr_khz;
double ynm1 = x->x_ynm1;
while(n--){
double xn = *in1++, ms = *in2++;
if(x->x_reset){ // reset
x->x_reset = 0;
*out++ = ynm1 = xn;
}
else{
if(ms <= 0)
*out++ = ynm1 = xn;
double *last_out = x->x_last_out;
for(int j = 0; j < x->x_nchans; j++){
for(int i = 0; i < n; i++){
double in = in1[j*n + i];
double ms = ch2 == 1 ? in2[i] : in2[j*n + i];
if(x->x_reset){ // reset
out[j*n + i] = last_out[j] = in;
if(j == (x->x_nchans - 1))
x->x_reset = 0;
}
else{
double a = exp(LOG001 / (ms * sr_khz));
*out++ = ynm1 = xn + a*(ynm1 - xn);
if(ms <= 0)
out[j*n + i] = last_out[j] = in;
else{
double a = exp(LOG001 / (ms * sr_khz));
out[j*n + i] = last_out[j] = in + a*(last_out[j] - in);
}
}
}
}
x->x_ynm1 = ynm1;
return(w+6);
x->x_last_out = last_out;
return(w+7);
}

static void lag_dsp(t_lag *x, t_signal **sp){
x->x_sr_khz = sp[0]->s_sr * 0.001;
dsp_add(lag_perform, 5, x, sp[0]->s_n, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec);
int chs = sp[0]->s_nchans, ch2 = sp[1]->s_nchans, n = sp[0]->s_n;
signal_setmultiout(&sp[2], chs);
if(x->x_nchans != chs){
x->x_last_out = (double *)resizebytes(x->x_last_out,
x->x_nchans * sizeof(double), chs * sizeof(double));
x->x_nchans = chs;
}
if(ch2 > 1 && ch2 != x->x_nchans){
dsp_add_zero(sp[2]->s_vec, chs*n);
pd_error(x, "[lag~]: channel sizes mismatch");
}
else
dsp_add(lag_perform, 6, x, n, ch2, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec);
}

static void lag_reset(t_lag *x){
x->x_reset = 1;
}

static void *lag_free(t_lag *x){
inlet_free(x->x_inlet_ms);
freebytes(x->x_last_out, x->x_nchans * sizeof(*x->x_last_out));
return(void *)x;
}

static void *lag_new(t_floatarg f){
t_lag *x = (t_lag *)pd_new(lag_class);
x->x_last_out = (double *)getbytes(sizeof(*x->x_last_out));
x->x_reset = 0;
x->x_inlet_ms = inlet_new((t_object *)x, (t_pd *)x, &s_signal, &s_signal);
pd_float((t_pd *)x->x_inlet_ms, f);
x->x_out = outlet_new((t_object *)x, &s_signal);
pd_float((t_pd *)x->x_inlet_ms, f);
outlet_new((t_object *)x, &s_signal);
return(x);
}

void lag_tilde_setup(void){
lag_class = class_new(gensym("lag~"), (t_newmethod)lag_new, 0,
sizeof(t_lag), 0, A_DEFFLOAT, 0);
CLASS_MAINSIGNALIN(lag_class, t_lag, x_in);
lag_class = class_new(gensym("lag~"), (t_newmethod)lag_new, (t_method)lag_free,
sizeof(t_lag), CLASS_MULTICHANNEL, A_DEFFLOAT, 0);
class_addmethod(lag_class, nullfn, gensym("signal"), 0);
class_addmethod(lag_class, (t_method)lag_dsp, gensym("dsp"), A_CANT, 0);
class_addmethod(lag_class, (t_method)lag_reset, gensym("reset"), 0);
}
20 changes: 13 additions & 7 deletions Code_source/Compiled/signal/slew~.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ static t_class *slew_class;
static t_int *slew_perform(t_int *w){
t_slew *x = (t_slew *)(w[1]);
int n = (int)(w[2]);
t_float *in1 = (t_float *)(w[3]);
t_float *in2 = (t_float *)(w[4]);
t_float *out = (t_float *)(w[5]);
int ch2 = (int)(w[3]);
t_float *in1 = (t_float *)(w[4]);
t_float *in2 = (t_float *)(w[5]);
t_float *out = (t_float *)(w[6]);
t_float *lastin = x->x_lastin;
for(int j = 0; j < x->x_nchans; j++){
for(int i = 0; i < n; i++){
float in = in1[j*n + i];
float limit = in2[i];
float limit = ch2 == 1 ? in2[i] : in2[j*n + i];
if(limit < 0)
out[j*n + i] = lastin[j] = in;
else{
Expand All @@ -38,19 +39,24 @@ static t_int *slew_perform(t_int *w){
}
}
x->x_lastin = lastin;
return(w+6);
return(w+7);
}

static void slew_dsp(t_slew *x, t_signal **sp){
x->x_sr_rec = 1 / sp[0]->s_sr;
int chs = sp[0]->s_nchans, n = sp[0]->s_n;
int chs = sp[0]->s_nchans, ch2 = sp[1]->s_nchans, n = sp[0]->s_n;
signal_setmultiout(&sp[2], chs);
if(x->x_nchans != chs){
x->x_lastin = (t_float *)resizebytes(x->x_lastin,
x->x_nchans * sizeof(t_float), chs * sizeof(t_float));
x->x_nchans = chs;
}
dsp_add(slew_perform, 5, x, n, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec);
if(ch2 > 1 && ch2 != x->x_nchans){
dsp_add_zero(sp[2]->s_vec, chs*n);
pd_error(x, "[slew~]: channel sizes mismatch");
}
else
dsp_add(slew_perform, 6, x, n, ch2, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec);
}

static void slew_set(t_slew *x, t_symbol *s, int ac, t_atom *av){
Expand Down

0 comments on commit 8e2ef63

Please sign in to comment.