DPF with Max Gen
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

205 lines
7.5KB

  1. /*******************************************************************************************************************
  2. Cycling '74 License for Max-Generated Code for Export
  3. Copyright (c) 2016 Cycling '74
  4. The code that Max generates automatically and that end users are capable of exporting and using, and any
  5. associated documentation files (the “Software”) is a work of authorship for which Cycling '74 is the author
  6. and owner for copyright purposes. A license is hereby granted, free of charge, to any person obtaining a
  7. copy of the Software (“Licensee”) to use, copy, modify, merge, publish, and distribute copies of the Software,
  8. and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  9. The Software is licensed to Licensee only for non-commercial use. Users who wish to make commercial use of the
  10. Software must contact the copyright owner to determine if a license for commercial use is available, and the
  11. terms and conditions for same, which may include fees or royalties. For commercial use, please send inquiries
  12. to licensing@cycling74.com. The determination of whether a use is commercial use or non-commercial use is based
  13. upon the use, not the user. The Software may be used by individuals, institutions, governments, corporations, or
  14. other business whether for-profit or non-profit so long as the use itself is not a commercialization of the
  15. materials or a use that generates or is intended to generate income, revenue, sales or profit.
  16. The above copyright notice and this license shall be included in all copies or substantial portions of the Software.
  17. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  18. THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  19. THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  20. CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. DEALINGS IN THE SOFTWARE.
  22. *******************************************************************************************************************/
  23. #ifndef GENLIB_H
  24. #define GENLIB_H 1
  25. #include "genlib_common.h"
  26. #ifndef MSP_ON_CLANG
  27. # include <math.h>
  28. #endif
  29. //////////// genlib.h ////////////
  30. // genlib.h -- max (gen~) version
  31. #ifndef GEN_WINDOWS
  32. # ifndef _SIZE_T
  33. # define _SIZE_T
  34. typedef __typeof__(sizeof(int)) size_t;
  35. # endif
  36. #endif
  37. #ifndef __INT32_TYPE__
  38. # define __INT32_TYPE__ int
  39. #endif
  40. #ifdef MSP_ON_CLANG
  41. // gen~ hosted:
  42. typedef unsigned __INT32_TYPE__ uint32_t;
  43. typedef unsigned __INT64_TYPE__ uint64_t;
  44. #else
  45. # ifdef __GNUC__
  46. # include <stdint.h>
  47. # endif
  48. #endif
  49. #ifdef GENLIB_USE_FLOAT32
  50. #define inf (__FLT_MAX__)
  51. #else
  52. #define inf (__DBL_MAX__)
  53. #endif
  54. #define GEN_UINT_MAX (4294967295)
  55. #define TWO_TO_32 (t_sample(4294967296.0))
  56. #define C74_CONST const
  57. // max_types.h:
  58. #ifdef C74_X64
  59. typedef unsigned long long t_ptr_uint;
  60. typedef long long t_ptr_int;
  61. typedef double t_atom_float;
  62. typedef t_ptr_uint t_getbytes_size;
  63. #elif defined(__GNUC__) && !defined(MSP_ON_CLANG)
  64. typedef uintptr_t t_ptr_uint;
  65. typedef intptr_t t_ptr_int;
  66. typedef float t_atom_float;
  67. typedef t_ptr_uint t_getbytes_size;
  68. #else
  69. typedef unsigned long t_ptr_uint;
  70. typedef long t_ptr_int;
  71. typedef float t_atom_float;
  72. typedef short t_getbytes_size;
  73. #endif // C74_X64
  74. typedef uint32_t t_uint32;
  75. typedef t_ptr_int t_atom_long; // the type that is an A_LONG in an atom
  76. typedef t_ptr_int t_int; ///< an integer @ingroup misc
  77. typedef t_ptr_uint t_ptr_size; ///< unsigned pointer-sized value for counting (like size_t) @ingroup misc
  78. typedef t_ptr_int t_atom_long; ///< the type that is an A_LONG in a #t_atom @ingroup misc
  79. typedef t_atom_long t_max_err; ///< an integer value suitable to be returned as an error code @ingroup misc
  80. extern "C" {
  81. extern t_sample gen_msp_pow (t_sample, t_sample);
  82. #ifdef MSP_ON_CLANG
  83. // TODO: remove (for debugging only)
  84. //int printf(const char *fmt, ...);
  85. // math.h:
  86. extern double acos(double);
  87. extern double asin(double);
  88. extern double atan(double);
  89. extern double atan2(double, double);
  90. extern double cos(double);
  91. extern double sin(double);
  92. extern double tan(double);
  93. extern double acosh(double);
  94. extern double asinh(double);
  95. extern double atanh(double);
  96. extern double cosh(double);
  97. extern double sinh(double);
  98. extern double tanh(double);
  99. extern double exp(double);
  100. extern double log(double);
  101. extern double log10(double);
  102. extern double fmod(double, double);
  103. extern double modf(double, double *);
  104. extern double fabs(double);
  105. extern double hypot(double, double);
  106. extern double pow(double, double);
  107. extern double sqrt(double);
  108. extern double ceil(double);
  109. extern double floor(double);
  110. extern double trunc(double);
  111. extern double round(double);
  112. extern int abs(int);
  113. extern char *strcpy(char *, const char *);
  114. #endif // MSP_ON_CLANG
  115. #if defined(GENLIB_USE_ARMMATH) // ARM embedded support
  116. # include "arm_math.h"
  117. # define sin(x) arm_sin_f32(x)
  118. # define sinf(x) arm_sin_f32(x)
  119. # define cos(x) arm_cos_f32(x)
  120. # define cosf(x) arm_cos_f32(x)
  121. # define sqrt(x) arm_sqrtf(x)
  122. # define sqrtf(x) arm_sqrtf(x)
  123. # define rand(...) arm_rand32()
  124. # undef RAND_MAX
  125. # define RAND_MAX UINT32_MAX
  126. #endif // GENLIB_USE_ARMMATH
  127. #if defined(GENLIB_USE_FASTMATH)
  128. # define tan(x) fastertanfull(x)
  129. # define exp(x) fasterexp(x)
  130. # define log2(x) fasterlog2(x)
  131. # define pow(x,y) fasterpow(x,y)
  132. # define pow2(x) fasterpow2(x)
  133. # define atan2(x,y) fasteratan2(x,y)
  134. # define tanh(x) fastertanh(x)
  135. # if !defined(GENLIB_USE_ARMMATH)
  136. # define sin(x) fastersinfull(x)
  137. # define cos(x) fastercosfull(x)
  138. # endif
  139. #endif // GENLIB_USE_FASTMATH
  140. // string reference handling:
  141. void *genlib_obtain_reference_from_string(const char *name);
  142. char *genlib_reference_getname(void *ref);
  143. // buffer handling:
  144. t_genlib_buffer *genlib_obtain_buffer_from_reference(void *ref);
  145. t_genlib_err genlib_buffer_edit_begin(t_genlib_buffer *b);
  146. t_genlib_err genlib_buffer_edit_end(t_genlib_buffer *b, long valid);
  147. t_genlib_err genlib_buffer_getinfo(t_genlib_buffer *b, t_genlib_buffer_info *info);
  148. void genlib_buffer_dirty(t_genlib_buffer *b);
  149. t_genlib_err genlib_buffer_perform_begin(t_genlib_buffer *b);
  150. void genlib_buffer_perform_end(t_genlib_buffer *b);
  151. // data handling:
  152. t_genlib_data *genlib_obtain_data_from_reference(void *ref);
  153. t_genlib_err genlib_data_getinfo(t_genlib_data *b, t_genlib_data_info *info);
  154. void genlib_data_resize(t_genlib_data *b, long dim, long channels);
  155. void genlib_data_setbuffer(t_genlib_data *b, void *ref);
  156. void genlib_data_release(t_genlib_data *b);
  157. void genlib_data_setcursor(t_genlib_data *b, long cursor);
  158. long genlib_data_getcursor(t_genlib_data *b);
  159. // other notification:
  160. void genlib_reset_complete(void *data);
  161. // get/set state of parameters
  162. size_t genlib_getstatesize(CommonState *cself, getparameter_method getmethod);
  163. short genlib_getstate(CommonState *cself, char *state, getparameter_method getmethod);
  164. short genlib_setstate(CommonState *cself, const char *state, setparameter_method setmethod);
  165. }; // extern "C"
  166. #define genlib_sysmem_newptr(s) sysmem_newptr(s)
  167. #define genlib_sysmem_newptrclear(s) sysmem_newptrclear(s)
  168. #define genlib_sysmem_resizeptr(p, s) sysmem_resizeptr(p, s)
  169. #define genlib_sysmem_resizeptrclear(p, s) sysmem_resizeptrclear(p, s)
  170. #define genlib_sysmem_ptrsize(p) sysmem_ptrsize(p)
  171. #define genlib_sysmem_freeptr(p) sysmem_freeptr(p)
  172. #define genlib_sysmem_copyptr(s, d, b) sysmem_copyptr(s, d, b)
  173. #define genlib_set_zero64(d, n) set_zero64(d, n)
  174. #define genlib_ticks systime_ticks
  175. #endif // GENLIB_H