summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2018-04-01 14:19:05 +0200
committerRicardo Wurmus <rekado@elephly.net>2018-04-01 14:19:05 +0200
commit6e975586e08dd8ab2d2aa3bfc04a71013d09db5d (patch)
tree83094f3fdffbad0635e2829b0d79021e4dbe87f7
parent0840d670bb883e726b9674fd90b79d33383de05d (diff)
env/ad m: Use less space.
-rw-r--r--objects/env/ad m.axo19
1 files changed, 11 insertions, 8 deletions
diff --git a/objects/env/ad m.axo b/objects/env/ad m.axo
index 9ae76f1..fd12bf9 100644
--- a/objects/env/ad m.axo
+++ b/objects/env/ad m.axo
@@ -19,24 +19,27 @@
</params>
<attribs/>
<code.declaration><![CDATA[
+// upper nibble: "triggered", lower nibble: stage (0x00 for decay, 0x0F for attack)
int8_t stage;
-int ntrig;
int32_t val;
]]></code.declaration>
<code.init><![CDATA[
-ntrig = 0;
+stage = 0x00;
val = 0;
]]></code.init>
<code.krate><![CDATA[
-if ((inlet_trig>0) && !ntrig) {
- ntrig = 1;
- stage = 1;
+
+// If trigger and not yet triggered
+if ((inlet_trig>0) && !((stage & 0xF0)>>4)) {
+ // set "triggered" and "attack"
+ stage = 0xFF;
} else if (!(inlet_trig>0)) {
- ntrig = 0;
+ // set "not triggered"
+ stage &= 0x0F;
}
// decay
-if (stage == 0) {
+if ((stage & 0x0F) == 0) {
val = ___SMMLA(val,(-1<<26)+(param_d>>1)+(inlet_d>>1),val);
// attack
@@ -51,7 +54,7 @@ if (stage == 0) {
// switch to decay phase at max
if (val > 0x07FFFFFF) {
val = 0x07FFFFFF;
- stage = 0;
+ stage &= 0xF0;
}
}
outlet_env = val;