| 1 |
/* |
| 2 |
mult.c: simple multiplying opcodes |
| 3 |
|
| 4 |
Copyright (C) 2018 Victor Lazzarini |
| 5 |
This file is part of Csound. |
| 6 |
|
| 7 |
The Csound Library is free software; you can redistribute it |
| 8 |
and/or modify it under the terms of the GNU Lesser General Public |
| 9 |
License as published by the Free Software Foundation; either |
| 10 |
version 2.1 of the License, or (at your option) any later version. |
| 11 |
|
| 12 |
Csound is distributed in the hope that it will be useful, |
| 13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU Lesser General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU Lesser General Public |
| 18 |
License along with Csound; if not, write to the Free Software |
| 19 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 20 |
02110-1301 USA |
| 21 |
*/ |
| 22 |
|
| 23 |
#include <csdl.h> |
| 24 |
#include "csound.h" |
| 25 |
|
| 26 |
typedef struct { |
| 27 |
OPDS h; |
| 28 |
MYFLT *out, *in1, *in2; |
| 29 |
} MULT; |
| 30 |
|
| 31 |
|
| 32 |
int mult_scalar(CSOUND *csound, MULT *p) { |
| 33 |
*p->out = *p->in1 * *p->in2; |
| 34 |
return OK; |
| 35 |
} |
| 36 |
|
| 37 |
int mult_vector(CSOUND *csound, MULT *p) { |
| 38 |
MYFLT *out = p->out; |
| 39 |
MYFLT *in1 = p->in1; |
| 40 |
MYFLT *in2 = p->in2; |
| 41 |
uint32_t offset = p->h.insdshead->ksmps_offset; |
| 42 |
uint32_t early = p->h.insdshead->ksmps_no_end; |
| 43 |
uint32_t n, nsmps = CS_KSMPS; |
| 44 |
|
| 45 |
if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); |
| 46 |
if (UNLIKELY(early)) { |
| 47 |
nsmps -= early; |
| 48 |
memset(&out[nsmps], '\0', early*sizeof(MYFLT)); |
| 49 |
} |
| 50 |
|
| 51 |
for(n = offset; n < nsmps; n++) |
| 52 |
out[n] = in1[n] * in2[n]; |
| 53 |
|
| 54 |
return OK; |
| 55 |
} |
| 56 |
|
| 57 |
/* The mult opcode is overloaded for |
| 58 |
a, k, and i inputs. For these cases, it is |
| 59 |
recommended to append an identifier extension . |
| 60 |
to the name for debugging purposes (not strictly required). |
| 61 |
For the user, the extension is not used and all |
| 62 |
overloads are called "mult" |
| 63 |
*/ |
| 64 |
|
| 65 |
static OENTRY localops[] = |
| 66 |
{ |
| 67 |
{ "mult.aa", sizeof(MULT), 0, 2, "a", "aa", |
| 68 |
NULL, (SUBR) mult_vector }, |
| 69 |
{ "mult.kk", sizeof(MULT), 0, 2, "k", "kk", |
| 70 |
NULL, (SUBR) mult_scalar }, |
| 71 |
{ "mult.ii", sizeof(MULT), 0, 1, "i", "ii", |
| 72 |
(SUBR) mult_scalar, NULL } |
| 73 |
}; |
| 74 |
|
| 75 |
LINKAGE |