annotate projects/heavy/envelopeTrigger/Heavy.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 "HvBase.h"
chris@162 18 #include "HvTable.h"
chris@162 19
chris@162 20 #if !HV_WIN
chris@162 21 #pragma mark - Heavy Table
chris@162 22 #endif
chris@162 23
chris@162 24 int hv_table_resize(HvTable *o, hv_uint32_t newLength) {
chris@162 25 return hTable_resize(o, newLength);
chris@162 26 }
chris@162 27
chris@162 28 float *hv_table_getBuffer(HvTable *o) {
chris@162 29 return hTable_getBuffer(o);
chris@162 30 }
chris@162 31
chris@162 32 hv_size_t hv_table_getLength(HvTable *o) {
chris@162 33 return hTable_getLength(o);
chris@162 34 }
chris@162 35
chris@162 36
chris@162 37
chris@162 38 #if !HV_WIN
chris@162 39 #pragma mark - Heavy Message
chris@162 40 #endif
chris@162 41
chris@162 42 hv_size_t hv_msg_getByteSize (hv_uint32_t numElements) {
chris@162 43 return msg_getByteSize(numElements);
chris@162 44 }
chris@162 45
chris@162 46 void hv_msg_init(HvMessage *m, int numElements, hv_uint32_t timestamp) {
chris@162 47 msg_init(m, numElements, timestamp);
chris@162 48 }
chris@162 49
chris@162 50 hv_size_t hv_msg_getNumElements(const HvMessage *const m) {
chris@162 51 return msg_getNumElements(m);
chris@162 52 }
chris@162 53
chris@162 54 double hv_msg_getTimestamp(const HvMessage *const m) {
chris@162 55 return msg_getTimestamp(m);
chris@162 56 }
chris@162 57
chris@162 58 void hv_msg_setTimestamp(HvMessage *m, hv_uint32_t timestamp) {
chris@162 59 msg_setTimestamp(m, timestamp);
chris@162 60 }
chris@162 61
chris@162 62 bool hv_msg_isBang(const HvMessage *const m, int i) {
chris@162 63 return msg_isBang(m,i);
chris@162 64 }
chris@162 65
chris@162 66 void hv_msg_setBang(HvMessage *m, int i) {
chris@162 67 msg_setBang(m,i);
chris@162 68 }
chris@162 69
chris@162 70 bool hv_msg_isFloat(const HvMessage *const m, int i) {
chris@162 71 return msg_isFloat(m, i);
chris@162 72 }
chris@162 73
chris@162 74 float hv_msg_getFloat(const HvMessage *const m, int i) {
chris@162 75 return msg_getFloat(m,i);
chris@162 76 }
chris@162 77
chris@162 78 void hv_msg_setFloat(HvMessage *m, int i, float f) {
chris@162 79 msg_setFloat(m,i,f);
chris@162 80 }
chris@162 81
chris@162 82 bool hv_msg_isSymbol(const HvMessage *const m, int i) {
chris@162 83 return msg_isSymbol(m,i);
chris@162 84 }
chris@162 85
chris@162 86 char *hv_msg_getSymbol(const HvMessage *const m, int i) {
chris@162 87 return msg_getSymbol(m,i);
chris@162 88 }
chris@162 89
chris@162 90 void hv_msg_setSymbol(HvMessage *m, int i, char *s) {
chris@162 91 msg_setSymbol(m,i,s);
chris@162 92 }
chris@162 93
chris@162 94 bool hv_msg_isHash(const HvMessage *const m, int i) {
chris@162 95 return msg_isHash(m, i);
chris@162 96 }
chris@162 97
chris@162 98 unsigned int hv_msg_getHash(const HvMessage *const m, int i) {
chris@162 99 return msg_getHash(m, i);
chris@162 100 }
chris@162 101
chris@162 102 bool hv_msg_hasFormat(const HvMessage *const m, const char *fmt) {
chris@162 103 return msg_hasFormat(m, fmt);
chris@162 104 }
chris@162 105
chris@162 106 char *hv_msg_toString(const HvMessage *const m) {
chris@162 107 return msg_toString(m);
chris@162 108 }
chris@162 109
chris@162 110 HvMessage *hv_msg_copy(HvMessage *m) {
chris@162 111 return msg_copy(m);
chris@162 112 }
chris@162 113
chris@162 114 void hv_msg_free(HvMessage *m) {
chris@162 115 msg_free(m);
chris@162 116 }
chris@162 117
chris@162 118
chris@162 119
chris@162 120 #if !HV_WIN
chris@162 121 #pragma mark - Heavy Common
chris@162 122 #endif
chris@162 123
chris@162 124 double hv_getSampleRate(HvBase *c) {
chris@162 125 return ctx_getSampleRate(c);
chris@162 126 }
chris@162 127
chris@162 128 int hv_getNumInputChannels(HvBase *c) {
chris@162 129 return ctx_getNumInputChannels(c);
chris@162 130 }
chris@162 131
chris@162 132 int hv_getNumOutputChannels(HvBase *c) {
chris@162 133 return ctx_getNumOutputChannels(c);
chris@162 134 }
chris@162 135
chris@162 136 const char *hv_getName(HvBase *c) {
chris@162 137 return ctx_getName(c);
chris@162 138 }
chris@162 139
chris@162 140 void hv_setPrintHook(HvBase *c, void (*f)(double, const char *, const char *, void *)) {
chris@162 141 ctx_setPrintHook(c, f);
chris@162 142 }
chris@162 143
chris@162 144 void hv_setSendHook(HvBase *c, void (*f)(double, const char *, const HvMessage *const, void *)) {
chris@162 145 ctx_setSendHook(c, f);
chris@162 146 }
chris@162 147
chris@162 148 void hv_vscheduleMessageForReceiver(HvBase *c, const char *receiverName, const double delayMs, const char *format, ...) {
chris@162 149 va_list ap;
chris@162 150 va_start(ap, format);
chris@162 151
chris@162 152 const int numElem = (int) hv_strlen(format);
chris@162 153 HvMessage *m = HV_MESSAGE_ON_STACK(numElem);
chris@162 154 msg_init(m, numElem, c->blockStartTimestamp + (hv_uint32_t) (hv_max_d(0.0, delayMs)*ctx_getSampleRate(c)/1000.0));
chris@162 155 for (int i = 0; i < numElem; i++) {
chris@162 156 switch (format[i]) {
chris@162 157 case 'b': msg_setBang(m,i); break;
chris@162 158 case 'f': msg_setFloat(m, i, (float) va_arg(ap, double)); break;
chris@162 159 case 's': msg_setSymbol(m, i, (char *) va_arg(ap, char *)); break;
chris@162 160 default: break;
chris@162 161 }
chris@162 162 }
chris@162 163 ctx_scheduleMessageForReceiver(c, receiverName, m);
chris@162 164
chris@162 165 va_end(ap);
chris@162 166 }
chris@162 167
chris@162 168 void hv_scheduleMessageForReceiver(HvBase *c, const char *receiverName, double delayMs, HvMessage *m) {
chris@162 169 hv_assert(delayMs >= 0.0);
chris@162 170 msg_setTimestamp(m, c->blockStartTimestamp + (hv_uint32_t) (delayMs*ctx_getSampleRate(c)/1000.0));
chris@162 171 ctx_scheduleMessageForReceiver(c, receiverName, m);
chris@162 172 }
chris@162 173
chris@162 174 HvTable *hv_getTableForName(HvBase *c, const char *tableName) {
chris@162 175 return ctx_getTableForName(c, tableName);
chris@162 176 }
chris@162 177
chris@162 178 void hv_cancelMessage(HvBase *c, HvMessage *m) {
chris@162 179 ctx_cancelMessage(c, m, NULL);
chris@162 180 }
chris@162 181
chris@162 182 double hv_getCurrentTime(HvBase *c) {
chris@162 183 return ((double) c->blockStartTimestamp)/c->sampleRate;
chris@162 184 }
chris@162 185
chris@162 186 void *hv_getUserData(HvBase *c) {
chris@162 187 return ctx_getUserData(c);
chris@162 188 }
chris@162 189
chris@162 190 void hv_setUserData(HvBase *c, void *userData) {
chris@162 191 ctx_setUserData(c, userData);
chris@162 192 }
chris@162 193
chris@162 194 void hv_setBasePath(HvBase *c, const char *basePath) {
chris@162 195 ctx_setBasePath(c, basePath);
chris@162 196 }