static void riddle_mute(t_riddle *rd, t_signal **sp) { int i, j, nouts = obj_nsigoutlets((t_object *)rd); t_rdsink *si = rd->rd_outslots; #ifdef RIDDLE_DEBUG riddlebug_post(rd, "MUTE", 0); #endif if (rd->rd_nsigoutlets != nouts) { loudbug_bug("riddle_mute"); riddle_validatesinks(rd); if (rd->rd_nsigoutlets != nouts) return; } i = 0; j = obj_nsiginlets((t_object *)rd); while (nouts--) { si->si_pattern = 0; si->si_block = sp[j]->s_n; si->si_outbuf[1].a_w.w_symbol = rdps__; si->si_outbuf[2].a_w.w_float = (t_float)si->si_block; si->si_isready = 1; dsp_add_zero(sp[j]->s_vec, sp[j]->s_n); i++; j++; si++; } }
t_sample* eobj_getsignaloutput(void *x, long index) { t_edsp* dsp = eobj_getdsp(x); if(dsp) { if(index < obj_nsigoutlets((t_object *)x) && index >= 0 && dsp->d_vectors) { if(dsp->d_misc == E_NO_INPLACE) return dsp->d_sigs_out[index]; else return (t_sample *)dsp->d_vectors[index + 7 + obj_nsiginlets((t_object *)x)]; } } return NULL; }
void eobj_dspsetup(void *x, long nins, long nouts) { int i; t_edsp* dsp = eobj_getdsp(x); if(dsp) { nins = (long)pd_clip_min(nins, 0); nouts = (long)pd_clip_min(nouts, 0); dsp->d_sigs_out = NULL; dsp->d_sigs_real = NULL; dsp->d_perform_method = NULL; dsp->d_size = 0; dsp->d_vectors = NULL; dsp->d_misc = E_INPLACE; for(i = obj_nsigoutlets((t_object *)x); i < nouts; i++) { outlet_new((t_object *)x, &s_signal); } for(i = obj_nsiginlets((t_object *)x); i < nins; i++) { eproxy_new(x, &s_signal); } } }
void eobj_dsp(void *x, t_signal **sp) { int i; short* count; t_int* temp; t_float **tempout, *tempreal; t_linetraverser t; t_outconnect *oc; t_eclass* c = eobj_getclass(x); t_edsp* dsp = eobj_getdsp(x); int nouts = obj_nsigoutlets((t_object *)x); int nins = obj_nsiginlets((t_object *)x); int samplesize; if(c && c->c_widget.w_dsp && dsp && (nins || nouts) && sp && sp[0]) { samplesize = sp[0]->s_n; dsp->d_perform_method = NULL; if(dsp->d_misc == E_NO_INPLACE) { if(dsp->d_sigs_out) { tempout = (t_float **)realloc(dsp->d_sigs_out, (size_t)nouts * sizeof(t_float *)); } else { tempout = (t_float **)malloc((size_t)nouts * sizeof(t_float *)); } if(!tempout) { if(dsp->d_sigs_out) { free(dsp->d_sigs_out); dsp->d_sigs_out = NULL; } pd_error(dsp, "can't allocate memory for ni inpace processing."); return; } dsp->d_sigs_out = tempout; if(dsp->d_sigs_real) { tempreal = (t_float *)realloc(dsp->d_sigs_real, (size_t)(nouts * samplesize) * sizeof(t_float)); } else { tempreal = (t_float *)malloc((size_t)(nouts * samplesize) * sizeof(t_float)); } if(!tempreal) { if(dsp->d_sigs_real) { free(dsp->d_sigs_real); dsp->d_sigs_real = NULL; } free(dsp->d_sigs_out); dsp->d_sigs_out = NULL; pd_error(dsp, "can't allocate memory for ni inpace processing."); return; } dsp->d_sigs_real = tempreal; for(i = 0; i < nouts; i++) { dsp->d_sigs_out[i] = dsp->d_sigs_real+i*samplesize; } } if(dsp->d_vectors) { temp = (t_int *)realloc(dsp->d_vectors, (size_t)(nins + nouts + 7) * sizeof(t_int)); } else { temp = (t_int *)malloc((size_t)(nins + nouts + 7) * sizeof(t_int)); } if(!temp) { if(dsp->d_vectors) { free(dsp->d_vectors); dsp->d_vectors = NULL; } free(dsp->d_sigs_real); dsp->d_sigs_real = NULL; free(dsp->d_sigs_out); dsp->d_sigs_out = NULL; dsp->d_size = 0; pd_error(x, "can't allocate memory for dsp vector."); return; } dsp->d_vectors = temp; dsp->d_size = nins + nouts + 7; count = (short*)malloc((size_t)(nins + nouts) * sizeof(short)); if(count) { for(i = 0; i < (nins + nouts); i++) { count[i] = 0; } linetraverser_start(&t, eobj_getcanvas(x)); while((oc = linetraverser_next(&t))) { if(t.tr_ob2 == x && obj_issignaloutlet(t.tr_ob, t.tr_outno)) { count[t.tr_inno] = 1; } } dsp->d_vectors[0] = (t_int)x; dsp->d_vectors[1] = (t_int)dsp; dsp->d_vectors[2] = (t_int)sp[0]->s_n; dsp->d_vectors[3] = (t_int)dsp->d_flags; dsp->d_vectors[4] = (t_int)dsp->d_user_param; dsp->d_vectors[5] = (t_int)nins; dsp->d_vectors[6] = (t_int)nouts; for(i = 7; i < dsp->d_size; i++) { if(sp[i - 7] && sp[i - 7]->s_vec) { dsp->d_vectors[i] = (t_int)(sp[i - 7]->s_vec); } else { free(count); free(dsp->d_vectors); dsp->d_vectors = NULL; free(dsp->d_sigs_real); dsp->d_sigs_real = NULL; free(dsp->d_sigs_out); dsp->d_sigs_out = NULL; dsp->d_size = 0; pd_error(x, "one of the signal isn't allocated."); return; } } c->c_widget.w_dsp(x, x, count, sp[0]->s_sr, sp[0]->s_n, 0); if(dsp->d_perform_method != NULL && dsp->d_misc == E_INPLACE) { dsp_addv(eobj_perform_inplace, (int)dsp->d_size, dsp->d_vectors); } else if(dsp->d_perform_method != NULL && dsp->d_misc == E_NO_INPLACE) { dsp_addv(eobj_perform_noinplace, (int)dsp->d_size, dsp->d_vectors); } free(count); return; } else { free(dsp->d_vectors); dsp->d_vectors = NULL; free(dsp->d_sigs_real); dsp->d_sigs_real = NULL; free(dsp->d_sigs_out); dsp->d_sigs_out = NULL; dsp->d_size = 0; pd_error(x, "can't allocate memory for dsp chain counter."); } } }
static void *riddle_new(t_symbol *s, int ac, t_atom *av) { /* IFBUILTIN remove: this is a bad hack */ t_pd *en = riddle_getenvironment(); t_newgimme newfn = (t_newgimme)zgetfn(en, s); if (!newfn) { loudbug_bug("riddle_new 1"); return (0); } else { t_riddle *rd = (t_riddle *)newfn(s, ac, av); int i, nslots; t_rdsource *inslot; t_rdsink *outslot; t_rdremote *re; if (!rd) return (0); rd->rd_private = getbytes(sizeof(*rd->rd_private)); rd->rd_disabled = 0; rd->rd_wasdisabled = 0; rd->rd_blockfn = (t_rdblockfn)zgetfn((t_pd *)rd, gensym("dspblock")); rd->rd_dspfn = (t_rddspfn)zgetfn((t_pd *)rd, gensym("_dsp")); if (!rd->rd_dspfn) loudbug_bug("riddle_new 2"); rd->rd_graphsr = (int)sys_getsr(); rd->rd_graphblock = sys_getblksize(); rd->rd_nsiginlets = obj_nsiginlets((t_object *)rd); rd->rd_nsigoutlets = obj_nsigoutlets((t_object *)rd); /* currently, rd_nremoteslots is incremented in rdbuffer_newreader(), which relies on calloc in pd_new(), LATER rethink */ nslots = rd->rd_nsiginlets + rd->rd_nremoteslots; rd->rd_inslots = getbytes(nslots * sizeof(*rd->rd_inslots)); for (i = 0, inslot = rd->rd_inslots; i < nslots; i++, inslot++) { inslot->so_riddle = rd; inslot->so_remote = 0; inslot->so_sourcecount = 0; inslot->so_pattern = 0; inslot->so_newpattern = 0; inslot->so_block = 0; inslot->so_newblock = 0; inslot->so_flags = 0; } rd->rd_remoteslots = rd->rd_inslots + rd->rd_nsiginlets; for (i = 0, inslot = rd->rd_remoteslots, re = rd->rd_remoteports; i < rd->rd_nremoteslots; i++, inslot++) { if (re = rdremote_nextreader(re)) inslot->so_remote = re; else { loudbug_bug("riddle_new 3"); break; /* FIXME this is fatal */ } } rd->rd_outslots = getbytes(rd->rd_nsigoutlets * sizeof(*rd->rd_outslots)); for (i = 0, outslot = rd->rd_outslots; i < rd->rd_nsigoutlets; i++, outslot++) { outslot->si_riddle = rd; outslot->si_outno = -1; outslot->si_pattern = 0; outslot->si_block = 0; outslot->si_flags = 0; outslot->si_outbuf[0].a_type = A_FLOAT; outslot->si_outbuf[1].a_type = A_SYMBOL; outslot->si_outbuf[1].a_w.w_symbol = rdps__; outslot->si_outbuf[2].a_type = A_FLOAT; outslot->si_outbuf[3].a_type = A_FLOAT; outslot->si_outbuf[3].a_w.w_float = 0.; outslot->si_feedchain = 0; outslot->si_isready = 0; } riddle_validatesinks(rd); for (i = 0, outslot = rd->rd_outslots; i < rd->rd_nsigoutlets; i++, outslot++) if (outslot->si_outno >= 0) outslot->si_feedchain = rdfeedchain_new(outslot->si_outno); rd->rd_idlepicker = rdpicker_attach(rd, gensym("_idle")); return (rd); } }