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