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: #ifndef _HEAVY_TABLE_H_ chris@162: #define _HEAVY_TABLE_H_ chris@162: chris@162: #include "HvBase.h" chris@162: #include "HvMessage.h" chris@162: #include "Utils.h" chris@162: chris@162: typedef struct HvTable { chris@162: float *buffer; chris@162: // the number of values that the table is requested to have chris@162: hv_uint32_t length; chris@162: chris@162: // the number of usable values that the table actually has chris@162: // this is always an even multiple of HV_N_SIMD chris@162: hv_uint32_t size; chris@162: chris@162: // Note that the true size of the table is (size + HV_N_SIMD), chris@162: // with the trailing values used by the system, e.g. to create a circular chris@162: // buffer chris@162: hv_uint32_t allocated; chris@162: chris@162: hv_uint32_t head; // the most recently written point chris@162: } HvTable; chris@162: chris@162: hv_size_t hTable_init(HvTable *o, int length); chris@162: chris@162: hv_size_t hTable_initWithData(HvTable *o, int length, const float *const data); chris@162: chris@162: hv_size_t hTable_initWithFinalData(HvTable *o, int length, float *data); chris@162: chris@162: void hTable_free(HvTable *o); chris@162: chris@162: int hTable_resize(HvTable *o, hv_uint32_t newLength); chris@162: chris@162: void hTable_onMessage(HvBase *_c, HvTable *o, int letIn, const HvMessage *const m, chris@162: void (*sendMessage)(HvBase *, int, const HvMessage *const)); chris@162: chris@162: static inline float *hTable_getBuffer(HvTable *o) { chris@162: return o->buffer; chris@162: } chris@162: chris@162: // the user-requested length of the table (number of floats) chris@162: static inline hv_uint32_t hTable_getLength(HvTable *o) { chris@162: return o->length; chris@162: } chris@162: chris@162: // the usable length of the table (an even multiple of HV_N_SIMD) chris@162: static inline hv_uint32_t hTable_getSize(HvTable *o) { chris@162: return o->size; chris@162: } chris@162: chris@162: // the number of floats allocated to this table (usually size + HV_N_SIMD) chris@162: static inline hv_uint32_t hTable_getAllocated(HvTable *o) { chris@162: return o->allocated; chris@162: } chris@162: chris@162: static inline hv_uint32_t hTable_getHead(HvTable *o) { chris@162: return o->head; chris@162: } chris@162: chris@162: static inline void hTable_setHead(HvTable *o, hv_uint32_t head) { chris@162: o->head = head; chris@162: } chris@162: chris@162: #endif // _HEAVY_TABLE_H_