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