comparison projects/heavy/envelopeTrigger/SignalRPole.h @ 162:c3e8226a5651 heavy-updated

- added additional flags to C rules (-DNDEBUG, -mfpu=neon) - sample-accurate envelope triggering pd/heavy example
author chnrx <chris.heinrichs@gmail.com>
date Thu, 12 Nov 2015 14:59:46 +0000
parents
children
comparison
equal deleted inserted replaced
161:07735c9d95c8 162:c3e8226a5651
1 /**
2 * Copyright (c) 2014, 2015, Enzien Audio Ltd.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #ifndef _SIGNAL_RPOLE_H_
18 #define _SIGNAL_RPOLE_H_
19
20 #include "HvBase.h"
21 #include "SignalDel1.h"
22 #include "HeavyMath.h"
23
24 // implements y[n] = x[n] - a*y[n-1]
25 // H(z) = 1/(1+a*z^-1)
26 typedef struct SignalRPole {
27 #if HV_SIMD_AVX
28 SignalDel1 sDel1_fxiLN;
29 SignalDel1 sDel1_kjkpV;
30 SignalDel1 sDel1_dkIWc;
31 SignalDel1 sDel1_bVeoW;
32 SignalDel1 sDel1_PulZn;
33 SignalDel1 sDel1_yTFig;
34 SignalDel1 sDel1_Is9Qf;
35 SignalDel1 sDel1_LIyNt;
36 SignalDel1 sDel1_VqpU3;
37 SignalDel1 sDel1_ZVYeg;
38 SignalDel1 sDel1_IVAZh;
39 SignalDel1 sDel1_F8WrY;
40 SignalDel1 sDel1_rkFMy;
41 SignalDel1 sDel1_BeqSK;
42 hv_bufferf_t ym;
43 #elif HV_SIMD_SSE || HV_SIMD_NEON
44 SignalDel1 sDel1_i8Twk;
45 SignalDel1 sDel1_KYibU;
46 SignalDel1 sDel1_spa5V;
47 SignalDel1 sDel1_3HXdb;
48 SignalDel1 sDel1_Aj1oK;
49 SignalDel1 sDel1_jNX1g;
50 hv_bufferf_t ym;
51 #else
52 hv_bufferf_t ym;
53 #endif
54 } SignalRPole;
55
56 hv_size_t sRPole_init(SignalRPole *o);
57
58 void sRPole_onMessage(HvBase *_c, SignalRPole *o, int letIn, const HvMessage *m);
59
60 static inline void __hv_rpole_f(SignalRPole *o, hv_bInf_t bIn0, hv_bInf_t bIn1, hv_bOutf_t bOut) {
61 #if HV_SIMD_AVX
62 hv_bufferf_t a, b, c, d, e, f, g, i, j, k, l, m, n;
63 __hv_del1_f(&o->sDel1_fxiLN, bIn1, &a);
64 __hv_mul_f(bIn1, a, &b);
65 __hv_del1_f(&o->sDel1_kjkpV, a, &a);
66 __hv_mul_f(b, a, &c);
67 __hv_del1_f(&o->sDel1_dkIWc, a, &a);
68 __hv_mul_f(c, a, &d);
69 __hv_del1_f(&o->sDel1_bVeoW, a, &a);
70 __hv_mul_f(d, a, &e);
71 __hv_del1_f(&o->sDel1_PulZn, a, &a);
72 __hv_mul_f(e, a, &f);
73 __hv_del1_f(&o->sDel1_yTFig, a, &a);
74 __hv_mul_f(f, a, &g);
75 __hv_del1_f(&o->sDel1_Is9Qf, a, &a);
76 __hv_mul_f(g, a, &a);
77 __hv_del1_f(&o->sDel1_LIyNt, bIn0, &i);
78 __hv_del1_f(&o->sDel1_VqpU3, i, &j);
79 __hv_del1_f(&o->sDel1_ZVYeg, j, &k);
80 __hv_del1_f(&o->sDel1_IVAZh, k, &l);
81 __hv_del1_f(&o->sDel1_F8WrY, l, &m);
82 __hv_del1_f(&o->sDel1_rkFMy, m, &n);
83 __hv_mul_f(i, bIn1, &i);
84 __hv_sub_f(bIn0, i, &i);
85 __hv_fma_f(j, b, i, &i);
86 __hv_mul_f(k, c, &c);
87 __hv_sub_f(i, c, &c);
88 __hv_fma_f(l, d, c, &c);
89 __hv_mul_f(m, e, &e);
90 __hv_sub_f(c, e, &e);
91 __hv_fma_f(n, f, e, &e);
92 __hv_del1_f(&o->sDel1_BeqSK, n, &n);
93 __hv_mul_f(n, g, &g);
94 __hv_sub_f(e, g, &g);
95 __hv_fma_f(a, o->ym, g, &g);
96 o->ym = g;
97 *bOut = g;
98 #elif HV_SIMD_SSE || HV_SIMD_NEON
99 hv_bufferf_t a, b, c, e, f;
100 __hv_del1_f(&o->sDel1_i8Twk, bIn1, &a);
101 __hv_mul_f(bIn1, a, &b);
102 __hv_del1_f(&o->sDel1_KYibU, a, &a);
103 __hv_mul_f(b, a, &c);
104 __hv_del1_f(&o->sDel1_spa5V, a, &a);
105 __hv_mul_f(c, a, &a);
106 __hv_del1_f(&o->sDel1_3HXdb, bIn0, &e);
107 __hv_del1_f(&o->sDel1_Aj1oK, e, &f);
108 __hv_mul_f(e, bIn1, &e);
109 __hv_sub_f(bIn0, e, &e);
110 __hv_fma_f(f, b, e, &e);
111 __hv_del1_f(&o->sDel1_jNX1g, f, &f);
112 __hv_mul_f(f, c, &c);
113 __hv_sub_f(e, c, &c);
114 __hv_fma_f(a, o->ym, c, &c);
115 o->ym = c;
116 *bOut = c;
117 #else
118 *bOut = bIn0 - bIn1 * o->ym;
119 o->ym = *bOut;
120 #endif
121 }
122
123 #endif // _SIGNAL_RPOLE_H_