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