chris@163: /** chris@163: * Copyright (c) 2014, 2015, Enzien Audio Ltd. chris@163: * chris@163: * Permission to use, copy, modify, and/or distribute this software for any chris@163: * purpose with or without fee is hereby granted, provided that the above chris@163: * copyright notice and this permission notice appear in all copies. chris@163: * chris@163: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH chris@163: * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY chris@163: * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, chris@163: * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM chris@163: * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR chris@163: * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR chris@163: * PERFORMANCE OF THIS SOFTWARE. chris@163: */ chris@163: chris@163: #include "SignalTabread.h" chris@163: chris@163: hv_size_t sTabread_init(SignalTabread *o, HvTable *table, bool forceAlignedLoads) { chris@163: o->table = table; chris@163: o->head = 0; chris@163: o->forceAlignedLoads = forceAlignedLoads; chris@163: return 0; chris@163: } chris@163: chris@163: void sTabread_onMessage(HvBase *_c, SignalTabread *o, int letIn, const HvMessage *const m) { chris@163: switch (letIn) { chris@163: case 0: { chris@163: if (o->table != NULL) { chris@163: switch (msg_getType(m,0)) { chris@163: case BANG: o->head = 0; break; chris@163: case FLOAT: { chris@163: hv_uint32_t h = (hv_uint32_t) hv_abs_f(msg_getFloat(m,0)); chris@163: if (msg_getFloat(m,0) < 0.0f) { chris@163: // if input is negative, wrap around the end of the table chris@163: h = (hv_uint32_t) hTable_getSize(o->table) - h; chris@163: } chris@163: o->head = o->forceAlignedLoads ? h & ~HV_N_SIMD_MASK : h; chris@163: break; chris@163: } chris@163: default: break; chris@163: } chris@163: } chris@163: break; chris@163: } chris@163: case 1: { chris@163: if (msg_isHashLike(m,0)) { chris@163: o->table = ctx_getTableForHash(_c, msg_getHash(m,0)); chris@163: } chris@163: break; chris@163: } chris@163: default: break; chris@163: } chris@163: } chris@163: chris@163: chris@163: chris@163: #if HV_APPLE chris@163: #pragma mark - Tabhead chris@163: #endif chris@163: chris@163: void sTabhead_onMessage(HvBase *_c, SignalTabhead *o, const HvMessage *const m) { chris@163: if (msg_isHashLike(m,0)) { chris@163: o->table = ctx_getTableForHash(_c, msg_getHash(m,0)); chris@163: } chris@163: } chris@163: chris@163: hv_size_t sTabhead_init(SignalTabhead *o, HvTable *table) { chris@163: o->table = table; chris@163: return 0; chris@163: }