@@ -19,6 +19,7 @@ TARGET_DIR = ../../bin | |||
BUILD_C_FLAGS += -I. | |||
BUILD_CXX_FLAGS += -I. -I../common -I../common/gen_dsp -I../../dpf/distrho -I../../dpf/dgl -Wno-unused-parameter | |||
BUILD_CXX_FLAGS += -DGENLIB_USE_FASTMATH -DGENLIB_USE_FLOAT32 -DGENLIB_USE_JSON=0 | |||
ifeq ($(HAVE_DGL),true) | |||
BASE_FLAGS += -DHAVE_DGL | |||
@@ -1,40 +1,46 @@ | |||
/******************************************************************************************************************* | |||
Copyright (c) 2012 Cycling '74 | |||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software | |||
and associated documentation files (the "Software"), to deal in the Software without restriction, | |||
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | |||
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | |||
subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in all copies | |||
or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE | |||
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |||
Cycling '74 License for Max-Generated Code for Export | |||
Copyright (c) 2016 Cycling '74 | |||
The code that Max generates automatically and that end users are capable of exporting and using, and any | |||
associated documentation files (the “Software”) is a work of authorship for which Cycling '74 is the author | |||
and owner for copyright purposes. A license is hereby granted, free of charge, to any person obtaining a | |||
copy of the Software (“Licensee”) to use, copy, modify, merge, publish, and distribute copies of the Software, | |||
and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |||
The Software is licensed to Licensee only for non-commercial use. Users who wish to make commercial use of the | |||
Software must contact the copyright owner to determine if a license for commercial use is available, and the | |||
terms and conditions for same, which may include fees or royalties. For commercial use, please send inquiries | |||
to licensing@cycling74.com. The determination of whether a use is commercial use or non-commercial use is based | |||
upon the use, not the user. The Software may be used by individuals, institutions, governments, corporations, or | |||
other business whether for-profit or non-profit so long as the use itself is not a commercialization of the | |||
materials or a use that generates or is intended to generate income, revenue, sales or profit. | |||
The above copyright notice and this license shall be included in all copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO | |||
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL | |||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |||
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
DEALINGS IN THE SOFTWARE. | |||
*******************************************************************************************************************/ | |||
#include "genlib.h" | |||
#include "genlib_exportfunctions.h" | |||
#include "stdlib.h" | |||
#include "stdio.h" | |||
#include "string.h" | |||
#include <cmath> | |||
#include <stdlib.h> // not cstdlib (causes problems with ARM embedded compiler) | |||
#include <cstdio> | |||
#include <cstring> | |||
#ifdef __APPLE__ | |||
# include <malloc/malloc.h> | |||
#elif !defined(GEN_WINDOWS) // WIN32? | |||
# include <malloc.h> | |||
# define malloc_size malloc_usable_size | |||
#endif | |||
#if DISTRHO_OS_MAC | |||
# include <malloc/malloc.h> | |||
#else | |||
# include <malloc.h> | |||
# if DISTRHO_OS_WINDOWS | |||
# define malloc_size _msize | |||
# else | |||
# define malloc_size malloc_usable_size | |||
# endif | |||
#ifdef MSP_ON_CLANG | |||
# include "json.c" | |||
# include "json_builder.c" | |||
#endif | |||
#if GENLIB_USE_JSON | |||
# include "json.h" | |||
# include "json_builder.h" | |||
#endif | |||
// DATA_MAXIMUM_ELEMENTS * 8 bytes = 256 mb limit | |||
@@ -54,10 +60,10 @@ t_ptr sysmem_newptr(t_ptr_size size) | |||
t_ptr sysmem_newptrclear(t_ptr_size size) | |||
{ | |||
t_ptr p = (t_ptr)malloc(size); | |||
if (p) | |||
my_memset(p, 0, size); | |||
return p; | |||
} | |||
@@ -68,13 +74,13 @@ t_ptr sysmem_resizeptr(void *ptr, t_ptr_size newsize) | |||
t_ptr sysmem_resizeptrclear(void *ptr, t_ptr_size newsize) | |||
{ | |||
t_ptr_size oldsize = malloc_size(ptr); | |||
size_t oldsize = malloc_size(ptr); | |||
t_ptr p = (t_ptr)realloc(ptr, newsize); | |||
if (p) { | |||
if (newsize > oldsize) | |||
my_memset((char *)p + oldsize, 0, newsize - oldsize); | |||
} | |||
} | |||
return p; | |||
} | |||
@@ -97,9 +103,9 @@ void my_memset(void *p, int c, long size) | |||
{ | |||
char *p2 = (char *)p; | |||
int i; | |||
for (i = 0; i < size; i++, p2++) | |||
*p2 = c; | |||
*p2 = char(c); | |||
} | |||
void my_memcpy(void *dst, const void *src, long size) | |||
@@ -107,7 +113,7 @@ void my_memcpy(void *dst, const void *src, long size) | |||
char *s2 = (char *)src; | |||
char *d2 = (char *)dst; | |||
int i; | |||
for (i = 0; i < size; i++, s2++, d2++) | |||
*d2 = *s2; | |||
} | |||
@@ -115,7 +121,7 @@ void my_memcpy(void *dst, const void *src, long size) | |||
void set_zero64(t_sample *memory, long size) | |||
{ | |||
long i; | |||
for (i = 0; i < size; i++, memory++) { | |||
*memory = 0.; | |||
} | |||
@@ -123,12 +129,16 @@ void set_zero64(t_sample *memory, long size) | |||
void genlib_report_error(const char *s) | |||
{ | |||
#ifndef GEN_NO_STDLIB | |||
fprintf(stderr, "%s\n", s); | |||
#endif | |||
} | |||
void genlib_report_message(const char *s) | |||
{ | |||
#ifndef GEN_NO_STDLIB | |||
fprintf(stdout, "%s\n", s); | |||
#endif | |||
} | |||
unsigned long systime_ticks(void) | |||
@@ -136,12 +146,21 @@ unsigned long systime_ticks(void) | |||
return 0; // Gen code can deal with this | |||
} | |||
void * genlib_obtain_reference_from_string(const char * name) { | |||
#ifdef GEN_WINDOWS | |||
// NEED THIS FOR WINDOWS: | |||
void *operator new(size_t size) { return sysmem_newptr(size); } | |||
void *operator new[](size_t size) { return sysmem_newptr(size); } | |||
void operator delete(void *p) throw() { sysmem_freeptr(p); } | |||
void operator delete[](void *p) throw() { sysmem_freeptr(p); } | |||
#endif | |||
void *genlib_obtain_reference_from_string(const char *name) | |||
{ | |||
return 0; // to be implemented | |||
} | |||
// the rest is stuff to isolate gensym, attrs, atoms, buffers etc. | |||
t_genlib_buffer * genlib_obtain_buffer_from_reference(void *ref) | |||
t_genlib_buffer *genlib_obtain_buffer_from_reference(void *ref) | |||
{ | |||
return 0; // to be implemented | |||
} | |||
@@ -175,7 +194,6 @@ t_genlib_err genlib_buffer_perform_begin(t_genlib_buffer *b) | |||
{ | |||
return 0; // to be implemented | |||
} | |||
void genlib_buffer_perform_end(t_genlib_buffer *b) | |||
{ | |||
// to be implemented | |||
@@ -183,22 +201,27 @@ void genlib_buffer_perform_end(t_genlib_buffer *b) | |||
t_sample gen_msp_pow(t_sample value, t_sample power) | |||
{ | |||
#ifdef GENLIB_USE_FLOAT32 | |||
return powf(value, power); | |||
#else | |||
return pow(value, power); | |||
#endif | |||
} | |||
void genlib_data_setbuffer(t_genlib_data *b, void *ref) { | |||
void genlib_data_setbuffer(t_genlib_data *b, void *ref) | |||
{ | |||
genlib_report_error("not supported for export targets\n"); | |||
} | |||
typedef struct { | |||
t_genlib_data_info info; | |||
t_sample cursor; // used by Delay | |||
//t_symbol * name; | |||
} t_dsp_gen_data; | |||
t_sample cursor; // used by Delay | |||
//t_symbol * name; | |||
} t_dsp_gen_data; | |||
t_genlib_data * genlib_obtain_data_from_reference(void *ref) | |||
t_genlib_data *genlib_obtain_data_from_reference(void *ref) | |||
{ | |||
t_dsp_gen_data * self = (t_dsp_gen_data *)malloc(sizeof(t_dsp_gen_data)); | |||
t_dsp_gen_data *self = (t_dsp_gen_data *)malloc(sizeof(t_dsp_gen_data)); | |||
self->info.dim = 0; | |||
self->info.channels = 0; | |||
self->info.data = 0; | |||
@@ -206,48 +229,53 @@ t_genlib_data * genlib_obtain_data_from_reference(void *ref) | |||
return (t_genlib_data *)self; | |||
} | |||
t_genlib_err genlib_data_getinfo(t_genlib_data *b, t_genlib_data_info *info) { | |||
t_dsp_gen_data * self = (t_dsp_gen_data *)b; | |||
t_genlib_err genlib_data_getinfo(t_genlib_data *b, t_genlib_data_info *info) | |||
{ | |||
t_dsp_gen_data *self = (t_dsp_gen_data *)b; | |||
info->dim = self->info.dim; | |||
info->channels = self->info.channels; | |||
info->data = self->info.data; | |||
return GENLIB_ERR_NONE; | |||
} | |||
void genlib_data_release(t_genlib_data *b) { | |||
t_dsp_gen_data * self = (t_dsp_gen_data *)b; | |||
void genlib_data_release(t_genlib_data *b) | |||
{ | |||
t_dsp_gen_data *self = (t_dsp_gen_data *)b; | |||
if (self->info.data) { | |||
genlib_sysmem_freeptr(self->info.data); | |||
self->info.data = 0; | |||
} | |||
} | |||
long genlib_data_getcursor(t_genlib_data *b) { | |||
t_dsp_gen_data * self = (t_dsp_gen_data *)b; | |||
return self->cursor; | |||
long genlib_data_getcursor(t_genlib_data *b) | |||
{ | |||
t_dsp_gen_data *self = (t_dsp_gen_data *)b; | |||
return long(self->cursor); | |||
} | |||
void genlib_data_setcursor(t_genlib_data *b, long cursor) { | |||
t_dsp_gen_data * self = (t_dsp_gen_data *)b; | |||
self->cursor = cursor; | |||
void genlib_data_setcursor(t_genlib_data *b, long cursor) | |||
{ | |||
t_dsp_gen_data *self = (t_dsp_gen_data *)b; | |||
self->cursor = t_sample(cursor); | |||
} | |||
void genlib_data_resize(t_genlib_data *b, long s, long c) { | |||
t_dsp_gen_data * self = (t_dsp_gen_data *)b; | |||
void genlib_data_resize(t_genlib_data *b, long s, long c) | |||
{ | |||
t_dsp_gen_data *self = (t_dsp_gen_data *)b; | |||
size_t sz, oldsz, copysz; | |||
t_sample * old = 0; | |||
t_sample * replaced = 0; | |||
t_sample *old = 0; | |||
t_sample *replaced = 0; | |||
int i, j, copydim, copychannels, olddim, oldchannels; | |||
//printf("data resize %d %d\n", s, c); | |||
// cache old for copying: | |||
old = self->info.data; | |||
olddim = self->info.dim; | |||
oldchannels = self->info.channels; | |||
// limit [data] size: | |||
if (s * c > DATA_MAXIMUM_ELEMENTS) { | |||
s = DATA_MAXIMUM_ELEMENTS/c; | |||
@@ -256,7 +284,7 @@ void genlib_data_resize(t_genlib_data *b, long s, long c) { | |||
// bytes required: | |||
sz = sizeof(t_sample) * s * c; | |||
oldsz = sizeof(t_sample) * olddim * oldchannels; | |||
if (old && sz == oldsz) { | |||
// no need to re-allocate, just resize | |||
// careful, audio thread may still be using it: | |||
@@ -267,15 +295,15 @@ void genlib_data_resize(t_genlib_data *b, long s, long c) { | |||
self->info.dim = s; | |||
self->info.channels = c; | |||
} | |||
set_zero64(self->info.data, s * c); | |||
return; | |||
} else { | |||
// allocate new: | |||
replaced = (t_sample *)sysmem_newptr(sz); | |||
// check allocation: | |||
if (replaced == 0) { | |||
genlib_report_error("allocating [data]: out of memory"); | |||
@@ -288,10 +316,10 @@ void genlib_data_resize(t_genlib_data *b, long s, long c) { | |||
} | |||
return; | |||
} | |||
// fill with zeroes: | |||
set_zero64(replaced, s * c); | |||
// copy in old data: | |||
if (old) { | |||
// frames to copy: | |||
@@ -308,14 +336,14 @@ void genlib_data_resize(t_genlib_data *b, long s, long c) { | |||
// clamp channels copied: | |||
copychannels = oldchannels > c ? c : oldchannels; | |||
//post("reset resize (different channels) %p %p, %d %d", self->info.data, old, copydim, copychannels); | |||
for (i = 0; i<copydim; i++) { | |||
for (j = 0; j<copychannels; j++) { | |||
replaced[j + i*c] = old[j + i*oldchannels]; | |||
for (i = 0; i < copydim; i++) { | |||
for (j = 0; j < copychannels; j++) { | |||
replaced[j + i * c] = old[j + i * oldchannels]; | |||
} | |||
} | |||
} | |||
} | |||
// now update info: | |||
if (old == 0) { | |||
self->info.data = replaced; | |||
@@ -348,15 +376,107 @@ void genlib_data_resize(t_genlib_data *b, long s, long c) { | |||
self->info.channels = c; | |||
} | |||
} | |||
// done with old: | |||
sysmem_freeptr(old); | |||
} | |||
} | |||
} | |||
void genlib_reset_complete(void *data) | |||
{ | |||
} | |||
#if GENLIB_USE_JSON | |||
void genlib_build_json(CommonState *cself, json_value **jsonvalue, getparameter_method getmethod) | |||
{ | |||
int i; | |||
*jsonvalue = json_object_new(0); | |||
for (i = 0; i < cself->numparams; i++) { | |||
t_param val; | |||
(getmethod)(cself, i, &val); | |||
json_object_push(*jsonvalue, cself->params[i].name, json_double_new(val)); | |||
} | |||
} | |||
void genlib_reset_complete(void *data) {} | |||
size_t genlib_getstatesize(CommonState *cself, getparameter_method getmethod) | |||
{ | |||
size_t size; | |||
json_value *jsonvalue; | |||
genlib_build_json(cself, &jsonvalue, getmethod); | |||
size = json_measure(jsonvalue); | |||
json_builder_free(jsonvalue); | |||
return size; | |||
} | |||
short genlib_getstate(CommonState *cself, char *state, getparameter_method getmethod) | |||
{ | |||
json_value *jsonvalue; | |||
genlib_build_json(cself, &jsonvalue, getmethod); | |||
json_serialize(state, jsonvalue); | |||
json_builder_free(jsonvalue); | |||
return 0; | |||
} | |||
static void *json_custom_alloc(size_t size, int zero, void *user_data) | |||
{ | |||
return zero ? genlib_sysmem_newptrclear(size) : genlib_sysmem_newptr(size); | |||
} | |||
static void json_custom_free(void *ptr, void *user_data) | |||
{ | |||
genlib_sysmem_freeptr(ptr); | |||
} | |||
short genlib_setstate(CommonState *cself, const char *state, setparameter_method setmethod) | |||
{ | |||
json_settings settings; | |||
char error[256]; | |||
memset(&settings, 0, sizeof(json_settings)); | |||
settings.mem_alloc = &json_custom_alloc; | |||
settings.mem_free = &json_custom_free; | |||
json_value *value = json_parse_ex(&settings, state, strlen(state), error); | |||
if (value == NULL) | |||
return 1; | |||
if (value->type == json_object) { | |||
unsigned int i; | |||
for (i = 0; i < value->u.object.length; i++) { | |||
char *name = NULL; | |||
t_param val = 0; | |||
int j; | |||
if (value->u.object.values[i].value->type == json_double) { | |||
name = value->u.object.values[i].name; | |||
val = t_param(value->u.object.values[i].value->u.dbl); | |||
} else if (value->u.object.values[i].value->type == json_integer) { | |||
name = value->u.object.values[i].name; | |||
val = t_param(value->u.object.values[i].value->u.integer); | |||
} | |||
if (name) { | |||
for (j = 0; j < cself->numparams; j++) { | |||
if (!strcmp(cself->params[j].name, name)) { | |||
(setmethod)(cself, j, val, NULL); | |||
} | |||
} | |||
} | |||
} | |||
} | |||
json_value_free_ex(&settings, value); | |||
return 0; | |||
} | |||
#endif // GENLIB_USE_JSON |
@@ -1,44 +1,87 @@ | |||
/******************************************************************************************************************* | |||
Copyright (c) 2012 Cycling '74 | |||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software | |||
and associated documentation files (the "Software"), to deal in the Software without restriction, | |||
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | |||
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | |||
subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in all copies | |||
or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE | |||
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |||
Cycling '74 License for Max-Generated Code for Export | |||
Copyright (c) 2016 Cycling '74 | |||
The code that Max generates automatically and that end users are capable of exporting and using, and any | |||
associated documentation files (the “Software”) is a work of authorship for which Cycling '74 is the author | |||
and owner for copyright purposes. A license is hereby granted, free of charge, to any person obtaining a | |||
copy of the Software (“Licensee”) to use, copy, modify, merge, publish, and distribute copies of the Software, | |||
and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |||
The Software is licensed to Licensee only for non-commercial use. Users who wish to make commercial use of the | |||
Software must contact the copyright owner to determine if a license for commercial use is available, and the | |||
terms and conditions for same, which may include fees or royalties. For commercial use, please send inquiries | |||
to licensing@cycling74.com. The determination of whether a use is commercial use or non-commercial use is based | |||
upon the use, not the user. The Software may be used by individuals, institutions, governments, corporations, or | |||
other business whether for-profit or non-profit so long as the use itself is not a commercialization of the | |||
materials or a use that generates or is intended to generate income, revenue, sales or profit. | |||
The above copyright notice and this license shall be included in all copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO | |||
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL | |||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |||
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
DEALINGS IN THE SOFTWARE. | |||
*******************************************************************************************************************/ | |||
#ifndef GENLIB_H | |||
#define GENLIB_H 1 | |||
#include "genlib_common.h" | |||
#ifndef MSP_ON_CLANG | |||
# include <math.h> | |||
#endif | |||
//////////// genlib.h //////////// | |||
// genlib.h -- max (gen~) version | |||
#include "DistrhoUtils.hpp" | |||
#define inf (__DBL_MAX__) | |||
#define GEN_UINT_MAX (4294967295) | |||
#define TWO_TO_32 (4294967296.0) | |||
#ifndef GEN_WINDOWS | |||
# ifndef _SIZE_T | |||
# define _SIZE_T | |||
typedef __typeof__(sizeof(int)) size_t; | |||
# endif | |||
#endif | |||
#ifndef __INT32_TYPE__ | |||
# define __INT32_TYPE__ int | |||
#endif | |||
#ifdef MSP_ON_CLANG | |||
// gen~ hosted: | |||
typedef unsigned __INT32_TYPE__ uint32_t; | |||
typedef unsigned __INT64_TYPE__ uint64_t; | |||
#else | |||
# ifdef __GNUC__ | |||
# include <stdint.h> | |||
# endif | |||
#endif | |||
#ifdef GENLIB_USE_FLOAT32 | |||
#define inf (__FLT_MAX__) | |||
#else | |||
#define inf (__DBL_MAX__) | |||
#endif | |||
#define GEN_UINT_MAX (4294967295) | |||
#define TWO_TO_32 (t_sample(4294967296.0)) | |||
#define C74_CONST const | |||
// max_types.h: | |||
#ifdef C74_X64 | |||
typedef unsigned long long t_ptr_uint; | |||
typedef long long t_ptr_int; | |||
typedef double t_atom_float; | |||
typedef t_ptr_uint t_getbytes_size; | |||
#elif defined(__GNUC__) && !defined(MSP_ON_CLANG) | |||
typedef uintptr_t t_ptr_uint; | |||
typedef intptr_t t_ptr_int; | |||
typedef float t_atom_float; | |||
typedef t_ptr_uint t_getbytes_size; | |||
#else | |||
typedef unsigned long t_ptr_uint; | |||
typedef long t_ptr_int; | |||
typedef float t_atom_float; | |||
typedef short t_getbytes_size; | |||
#endif // C74_X64 | |||
typedef uint32_t t_uint32; | |||
typedef t_ptr_int t_atom_long; // the type that is an A_LONG in an atom | |||
@@ -49,11 +92,76 @@ typedef t_ptr_int t_atom_long; ///< the type that is an A_LONG in a #t_atom @i | |||
typedef t_atom_long t_max_err; ///< an integer value suitable to be returned as an error code @ingroup misc | |||
extern "C" { | |||
extern t_sample gen_msp_pow (t_sample, t_sample); | |||
#ifdef MSP_ON_CLANG | |||
// TODO: remove (for debugging only) | |||
//int printf(const char *fmt, ...); | |||
// math.h: | |||
extern double acos(double); | |||
extern double asin(double); | |||
extern double atan(double); | |||
extern double atan2(double, double); | |||
extern double cos(double); | |||
extern double sin(double); | |||
extern double tan(double); | |||
extern double acosh(double); | |||
extern double asinh(double); | |||
extern double atanh(double); | |||
extern double cosh(double); | |||
extern double sinh(double); | |||
extern double tanh(double); | |||
extern double exp(double); | |||
extern double log(double); | |||
extern double log10(double); | |||
extern double fmod(double, double); | |||
extern double modf(double, double *); | |||
extern double fabs(double); | |||
extern double hypot(double, double); | |||
extern double pow(double, double); | |||
extern double sqrt(double); | |||
extern double ceil(double); | |||
extern double floor(double); | |||
extern double trunc(double); | |||
extern double round(double); | |||
extern int abs(int); | |||
extern char *strcpy(char *, const char *); | |||
#endif // MSP_ON_CLANG | |||
#if defined(GENLIB_USE_ARMMATH) // ARM embedded support | |||
# include "arm_math.h" | |||
# define sin(x) arm_sin_f32(x) | |||
# define sinf(x) arm_sin_f32(x) | |||
# define cos(x) arm_cos_f32(x) | |||
# define cosf(x) arm_cos_f32(x) | |||
# define sqrt(x) arm_sqrtf(x) | |||
# define sqrtf(x) arm_sqrtf(x) | |||
# define rand(...) arm_rand32() | |||
# undef RAND_MAX | |||
# define RAND_MAX UINT32_MAX | |||
#endif // GENLIB_USE_ARMMATH | |||
#if defined(GENLIB_USE_FASTMATH) | |||
# define tan(x) fastertanfull(x) | |||
# define exp(x) fasterexp(x) | |||
# define log2(x) fasterlog2(x) | |||
# define pow(x,y) fasterpow(x,y) | |||
# define pow2(x) fasterpow2(x) | |||
# define atan2(x,y) fasteratan2(x,y) | |||
# define tanh(x) fastertanh(x) | |||
# if !defined(GENLIB_USE_ARMMATH) | |||
# define sin(x) fastersinfull(x) | |||
# define cos(x) fastercosfull(x) | |||
# endif | |||
#endif // GENLIB_USE_FASTMATH | |||
// string reference handling: | |||
void * genlib_obtain_reference_from_string(const char * name); | |||
void *genlib_obtain_reference_from_string(const char *name); | |||
char *genlib_reference_getname(void *ref); | |||
// buffer handling: | |||
t_genlib_buffer *genlib_obtain_buffer_from_reference(void *ref); | |||
t_genlib_err genlib_buffer_edit_begin(t_genlib_buffer *b); | |||
@@ -62,7 +170,7 @@ extern "C" { | |||
void genlib_buffer_dirty(t_genlib_buffer *b); | |||
t_genlib_err genlib_buffer_perform_begin(t_genlib_buffer *b); | |||
void genlib_buffer_perform_end(t_genlib_buffer *b); | |||
// data handling: | |||
t_genlib_data *genlib_obtain_data_from_reference(void *ref); | |||
t_genlib_err genlib_data_getinfo(t_genlib_data *b, t_genlib_data_info *info); | |||
@@ -71,17 +179,17 @@ extern "C" { | |||
void genlib_data_release(t_genlib_data *b); | |||
void genlib_data_setcursor(t_genlib_data *b, long cursor); | |||
long genlib_data_getcursor(t_genlib_data *b); | |||
// other notification: | |||
void genlib_reset_complete(void *data); | |||
// get/set state of parameters | |||
size_t genlib_getstatesize(CommonState *cself, getparameter_method getmethod); | |||
short genlib_getstate(CommonState *cself, char *state, getparameter_method getmethod); | |||
short genlib_setstate(CommonState *cself, const char *state, setparameter_method setmethod); | |||
// get/set state of parameters | |||
size_t genlib_getstatesize(CommonState *cself, getparameter_method getmethod); | |||
short genlib_getstate(CommonState *cself, char *state, getparameter_method getmethod); | |||
short genlib_setstate(CommonState *cself, const char *state, setparameter_method setmethod); | |||
}; // extern "C" | |||
#define genlib_sysmem_newptr(s) sysmem_newptr(s) | |||
#define genlib_sysmem_newptrclear(s) sysmem_newptrclear(s) | |||
#define genlib_sysmem_resizeptr(p, s) sysmem_resizeptr(p, s) | |||
@@ -93,3 +201,4 @@ extern "C" { | |||
#define genlib_ticks systime_ticks | |||
#endif // GENLIB_H | |||
@@ -1,36 +1,51 @@ | |||
/******************************************************************************************************************* | |||
Copyright (c) 2012 Cycling '74 | |||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software | |||
and associated documentation files (the "Software"), to deal in the Software without restriction, | |||
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | |||
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | |||
subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in all copies | |||
or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE | |||
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |||
Cycling '74 License for Max-Generated Code for Export | |||
Copyright (c) 2016 Cycling '74 | |||
The code that Max generates automatically and that end users are capable of exporting and using, and any | |||
associated documentation files (the “Software”) is a work of authorship for which Cycling '74 is the author | |||
and owner for copyright purposes. A license is hereby granted, free of charge, to any person obtaining a | |||
copy of the Software (“Licensee”) to use, copy, modify, merge, publish, and distribute copies of the Software, | |||
and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |||
The Software is licensed to Licensee only for non-commercial use. Users who wish to make commercial use of the | |||
Software must contact the copyright owner to determine if a license for commercial use is available, and the | |||
terms and conditions for same, which may include fees or royalties. For commercial use, please send inquiries | |||
to licensing@cycling74.com. The determination of whether a use is commercial use or non-commercial use is based | |||
upon the use, not the user. The Software may be used by individuals, institutions, governments, corporations, or | |||
other business whether for-profit or non-profit so long as the use itself is not a commercialization of the | |||
materials or a use that generates or is intended to generate income, revenue, sales or profit. | |||
The above copyright notice and this license shall be included in all copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO | |||
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL | |||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |||
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
DEALINGS IN THE SOFTWARE. | |||
*******************************************************************************************************************/ | |||
#ifndef GENLIB_COMMON_H | |||
#define GENLIB_COMMON_H 1 | |||
#include "genlib_platform.h" | |||
//////////// genlib_common.h //////////// | |||
// common data structure header file -- this is the stuff required by the | |||
// common code and accessed by the export and max code | |||
#define DSP_GEN_MAX_SIGNALS 16 | |||
// json is enabled by default, but can be disabled if not needed | |||
#ifndef GENLIB_USE_JSON | |||
#define GENLIB_USE_JSON 1 | |||
#endif | |||
#ifdef GENLIB_USE_FLOAT32 | |||
typedef float t_sample; | |||
typedef float t_param; | |||
#else | |||
typedef double t_sample; | |||
typedef double t_param; | |||
#endif | |||
typedef char *t_ptr; | |||
typedef long t_genlib_err; | |||
typedef enum { | |||
GENLIB_ERR_NONE = 0, ///< No error | |||
@@ -38,10 +53,10 @@ typedef enum { | |||
GENLIB_ERR_INVALID_PTR = -2, ///< Invalid Pointer | |||
GENLIB_ERR_DUPLICATE = -3, ///< Duplicate | |||
GENLIB_ERR_OUT_OF_MEM = -4, ///< Out of memory | |||
GENLIB_ERR_LOOP_OVERFLOW = 100, // too many iterations of loops in perform() | |||
GENLIB_ERR_NULL_BUFFER = 101 // missing signal data in perform() | |||
} e_genlib_errorcodes; | |||
typedef enum { | |||
@@ -52,7 +67,7 @@ typedef enum { | |||
struct ParamInfo | |||
{ | |||
t_param defaultvalue; | |||
void * defaultref; | |||
void *defaultref; | |||
char hasinputminmax; | |||
char hasminmax; | |||
t_param inputmin, inputmax; | |||
@@ -66,16 +81,16 @@ struct ParamInfo | |||
struct CommonState | |||
{ | |||
t_sample sr; | |||
int vs; | |||
int vs; | |||
int numins; | |||
int numouts; | |||
const char **inputnames; | |||
const char **outputnames; | |||
int numparams; | |||
ParamInfo *params; | |||
void * parammap; // implementation-dependent | |||
void * api; // implementation-dependent | |||
void *parammap; // implementation-dependent | |||
void *api; // implementation-dependent | |||
}; | |||
// opaque interface to float32 buffer: | |||
@@ -91,7 +106,7 @@ typedef struct { | |||
long b_rfu[57]; ///< reserved for future use | |||
} t_genlib_buffer_info; | |||
// opaque interface to float64 buffer: | |||
// opaque interface to float64 buffer: | |||
typedef struct _genlib_data t_genlib_data; | |||
typedef struct { | |||
int dim, channels; | |||
@@ -104,3 +119,4 @@ typedef void (*getparameter_method) (CommonState *, long, t_param *); | |||
#endif // GENLIB_COMMON_H | |||
@@ -0,0 +1,48 @@ | |||
/******************************************************************************************************************* | |||
Cycling '74 License for Max-Generated Code for Export | |||
Copyright (c) 2016 Cycling '74 | |||
The code that Max generates automatically and that end users are capable of exporting and using, and any | |||
associated documentation files (the “Software”) is a work of authorship for which Cycling '74 is the author | |||
and owner for copyright purposes. A license is hereby granted, free of charge, to any person obtaining a | |||
copy of the Software (“Licensee”) to use, copy, modify, merge, publish, and distribute copies of the Software, | |||
and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |||
The Software is licensed to Licensee only for non-commercial use. Users who wish to make commercial use of the | |||
Software must contact the copyright owner to determine if a license for commercial use is available, and the | |||
terms and conditions for same, which may include fees or royalties. For commercial use, please send inquiries | |||
to licensing@cycling74.com. The determination of whether a use is commercial use or non-commercial use is based | |||
upon the use, not the user. The Software may be used by individuals, institutions, governments, corporations, or | |||
other business whether for-profit or non-profit so long as the use itself is not a commercialization of the | |||
materials or a use that generates or is intended to generate income, revenue, sales or profit. | |||
The above copyright notice and this license shall be included in all copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO | |||
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL | |||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |||
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
DEALINGS IN THE SOFTWARE. | |||
*******************************************************************************************************************/ | |||
#ifndef GENLIB_COMMON_WIN_H | |||
#define GENLIB_COMMON_WIN_H | |||
#ifdef _MSC_VER | |||
#define GEN_WINDOWS | |||
#endif | |||
#ifdef GEN_WINDOWS | |||
#include <malloc.h> | |||
#include <limits> | |||
typedef __int32 int32_t; | |||
typedef unsigned __int32 uint32_t; | |||
typedef __int64 int64_t; | |||
typedef unsigned __int64 uint64_t; | |||
#define malloc_size _msize | |||
#define __DBL_EPSILON__ (DBL_EPSILON) | |||
#endif | |||
#endif | |||
@@ -1,26 +1,30 @@ | |||
/******************************************************************************************************************* | |||
Copyright (c) 2012 Cycling '74 | |||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software | |||
and associated documentation files (the "Software"), to deal in the Software without restriction, | |||
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | |||
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | |||
subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in all copies | |||
or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE | |||
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |||
Cycling '74 License for Max-Generated Code for Export | |||
Copyright (c) 2016 Cycling '74 | |||
The code that Max generates automatically and that end users are capable of exporting and using, and any | |||
associated documentation files (the “Software”) is a work of authorship for which Cycling '74 is the author | |||
and owner for copyright purposes. A license is hereby granted, free of charge, to any person obtaining a | |||
copy of the Software (“Licensee”) to use, copy, modify, merge, publish, and distribute copies of the Software, | |||
and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |||
The Software is licensed to Licensee only for non-commercial use. Users who wish to make commercial use of the | |||
Software must contact the copyright owner to determine if a license for commercial use is available, and the | |||
terms and conditions for same, which may include fees or royalties. For commercial use, please send inquiries | |||
to licensing@cycling74.com. The determination of whether a use is commercial use or non-commercial use is based | |||
upon the use, not the user. The Software may be used by individuals, institutions, governments, corporations, or | |||
other business whether for-profit or non-profit so long as the use itself is not a commercialization of the | |||
materials or a use that generates or is intended to generate income, revenue, sales or profit. | |||
The above copyright notice and this license shall be included in all copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO | |||
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL | |||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |||
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
DEALINGS IN THE SOFTWARE. | |||
*******************************************************************************************************************/ | |||
#ifndef GENLIB_EXPORT_FUNCTIONS_H | |||
#define GENLIB_EXPORT_FUNCTIONS_H 1 | |||
typedef char *t_ptr; | |||
typedef char *t_ptr; | |||
t_ptr sysmem_newptr(t_ptr_size size); | |||
t_ptr sysmem_newptrclear(t_ptr_size size); | |||
@@ -36,3 +40,4 @@ void genlib_report_message(const char *s); | |||
void set_zero64(t_sample *mem, long size); | |||
#endif // GENLIB_EXPORT_FUNCTIONS_H | |||
@@ -0,0 +1,40 @@ | |||
/******************************************************************************************************************* | |||
Cycling '74 License for Max-Generated Code for Export | |||
Copyright (c) 2016 Cycling '74 | |||
The code that Max generates automatically and that end users are capable of exporting and using, and any | |||
associated documentation files (the “Software”) is a work of authorship for which Cycling '74 is the author | |||
and owner for copyright purposes. A license is hereby granted, free of charge, to any person obtaining a | |||
copy of the Software (“Licensee”) to use, copy, modify, merge, publish, and distribute copies of the Software, | |||
and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |||
The Software is licensed to Licensee only for non-commercial use. Users who wish to make commercial use of the | |||
Software must contact the copyright owner to determine if a license for commercial use is available, and the | |||
terms and conditions for same, which may include fees or royalties. For commercial use, please send inquiries | |||
to licensing@cycling74.com. The determination of whether a use is commercial use or non-commercial use is based | |||
upon the use, not the user. The Software may be used by individuals, institutions, governments, corporations, or | |||
other business whether for-profit or non-profit so long as the use itself is not a commercialization of the | |||
materials or a use that generates or is intended to generate income, revenue, sales or profit. | |||
The above copyright notice and this license shall be included in all copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO | |||
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL | |||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |||
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
DEALINGS IN THE SOFTWARE. | |||
*******************************************************************************************************************/ | |||
#ifndef GENLIB_PLATFORM_H | |||
#define GENLIB_PLATFORM_H 1 | |||
#include "genlib_common_win.h" | |||
#if defined(ARM_MATH_CM4) || defined(ARM_MATH_CM7) // embedded ARM cortex support | |||
#define GENLIB_USE_ARMMATH | |||
#define GENLIB_USE_FASTMATH | |||
#endif // defined(ARM_MATH_CM4) || defined(ARM_MATH_CM7) | |||
#if defined (__arm__) // general ARM support | |||
#define GENLIB_USE_FLOAT32 | |||
#endif | |||
#endif // ifdef GENLIB_PLATFORM_H |