aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2017-03-22 14:38:14 +0100
committerHanspeter Portner <dev@open-music-kontrollers.ch>2017-03-22 14:38:14 +0100
commit60c4e7231f76536e6111e4cf61c324e537c26846 (patch)
tree75805c8a78658b6bbd2aede96b02da70ad3bd66b
parent52abc1ad3a4d0226e1d8a5a3d8bc63bf7dc67a31 (diff)
downloadvm.lv2-60c4e7231f76536e6111e4cf61c324e537c26846.tar.xz
add more opcodes.
-rw-r--r--VERSION2
-rw-r--r--vm.c150
-rw-r--r--vm.h196
-rw-r--r--vm.ttl143
4 files changed, 431 insertions, 60 deletions
diff --git a/VERSION b/VERSION
index 0ff20af..92596b8 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.2863
+0.1.2865
diff --git a/vm.c b/vm.c
index 13cd2b5..49a0b3f 100644
--- a/vm.c
+++ b/vm.c
@@ -259,9 +259,7 @@ connect_port(LV2_Handle instance, uint32_t port, void *data)
}
}
-#define MIN(a, b) (a < b ? a : b)
-#define MAX(a, b) (a > b ? a : b)
-#define CLIP(a, v, b) MIN(MAX(a, v), b)
+#define CLIP(a, v, b) fmin(fmax(a, v), b)
static void
run(LV2_Handle instance, uint32_t nsamples)
@@ -447,6 +445,51 @@ run(LV2_Handle instance, uint32_t nsamples)
const num_t c = sqrt(a);
_stack_push(&handle->stack, c);
} break;
+ case OP_CBRT:
+ {
+ const num_t a = _stack_pop(&handle->stack);
+ const num_t c = cbrt(a);
+ _stack_push(&handle->stack, c);
+ } break;
+
+ case OP_FLOOR:
+ {
+ const num_t a = _stack_pop(&handle->stack);
+ const num_t c = floor(a);
+ _stack_push(&handle->stack, c);
+ } break;
+ case OP_CEIL:
+ {
+ const num_t a = _stack_pop(&handle->stack);
+ const num_t c = ceil(a);
+ _stack_push(&handle->stack, c);
+ } break;
+ case OP_ROUND:
+ {
+ const num_t a = _stack_pop(&handle->stack);
+ const num_t c = round(a);
+ _stack_push(&handle->stack, c);
+ } break;
+ case OP_RINT:
+ {
+ const num_t a = _stack_pop(&handle->stack);
+ const num_t c = rint(a);
+ _stack_push(&handle->stack, c);
+ } break;
+ case OP_TRUNC:
+ {
+ const num_t a = _stack_pop(&handle->stack);
+ const num_t c = trunc(a);
+ _stack_push(&handle->stack, c);
+ } break;
+ case OP_MODF:
+ {
+ const num_t a = _stack_pop(&handle->stack);
+ num_t d;
+ const num_t c = modf(a, &d);
+ _stack_push(&handle->stack, c);
+ _stack_push(&handle->stack, d);
+ } break;
case OP_EXP:
{
@@ -460,6 +503,21 @@ run(LV2_Handle instance, uint32_t nsamples)
const num_t c = exp2(a);
_stack_push(&handle->stack, c);
} break;
+ case OP_LD_EXP:
+ {
+ num_t ab [2];
+ _stack_pop_num(&handle->stack, ab, 2);
+ const num_t c = ldexp(ab[1], ab[0]);
+ _stack_push(&handle->stack, c);
+ } break;
+ case OP_FR_EXP:
+ {
+ const num_t a = _stack_pop(&handle->stack);
+ int d;
+ const num_t c = frexp(a, &d);
+ _stack_push(&handle->stack, c);
+ _stack_push(&handle->stack, d);
+ } break;
case OP_LOG:
{
const num_t a = _stack_pop(&handle->stack);
@@ -479,6 +537,11 @@ run(LV2_Handle instance, uint32_t nsamples)
_stack_push(&handle->stack, c);
} break;
+ case OP_PI:
+ {
+ num_t c = M_PI;
+ _stack_push(&handle->stack, c);
+ } break;
case OP_SIN:
{
const num_t a = _stack_pop(&handle->stack);
@@ -491,9 +554,71 @@ run(LV2_Handle instance, uint32_t nsamples)
const num_t c = cos(a);
_stack_push(&handle->stack, c);
} break;
- case OP_PI:
+ case OP_TAN:
{
- num_t c = M_PI;
+ const num_t a = _stack_pop(&handle->stack);
+ const num_t c = tan(a);
+ _stack_push(&handle->stack, c);
+ } break;
+ case OP_ASIN:
+ {
+ const num_t a = _stack_pop(&handle->stack);
+ const num_t c = asin(a);
+ _stack_push(&handle->stack, c);
+ } break;
+ case OP_ACOS:
+ {
+ const num_t a = _stack_pop(&handle->stack);
+ const num_t c = acos(a);
+ _stack_push(&handle->stack, c);
+ } break;
+ case OP_ATAN:
+ {
+ const num_t a = _stack_pop(&handle->stack);
+ const num_t c = atan(a);
+ _stack_push(&handle->stack, c);
+ } break;
+ case OP_ATAN2:
+ {
+ num_t ab [2];
+ _stack_pop_num(&handle->stack, ab, 2);
+ const num_t c = atan2(ab[1], ab[0]);
+ _stack_push(&handle->stack, c);
+ } break;
+ case OP_SINH:
+ {
+ const num_t a = _stack_pop(&handle->stack);
+ const num_t c = sinh(a);
+ _stack_push(&handle->stack, c);
+ } break;
+ case OP_COSH:
+ {
+ const num_t a = _stack_pop(&handle->stack);
+ const num_t c = cosh(a);
+ _stack_push(&handle->stack, c);
+ } break;
+ case OP_TANH:
+ {
+ const num_t a = _stack_pop(&handle->stack);
+ const num_t c = tanh(a);
+ _stack_push(&handle->stack, c);
+ } break;
+ case OP_ASINH:
+ {
+ const num_t a = _stack_pop(&handle->stack);
+ const num_t c = asinh(a);
+ _stack_push(&handle->stack, c);
+ } break;
+ case OP_ACOSH:
+ {
+ const num_t a = _stack_pop(&handle->stack);
+ const num_t c = acosh(a);
+ _stack_push(&handle->stack, c);
+ } break;
+ case OP_ATANH:
+ {
+ const num_t a = _stack_pop(&handle->stack);
+ const num_t c = atanh(a);
_stack_push(&handle->stack, c);
} break;
@@ -539,6 +664,20 @@ run(LV2_Handle instance, uint32_t nsamples)
const bool c = ab[0];
_stack_push(&handle->stack, c ? ab[2] : ab[1]);
} break;
+ case OP_MINI:
+ {
+ num_t ab [2];
+ _stack_pop_num(&handle->stack, ab, 2);
+ const num_t c = fmin(ab[1], ab[0]);
+ _stack_push(&handle->stack, c);
+ } break;
+ case OP_MAXI:
+ {
+ num_t ab [2];
+ _stack_pop_num(&handle->stack, ab, 2);
+ const num_t c = fmax(ab[1], ab[0]);
+ _stack_push(&handle->stack, c);
+ } break;
case OP_AND:
{
@@ -554,6 +693,7 @@ run(LV2_Handle instance, uint32_t nsamples)
const bool c = ab[1] || ab[0];
_stack_push(&handle->stack, c);
} break;
+
case OP_NOT:
{
const int a = _stack_pop(&handle->stack);
diff --git a/vm.h b/vm.h
index 7d1dbcd..725a918 100644
--- a/vm.h
+++ b/vm.h
@@ -93,16 +93,37 @@ enum _vm_opcode_enum_t {
OP_NEG,
OP_ABS,
OP_SQRT,
+ OP_CBRT,
+
+ OP_FLOOR,
+ OP_CEIL,
+ OP_ROUND,
+ OP_RINT,
+ OP_TRUNC,
+ OP_MODF,
OP_EXP,
OP_EXP_2,
+ OP_LD_EXP,
+ OP_FR_EXP,
OP_LOG,
OP_LOG_2,
OP_LOG_10,
+ OP_PI,
OP_SIN,
OP_COS,
- OP_PI,
+ OP_TAN,
+ OP_ASIN,
+ OP_ACOS,
+ OP_ATAN,
+ OP_ATAN2,
+ OP_SINH,
+ OP_COSH,
+ OP_TANH,
+ OP_ASINH,
+ OP_ACOSH,
+ OP_ATANH,
OP_EQ,
OP_LT,
@@ -110,6 +131,8 @@ enum _vm_opcode_enum_t {
OP_LE,
OP_GE,
OP_TER,
+ OP_MINI,
+ OP_MAXI,
OP_AND,
OP_OR,
@@ -197,14 +220,14 @@ static const vm_api_def_t vm_api_def [OP_MAX] = {
},
[OP_PUSH] = {
.uri = VM_PREFIX"opPush",
- .label = "Push top",
+ .label = "Push topmost value",
.mnemo = "push",
.npops = 1,
.npushs = 2
},
[OP_SWAP] = {
.uri = VM_PREFIX"opSwap",
- .label = "Swap",
+ .label = "Swap 2 topmost values",
.mnemo = "swap",
.npops = 2,
.npushs = 2
@@ -226,7 +249,7 @@ static const vm_api_def_t vm_api_def [OP_MAX] = {
[OP_RAND] = {
.uri = VM_PREFIX"opRand",
- .label = "Random number",
+ .label = "Generate random number",
.mnemo = "rand",
.npops = 0,
.npushs = 1
@@ -296,6 +319,56 @@ static const vm_api_def_t vm_api_def [OP_MAX] = {
.npops = 1,
.npushs = 1
},
+ [OP_CBRT] = {
+ .uri = VM_PREFIX"opCbrt",
+ .label = "Cubic root",
+ .mnemo = "cbrt",
+ .npops = 1,
+ .npushs = 1
+ },
+
+ [OP_FLOOR] = {
+ .uri = VM_PREFIX"opFloor",
+ .label = "Floor",
+ .mnemo = "floor",
+ .npops = 1,
+ .npushs = 1
+ },
+ [OP_CEIL] = {
+ .uri = VM_PREFIX"opCeil",
+ .label = "Ceiling",
+ .mnemo = "ceil",
+ .npops = 1,
+ .npushs = 1
+ },
+ [OP_ROUND] = {
+ .uri = VM_PREFIX"opRound",
+ .label = "Round",
+ .mnemo = "round",
+ .npops = 1,
+ .npushs = 1
+ },
+ [OP_RINT] = {
+ .uri = VM_PREFIX"opRint",
+ .label = "Rint",
+ .mnemo = "rint",
+ .npops = 1,
+ .npushs = 1
+ },
+ [OP_TRUNC] = {
+ .uri = VM_PREFIX"opTrunc",
+ .label = "Truncate",
+ .mnemo = "trunc",
+ .npops = 1,
+ .npushs = 1
+ },
+ [OP_MODF] = {
+ .uri = VM_PREFIX"opModF",
+ .label = "Break number into integer and fractional parts",
+ .mnemo = "modf",
+ .npops = 1,
+ .npushs = 2
+ },
[OP_EXP] = {
.uri = VM_PREFIX"opExp",
@@ -311,6 +384,20 @@ static const vm_api_def_t vm_api_def [OP_MAX] = {
.npops = 1,
.npushs = 1
},
+ [OP_LD_EXP] = {
+ .uri = VM_PREFIX"opLDExp",
+ .label = "Multiply number by 2 raised to a power",
+ .mnemo = "ldexp",
+ .npops = 2,
+ .npushs = 1
+ },
+ [OP_FR_EXP] = {
+ .uri = VM_PREFIX"opFRExp",
+ .label = "Break number into significand and power of 2",
+ .mnemo = "frexp",
+ .npops = 1,
+ .npushs = 2
+ },
[OP_LOG] = {
.uri = VM_PREFIX"opLog",
.label = "Logarithm",
@@ -333,6 +420,13 @@ static const vm_api_def_t vm_api_def [OP_MAX] = {
.npushs = 1
},
+ [OP_PI] = {
+ .uri = VM_PREFIX"opPi",
+ .label = "Pi",
+ .mnemo = "pi",
+ .npops = 0,
+ .npushs = 1
+ },
[OP_SIN] = {
.uri = VM_PREFIX"opSin",
.label = "Sinus",
@@ -347,11 +441,81 @@ static const vm_api_def_t vm_api_def [OP_MAX] = {
.npops = 1,
.npushs = 1
},
- [OP_PI] = {
- .uri = VM_PREFIX"opPi",
- .label = "Pi",
- .mnemo = "pi",
- .npops = 0,
+ [OP_TAN] = {
+ .uri = VM_PREFIX"opTan",
+ .label = "Tangens",
+ .mnemo = "tan",
+ .npops = 1,
+ .npushs = 1
+ },
+ [OP_ASIN] = {
+ .uri = VM_PREFIX"opASin",
+ .label = "Arcus Sinus",
+ .mnemo = "asin",
+ .npops = 1,
+ .npushs = 1
+ },
+ [OP_ACOS] = {
+ .uri = VM_PREFIX"opACos",
+ .label = "Arcus Cosinus",
+ .mnemo = "acos",
+ .npops = 1,
+ .npushs = 1
+ },
+ [OP_ATAN] = {
+ .uri = VM_PREFIX"opATan",
+ .label = "Arcus Tangens",
+ .mnemo = "atan",
+ .npops = 1,
+ .npushs = 1
+ },
+ [OP_ATAN2] = {
+ .uri = VM_PREFIX"opATan2",
+ .label = "Arcus Tangens using quadrants",
+ .mnemo = "atan2",
+ .npops = 2,
+ .npushs = 1
+ },
+ [OP_SINH] = {
+ .uri = VM_PREFIX"opSinH",
+ .label = "Sinus Hyperbolicus",
+ .mnemo = "sinh",
+ .npops = 1,
+ .npushs = 1
+ },
+ [OP_COSH] = {
+ .uri = VM_PREFIX"opCosH",
+ .label = "Cosinus Hyperbolicus",
+ .mnemo = "cosh",
+ .npops = 1,
+ .npushs = 1
+ },
+ [OP_TANH] = {
+ .uri = VM_PREFIX"opTanH",
+ .label = "Tangens Hyperbolicus",
+ .mnemo = "tanh",
+ .npops = 1,
+ .npushs = 1
+ },
+ [OP_ASINH] = {
+ .uri = VM_PREFIX"opASinH",
+ .label = "Arcus Sinus Hyperbolicus",
+ .mnemo = "asinh",
+ .npops = 1,
+ .npushs = 1
+ },
+ [OP_ACOSH] = {
+ .uri = VM_PREFIX"opACosH",
+ .label = "Arcus Cosinus Hyperbolicus",
+ .mnemo = "acosh",
+ .npops = 1,
+ .npushs = 1
+ },
+ [OP_ATANH] = {
+ .uri = VM_PREFIX"opATanH",
+ .label = "Arcus Tangens Hyperbolicus",
+ .mnemo = "atanh",
+ .npops = 1,
.npushs = 1
},
@@ -397,6 +561,20 @@ static const vm_api_def_t vm_api_def [OP_MAX] = {
.npops = 3,
.npushs = 1
},
+ [OP_MINI] = {
+ .uri = VM_PREFIX"opMin",
+ .label = "Minimum",
+ .mnemo = "min",
+ .npops = 2,
+ .npushs = 1
+ },
+ [OP_MAXI] = {
+ .uri = VM_PREFIX"opMax",
+ .label = "Maximum",
+ .mnemo = "max",
+ .npops = 2,
+ .npushs = 1
+ },
[OP_AND] = {
.uri = VM_PREFIX"opAnd",
diff --git a/vm.ttl b/vm.ttl
index 350e88e..daf6598 100644
--- a/vm.ttl
+++ b/vm.ttl
@@ -57,79 +57,132 @@ vm:graph
rdfs:comment "vm graph tuple" .
vm:opInput
- a rdfs:Datatype ; rdfs:label "Input port value" .
+ a rdfs:Datatype .
vm:opPush
- a rdfs:Datatype ; rdfs:label "Push Top of stack" .
+ a rdfs:Datatype .
+vm:opSwap
+ a rdfs:Datatype .
+vm:opStore
+ a rdfs:Datatype .
+vm:opLoad
+ a rdfs:Datatype .
+
+vm:opRand
+ a rdfs:Datatype .
+
vm:opAdd
- a rdfs:Datatype ; rdfs:label "Addition" .
+ a rdfs:Datatype .
vm:opSub
- a rdfs:Datatype ; rdfs:label "Subtraction" .
+ a rdfs:Datatype .
vm:opMul
- a rdfs:Datatype ; rdfs:label "Multiplication" .
+ a rdfs:Datatype .
vm:opDiv
- a rdfs:Datatype ; rdfs:label "Division" .
+ a rdfs:Datatype .
+vm:opMod
+ a rdfs:Datatype .
+vm:opPow
+ a rdfs:Datatype .
+
vm:opNeg
- a rdfs:Datatype ; rdfs:label "Negate" .
+ a rdfs:Datatype .
vm:opAbs
- a rdfs:Datatype ; rdfs:label "Absolute value" .
-vm:opPow
- a rdfs:Datatype ; rdfs:label "Power" .
+ a rdfs:Datatype .
vm:opSqrt
- a rdfs:Datatype ; rdfs:label "Square root" .
-vm:opMod
- a rdfs:Datatype ; rdfs:label "Modulo" .
+ a rdfs:Datatype .
+vm:opCbrt
+ a rdfs:Datatype .
+
+vm:opFloor
+ a rdfs:Datatype .
+vm:opCeil
+ a rdfs:Datatype .
+vm:opRound
+ a rdfs:Datatype .
+vm:opRint
+ a rdfs:Datatype .
+vm:opTrunc
+ a rdfs:Datatype .
+vm:opModF
+ a rdfs:Datatype .
+
vm:opExp
- a rdfs:Datatype ; rdfs:label "Exponentiation" .
+ a rdfs:Datatype .
vm:opExp2
- a rdfs:Datatype ; rdfs:label "Exponentiation base 2" .
+ a rdfs:Datatype .
+vm:opLDExp
+ a rdfs:Datatype .
+vm:opFRExp
+ a rdfs:Datatype .
vm:opLog
- a rdfs:Datatype ; rdfs:label "Logarithm" .
+ a rdfs:Datatype .
vm:opLog2
- a rdfs:Datatype ; rdfs:label "Logarithm base 2" .
+ a rdfs:Datatype .
vm:opLog10
- a rdfs:Datatype ; rdfs:label "Logarithm base 10" .
+ a rdfs:Datatype .
+
+vm:opPi
+ a rdfs:Datatype .
vm:opSin
- a rdfs:Datatype ; rdfs:label "Sinus" .
+ a rdfs:Datatype .
vm:opCos
- a rdfs:Datatype ; rdfs:label "Cosinus" .
-vm:opSwap
- a rdfs:Datatype ; rdfs:label "Swap" .
-vm:opPi
- a rdfs:Datatype ; rdfs:label "Pi" .
+ a rdfs:Datatype .
+vm:opTan
+ a rdfs:Datatype .
+vm:opASin
+ a rdfs:Datatype .
+vm:opACos
+ a rdfs:Datatype .
+vm:opATan
+ a rdfs:Datatype .
+vm:opATan2
+ a rdfs:Datatype .
+vm:opSinH
+ a rdfs:Datatype .
+vm:opCosH
+ a rdfs:Datatype .
+vm:opTanH
+ a rdfs:Datatype .
+vm:opASinH
+ a rdfs:Datatype .
+vm:opACosH
+ a rdfs:Datatype .
+vm:opATanH
+ a rdfs:Datatype .
+
vm:opEq
- a rdfs:Datatype ; rdfs:label "Equal" .
+ a rdfs:Datatype .
vm:opLt
- a rdfs:Datatype ; rdfs:label "Less than" .
+ a rdfs:Datatype .
vm:opGt
- a rdfs:Datatype ; rdfs:label "Greater than" .
+ a rdfs:Datatype .
vm:opLe
- a rdfs:Datatype ; rdfs:label "Less or equal" .
+ a rdfs:Datatype .
vm:opGe
- a rdfs:Datatype ; rdfs:label "Greater or equal" .
+ a rdfs:Datatype .
+vm:opTernary
+ a rdfs:Datatype .
+vm:opMin
+ a rdfs:Datatype .
+vm:opMax
+ a rdfs:Datatype .
+
vm:opAnd
- a rdfs:Datatype ; rdfs:label "And" .
+ a rdfs:Datatype .
vm:opOr
- a rdfs:Datatype ; rdfs:label "Or" .
+ a rdfs:Datatype .
vm:opNot
- a rdfs:Datatype ; rdfs:label "Not" .
+ a rdfs:Datatype .
+
vm:opBAnd
- a rdfs:Datatype ; rdfs:label "Bitwise And" .
+ a rdfs:Datatype .
vm:opBOr
- a rdfs:Datatype ; rdfs:label "Bitwise Or" .
+ a rdfs:Datatype .
vm:opBNot
- a rdfs:Datatype ; rdfs:label "Bitwise Not" .
+ a rdfs:Datatype .
vm:opLShift
- a rdfs:Datatype ; rdfs:label "Left shift" .
+ a rdfs:Datatype .
vm:opRShift
- a rdfs:Datatype ; rdfs:label "Right shift" .
-vm:opTernary
- a rdfs:Datatype ; rdfs:label "Ternary" .
-vm:opStore
- a rdfs:Datatype ; rdfs:label "Store in register" .
-vm:opLoad
- a rdfs:Datatype ; rdfs:label "Load from register" .
-vm:opRand
- a rdfs:Datatype ; rdfs:label "Random" .
+ a rdfs:Datatype .
# Plugin
vm:vm