annotate CloneChannel/plugins/common/gen_dsp/genlib.cpp @ 25:404e262cd7e7 default tip

png rm
author Przemyslaw <prymula76@outlook.com>
date Mon, 01 Apr 2024 07:18:10 +0200
parents 24d60bdea349
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
1 /*******************************************************************************************************************
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
2 Copyright (c) 2012 Cycling '74
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
3
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
4 Permission is hereby granted, free of charge, to any person obtaining a copy of this software
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
5 and associated documentation files (the "Software"), to deal in the Software without restriction,
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
6 including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
7 and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
8 subject to the following conditions:
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
9
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
10 The above copyright notice and this permission notice shall be included in all copies
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
11 or substantial portions of the Software.
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
12
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
14 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
15 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
16 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
17 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
18 *******************************************************************************************************************/
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
19
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
20
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
21 #include "genlib.h"
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
22 #include "genlib_exportfunctions.h"
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
23 #include "stdlib.h"
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
24 #include "stdio.h"
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
25 #include "string.h"
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
26
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
27 #include <cmath>
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
28
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
29 #if DISTRHO_OS_MAC
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
30 # include <malloc/malloc.h>
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
31 #else
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
32 # include <malloc.h>
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
33 # if DISTRHO_OS_WINDOWS
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
34 # define malloc_size _msize
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
35 # else
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
36 # define malloc_size malloc_usable_size
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
37 # endif
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
38 #endif
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
39
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
40 // DATA_MAXIMUM_ELEMENTS * 8 bytes = 256 mb limit
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
41 #define DATA_MAXIMUM_ELEMENTS (33554432)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
42
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
43 //////////// export_genlib.cpp ////////////
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
44 // export version
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
45
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
46 void my_memset(void *p, int c, long size);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
47 void my_memcpy(void *dst, const void *src, long size);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
48
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
49 t_ptr sysmem_newptr(t_ptr_size size)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
50 {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
51 return (t_ptr)malloc(size);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
52 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
53
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
54 t_ptr sysmem_newptrclear(t_ptr_size size)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
55 {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
56 t_ptr p = (t_ptr)malloc(size);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
57
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
58 if (p)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
59 my_memset(p, 0, size);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
60
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
61 return p;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
62 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
63
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
64 t_ptr sysmem_resizeptr(void *ptr, t_ptr_size newsize)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
65 {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
66 return (t_ptr)realloc(ptr, newsize);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
67 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
68
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
69 t_ptr sysmem_resizeptrclear(void *ptr, t_ptr_size newsize)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
70 {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
71 t_ptr_size oldsize = malloc_size(ptr);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
72 t_ptr p = (t_ptr)realloc(ptr, newsize);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
73
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
74 if (p) {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
75 if (newsize > oldsize)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
76 my_memset((char *)p + oldsize, 0, newsize - oldsize);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
77 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
78 return p;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
79 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
80
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
81 t_ptr_size sysmem_ptrsize(void *ptr)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
82 {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
83 return malloc_size(ptr);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
84 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
85
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
86 void sysmem_freeptr(void *ptr)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
87 {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
88 free(ptr);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
89 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
90
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
91 void sysmem_copyptr(const void *src, void *dst, t_ptr_size bytes)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
92 {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
93 my_memcpy(dst, src, bytes);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
94 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
95
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
96 void my_memset(void *p, int c, long size)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
97 {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
98 char *p2 = (char *)p;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
99 int i;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
100
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
101 for (i = 0; i < size; i++, p2++)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
102 *p2 = c;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
103 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
104
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
105 void my_memcpy(void *dst, const void *src, long size)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
106 {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
107 char *s2 = (char *)src;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
108 char *d2 = (char *)dst;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
109 int i;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
110
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
111 for (i = 0; i < size; i++, s2++, d2++)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
112 *d2 = *s2;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
113 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
114
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
115 void set_zero64(t_sample *memory, long size)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
116 {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
117 long i;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
118
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
119 for (i = 0; i < size; i++, memory++) {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
120 *memory = 0.;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
121 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
122 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
123
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
124 void genlib_report_error(const char *s)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
125 {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
126 fprintf(stderr, "%s\n", s);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
127 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
128
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
129 void genlib_report_message(const char *s)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
130 {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
131 fprintf(stdout, "%s\n", s);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
132 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
133
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
134 unsigned long systime_ticks(void)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
135 {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
136 return 0; // Gen code can deal with this
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
137 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
138
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
139 void * genlib_obtain_reference_from_string(const char * name) {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
140 return 0; // to be implemented
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
141 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
142
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
143 // the rest is stuff to isolate gensym, attrs, atoms, buffers etc.
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
144 t_genlib_buffer * genlib_obtain_buffer_from_reference(void *ref)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
145 {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
146 return 0; // to be implemented
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
147 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
148
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
149 t_genlib_err genlib_buffer_edit_begin(t_genlib_buffer *b)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
150 {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
151 return 0; // to be implemented
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
152 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
153
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
154 t_genlib_err genlib_buffer_edit_end(t_genlib_buffer *b, long valid)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
155 {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
156 return 0; // to be implemented
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
157 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
158
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
159 t_genlib_err genlib_buffer_getinfo(t_genlib_buffer *b, t_genlib_buffer_info *info)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
160 {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
161 return 0; // to be implemented
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
162 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
163
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
164 char *genlib_reference_getname(void *ref)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
165 {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
166 return 0; // to be implemented
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
167 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
168
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
169 void genlib_buffer_dirty(t_genlib_buffer *b)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
170 {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
171 // to be implemented
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
172 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
173
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
174 t_genlib_err genlib_buffer_perform_begin(t_genlib_buffer *b)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
175 {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
176 return 0; // to be implemented
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
177 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
178
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
179 void genlib_buffer_perform_end(t_genlib_buffer *b)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
180 {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
181 // to be implemented
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
182 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
183
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
184 t_sample gen_msp_pow(t_sample value, t_sample power)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
185 {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
186 return powf(value, power);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
187 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
188
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
189 void genlib_data_setbuffer(t_genlib_data *b, void *ref) {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
190 genlib_report_error("not supported for export targets\n");
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
191 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
192
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
193 typedef struct {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
194 t_genlib_data_info info;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
195 t_sample cursor; // used by Delay
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
196 //t_symbol * name;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
197 } t_dsp_gen_data;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
198
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
199 t_genlib_data * genlib_obtain_data_from_reference(void *ref)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
200 {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
201 t_dsp_gen_data * self = (t_dsp_gen_data *)malloc(sizeof(t_dsp_gen_data));
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
202 self->info.dim = 0;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
203 self->info.channels = 0;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
204 self->info.data = 0;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
205 self->cursor = 0;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
206 return (t_genlib_data *)self;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
207 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
208
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
209 t_genlib_err genlib_data_getinfo(t_genlib_data *b, t_genlib_data_info *info) {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
210 t_dsp_gen_data * self = (t_dsp_gen_data *)b;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
211 info->dim = self->info.dim;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
212 info->channels = self->info.channels;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
213 info->data = self->info.data;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
214 return GENLIB_ERR_NONE;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
215 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
216
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
217 void genlib_data_release(t_genlib_data *b) {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
218 t_dsp_gen_data * self = (t_dsp_gen_data *)b;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
219
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
220 if (self->info.data) {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
221 genlib_sysmem_freeptr(self->info.data);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
222 self->info.data = 0;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
223 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
224 genlib_sysmem_freeptr(self);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
225 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
226
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
227 long genlib_data_getcursor(t_genlib_data *b) {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
228 t_dsp_gen_data * self = (t_dsp_gen_data *)b;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
229 return self->cursor;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
230 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
231
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
232 void genlib_data_setcursor(t_genlib_data *b, long cursor) {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
233 t_dsp_gen_data * self = (t_dsp_gen_data *)b;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
234 self->cursor = cursor;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
235 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
236
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
237 void genlib_data_resize(t_genlib_data *b, long s, long c) {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
238 t_dsp_gen_data * self = (t_dsp_gen_data *)b;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
239
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
240 size_t sz, oldsz, copysz;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
241 t_sample * old = 0;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
242 t_sample * replaced = 0;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
243 int i, j, copydim, copychannels, olddim, oldchannels;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
244
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
245 //printf("data resize %d %d\n", s, c);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
246
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
247 // cache old for copying:
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
248 old = self->info.data;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
249 olddim = self->info.dim;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
250 oldchannels = self->info.channels;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
251
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
252 // limit [data] size:
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
253 if (s * c > DATA_MAXIMUM_ELEMENTS) {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
254 s = DATA_MAXIMUM_ELEMENTS/c;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
255 genlib_report_message("warning: constraining [data] to < 256MB");
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
256 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
257 // bytes required:
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
258 sz = sizeof(t_sample) * s * c;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
259 oldsz = sizeof(t_sample) * olddim * oldchannels;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
260
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
261 if (old && sz == oldsz) {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
262 // no need to re-allocate, just resize
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
263 // careful, audio thread may still be using it:
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
264 if (s > olddim) {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
265 self->info.channels = c;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
266 self->info.dim = s;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
267 } else {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
268 self->info.dim = s;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
269 self->info.channels = c;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
270 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
271
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
272 set_zero64(self->info.data, s * c);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
273 return;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
274
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
275 } else {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
276
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
277 // allocate new:
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
278 replaced = (t_sample *)sysmem_newptr(sz);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
279
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
280 // check allocation:
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
281 if (replaced == 0) {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
282 genlib_report_error("allocating [data]: out of memory");
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
283 // try to reallocate with a default/minimal size instead:
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
284 if (s > 512 || c > 1) {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
285 genlib_data_resize((t_genlib_data *)self, 512, 1);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
286 } else {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
287 // if this fails, then Max is kaput anyway...
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
288 genlib_data_resize((t_genlib_data *)self, 4, 1);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
289 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
290 return;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
291 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
292
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
293 // fill with zeroes:
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
294 set_zero64(replaced, s * c);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
295
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
296 // copy in old data:
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
297 if (old) {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
298 // frames to copy:
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
299 // clamped:
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
300 copydim = olddim > s ? s : olddim;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
301 // use memcpy if channels haven't changed:
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
302 if (c == oldchannels) {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
303 copysz = sizeof(t_sample) * copydim * c;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
304 //post("reset resize (same channels) %p %p, %d", self->info.data, old, copysz);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
305 memcpy(replaced, old, copysz);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
306 } else {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
307 // memcpy won't work if channels have changed,
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
308 // because data is interleaved.
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
309 // clamp channels copied:
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
310 copychannels = oldchannels > c ? c : oldchannels;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
311 //post("reset resize (different channels) %p %p, %d %d", self->info.data, old, copydim, copychannels);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
312 for (i = 0; i<copydim; i++) {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
313 for (j = 0; j<copychannels; j++) {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
314 replaced[j + i*c] = old[j + i*oldchannels];
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
315 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
316 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
317 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
318 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
319
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
320 // now update info:
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
321 if (old == 0) {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
322 self->info.data = replaced;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
323 self->info.dim = s;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
324 self->info.channels = c;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
325 } else {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
326 // need to be careful; the audio thread may still be using it
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
327 // since dsp_gen_data is preserved through edits
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
328 // the order of resizing has to be carefully done
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
329 // to prevent indexing out of bounds
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
330 // (or maybe I'm being too paranoid here...)
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
331 if (oldsz > sz) {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
332 // shrink size first
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
333 if (s > olddim) {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
334 self->info.channels = c;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
335 self->info.dim = s;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
336 } else {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
337 self->info.dim = s;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
338 self->info.channels = c;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
339 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
340 self->info.data = replaced;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
341 } else {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
342 // shrink size after
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
343 self->info.data = replaced;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
344 if (s > olddim) {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
345 self->info.channels = c;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
346 self->info.dim = s;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
347 } else {
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
348 self->info.dim = s;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
349 self->info.channels = c;
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
350 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
351 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
352
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
353 // done with old:
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
354 sysmem_freeptr(old);
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
355
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
356 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
357
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
358 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
359 }
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
360
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
361 void genlib_reset_complete(void *data) {}
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
362
24d60bdea349 ClonneChannel
prymula <prymula76@outlook.com>
parents:
diff changeset
363