annotate projects/heavy/envelopeTrigger/SignalVar.c @ 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
rev   line source
chris@162 1 /**
chris@162 2 * Copyright (c) 2014, 2015, Enzien Audio Ltd.
chris@162 3 *
chris@162 4 * Permission to use, copy, modify, and/or distribute this software for any
chris@162 5 * purpose with or without fee is hereby granted, provided that the above
chris@162 6 * copyright notice and this permission notice appear in all copies.
chris@162 7 *
chris@162 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
chris@162 9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
chris@162 10 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
chris@162 11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
chris@162 12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
chris@162 13 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
chris@162 14 * PERFORMANCE OF THIS SOFTWARE.
chris@162 15 */
chris@162 16
chris@162 17 #include "SignalVar.h"
chris@162 18
chris@162 19 // __var~f
chris@162 20
chris@162 21 static void sVarf_update(SignalVarf *o, float k, float step, bool reverse) {
chris@162 22 #if HV_SIMD_AVX
chris@162 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);
chris@162 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);
chris@162 25 #elif HV_SIMD_SSE
chris@162 26 if (reverse) o->v = _mm_setr_ps(k+3.0f*step, k+2.0f*step, k+step, k);
chris@162 27 else o->v = _mm_set_ps(k+3.0f*step, k+2.0f*step, k+step, k);
chris@162 28 #elif HV_SIMD_NEON
chris@162 29 if (reverse) o->v = (float32x4_t) {3.0f*step+k, 2.0f*step+k, step+k, k};
chris@162 30 else o->v = (float32x4_t) {k, step+k, 2.0f*step+k, 3.0f*step+k};
chris@162 31 #else // HV_SIMD_NONE
chris@162 32 o->v = k;
chris@162 33 #endif
chris@162 34 }
chris@162 35
chris@162 36 hv_size_t sVarf_init(SignalVarf *o, float k, float step, bool reverse) {
chris@162 37 sVarf_update(o, k, step, reverse);
chris@162 38 return 0;
chris@162 39 }
chris@162 40
chris@162 41 void sVarf_onMessage(HvBase *_c, SignalVarf *o, const HvMessage *m) {
chris@162 42 if (msg_isFloat(m,0)) {
chris@162 43 sVarf_update(o, msg_getFloat(m,0), msg_isFloat(m,1) ? msg_getFloat(m,1) : 0.0f, msg_getNumElements(m) == 3);
chris@162 44 }
chris@162 45 }
chris@162 46
chris@162 47
chris@162 48
chris@162 49 // __var~i
chris@162 50
chris@162 51 static void sVari_update(SignalVari *o, int k, int step, bool reverse) {
chris@162 52 #if HV_SIMD_AVX
chris@162 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);
chris@162 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);
chris@162 55 #elif HV_SIMD_SSE
chris@162 56 if (reverse) o->v = _mm_setr_epi32(k+3*step, k+2*step, k+step, k);
chris@162 57 else o->v = _mm_set_epi32(k+3*step, k+2*step, k+step, k);
chris@162 58 #elif HV_SIMD_NEON
chris@162 59 if (reverse) o->v = (int32x4_t) {3*step+k, 2*step+k, step+k, k};
chris@162 60 else o->v = (int32x4_t) {k, step+k, 2*step+k, 3*step+k};
chris@162 61 #else // HV_SIMD_NEON
chris@162 62 o->v = k;
chris@162 63 #endif
chris@162 64 }
chris@162 65
chris@162 66 hv_size_t sVari_init(SignalVari *o, int k, int step, bool reverse) {
chris@162 67 sVari_update(o, k, step, reverse);
chris@162 68 return 0;
chris@162 69 }
chris@162 70
chris@162 71 void sVari_onMessage(HvBase *_c, SignalVari *o, const HvMessage *m) {
chris@162 72 if (msg_isFloat(m,0)) {
chris@162 73 sVari_update(o, (int) msg_getFloat(m,0), msg_isFloat(m,1) ? (int) msg_getFloat(m,1) : 0, msg_getNumElements(m) == 3);
chris@162 74 }
chris@162 75 }