Mercurial > hg > beaglert
comparison projects/heavy/circularBuffer/SignalVar.c @ 163:20b52283c7b4 heavy-updated
- added circular buffer pd/heavy example (works but process needs to be killed manually if launched via ssh?)
author | chnrx <chris.heinrichs@gmail.com> |
---|---|
date | Thu, 12 Nov 2015 15:55:30 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
162:c3e8226a5651 | 163:20b52283c7b4 |
---|---|
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 #include "SignalVar.h" | |
18 | |
19 // __var~f | |
20 | |
21 static void sVarf_update(SignalVarf *o, float k, float step, bool reverse) { | |
22 #if HV_SIMD_AVX | |
23 if (reverse) o->v = _mm256_setr_ps(k+7.0f*step, k+6.0f*step, k+5.0f*step, k+4.0f*step, k+3.0f*step, k+2.0f*step, k+step, k); | |
24 else o->v = _mm256_set_ps(k+7.0f*step, k+6.0f*step, k+5.0f*step, k+4.0f*step, k+3.0f*step, k+2.0f*step, k+step, k); | |
25 #elif HV_SIMD_SSE | |
26 if (reverse) o->v = _mm_setr_ps(k+3.0f*step, k+2.0f*step, k+step, k); | |
27 else o->v = _mm_set_ps(k+3.0f*step, k+2.0f*step, k+step, k); | |
28 #elif HV_SIMD_NEON | |
29 if (reverse) o->v = (float32x4_t) {3.0f*step+k, 2.0f*step+k, step+k, k}; | |
30 else o->v = (float32x4_t) {k, step+k, 2.0f*step+k, 3.0f*step+k}; | |
31 #else // HV_SIMD_NONE | |
32 o->v = k; | |
33 #endif | |
34 } | |
35 | |
36 hv_size_t sVarf_init(SignalVarf *o, float k, float step, bool reverse) { | |
37 sVarf_update(o, k, step, reverse); | |
38 return 0; | |
39 } | |
40 | |
41 void sVarf_onMessage(HvBase *_c, SignalVarf *o, const HvMessage *m) { | |
42 if (msg_isFloat(m,0)) { | |
43 sVarf_update(o, msg_getFloat(m,0), msg_isFloat(m,1) ? msg_getFloat(m,1) : 0.0f, msg_getNumElements(m) == 3); | |
44 } | |
45 } | |
46 | |
47 | |
48 | |
49 // __var~i | |
50 | |
51 static void sVari_update(SignalVari *o, int k, int step, bool reverse) { | |
52 #if HV_SIMD_AVX | |
53 if (reverse) o->v = _mm256_setr_epi32(k+7*step, k+6*step, k+5*step, k+4*step, k+3*step, k+2*step, k+step, k); | |
54 else o->v = _mm256_set_epi32(k+7*step, k+6*step, k+5*step, k+4*step, k+3*step, k+2*step, k+step, k); | |
55 #elif HV_SIMD_SSE | |
56 if (reverse) o->v = _mm_setr_epi32(k+3*step, k+2*step, k+step, k); | |
57 else o->v = _mm_set_epi32(k+3*step, k+2*step, k+step, k); | |
58 #elif HV_SIMD_NEON | |
59 if (reverse) o->v = (int32x4_t) {3*step+k, 2*step+k, step+k, k}; | |
60 else o->v = (int32x4_t) {k, step+k, 2*step+k, 3*step+k}; | |
61 #else // HV_SIMD_NEON | |
62 o->v = k; | |
63 #endif | |
64 } | |
65 | |
66 hv_size_t sVari_init(SignalVari *o, int k, int step, bool reverse) { | |
67 sVari_update(o, k, step, reverse); | |
68 return 0; | |
69 } | |
70 | |
71 void sVari_onMessage(HvBase *_c, SignalVari *o, const HvMessage *m) { | |
72 if (msg_isFloat(m,0)) { | |
73 sVari_update(o, (int) msg_getFloat(m,0), msg_isFloat(m,1) ? (int) msg_getFloat(m,1) : 0, msg_getNumElements(m) == 3); | |
74 } | |
75 } |