Branch
Hash :
839078f3
Author :
Thomas de Grivel
Date :
2023-01-17T10:51:23
rtbuf_gtk3 test/sinus
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
/* rtbuf
* Copyright 2018-2023 kmx.io <contact@kmx.io>
*
* Permission is hereby granted to use this software excepted
* on Apple computers granted the above copyright notice and
* this permission paragraph are included in all copies and
* substantial portions of this software.
*
* THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
* PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
/**
* @file
* @brief rtbuf main header.
*
* Main include file for librtbuf. Include this file in your project
* to use librtbuf.
*
* Use librtbuf_init to initialize librtbuf.
* You can then load libraries using rtbuf_lib_*
*/
#ifndef RTBUF_H
#define RTBUF_H
#include "data.h"
#include "defs.h"
#include "type.h"
#include "proc.h"
/**
* @brief Rtbuf sort flag. Set if buffer order was changed.
*/
#define RTBUF_SORT 0x0001
/**
* @brief Rtbuf delete flag. Set if buffer should be deleted.
*/
#define RTBUF_DELETE 0x0002
/**
* @brief Rtbuf new flag. Set when buffer is new and should be started.
*/
#define RTBUF_NEW 0x0004
/**
* @brief Rtbuf ready flag. Set when buffer is ready to use.
*/
#define RTBUF_READY 0x0008
/**
* @brief Binding to an rtbuf output.
*
* s_rtbuf_binding is used to bind to an arbitrary output of an
* arbitrary rtbuf.
*/
struct rtbuf_binding
{
int rtb; /**< The source rtbuf index in g_rtbuf. */
unsigned int out; /**< The source rtbuf output index. */
};
/**
* @brief Real-time buffer.
*
* s_rtbuf is a real-time buffer with a procedure (start, run, stop).
* Use rtbuf_new or rtbuf_new_ptr to allocate and initialize.
*/
struct rtbuf
{
void *data; /**< Pointer to buffer memory. */
unsigned int flags; /**< Flags for buffer state. */
s_rtbuf_proc *proc; /**< The procedure for the buffer (start, run, stop). */
unsigned int refc; /**< Reference count. */
s_rtbuf_binding in[RTBUF_PROC_IN_MAX]; /**< Inputs are bindings to other buffers outputs. */
unsigned int in_n; /**< Number of inputs. */
void *user_ptr; /**< User pointer. */
};
/**
* Maximum number of s_rtbuf allocated at the same time globally.
*/
#define RTBUF_MAX 10000
/**
* Maximum number of s_rtbuf allocated at the same time for each
* procedure.
*/
#define RTBUF_INSTANCE_MAX 100
/**
* @brief Real time allocator for g_rtbuf.
*/
extern s_data_alloc g_rtbuf_alloc;
/**
* @brief Global index of s_rtbuf.
*/
extern s_rtbuf *g_rtbuf;
/**
* @brief Run loop should exit when g_rtbuf_run is zero.
*/
extern int g_rtbuf_run;
/**
* @brief Is the main loop still active ?
*/
extern int g_rtbuf_running;
/**
* @brief Callback function for rtbuf_err.
*/
typedef void (*f_rtbuf_err_cb) (const char *msg);
/**
* @brief Callback function for rtbuf_new.
*/
typedef void (*f_rtbuf_new_cb) (s_rtbuf *rtb);
/**
* @brief Callback function for rtbuf_delete.
*/
typedef void (*f_rtbuf_delete_cb) (s_rtbuf *rtb);
/**
* @brief Callback function for rtbuf_bind.
*/
typedef void (*f_rtbuf_bind_cb) (s_rtbuf *src, unsigned int out,
s_rtbuf *dest, unsigned int in);
/**
* @brief Callback function for rtbuf_unbind.
*/
typedef void (*f_rtbuf_unbind_cb) (s_rtbuf *src, unsigned int out,
s_rtbuf *dest, unsigned int in);
/**
* @brief Callback function for rtbuf_err.
*/
extern f_rtbuf_err_cb g_rtbuf_err_cb;
/**
* @brief Callback function for rtbuf_new.
*/
extern f_rtbuf_new_cb g_rtbuf_new_cb;
/**
* @brief Callback function for rtbuf_delete.
*/
extern f_rtbuf_delete_cb g_rtbuf_delete_cb;
/**
* @brief Callback function for rtbuf_bind.
*/
extern f_rtbuf_bind_cb g_rtbuf_bind_cb;
/**
* @brief Callback function for rtbuf_unbind.
*/
extern f_rtbuf_unbind_cb g_rtbuf_unbind_cb;
/**
* @brief Initialize librtbuf.
*
* Should be called before any other rtbuf function.
*
* @sa librtbuf_shutdown
*/
int librtbuf_init ();
/**
* @brief Shutdown librtbuf.
*
* Should be called only after any other rtbuf function, when the
* program shuts down.
*
* @sa librtbuf_init
*/
void librtbuf_shutdown ();
int rtbuf_err (const char *msg);
void rtbuf_err_default (const char *msg);
/**
* @brief Create a new real time buffer.
*
* The buffer is allocated in real time and is ready to be bound.
* This is equivalent to calling rtbuf_new_ptr with user_ptr
* set to NULL.
*
* @param rp The procedure for the new rtbuf.
* @return The index of the new rtbuf in g_rtbuf.
*/
int rtbuf_new (s_rtbuf_proc *rp);
/**
* @brief Create a new real time buffer.
*
* The buffer is allocated in real time and is ready to be bound.
* Its user pointer is set to user_ptr.
*
* @param rp The procedure for the new rtbuf.
* @param ptr The user pointer for the new rtbuf.
* @return The index of the new rtbuf in g_rtbuf.
*/
int rtbuf_new_ptr (s_rtbuf_proc *rp, void *user_ptr);
void rtbuf_in_unbind (s_rtbuf *rtb, unsigned int in);
void rtbuf_out_unbind (s_rtbuf *rtb, unsigned int out);
void rtbuf_unbind_all (s_rtbuf *rtb);
void rtbuf_delete (s_rtbuf *rtb);
int rtbuf_clone (s_rtbuf *rtb);
int rtbuf_find (symbol sym);
int rtbuf_in_find (s_rtbuf *rtb, const char *x);
void rtbuf_bind (unsigned int src, unsigned int out,
s_rtbuf *dest, unsigned int in);
int rtbuf_out_find (s_rtbuf *rtb, symbol sym);
int rtbuf_data_set (s_rtbuf *rtb, symbol name, void *value,
unsigned int size);
void rtbuf_sort ();
int rtbuf_start ();
int rtbuf_run ();
void rtbuf_stop ();
void rtbuf_print (const s_rtbuf *rtbuf);
void rtbuf_print_long (const s_rtbuf *rtbuf);
void rtbuf_print_sorted ();
int rtbuf_out_int (s_rtbuf *rtb, unsigned int out, int default_value);
double * rtbuf_in_unbound_value (s_rtbuf *rtb, unsigned int in);
double min (double a, double b);
double max (double a, double b);
double clamp (double inf, double x, double sup);
#endif /* RTBUF_H */