1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
/*
ugakbari.c:
Copyright (C) 2006 by David Akbari
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., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "csoundCore.h"
#include "interlocks.h"
#include <math.h>
#define LOGCURVE(x,y) ((LOG(x * (y-FL(1.0))+FL(1.0)))/(LOG(y)))
#define EXPCURVE(x,y) ((EXP(x * LOG(y))-FL(1.0))/(y-FL(1.0)))
#define GAINSLIDER(x) (FL(0.000145) * EXP(x * FL(0.06907)))
typedef struct _scale {
OPDS h;
MYFLT *koutval;
MYFLT *kinval, *kmax, *kmin;
} scale;
typedef struct _expcurve {
OPDS h;
MYFLT *kout;
MYFLT *kin, *ksteepness;
} expcurve;
typedef struct _logcurve {
OPDS h;
MYFLT *kout;
MYFLT *kin, *ksteepness;
} logcurve;
typedef struct _gainslider {
OPDS h;
MYFLT *koutsig;
MYFLT *kindex;
} gainslider;
/* scale opcode */
static int32_t scale_process(CSOUND *csound, scale *p)
{
IGN(csound);
if (*p->kmin != *p->kmax) {
*p->koutval = (*p->kinval * (*p->kmax - *p->kmin) + *p->kmin);
}
return OK;
}
/* expcurve opcode */
static int32_t expcurve_perf(CSOUND *csound, expcurve *p)
{
IGN(csound);
MYFLT ki = *p->kin;
MYFLT ks = *p->ksteepness;
*p->kout = EXPCURVE(ki, ks);
return OK;
}
/* logcurve opcode */
static int32_t logcurve_perf(CSOUND *csound, logcurve *p)
{
IGN(csound);
MYFLT ki = *p->kin;
MYFLT ks = *p->ksteepness;
*p->kout = LOGCURVE(ki, ks);
return OK;
}
/* gainslider opcode */
static int32_t
gainslider_perf(CSOUND *csound, gainslider *p)
{
IGN(csound);
if (*p->kindex <= FL(0.0)) {
*p->koutsig = FL(0.0);
}
else {
*p->koutsig = GAINSLIDER(*p->kindex);
}
return OK;
}
/* opcode library entries */
static OENTRY ugakbari_localops[] = {
{ "scale", sizeof(scale), 0, 2, "k", "kkk", NULL, (SUBR)scale_process, NULL },
{ "expcurve", sizeof(expcurve), 0, 2, "k", "kk", NULL,
(SUBR)expcurve_perf, NULL },
{ "logcurve", sizeof(logcurve), 0, 2, "k", "kk", NULL,
(SUBR)logcurve_perf, NULL },
{ "gainslider", sizeof(gainslider), 0, 2, "k", "k", NULL,
(SUBR)gainslider_perf, NULL }
};
LINKAGE_BUILTIN(ugakbari_localops)
|