chris@160: /** chris@160: * Copyright (c) 2014, 2015, Enzien Audio Ltd. chris@160: * chris@160: * Permission to use, copy, modify, and/or distribute this software for any chris@160: * purpose with or without fee is hereby granted, provided that the above chris@160: * copyright notice and this permission notice appear in all copies. chris@160: * chris@160: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH chris@160: * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY chris@160: * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, chris@160: * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM chris@160: * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR chris@160: * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR chris@160: * PERFORMANCE OF THIS SOFTWARE. chris@160: */ chris@160: chris@160: #ifndef _HEAVY_TABLE_H_ chris@160: #define _HEAVY_TABLE_H_ chris@160: chris@160: #include "HvBase.h" chris@160: #include "HvMessage.h" chris@160: #include "Utils.h" chris@160: chris@160: typedef struct HvTable { chris@160: float *buffer; chris@160: // the number of values that the table is requested to have chris@160: hv_uint32_t length; chris@160: chris@160: // the number of usable values that the table actually has chris@160: // this is always an even multiple of HV_N_SIMD chris@160: hv_uint32_t size; chris@160: chris@160: // Note that the true size of the table is (size + HV_N_SIMD), chris@160: // with the trailing values used by the system, e.g. to create a circular chris@160: // buffer chris@160: hv_uint32_t allocated; chris@160: chris@160: hv_uint32_t head; // the most recently written point chris@160: } HvTable; chris@160: chris@160: hv_size_t hTable_init(HvTable *o, int length); chris@160: chris@160: hv_size_t hTable_initWithData(HvTable *o, int length, const float *const data); chris@160: chris@160: hv_size_t hTable_initWithFinalData(HvTable *o, int length, float *data); chris@160: chris@160: void hTable_free(HvTable *o); chris@160: chris@160: int hTable_resize(HvTable *o, hv_uint32_t newLength); chris@160: chris@160: void hTable_onMessage(HvBase *_c, HvTable *o, int letIn, const HvMessage *const m, chris@160: void (*sendMessage)(HvBase *, int, const HvMessage *const)); chris@160: chris@160: static inline float *hTable_getBuffer(HvTable *o) { chris@160: return o->buffer; chris@160: } chris@160: chris@160: // the user-requested length of the table (number of floats) chris@160: static inline hv_uint32_t hTable_getLength(HvTable *o) { chris@160: return o->length; chris@160: } chris@160: chris@160: // the usable length of the table (an even multiple of HV_N_SIMD) chris@160: static inline hv_uint32_t hTable_getSize(HvTable *o) { chris@160: return o->size; chris@160: } chris@160: chris@160: // the number of floats allocated to this table (usually size + HV_N_SIMD) chris@160: static inline hv_uint32_t hTable_getAllocated(HvTable *o) { chris@160: return o->allocated; chris@160: } chris@160: chris@160: static inline hv_uint32_t hTable_getHead(HvTable *o) { chris@160: return o->head; chris@160: } chris@160: chris@160: static inline void hTable_setHead(HvTable *o, hv_uint32_t head) { chris@160: o->head = head; chris@160: } chris@160: chris@160: #endif // _HEAVY_TABLE_H_