/* Copyright (C) 1991-2000 Barry Vercoe, John ffitch This file is part of Csound. The Csound Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. Csound is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with Csound; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "csdl.h" /* PANS.C */ #include extern void perferror(char *s); extern FUNC * ftfind(MYFLT *argp); typedef struct { OPDS h; MYFLT *r1, *r2, *asig, *kx, *ifn, *imode, *ioffset; MYFLT xmul; long xoff; FUNC *ftp; } PANS; void pansset(PANS *p) { FUNC *ftp; if ((ftp = ftfind(p->ifn)) == NULL) return; p->ftp = ftp; if (*p->imode) p->xmul = (MYFLT)ftp->flen; else p->xmul = FL(1.0); if (*p->ioffset) p->xoff = ftp->flen >> 1; else p->xoff = 0; } void pans(PANS *p) { MYFLT *r1, *r2, *sigp, ch1, ch2; long xndx, flen; int nsmps = ksmps; FUNC *ftp; ftp = p->ftp; if (ftp==NULL) { /* RWD fix */ perferror("pans: not initialised"); return; } flen = ftp->flen; xndx = (long)(*p->kx * p->xmul) - p->xoff; if (xndx < 0L || xndx > flen) { if (xndx < 0) xndx = 0; else if (xndx > flen) xndx = flen; } ch2 = *(ftp->ftable + xndx); ch1 = *(ftp->ftable + flen - xndx); r1 = p->r1; r2 = p->r2; sigp = p->asig; do { *r1++ = *sigp * ch1; *r2++ = *sigp * ch2; sigp++; } while (--nsmps); } #define S sizeof static OENTRY localops[] = { { "pans", S(PANS), 5, "aa", "akioo", (SUBR)pansset, NULL, (SUBR)pans } }; long opcode_size(void) { return sizeof(localops); } OENTRY *opcode_init(GLOBALS *xx) { pcglob = xx; return localops; }