comparison projects/heavy/envelopeTrigger/Heavy_bbb.h @ 162:c3e8226a5651 heavy-updated

- added additional flags to C rules (-DNDEBUG, -mfpu=neon) - sample-accurate envelope triggering pd/heavy example
author chnrx <chris.heinrichs@gmail.com>
date Thu, 12 Nov 2015 14:59:46 +0000
parents
children
comparison
equal deleted inserted replaced
161:07735c9d95c8 162:c3e8226a5651
1
2 /**
3 * Copyright (c) 2014,2015 Enzien Audio, Ltd.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, and/or
9 * sublicense copies of the Software, strictly on a non-commercial basis,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 *
24 * DO NOT MODIFY. THIS CODE IS MACHINE GENERATED BY THE SECTION6 HEAVY COMPILER.
25 */
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 #include "Utils.h"
32
33 #if !HV_MSVC
34 #pragma mark - Heavy Table
35 #endif
36
37 #ifndef _HEAVY_TABLE_H_
38 #define _HEAVY_TABLE_H_
39
40 typedef struct HvTable HvTable;
41
42 /**
43 * Resizes the table to the given length. Length must be positive.
44 * Existing contents are copied to the new table. Remaining space is cleared.
45 * The change in byte-size of the table is returned. A value of zero indicates error.
46 */
47 HV_EXPORT int hv_table_resize(HvTable *o, hv_uint32_t newLength);
48
49 /** Returns a pointer to the raw buffer backing this table. DO NOT free it. */
50 HV_EXPORT float *hv_table_getBuffer(HvTable *o);
51
52 /** Returns the length of this table in samples. */
53 HV_EXPORT int hv_table_getLength(HvTable *o);
54
55 #endif // _HEAVY_TABLE_H_
56
57
58
59 #if !HV_MSVC
60 #pragma mark - Heavy Message
61 #endif
62
63 #ifndef _HEAVY_MESSAGE_H_
64 #define _HEAVY_MESSAGE_H_
65
66 HV_EXPORT typedef struct HvMessage HvMessage;
67
68 /** Returns the byte size of a HvMessage with a number of elements on the heap. */
69 HV_EXPORT hv_size_t hv_msg_getByteSize(int numElements);
70
71 /** Create a HvMessage on the stack with a number of elements. This message MUST NOT be freed. */
72 #define hv_msg_onStack(_n) ((HvMessage *) hv_alloca(hv_msg_getByteSize(_n)))
73
74 /** Initialise a message with the number of elements and a timestamp (in milliseconds). */
75 HV_EXPORT void hv_msg_init(HvMessage *m, int numElements, double timestamp);
76
77 /** Returns the number of elements in this message. */
78 HV_EXPORT int hv_msg_getNumElements(const HvMessage *const m);
79
80 /** Returns the time at which this message exists (in milliseconds). */
81 HV_EXPORT hv_uint32_t hv_msg_getTimestamp(const HvMessage *const m);
82
83 /** Set the time at which this message should be executed (in milliseconds). */
84 HV_EXPORT void hv_msg_setTimestamp(HvMessage *m, hv_uint32_t timestamp);
85
86 /** Returns true of the indexed element is a bang. False otherwise. Index is not bounds checked. */
87 HV_EXPORT bool hv_msg_isBang(const HvMessage *const m, int i);
88
89 /** Sets the indexed element to a bang. Index is not bounds checked. */
90 HV_EXPORT void hv_msg_setBang(HvMessage *m, int i);
91
92 /** Returns true of the indexed element is a float. False otherwise. Index is not bounds checked. */
93 HV_EXPORT bool hv_msg_isFloat(const HvMessage *const m, int i);
94
95 /** Returns the indexed element as a float value. Index is not bounds checked. */
96 HV_EXPORT float hv_msg_getFloat(const HvMessage *const m, int i);
97
98 /** Sets the indexed element to float value. Index is not bounds checked. */
99 HV_EXPORT void hv_msg_setFloat(HvMessage *m, int i, float f);
100
101 /** Returns true of the indexed element is a symbol. False otherwise. Index is not bounds checked. */
102 HV_EXPORT bool hv_msg_isSymbol(const HvMessage *const m, int i);
103
104 /** Returns the indexed element as a symbol value. Index is not bounds checked. */
105 HV_EXPORT char *hv_msg_getSymbol(const HvMessage *const m, int i);
106
107 /** Returns true of the indexed element is a hash. False otherwise. Index is not bounds checked. */
108 HV_EXPORT bool hv_msg_isHash(const HvMessage *const m, int i);
109
110 /** Returns the indexed element as a hash value. Index is not bounds checked. */
111 HV_EXPORT unsigned int hv_msg_getHash(const HvMessage *const m, int i);
112
113 /** Sets the indexed element to symbol value. Index is not bounds checked. */
114 HV_EXPORT void hv_msg_setSymbol(HvMessage *m, int i, const char *s);
115
116 /**
117 * Returns true if the message has the given format, in number of elements and type. False otherwise.
118 * Valid element types are:
119 * 'b': bang
120 * 'f': float
121 * 's': symbol
122 *
123 * For example, a message with three floats would have a format of "fff". A single bang is "b".
124 * A message with two symbols is "ss". These types can be mixed and matched in any way.
125 */
126 HV_EXPORT bool hv_msg_hasFormat(const HvMessage *const m, const char *fmt);
127
128 /**
129 * Returns a basic string representation of the message.
130 * The character array MUST be deallocated by the caller.
131 */
132 HV_EXPORT char *hv_msg_toString(const HvMessage *const m);
133
134 /** Copy a message onto the stack. The message persists. */
135 HV_EXPORT HvMessage *hv_msg_copy(const HvMessage *const m);
136
137 /** Free a copied message. */
138 HV_EXPORT void hv_msg_free(HvMessage *m);
139
140 #endif // _HEAVY_MESSAGE_H_
141
142
143
144 #if !HV_MSVC
145 #pragma mark - Heavy Patch
146 #endif
147
148 #ifndef _HEAVY_BBB_H_
149 #define _HEAVY_BBB_H_
150
151 typedef struct Hv_bbb Hv_bbb;
152
153 /**
154 * Creates a new patch instance.
155 * Sample rate should be positive and in Hertz.
156 */
157 HV_EXPORT Hv_bbb *hv_bbb_new(double sampleRate);
158
159 /**
160 * Creates a new patch instance.
161 * Sample rate should be positive and in Hertz.
162 * Pool size is in kilobytes, and determines the maximum amount of memory
163 * allocated to messages at any time. By default this is 10.
164 */
165 HV_EXPORT Hv_bbb *hv_bbb_new_with_pool(double sampleRate, int poolKb);
166
167 /** Frees a patch instance. */
168 HV_EXPORT void hv_bbb_free(Hv_bbb *c);
169
170 /** Processes one block of samples for a patch instance. The buffer format is an array of float channel arrays. */
171 HV_EXPORT int hv_bbb_process(Hv_bbb *c, float **const inputBuffers, float **const outputBuffers, int n4);
172
173 /** Processes one block of samples for a patch instance. The buffer format is an uninterleaved float array of channels. */
174 HV_EXPORT int hv_bbb_process_inline(Hv_bbb *c, float *const inputBuffers, float *const outputBuffers, int n4);
175
176 /** Processes one block of samples for a patch instance. The buffer format is an interleaved short array of channels. */
177 HV_EXPORT int hv_bbb_process_inline_short(Hv_bbb *c, short *const inputBuffers, short *const outputBuffers, int n4);
178 #endif // _HEAVY_BBB_H_
179
180
181
182 #if !HV_MSVC
183 #pragma mark - Heavy Common
184 #endif
185
186 #ifndef _HEAVY_COMMON_H_
187 #define _HEAVY_COMMON_H_
188
189 typedef void Heavy;
190
191 /** Returns the sample rate with which this patch has been configured. */
192 HV_EXPORT double hv_getSampleRate(Heavy *c);
193
194 /** Returns the number of input channels with which this patch has been configured. */
195 HV_EXPORT int hv_getNumInputChannels(Heavy *c);
196
197 /** Returns the number of output channels with which this patch has been configured. */
198 HV_EXPORT int hv_getNumOutputChannels(Heavy *c);
199
200 /** Set the print hook. The function is called whenever a message is sent to a print object. */
201 HV_EXPORT void hv_setPrintHook(Heavy *c,
202 void (*f)(double timestamp, const char *printName, const char *message, void *userData));
203
204 /**
205 * Set the send hook. The function is called whenever a message is sent to any send object.
206 * Messages returned by this function should NEVER be freed. If the message must persist, call
207 * hv_msg_copy() first.
208 */
209 HV_EXPORT void hv_setSendHook(Heavy *c, void (*f)(double timestamp, const char *receiverName, const HvMessage *const m, void *userData));
210
211 HV_EXPORT void hv_vscheduleMessageForReceiver(
212 Heavy *c, const char *receiverName, double delayMs, const char *format, ...);
213
214 HV_EXPORT void hv_scheduleMessageForReceiver(Heavy *c, const char *receiverName, double delayMs, HvMessage *m);
215
216 /** Cancels a previously scheduled message. */
217 HV_EXPORT void hv_cancelMessage(Heavy *c, HvMessage *m);
218
219 /** Returns a table object given its name. NULL if no table with that name exists. */
220 HV_EXPORT HvTable *hv_getTableForName(Heavy *c, const char *tableName);
221
222 /** Returns the current patch time in milliseconds. */
223 HV_EXPORT double hv_getCurrentTime(Heavy *c);
224
225 /** Sets a user-definable value. This value is never manipulated by Heavy. */
226 HV_EXPORT void hv_setUserData(Heavy *c, void *userData);
227
228 /** Returns the user-defined data. */
229 HV_EXPORT void *hv_getUserData(Heavy *c);
230
231 /** Define the base path of the patch. Used as the root path to locate assets. */
232 HV_EXPORT void hv_setBasePath(Heavy *c, const char *basePath);
233
234 /** Returns the read-only user-assigned name of this patch. */
235 HV_EXPORT const char *hv_getName(Heavy *c);
236
237 #endif // _HEAVY_COMMON_H_
238
239 #ifdef __cplusplus
240 } // extern "C"
241 #endif