Mercurial > hg > beaglert
comparison projects/heavy/samphold/HvContext_bbb.c @ 160:5bcf04234f80 heavy-updated
- added -std=c99 to Makefile for user-supplied C files (required for heavy files)
- changed heavy core render.cpp file to use latest API and removed all redundant functions (e.g. foleyDesigner/touchkey stuff)
- use build_pd.sh to compile and run pd files (-h for usage instructions)
author | chnrx <chris.heinrichs@gmail.com> |
---|---|
date | Thu, 05 Nov 2015 18:58:26 +0000 |
parents | |
children | c3e8226a5651 |
comparison
equal
deleted
inserted
replaced
159:1e7db6610600 | 160:5bcf04234f80 |
---|---|
1 | |
2 /** | |
3 * Copyright (c) 2014,2015 Enzien Audio, Ltd. | |
4 * | |
5 * Permission is hereby granted, free of charge, to any person obtaining a copy | |
6 * of this software and associated documentation files (the "Software"), | |
7 * to deal in the Software without restriction, including without limitation | |
8 * the rights to use, copy, modify, merge, publish, distribute, and/or | |
9 * sublicense copies of the Software, strictly on a non-commercial basis, | |
10 * and to permit persons to whom the Software is furnished to do so, | |
11 * subject to the following conditions: | |
12 * | |
13 * The above copyright notice and this permission notice shall be included in | |
14 * all copies or substantial portions of the Software. | |
15 * | |
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
22 * IN THE SOFTWARE. | |
23 * | |
24 * DO NOT MODIFY. THIS CODE IS MACHINE GENERATED BY THE SECTION6 HEAVY COMPILER. | |
25 */ | |
26 | |
27 /* | |
28 * System Includes | |
29 */ | |
30 | |
31 #include <assert.h> | |
32 #include <math.h> | |
33 #include <string.h> | |
34 #include <stdarg.h> | |
35 #include "HvContext_bbb.h" | |
36 #include "HeavyMath.h" | |
37 | |
38 | |
39 /* | |
40 * Function Declarations | |
41 */ | |
42 static void cBinop_62MLs_sendMessage(HvBase *, int, const HvMessage *const); | |
43 static void cUnop_Rm4T9_sendMessage(HvBase *, int, const HvMessage *const); | |
44 static void cRandom_Uxs9y_sendMessage(HvBase *, int, const HvMessage *const); | |
45 static void cLoadbang_XJMP6_sendMessage(HvBase *, int, const HvMessage *const); | |
46 static void cMsg_eMw6t_sendMessage(HvBase *, int, const HvMessage *const); | |
47 static void cBinop_vHnCM_sendMessage(HvBase *, int, const HvMessage *const); | |
48 static void cBinop_PmuD1_sendMessage(HvBase *, int, const HvMessage *const); | |
49 static void cBinop_lT4qw_sendMessage(HvBase *, int, const HvMessage *const); | |
50 static void cBinop_vpZDi_sendMessage(HvBase *, int, const HvMessage *const); | |
51 static void cMsg_zpcIL_sendMessage(HvBase *, int, const HvMessage *const); | |
52 static void cMsg_pfnj7_sendMessage(HvBase *, int, const HvMessage *const); | |
53 static void cSystem_lJZJR_sendMessage(HvBase *, int, const HvMessage *const); | |
54 static void cVar_cPxQc_sendMessage(HvBase *, int, const HvMessage *const); | |
55 static void cBinop_1u9M5_sendMessage(HvBase *, int, const HvMessage *const); | |
56 static void cLoadbang_AXnu9_sendMessage(HvBase *, int, const HvMessage *const); | |
57 | |
58 | |
59 | |
60 /* | |
61 * Static Helper Functions | |
62 */ | |
63 | |
64 static void ctx_intern_scheduleMessageForReceiver( | |
65 HvBase *const _c, const char *name, HvMessage *m) { | |
66 switch (msg_symbolToHash(name)) { | |
67 default: return; | |
68 } | |
69 } | |
70 | |
71 static struct HvTable *ctx_intern_getTableForHash(HvBase *const _c, hv_uint32_t h) { | |
72 switch (h) { | |
73 default: return NULL; | |
74 } | |
75 } | |
76 | |
77 | |
78 | |
79 /* | |
80 * Context Include and Implementatons | |
81 */ | |
82 | |
83 Hv_bbb *hv_bbb_new_with_pool(double sampleRate, int poolKb) { | |
84 hv_assert(sampleRate > 0.0); // can't initialise with sampling rate of 0 | |
85 hv_assert(poolKb >= 1); // a message pool of some reasonable size is always needed | |
86 Hv_bbb *const _c = (Hv_bbb *) hv_malloc(sizeof(Hv_bbb)); | |
87 | |
88 Base(_c)->numInputChannels = 0; | |
89 Base(_c)->numOutputChannels = 2; | |
90 Base(_c)->sampleRate = sampleRate; | |
91 Base(_c)->blockStartTimestamp = 0; | |
92 Base(_c)->f_scheduleMessageForReceiver = &ctx_intern_scheduleMessageForReceiver; | |
93 Base(_c)->f_getTableForHash = &ctx_intern_getTableForHash; | |
94 mq_initWithPoolSize(&Base(_c)->mq, poolKb); | |
95 Base(_c)->basePath = NULL; | |
96 Base(_c)->printHook = NULL; | |
97 Base(_c)->sendHook = NULL; | |
98 Base(_c)->userData = NULL; | |
99 Base(_c)->name = "bbb"; | |
100 | |
101 Base(_c)->numBytes = sizeof(Hv_bbb); | |
102 Base(_c)->numBytes += sVari_init(&_c->sVari_ecpIx, 0, 0, false); | |
103 Base(_c)->numBytes += sVarf_init(&_c->sVarf_VF9rD, 0.0f, 0.0f, false); | |
104 Base(_c)->numBytes += sVarf_init(&_c->sVarf_0bFmM, 0.0f, 0.0f, false); | |
105 Base(_c)->numBytes += sRPole_init(&_c->sRPole_WxgWS); | |
106 Base(_c)->numBytes += sPhasor_k_init(&_c->sPhasor_YcHM3, 880.0f, sampleRate); | |
107 Base(_c)->numBytes += sDel1_init(&_c->sDel1_FfVih); | |
108 Base(_c)->numBytes += sSamphold_init(&_c->sSamphold_hq9sm); | |
109 Base(_c)->numBytes += sPhasor_init(&_c->sPhasor_n1TcS, sampleRate); | |
110 Base(_c)->numBytes += cBinop_init(&_c->cBinop_62MLs, 8388610.0f); // __mul | |
111 Base(_c)->numBytes += cRandom_init(&_c->cRandom_Uxs9y, -1512500956); | |
112 Base(_c)->numBytes += cBinop_init(&_c->cBinop_vHnCM, 1.0f); // __min | |
113 Base(_c)->numBytes += cBinop_init(&_c->cBinop_PmuD1, 0.0f); // __max | |
114 Base(_c)->numBytes += cBinop_init(&_c->cBinop_lT4qw, 0.0f); // __mul | |
115 Base(_c)->numBytes += cVar_init_f(&_c->cVar_cPxQc, 1.0f); | |
116 | |
117 // loadbang | |
118 ctx_scheduleMessage(Base(_c), msg_initWithBang(HV_MESSAGE_ON_STACK(1), 0), &cLoadbang_AXnu9_sendMessage, 0); | |
119 ctx_scheduleMessage(Base(_c), msg_initWithBang(HV_MESSAGE_ON_STACK(1), 0), &cLoadbang_XJMP6_sendMessage, 0); | |
120 | |
121 return _c; | |
122 } | |
123 | |
124 Hv_bbb *hv_bbb_new(double sampleRate) { | |
125 return hv_bbb_new_with_pool(sampleRate, 10); // default to 10KB MessagePool | |
126 } | |
127 | |
128 void hv_bbb_free(Hv_bbb *_c) { | |
129 | |
130 hv_free(Base(_c)->basePath); | |
131 mq_free(&Base(_c)->mq); // free queue after all objects have been freed, messages may be cancelled | |
132 | |
133 hv_free(_c); | |
134 } | |
135 | |
136 | |
137 | |
138 /* | |
139 * Static Function Implementation | |
140 */ | |
141 static void cBinop_62MLs_sendMessage(HvBase *_c, int letIn, const HvMessage *const m) { | |
142 cUnop_onMessage(_c, HV_UNOP_FLOOR, m, &cUnop_Rm4T9_sendMessage); | |
143 } | |
144 | |
145 static void cUnop_Rm4T9_sendMessage(HvBase *_c, int letIn, const HvMessage *const m) { | |
146 cMsg_eMw6t_sendMessage(_c, 0, m); | |
147 } | |
148 | |
149 static void cRandom_Uxs9y_sendMessage(HvBase *_c, int letIn, const HvMessage *const m) { | |
150 cBinop_onMessage(_c, &Context(_c)->cBinop_62MLs, HV_BINOP_MULTIPLY, 0, m, &cBinop_62MLs_sendMessage); | |
151 } | |
152 | |
153 static void cLoadbang_XJMP6_sendMessage(HvBase *_c, int letIn, const HvMessage *const m) { | |
154 cRandom_onMessage(_c, &Context(_c)->cRandom_Uxs9y, 0, m, &cRandom_Uxs9y_sendMessage); | |
155 } | |
156 | |
157 static void cMsg_eMw6t_sendMessage(HvBase *_c, int letIn, const HvMessage *const n) { | |
158 HvMessage *m = NULL; | |
159 m = HV_MESSAGE_ON_STACK(2); | |
160 msg_init(m, 2, msg_getTimestamp(n)); | |
161 msg_setElementToFrom(m, 0, n, 0); | |
162 msg_setFloat(m, 1, 1.0f); | |
163 sVari_onMessage(_c, &Context(_c)->sVari_ecpIx, m); | |
164 } | |
165 | |
166 static void cBinop_vHnCM_sendMessage(HvBase *_c, int letIn, const HvMessage *const m) { | |
167 cBinop_onMessage(_c, &Context(_c)->cBinop_PmuD1, HV_BINOP_MAX, 0, m, &cBinop_PmuD1_sendMessage); | |
168 } | |
169 | |
170 static void cBinop_PmuD1_sendMessage(HvBase *_c, int letIn, const HvMessage *const m) { | |
171 cBinop_k_onMessage(_c, NULL, HV_BINOP_SUBTRACT, 1.0f, 0, m, &cBinop_1u9M5_sendMessage); | |
172 sVarf_onMessage(_c, &Context(_c)->sVarf_VF9rD, m); | |
173 } | |
174 | |
175 static void cBinop_lT4qw_sendMessage(HvBase *_c, int letIn, const HvMessage *const m) { | |
176 cBinop_onMessage(_c, &Context(_c)->cBinop_vHnCM, HV_BINOP_MIN, 0, m, &cBinop_vHnCM_sendMessage); | |
177 } | |
178 | |
179 static void cBinop_vpZDi_sendMessage(HvBase *_c, int letIn, const HvMessage *const m) { | |
180 cBinop_onMessage(_c, &Context(_c)->cBinop_lT4qw, HV_BINOP_MULTIPLY, 1, m, &cBinop_lT4qw_sendMessage); | |
181 } | |
182 | |
183 static void cMsg_zpcIL_sendMessage(HvBase *_c, int letIn, const HvMessage *const n) { | |
184 HvMessage *m = NULL; | |
185 m = HV_MESSAGE_ON_STACK(2); | |
186 msg_init(m, 2, msg_getTimestamp(n)); | |
187 msg_setFloat(m, 0, 6.28319f); | |
188 msg_setElementToFrom(m, 1, n, 0); | |
189 cBinop_k_onMessage(_c, NULL, HV_BINOP_DIVIDE, 0.0f, 0, m, &cBinop_vpZDi_sendMessage); | |
190 } | |
191 | |
192 static void cMsg_pfnj7_sendMessage(HvBase *_c, int letIn, const HvMessage *const n) { | |
193 HvMessage *m = NULL; | |
194 m = HV_MESSAGE_ON_STACK(1); | |
195 msg_init(m, 1, msg_getTimestamp(n)); | |
196 msg_setSymbol(m, 0, "samplerate"); | |
197 cSystem_onMessage(_c, NULL, 0, m, &cSystem_lJZJR_sendMessage); | |
198 } | |
199 | |
200 static void cSystem_lJZJR_sendMessage(HvBase *_c, int letIn, const HvMessage *const m) { | |
201 cMsg_zpcIL_sendMessage(_c, 0, m); | |
202 } | |
203 | |
204 static void cVar_cPxQc_sendMessage(HvBase *_c, int letIn, const HvMessage *const m) { | |
205 cBinop_onMessage(_c, &Context(_c)->cBinop_lT4qw, HV_BINOP_MULTIPLY, 0, m, &cBinop_lT4qw_sendMessage); | |
206 } | |
207 | |
208 static void cBinop_1u9M5_sendMessage(HvBase *_c, int letIn, const HvMessage *const m) { | |
209 sVarf_onMessage(_c, &Context(_c)->sVarf_0bFmM, m); | |
210 } | |
211 | |
212 static void cLoadbang_AXnu9_sendMessage(HvBase *_c, int letIn, const HvMessage *const m) { | |
213 cMsg_pfnj7_sendMessage(_c, 0, m); | |
214 cVar_onMessage(_c, &Context(_c)->cVar_cPxQc, 0, m, &cVar_cPxQc_sendMessage); | |
215 } | |
216 | |
217 | |
218 | |
219 | |
220 /* | |
221 * Context Process Implementation | |
222 */ | |
223 | |
224 int hv_bbb_process(Hv_bbb *const _c, float **const inputBuffers, float **const outputBuffers, int nx) { | |
225 const int n4 = nx & ~HV_N_SIMD_MASK; // ensure that the block size is a multiple of HV_N_SIMD | |
226 | |
227 // temporary signal vars | |
228 hv_bufferf_t Bf0, Bf1, Bf2, Bf3, Bf4; | |
229 hv_bufferi_t Bi0, Bi1; | |
230 | |
231 // input and output vars | |
232 hv_bufferf_t O0, O1; | |
233 | |
234 // declare and init the zero buffer | |
235 hv_bufferf_t ZERO; __hv_zero_f(VOf(ZERO)); | |
236 | |
237 hv_uint32_t nextBlock = Base(_c)->blockStartTimestamp; | |
238 for (int n = 0; n < n4; n += HV_N_SIMD) { | |
239 | |
240 // process all of the messages for this block | |
241 nextBlock += HV_N_SIMD; | |
242 while (mq_hasMessageBefore(&Base(_c)->mq, nextBlock)) { | |
243 MessageNode *const node = mq_peek(&Base(_c)->mq); | |
244 node->sendMessage(Base(_c), node->let, node->m); | |
245 mq_pop(&Base(_c)->mq); | |
246 } | |
247 | |
248 | |
249 | |
250 // zero output buffers | |
251 __hv_zero_f(VOf(O0)); | |
252 __hv_zero_f(VOf(O1)); | |
253 | |
254 // process all signal functions | |
255 __hv_var_i(&_c->sVari_ecpIx, VOi(Bi0)); | |
256 __hv_var_k_i(VOi(Bi1), 16807, 16807, 16807, 16807, 16807, 16807, 16807, 16807, 0); | |
257 __hv_mul_i(VIi(Bi0), VIi(Bi1), VOi(Bi1)); | |
258 __hv_cast_if(VIi(Bi1), VOf(Bf0)); | |
259 __hv_var_k_f(VOf(Bf1), 4.65661e-10f, 4.65661e-10f, 4.65661e-10f, 4.65661e-10f, 4.65661e-10f, 4.65661e-10f, 4.65661e-10f, 4.65661e-10f, 0); | |
260 __hv_mul_f(VIf(Bf0), VIf(Bf1), VOf(Bf1)); | |
261 sVarseti_process(&_c->sVari_ecpIx, VIi(Bi1)); | |
262 __hv_var_f(&_c->sVarf_VF9rD, VOf(Bf0)); | |
263 __hv_mul_f(VIf(Bf1), VIf(Bf0), VOf(Bf0)); | |
264 __hv_var_f(&_c->sVarf_0bFmM, VOf(Bf1)); | |
265 __hv_rpole_f(&_c->sRPole_WxgWS, VIf(Bf0), VIf(Bf1), VOf(Bf1)); | |
266 __hv_var_k_f(VOf(Bf0), 1000000.0f, 1000000.0f, 1000000.0f, 1000000.0f, 1000000.0f, 1000000.0f, 1000000.0f, 1000000.0f, 0); | |
267 __hv_mul_f(VIf(Bf1), VIf(Bf0), VOf(Bf0)); | |
268 __hv_phasor_k_f(&_c->sPhasor_YcHM3, VOf(Bf1)); | |
269 __hv_del1_f(&_c->sDel1_FfVih, VIf(Bf1), VOf(Bf2)); | |
270 __hv_lt_f(VIf(Bf1), VIf(Bf2), VOf(Bf2)); | |
271 __hv_samphold_f(&_c->sSamphold_hq9sm, VIf(Bf0), VIf(Bf2), VOf(Bf2)); | |
272 __hv_phasor_f(&_c->sPhasor_n1TcS, VIf(Bf2), VOf(Bf2)); | |
273 __hv_var_k_f(VOf(Bf0), 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0); | |
274 __hv_sub_f(VIf(Bf2), VIf(Bf0), VOf(Bf0)); | |
275 __hv_abs_f(VIf(Bf0), VOf(Bf0)); | |
276 __hv_var_k_f(VOf(Bf2), 0.25f, 0.25f, 0.25f, 0.25f, 0.25f, 0.25f, 0.25f, 0.25f, 0); | |
277 __hv_sub_f(VIf(Bf0), VIf(Bf2), VOf(Bf2)); | |
278 __hv_var_k_f(VOf(Bf0), 6.28319f, 6.28319f, 6.28319f, 6.28319f, 6.28319f, 6.28319f, 6.28319f, 6.28319f, 0); | |
279 __hv_mul_f(VIf(Bf2), VIf(Bf0), VOf(Bf0)); | |
280 __hv_mul_f(VIf(Bf0), VIf(Bf0), VOf(Bf2)); | |
281 __hv_mul_f(VIf(Bf0), VIf(Bf2), VOf(Bf1)); | |
282 __hv_mul_f(VIf(Bf1), VIf(Bf2), VOf(Bf2)); | |
283 __hv_var_k_f(VOf(Bf3), 0.00784314f, 0.00784314f, 0.00784314f, 0.00784314f, 0.00784314f, 0.00784314f, 0.00784314f, 0.00784314f, 0); | |
284 __hv_var_k_f(VOf(Bf4), 0.166667f, 0.166667f, 0.166667f, 0.166667f, 0.166667f, 0.166667f, 0.166667f, 0.166667f, 0); | |
285 __hv_mul_f(VIf(Bf1), VIf(Bf4), VOf(Bf4)); | |
286 __hv_sub_f(VIf(Bf0), VIf(Bf4), VOf(Bf4)); | |
287 __hv_fma_f(VIf(Bf2), VIf(Bf3), VIf(Bf4), VOf(Bf4)); | |
288 __hv_var_k_f(VOf(Bf3), 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0); | |
289 __hv_mul_f(VIf(Bf4), VIf(Bf3), VOf(Bf3)); | |
290 __hv_add_f(VIf(Bf3), VIf(O0), VOf(O0)); | |
291 __hv_add_f(VIf(Bf3), VIf(O1), VOf(O1)); | |
292 | |
293 // save output vars to output buffer | |
294 __hv_store_f(outputBuffers[0]+n, VIf(O0)); | |
295 __hv_store_f(outputBuffers[1]+n, VIf(O1)); | |
296 } | |
297 | |
298 Base(_c)->blockStartTimestamp = nextBlock; | |
299 | |
300 return n4; // return the number of frames processed | |
301 } | |
302 | |
303 int hv_bbb_process_inline(Hv_bbb *c, float *const inputBuffers, float *const outputBuffers, int n4) { | |
304 hv_assert(!(n4 & HV_N_SIMD_MASK)); // ensure that n4 is a multiple of HV_N_SIMD | |
305 int i = ctx_getNumInputChannels(Base(c)); | |
306 float **bIn = (float **) hv_alloca(i*sizeof(float *)); | |
307 while (i--) bIn[i] = inputBuffers+(i*n4); | |
308 | |
309 i = ctx_getNumOutputChannels(Base(c)); | |
310 float **bOut = (float **) hv_alloca(i*sizeof(float *)); | |
311 while (i--) bOut[i] = outputBuffers+(i*n4); | |
312 | |
313 int n = hv_bbb_process(c, bIn, bOut, n4); | |
314 return n; | |
315 } | |
316 | |
317 int hv_bbb_process_inline_short(Hv_bbb *c, short *const inputBuffers, short *const outputBuffers, int n4) { | |
318 hv_assert(!(n4 & HV_N_SIMD_MASK)); // ensure that n4 is a multiple of HV_N_SIMD | |
319 int numChannels = ctx_getNumInputChannels(Base(c)); | |
320 float *bIn = (float *) hv_alloca(numChannels*n4*sizeof(float)); | |
321 for (int i = 0; i < numChannels; ++i) { | |
322 for (int j = 0; j < n4; ++j) { | |
323 bIn[i*n4+j] = ((float) inputBuffers[i+numChannels*j]) * 0.00003051757813f; | |
324 } | |
325 } | |
326 | |
327 numChannels = ctx_getNumOutputChannels(Base(c)); | |
328 float *bOut = (float *) hv_alloca(numChannels*n4*sizeof(float)); | |
329 | |
330 int n = hv_bbb_process_inline(c, bIn, bOut, n4); | |
331 | |
332 for (int i = 0; i < numChannels; ++i) { | |
333 for (int j = 0; j < n4; ++j) { | |
334 outputBuffers[i+numChannels*j] = (short) (bOut[i*n4+j] * 32767.0f); | |
335 } | |
336 } | |
337 | |
338 return n; | |
339 } |