comparison projects/heavy/hello-world/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
43
44
45 /*
46 * Static Helper Functions
47 */
48
49 static void ctx_intern_scheduleMessageForReceiver(
50 HvBase *const _c, const char *name, HvMessage *m) {
51 switch (msg_symbolToHash(name)) {
52 default: return;
53 }
54 }
55
56 static struct HvTable *ctx_intern_getTableForHash(HvBase *const _c, hv_uint32_t h) {
57 switch (h) {
58 default: return NULL;
59 }
60 }
61
62
63
64 /*
65 * Context Include and Implementatons
66 */
67
68 Hv_bbb *hv_bbb_new_with_pool(double sampleRate, int poolKb) {
69 hv_assert(sampleRate > 0.0); // can't initialise with sampling rate of 0
70 hv_assert(poolKb >= 1); // a message pool of some reasonable size is always needed
71 Hv_bbb *const _c = (Hv_bbb *) hv_malloc(sizeof(Hv_bbb));
72
73 Base(_c)->numInputChannels = 0;
74 Base(_c)->numOutputChannels = 2;
75 Base(_c)->sampleRate = sampleRate;
76 Base(_c)->blockStartTimestamp = 0;
77 Base(_c)->f_scheduleMessageForReceiver = &ctx_intern_scheduleMessageForReceiver;
78 Base(_c)->f_getTableForHash = &ctx_intern_getTableForHash;
79 mq_initWithPoolSize(&Base(_c)->mq, poolKb);
80 Base(_c)->basePath = NULL;
81 Base(_c)->printHook = NULL;
82 Base(_c)->sendHook = NULL;
83 Base(_c)->userData = NULL;
84 Base(_c)->name = "bbb";
85
86 Base(_c)->numBytes = sizeof(Hv_bbb);
87 Base(_c)->numBytes += sPhasor_k_init(&_c->sPhasor_O587H, 440.0f, sampleRate);
88
89 // loadbang
90
91 return _c;
92 }
93
94 Hv_bbb *hv_bbb_new(double sampleRate) {
95 return hv_bbb_new_with_pool(sampleRate, 10); // default to 10KB MessagePool
96 }
97
98 void hv_bbb_free(Hv_bbb *_c) {
99
100 hv_free(Base(_c)->basePath);
101 mq_free(&Base(_c)->mq); // free queue after all objects have been freed, messages may be cancelled
102
103 hv_free(_c);
104 }
105
106
107
108 /*
109 * Static Function Implementation
110 */
111
112
113
114 /*
115 * Context Process Implementation
116 */
117
118 int hv_bbb_process(Hv_bbb *const _c, float **const inputBuffers, float **const outputBuffers, int nx) {
119 const int n4 = nx & ~HV_N_SIMD_MASK; // ensure that the block size is a multiple of HV_N_SIMD
120
121 // temporary signal vars
122 hv_bufferf_t Bf0, Bf1, Bf2, Bf3, Bf4;
123
124 // input and output vars
125 hv_bufferf_t O0, O1;
126
127 // declare and init the zero buffer
128 hv_bufferf_t ZERO; __hv_zero_f(VOf(ZERO));
129
130 hv_uint32_t nextBlock = Base(_c)->blockStartTimestamp;
131 for (int n = 0; n < n4; n += HV_N_SIMD) {
132
133 // process all of the messages for this block
134 nextBlock += HV_N_SIMD;
135 while (mq_hasMessageBefore(&Base(_c)->mq, nextBlock)) {
136 MessageNode *const node = mq_peek(&Base(_c)->mq);
137 node->sendMessage(Base(_c), node->let, node->m);
138 mq_pop(&Base(_c)->mq);
139 }
140
141
142
143 // zero output buffers
144 __hv_zero_f(VOf(O0));
145 __hv_zero_f(VOf(O1));
146
147 // process all signal functions
148 __hv_phasor_k_f(&_c->sPhasor_O587H, VOf(Bf0));
149 __hv_var_k_f(VOf(Bf1), 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0);
150 __hv_sub_f(VIf(Bf0), VIf(Bf1), VOf(Bf1));
151 __hv_abs_f(VIf(Bf1), VOf(Bf1));
152 __hv_var_k_f(VOf(Bf0), 0.25f, 0.25f, 0.25f, 0.25f, 0.25f, 0.25f, 0.25f, 0.25f, 0);
153 __hv_sub_f(VIf(Bf1), VIf(Bf0), VOf(Bf0));
154 __hv_var_k_f(VOf(Bf1), 6.28319f, 6.28319f, 6.28319f, 6.28319f, 6.28319f, 6.28319f, 6.28319f, 6.28319f, 0);
155 __hv_mul_f(VIf(Bf0), VIf(Bf1), VOf(Bf1));
156 __hv_mul_f(VIf(Bf1), VIf(Bf1), VOf(Bf0));
157 __hv_mul_f(VIf(Bf1), VIf(Bf0), VOf(Bf2));
158 __hv_mul_f(VIf(Bf2), VIf(Bf0), VOf(Bf0));
159 __hv_var_k_f(VOf(Bf3), 0.00784314f, 0.00784314f, 0.00784314f, 0.00784314f, 0.00784314f, 0.00784314f, 0.00784314f, 0.00784314f, 0);
160 __hv_var_k_f(VOf(Bf4), 0.166667f, 0.166667f, 0.166667f, 0.166667f, 0.166667f, 0.166667f, 0.166667f, 0.166667f, 0);
161 __hv_mul_f(VIf(Bf2), VIf(Bf4), VOf(Bf4));
162 __hv_sub_f(VIf(Bf1), VIf(Bf4), VOf(Bf4));
163 __hv_fma_f(VIf(Bf0), VIf(Bf3), VIf(Bf4), VOf(Bf4));
164 __hv_var_k_f(VOf(Bf3), 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0);
165 __hv_mul_f(VIf(Bf4), VIf(Bf3), VOf(Bf3));
166 __hv_add_f(VIf(Bf3), VIf(O1), VOf(O1));
167 __hv_add_f(VIf(Bf3), VIf(O0), VOf(O0));
168
169 // save output vars to output buffer
170 __hv_store_f(outputBuffers[0]+n, VIf(O0));
171 __hv_store_f(outputBuffers[1]+n, VIf(O1));
172 }
173
174 Base(_c)->blockStartTimestamp = nextBlock;
175
176 return n4; // return the number of frames processed
177 }
178
179 int hv_bbb_process_inline(Hv_bbb *c, float *const inputBuffers, float *const outputBuffers, int n4) {
180 hv_assert(!(n4 & HV_N_SIMD_MASK)); // ensure that n4 is a multiple of HV_N_SIMD
181 int i = ctx_getNumInputChannels(Base(c));
182 float **bIn = (float **) hv_alloca(i*sizeof(float *));
183 while (i--) bIn[i] = inputBuffers+(i*n4);
184
185 i = ctx_getNumOutputChannels(Base(c));
186 float **bOut = (float **) hv_alloca(i*sizeof(float *));
187 while (i--) bOut[i] = outputBuffers+(i*n4);
188
189 int n = hv_bbb_process(c, bIn, bOut, n4);
190 return n;
191 }
192
193 int hv_bbb_process_inline_short(Hv_bbb *c, short *const inputBuffers, short *const outputBuffers, int n4) {
194 hv_assert(!(n4 & HV_N_SIMD_MASK)); // ensure that n4 is a multiple of HV_N_SIMD
195 int numChannels = ctx_getNumInputChannels(Base(c));
196 float *bIn = (float *) hv_alloca(numChannels*n4*sizeof(float));
197 for (int i = 0; i < numChannels; ++i) {
198 for (int j = 0; j < n4; ++j) {
199 bIn[i*n4+j] = ((float) inputBuffers[i+numChannels*j]) * 0.00003051757813f;
200 }
201 }
202
203 numChannels = ctx_getNumOutputChannels(Base(c));
204 float *bOut = (float *) hv_alloca(numChannels*n4*sizeof(float));
205
206 int n = hv_bbb_process_inline(c, bIn, bOut, n4);
207
208 for (int i = 0; i < numChannels; ++i) {
209 for (int j = 0; j < n4; ++j) {
210 outputBuffers[i+numChannels*j] = (short) (bOut[i*n4+j] * 32767.0f);
211 }
212 }
213
214 return n;
215 }