static int phaser1set(CSOUND *csound, PHASER1 *p) { int loop = (int) MYFLT2LONG(*p->iorder); int32 nBytes = (int32) loop * (int32) sizeof(MYFLT); if (*p->istor == FL(0.0) || p->auxx.auxp == NULL || (int)p->auxx.size<nBytes || p->auxy.auxp == NULL || (int)p->auxy.size<nBytes) { csound->AuxAlloc(csound, nBytes, &p->auxx); csound->AuxAlloc(csound, nBytes, &p->auxy); p->xnm1 = (MYFLT *) p->auxx.auxp; p->ynm1 = (MYFLT *) p->auxy.auxp; } else if ((int32) p->auxx.size < nBytes || (int32) p->auxy.size < nBytes) { /* Existing arrays too small so copy */ void *tmp1, *tmp2; size_t oldSize1 = (size_t) p->auxx.size; size_t oldSize2 = (size_t) p->auxy.size; tmp1 = malloc(oldSize1 + oldSize2); tmp2 = (char*) tmp1 + (int) oldSize1; memcpy(tmp1, p->auxx.auxp, oldSize1); memcpy(tmp2, p->auxy.auxp, oldSize2); csound->AuxAlloc(csound, nBytes, &p->auxx); csound->AuxAlloc(csound, nBytes, &p->auxy); memcpy(p->auxx.auxp, tmp1, oldSize1); memcpy(p->auxy.auxp, tmp2, oldSize2); free(tmp1); p->xnm1 = (MYFLT *) p->auxx.auxp; p->ynm1 = (MYFLT *) p->auxy.auxp; } p->loop = loop; return OK; }
static int check(CSOUND *csound, CNTRL *p) { CONTROL_GLOBALS *pp = get_globals(csound, &(p->p)); readvalues(pp); *p->kdest = pp->checks[(int) MYFLT2LONG(*p->kcntl)]; return OK; }
static int button(CSOUND *csound, CNTRL *p) { CONTROL_GLOBALS *pp = get_globals(csound, &(p->p)); int t = (int)MYFLT2LONG(*p->kcntl); readvalues(pp); *p->kdest = pp->buttons[t]; pp->buttons[t] = 0; return OK; }
static int32_t lowpr_w_sep_set(CSOUND *csound, LOWPR_SEP *p) { int32_t j; if ((p->loop = (int32_t) MYFLT2LONG(*p->ord)) < 1) p->loop = 4; /*default value*/ else if (UNLIKELY(p->loop > 10)) { return csound->InitError(csound, Str("illegal order num. (min 1, max 10)")); } for (j=0; j< p->loop; j++) p->ynm1[j] = p->ynm2[j] = FL(0.0); return OK; }
static int check_set(CSOUND *csound, CNTRL *p) { CONTROL_GLOBALS *pp = get_globals(csound, &(p->p)); int n = (int) MYFLT2LONG(*p->kcntl); if (pp->wish_pid == 0) start_tcl_tk(pp); if (n > pp->max_check) { pp->checks = (int*) realloc(pp->checks, (n + 1) * sizeof(int)); do { pp->checks[++(pp->max_check)] = 0; } while (pp->max_check < n); } fprintf(pp->wish_cmd, "displaycheck %d\n", n); return OK; }
static int ocontrol_(CSOUND *csound, SCNTRL *p, int istring) { CONTROL_GLOBALS *pp = get_globals(csound, &(p->p)); int c = (int) *p->which; int slider = (int) MYFLT2LONG(*p->kcntl); /* csound->Message(csound, "ocontrol: %d %d %f\n", slider, c, *p->val); */ ensure_slider(pp, slider); switch (c) { case 1: fprintf(pp->wish_cmd, "setvalue %d %d\n", slider, (int) *p->val); pp->values[slider] = (int) *p->val; break; case 2: if (pp->minvals[slider] != (int) *p->val) { fprintf(pp->wish_cmd, "setmin %d %d\n", slider, (int) *p->val); pp->minvals[slider] = (int) *p->val; } break; case 3: if (pp->maxvals[slider] != (int) *p->val) { fprintf(pp->wish_cmd, "setmax %d %d\n", slider, (int) *p->val); pp->maxvals[slider] = (int) *p->val; } break; case 4: { char buffer[100]; if(istring) { csound->strarg2name(csound, buffer, ((STRINGDAT *)p->val)->data, "Control ",istring); } else csound->strarg2name(csound, buffer, p->val, "Control ",istring); csound->Message(csound, Str("Slider %d set to %s\n"), slider, buffer); fprintf(pp->wish_cmd, "setlab %d \"%s\"\n", slider, buffer); break; } default: return csound->InitError(csound, Str("Unknown control %d"), c); } return OK; }
static int phaser2set(CSOUND *csound, PHASER2 *p) { int modetype; int loop; p->modetype = modetype = (int)*p->mode; if (UNLIKELY(UNLIKELY(modetype && modetype != 1 && modetype != 2))) { return csound->InitError(csound, Str("Phaser mode must be either 1 or 2")); } loop = p->loop = (int) MYFLT2LONG(*p->order); csound->AuxAlloc(csound, (size_t)loop*sizeof(MYFLT), &p->aux1); csound->AuxAlloc(csound, (size_t)loop*sizeof(MYFLT), &p->aux2); p->nm1 = (MYFLT *) p->aux1.auxp; p->nm2 = (MYFLT *) p->aux2.auxp; /* *** This is unnecessary as AuxAlloc zeros *** */ /* for (j=0; j< loop; j++) */ /* p->nm1[j] = p->nm2[j] = FL(0.0); */ return OK; }
static int textflash_(CSOUND *csound, TXTWIN *p, int istring) { CONTROL_GLOBALS *pp = get_globals(csound, &(p->p)); int wind = (int) MYFLT2LONG(*p->kcntl); char buffer[100]; if (pp->wish_pid == 0) start_tcl_tk(pp); if (istring) { csound->strarg2name(csound, buffer, ((STRINGDAT *)p->val)->data, "", istring); /* csound->Message(csound, "settext %d \"%s\"\n", wind, buffer); */ fprintf(pp->wish_cmd, "settext %d \"%s\"\n", wind, buffer); } else if(ISSTRCOD(*p->val)) { csound->strarg2name(csound, buffer, csound->GetString(csound, *p->val), "", 1); } else { /* csound->Message(csound, "deltext %d\n", wind); */ fprintf(pp->wish_cmd, "deltext %d\n", wind); } return OK; }
int vbap_zak_moving_init(CSOUND *csound, VBAP_ZAK_MOVING *p) { int i, j, indx; MYFLT *ls_table, *ptr; LS_SET *ls_set_ptr; int n = p->n; p->n = (int)MYFLT2LONG(*p->numb); /* Set size */ /* Check to see this index is within the limits of za space. */ indx = (int32) *p->ndx; if (UNLIKELY(indx > csound->zalast)) { return csound->PerfError(csound, p->h.insdshead, Str("outz index > isizea. No output")); } else if (UNLIKELY(indx < 0)) { return csound->PerfError(csound, p->h.insdshead, Str("outz index < 0. No output.")); } /* Now read from the array in za space and write to the output. */ p->out_array = csound->zastart + (indx * CS_KSMPS);/* outputs */ csound->AuxAlloc(csound, p->n*sizeof(MYFLT)*4, &p->auxch); p->curr_gains = (MYFLT*)p->auxch.auxp; p->beg_gains = p->curr_gains + p->n; p->end_gains = p->beg_gains + p->n; p->updated_gains = p->end_gains + p->n; /* reading in loudspeaker info */ ls_table = (MYFLT*) (csound->QueryGlobalVariableNoCheck(csound, "vbap_ls_table_0")); p->dim = (int) ls_table[0]; p->ls_am = (int) ls_table[1]; p->ls_set_am = (int) ls_table[2]; ptr = &(ls_table[3]); csound->AuxAlloc(csound, p->ls_set_am * sizeof (LS_SET), &p->aux); if (UNLIKELY(p->aux.auxp == NULL)) { return csound->InitError(csound, Str("could not allocate memory")); } p->ls_sets = (LS_SET*) p->aux.auxp; ls_set_ptr = p->ls_sets; for (i=0 ; i < p->ls_set_am ; i++) { ls_set_ptr[i].ls_nos[2] = 0; /* initial setting */ for (j=0 ; j < p->dim ; j++) { ls_set_ptr[i].ls_nos[j] = (int) *(ptr++); } for (j=0 ; j < 9; j++) ls_set_ptr[i].ls_mx[j] = FL(0.0); /* initial setting */ for (j=0 ; j < (p->dim) * (p->dim); j++) { ls_set_ptr[i].ls_mx[j] = (MYFLT) *(ptr++); } } /* other initialization */ p->ele_vel = FL(1.0); /* functions specific to movement */ if (UNLIKELY(fabs(*p->field_am) < (2+ (p->dim - 2)*2))) { return csound->InitError(csound, Str("Have to have at least %d directions in vbapzmove"), 2 + (p->dim - 2) * 2); } if (p->dim == 2) p->point_change_interval = (int) (CS_EKR * *p->dur / (fabs(*p->field_am) - 1.0)); else if (LIKELY(p->dim == 3)) p->point_change_interval = (int) (CS_EKR * *p->dur / (fabs(*p->field_am) * 0.5 - 1.0)); else return csound->InitError(csound, Str("Wrong dimension")); p->point_change_counter = 0; p->curr_fld = 0; p->next_fld = 1; p->ang_dir.azi = *p->fld[0]; if (p->dim == 3) { p->ang_dir.ele = *p->fld[1]; } else { p->ang_dir.ele = FL(0.0); } if (p->dim == 3) { p->curr_fld = 1; p->next_fld = 2; } angle_to_cart(p->ang_dir, &(p->cart_dir)); p->spread_base.x = p->cart_dir.y; p->spread_base.y = p->cart_dir.z; p->spread_base.z = -p->cart_dir.x; vbap_zak_moving_control(csound,p); for (i=0;i<n;i++) { p->beg_gains[i] = p->updated_gains[i]; p->end_gains[i] = p->updated_gains[i]; } return OK; }
int vbap_zak_init(CSOUND *csound, VBAP_ZAK *p) { /* Initializations before run time */ int i, j, indx; MYFLT *ls_table, *ptr; /* , *gains; */ LS_SET *ls_set_ptr; int n = p->n = (int)MYFLT2LONG(*p->numb); /* Set size */ char name[24]; /* Check to see this index is within the limits of za space. */ indx = (int32) *p->ndx; if (UNLIKELY(indx > csound->zalast)) { return csound->PerfError(csound, p->h.insdshead, Str("outz index > isizea. No output")); } else if (UNLIKELY(indx < 0)) { return csound->PerfError(csound, p->h.insdshead, Str("outz index < 0. No output.")); } if ((int)*p->layout==0) strcpy(name, "vbap_ls_table"); else snprintf(name, 24, "vbap_ls_table_%d", (int)*p->layout==0); /* Now read from the array in za space and write to the output. */ p->out_array = csound->zastart + (indx * CS_KSMPS);/* outputs */ csound->AuxAlloc(csound, p->n*sizeof(MYFLT)*4, &p->auxch); p->curr_gains = (MYFLT*)p->auxch.auxp; p->beg_gains = p->curr_gains + p->n; p->end_gains = p->beg_gains + p->n; p->updated_gains = p->end_gains + p->n; ls_table = (MYFLT*) (csound->QueryGlobalVariableNoCheck(csound, name)); p->dim = (int) ls_table[0]; /* reading in loudspeaker info */ p->ls_am = (int) ls_table[1]; p->ls_set_am = (int) ls_table[2]; ptr = &(ls_table[3]); csound->AuxAlloc(csound, p->ls_set_am * sizeof (LS_SET), &p->aux); if (UNLIKELY(p->aux.auxp == NULL)) { return csound->InitError(csound, Str("could not allocate memory")); } p->ls_sets = (LS_SET*) p->aux.auxp; ls_set_ptr = p->ls_sets; for (i=0 ; i < p->ls_set_am ; i++) { ls_set_ptr[i].ls_nos[2] = 0; /* initial setting */ for (j=0 ; j < p->dim ; j++) { ls_set_ptr[i].ls_nos[j] = (int) *(ptr++); } for (j=0 ; j < 9; j++) ls_set_ptr[i].ls_mx[j] = FL(0.0); /* initial setting */ for (j=0 ; j < (p->dim) * (p->dim); j++) { ls_set_ptr[i].ls_mx[j] = (MYFLT) *(ptr++); } } /* other initialization */ if (UNLIKELY(p->dim == 2 && fabs(*p->ele) > 0.0)) { csound->Warning(csound, Str("Warning: truncating elevation to 2-D plane\n")); *p->ele = FL(0.0); } p->ang_dir.azi = (MYFLT) *p->azi; p->ang_dir.ele = (MYFLT) *p->ele; p->ang_dir.length = FL(1.0); angle_to_cart(p->ang_dir, &(p->cart_dir)); p->spread_base.x = p->cart_dir.y; p->spread_base.y = p->cart_dir.z; p->spread_base.z = -p->cart_dir.x; vbap_zak_control(csound,p); for (i=0;i<n;i++) { p->beg_gains[i] = p->updated_gains[i]; p->end_gains[i] = p->updated_gains[i]; } return OK; }
static int vco(CSOUND *csound, VCO *p) { FUNC *ftp; MYFLT *ar, *ampp, *cpsp, *ftbl; int32 phs, inc, lobits, dwnphs, tnp1, lenmask, maxd, indx; MYFLT leaky, /*rtfqc,*/ amp, fqc; MYFLT sicvt2, over2n, scal, num, denom, pulse = FL(0.0), saw = FL(0.0); MYFLT sqr = FL(0.0), tri = FL(0.0); uint32_t offset = p->h.insdshead->ksmps_offset; uint32_t early = p->h.insdshead->ksmps_no_end; uint32_t n, nsmps = CS_KSMPS; int knh; /* VDelay Inserted here */ MYFLT *buf = (MYFLT *)p->aux.auxp; MYFLT fv1, out1; int32 v1, v2; int wave = (int)MYFLT2LONG(*p->wave); /* Save recalculation and also round */ leaky = p->leaky; ftp = p->ftp; if (UNLIKELY(buf==NULL || ftp==NULL)) goto err1; /* RWD fix */ maxd = (uint32) (*p->maxd * CS_ESR); if (UNLIKELY(maxd == 0)) maxd = 1; /* Degenerate case */ indx = p->left; /* End of VDelay insert */ ftbl = ftp->ftable; sicvt2 = csound->sicvt * FL(0.5); /* for theta/2 */ lobits = ftp->lobits; lenmask = ftp->lenmask; ampp = p->xamp; cpsp = p->xcps; fqc = *cpsp; //rtfqc = SQRT(fqc); knh = (int)(CS_ESR*p->nyq/fqc); if (UNLIKELY((n = (int)knh) <= 0)) { csound->Warning(csound, "knh=%x nyq=%f fqc=%f\n" "vco knh (%d) <= 0; taken as 1\n", knh, p->nyq, fqc, n); n = 1; } tnp1 = n + n + 1; /* calc 2n + 1 */ over2n = FL(0.5) / n; amp = *ampp; scal = over2n; inc = (int32)(fqc * sicvt2); ar = p->ar; phs = p->lphs; if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); if (UNLIKELY(early)) { nsmps -= early; memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); } /*-----------------------------------------------------*/ /* PWM Wave */ /*-----------------------------------------------------*/ if (wave==2) { MYFLT pw = *p->pw; for (n=offset; n<nsmps; n++) { dwnphs = phs >> lobits; denom = *(ftbl + dwnphs); if (denom > FL(0.00001) || denom < -FL(0.00001)) { num = *(ftbl + (dwnphs * tnp1 & lenmask)); pulse = (num / denom - FL(1.0)) * scal; } else pulse = FL(1.0); phs += inc; phs &= PHMASK; if (p->ampcod) { amp = ampp[n]; scal = over2n; /* Why is this needed?? */ } if (p->cpscod) { fqc = cpsp[n]; inc = (int32)(fqc* sicvt2); } /* VDelay inserted here */ buf[indx] = pulse; fv1 = (MYFLT) indx - CS_ESR * pw / fqc; v1 = (int32) fv1; if (fv1 < FL(0.0)) v1--; fv1 -= (MYFLT) v1; /* Make sure Inside the buffer */ while (v1 >= maxd) v1 -= maxd; while (v1 < 0L) v1 += maxd; /* Find next sample for interpolation */ v2 = (v1 < (maxd - 1L) ? v1 + 1L : 0L); out1 = buf[v1] + fv1 * (buf[v2] - buf[v1]); if (++indx == maxd) indx = 0; /* Advance current pointer */ /* End of VDelay */ sqr = pulse - out1 + leaky*p->ynm1; p->ynm1 = sqr; ar[n] = (sqr + pw - FL(0.5)) * FL(1.9) * amp; } }
static int cntrl_set(CSOUND *csound, CNTRL *p) { ensure_slider(get_globals(csound, &(p->p)), (int) MYFLT2LONG(*p->kcntl)); return OK; }