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