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