annotate projects/heavy/circularBuffer/HvTable.h @ 163:20b52283c7b4 heavy-updated

- added circular buffer pd/heavy example (works but process needs to be killed manually if launched via ssh?)
author chnrx <chris.heinrichs@gmail.com>
date Thu, 12 Nov 2015 15:55:30 +0000
parents
children
rev   line source
chris@163 1 /**
chris@163 2 * Copyright (c) 2014, 2015, Enzien Audio Ltd.
chris@163 3 *
chris@163 4 * Permission to use, copy, modify, and/or distribute this software for any
chris@163 5 * purpose with or without fee is hereby granted, provided that the above
chris@163 6 * copyright notice and this permission notice appear in all copies.
chris@163 7 *
chris@163 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
chris@163 9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
chris@163 10 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
chris@163 11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
chris@163 12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
chris@163 13 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
chris@163 14 * PERFORMANCE OF THIS SOFTWARE.
chris@163 15 */
chris@163 16
chris@163 17 #ifndef _HEAVY_TABLE_H_
chris@163 18 #define _HEAVY_TABLE_H_
chris@163 19
chris@163 20 #include "HvBase.h"
chris@163 21 #include "HvMessage.h"
chris@163 22 #include "Utils.h"
chris@163 23
chris@163 24 typedef struct HvTable {
chris@163 25 float *buffer;
chris@163 26 // the number of values that the table is requested to have
chris@163 27 hv_uint32_t length;
chris@163 28
chris@163 29 // the number of usable values that the table actually has
chris@163 30 // this is always an even multiple of HV_N_SIMD
chris@163 31 hv_uint32_t size;
chris@163 32
chris@163 33 // Note that the true size of the table is (size + HV_N_SIMD),
chris@163 34 // with the trailing values used by the system, e.g. to create a circular
chris@163 35 // buffer
chris@163 36 hv_uint32_t allocated;
chris@163 37
chris@163 38 hv_uint32_t head; // the most recently written point
chris@163 39 } HvTable;
chris@163 40
chris@163 41 hv_size_t hTable_init(HvTable *o, int length);
chris@163 42
chris@163 43 hv_size_t hTable_initWithData(HvTable *o, int length, const float *const data);
chris@163 44
chris@163 45 hv_size_t hTable_initWithFinalData(HvTable *o, int length, float *data);
chris@163 46
chris@163 47 void hTable_free(HvTable *o);
chris@163 48
chris@163 49 int hTable_resize(HvTable *o, hv_uint32_t newLength);
chris@163 50
chris@163 51 void hTable_onMessage(HvBase *_c, HvTable *o, int letIn, const HvMessage *const m,
chris@163 52 void (*sendMessage)(HvBase *, int, const HvMessage *const));
chris@163 53
chris@163 54 static inline float *hTable_getBuffer(HvTable *o) {
chris@163 55 return o->buffer;
chris@163 56 }
chris@163 57
chris@163 58 // the user-requested length of the table (number of floats)
chris@163 59 static inline hv_uint32_t hTable_getLength(HvTable *o) {
chris@163 60 return o->length;
chris@163 61 }
chris@163 62
chris@163 63 // the usable length of the table (an even multiple of HV_N_SIMD)
chris@163 64 static inline hv_uint32_t hTable_getSize(HvTable *o) {
chris@163 65 return o->size;
chris@163 66 }
chris@163 67
chris@163 68 // the number of floats allocated to this table (usually size + HV_N_SIMD)
chris@163 69 static inline hv_uint32_t hTable_getAllocated(HvTable *o) {
chris@163 70 return o->allocated;
chris@163 71 }
chris@163 72
chris@163 73 static inline hv_uint32_t hTable_getHead(HvTable *o) {
chris@163 74 return o->head;
chris@163 75 }
chris@163 76
chris@163 77 static inline void hTable_setHead(HvTable *o, hv_uint32_t head) {
chris@163 78 o->head = head;
chris@163 79 }
chris@163 80
chris@163 81 #endif // _HEAVY_TABLE_H_