Debian Codegraph @

src/objects/chorusmodule.c

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /**************************************************************************
2 * Copyright 2009-2015 Olivier Belanger *
3 * *
4 * This file is part of pyo, a python module to help digital signal *
5 * processing script creation. *
6 * *
7 * pyo is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU Lesser General Public License as *
9 * published by the Free Software Foundation, either version 3 of the *
10 * License, or (at your option) any later version. *
11 * *
12 * pyo is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU Lesser General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with pyo. If not, see <http://www.gnu.org/licenses/>. *
19 *************************************************************************/
20
21 #include <Python.h>
22 #include "structmember.h"
23 #include "pyomodule.h"
24 #include "streammodule.h"
25 #include "servermodule.h"
26 #include "dummymodule.h"
27
28 static MYFLT LFO_ARRAY[513] = {0.0, 0.012271538285719925, 0.024541228522912288, 0.036807222941358832, 0.049067674327418015, 0.061320736302208578, 0.073564563599667426, 0.085797312344439894, 0.098017140329560604, 0.11022220729388306, 0.1224106751992162, 0.13458070850712617, 0.14673047445536175, 0.15885814333386145, 0.17096188876030122, 0.18303988795514095, 0.19509032201612825, 0.20711137619221856, 0.2191012401568698, 0.23105810828067111, 0.24298017990326387, 0.25486565960451457, 0.26671275747489837, 0.27851968938505306, 0.29028467725446233, 0.30200594931922808, 0.31368174039889152, 0.32531029216226293, 0.33688985339222005, 0.34841868024943456, 0.35989503653498811, 0.37131719395183754, 0.38268343236508978, 0.3939920400610481, 0.40524131400498986, 0.41642956009763715, 0.42755509343028208, 0.43861623853852766, 0.44961132965460654, 0.46053871095824001, 0.47139673682599764, 0.48218377207912272, 0.49289819222978404, 0.50353838372571758, 0.51410274419322166, 0.52458968267846895, 0.53499761988709715, 0.54532498842204646, 0.55557023301960218, 0.56573181078361312, 0.57580819141784534, 0.58579785745643886, 0.59569930449243336, 0.60551104140432555, 0.61523159058062682, 0.62485948814238634, 0.63439328416364549, 0.64383154288979139, 0.65317284295377676, 0.66241577759017178, 0.67155895484701833, 0.68060099779545302, 0.68954054473706683, 0.69837624940897292, 0.70710678118654746, 0.71573082528381859, 0.72424708295146689, 0.7326542716724127, 0.74095112535495899, 0.74913639452345926, 0.75720884650648446, 0.76516726562245885, 0.77301045336273688, 0.78073722857209438, 0.78834642762660623, 0.79583690460888346, 0.80320753148064483, 0.81045719825259477, 0.81758481315158371, 0.82458930278502529, 0.83146961230254512, 0.83822470555483797, 0.84485356524970701, 0.8513551931052652, 0.85772861000027212, 0.8639728561215867, 0.87008699110871135, 0.87607009419540649, 0.88192126434835494, 0.88763962040285393, 0.89322430119551532, 0.89867446569395382, 0.90398929312344334, 0.90916798309052238, 0.91420975570353069, 0.91911385169005777, 0.92387953251128674, 0.92850608047321548, 0.93299279883473885, 0.93733901191257496, 0.94154406518302081, 0.94560732538052128, 0.94952818059303667, 0.95330604035419375, 0.95694033573220894, 0.96043051941556579, 0.96377606579543984, 0.96697647104485207, 0.97003125319454397, 0.97293995220556007, 0.97570213003852857, 0.97831737071962765, 0.98078528040323043, 0.98310548743121629, 0.98527764238894122, 0.98730141815785843, 0.98917650996478101, 0.99090263542778001, 0.99247953459870997, 0.99390697000235606, 0.99518472667219682, 0.996312612182778, 0.99729045667869021, 0.99811811290014918, 0.99879545620517241, 0.99932238458834954, 0.99969881869620425, 0.9999247018391445, 1.0, 0.9999247018391445, 0.99969881869620425, 0.99932238458834954, 0.99879545620517241, 0.99811811290014918, 0.99729045667869021, 0.996312612182778, 0.99518472667219693, 0.99390697000235606, 0.99247953459870997, 0.99090263542778001, 0.98917650996478101, 0.98730141815785843, 0.98527764238894122, 0.98310548743121629, 0.98078528040323043, 0.97831737071962765, 0.97570213003852857, 0.97293995220556018, 0.97003125319454397, 0.96697647104485207, 0.96377606579543984, 0.9604305194155659, 0.95694033573220894, 0.95330604035419386, 0.94952818059303667, 0.94560732538052139, 0.94154406518302081, 0.93733901191257496, 0.93299279883473885, 0.92850608047321559, 0.92387953251128674, 0.91911385169005777, 0.91420975570353069, 0.90916798309052249, 0.90398929312344345, 0.89867446569395393, 0.89322430119551521, 0.88763962040285393, 0.88192126434835505, 0.8760700941954066, 0.87008699110871146, 0.86397285612158681, 0.85772861000027212, 0.8513551931052652, 0.84485356524970723, 0.83822470555483819, 0.83146961230254546, 0.82458930278502529, 0.81758481315158371, 0.81045719825259477, 0.80320753148064494, 0.79583690460888357, 0.78834642762660634, 0.7807372285720946, 0.7730104533627371, 0.76516726562245907, 0.75720884650648479, 0.74913639452345926, 0.74095112535495899, 0.73265427167241282, 0.724247082951467, 0.71573082528381871, 0.70710678118654757, 0.69837624940897292, 0.68954054473706705, 0.68060099779545324, 0.67155895484701855, 0.66241577759017201, 0.65317284295377664, 0.64383154288979139, 0.63439328416364549, 0.62485948814238634, 0.61523159058062693, 0.60551104140432555, 0.59569930449243347, 0.58579785745643898, 0.57580819141784545, 0.56573181078361345, 0.55557023301960218, 0.54532498842204635, 0.53499761988709715, 0.52458968267846895, 0.51410274419322177, 0.50353838372571758, 0.49289819222978415, 0.48218377207912289, 0.47139673682599781, 0.46053871095824023, 0.44961132965460687, 0.43861623853852755, 0.42755509343028203, 0.41642956009763715, 0.40524131400498986, 0.39399204006104815, 0.38268343236508984, 0.37131719395183765, 0.35989503653498833, 0.34841868024943479, 0.33688985339222027, 0.3253102921622632, 0.31368174039889141, 0.30200594931922803, 0.29028467725446233, 0.27851968938505312, 0.26671275747489848, 0.25486565960451468, 0.24298017990326404, 0.2310581082806713, 0.21910124015687002, 0.20711137619221884, 0.19509032201612858, 0.1830398879551409, 0.17096188876030119, 0.15885814333386145, 0.1467304744553618, 0.13458070850712628, 0.12241067519921635, 0.11022220729388325, 0.09801714032956084, 0.085797312344440158, 0.073564563599667745, 0.061320736302208495, 0.049067674327417973, 0.036807222941358832, 0.024541228522912326, 0.012271538285720007, 1.2246467991473532e-16, -0.012271538285719761, -0.024541228522912083, -0.036807222941358582, -0.049067674327417724, -0.061320736302208245, -0.073564563599667496, -0.085797312344439922, -0.09801714032956059, -0.110222207293883, -0.1224106751992161, -0.13458070850712606, -0.14673047445536158, -0.15885814333386122, -0.17096188876030097, -0.18303988795514067, -0.19509032201612836, -0.20711137619221862, -0.21910124015686983, -0.23105810828067111, -0.24298017990326382, -0.25486565960451446, -0.26671275747489825, -0.27851968938505289, -0.29028467725446216, -0.30200594931922781, -0.31368174039889118, -0.32531029216226304, -0.33688985339222011, -0.34841868024943456, -0.35989503653498811, -0.37131719395183749, -0.38268343236508967, -0.39399204006104793, -0.40524131400498969, -0.41642956009763693, -0.42755509343028181, -0.43861623853852733, -0.44961132965460665, -0.46053871095824006, -0.47139673682599764, -0.48218377207912272, -0.49289819222978393, -0.50353838372571746, -0.51410274419322155, -0.52458968267846873, -0.53499761988709693, -0.54532498842204613, -0.55557023301960196, -0.56573181078361323, -0.57580819141784534, -0.58579785745643886, -0.59569930449243325, -0.60551104140432543, -0.61523159058062671, -0.62485948814238623, -0.63439328416364527, -0.64383154288979128, -0.65317284295377653, -0.66241577759017178, -0.67155895484701844, -0.68060099779545302, -0.68954054473706683, -0.6983762494089728, -0.70710678118654746, -0.71573082528381848, -0.72424708295146667, -0.73265427167241259, -0.74095112535495877, -0.74913639452345904, -0.75720884650648423, -0.76516726562245885, -0.77301045336273666, -0.78073722857209438, -0.78834642762660589, -0.79583690460888334, -0.80320753148064505, -0.81045719825259466, -0.81758481315158371, -0.82458930278502507, -0.83146961230254524, -0.83822470555483775, -0.84485356524970712, -0.85135519310526486, -0.85772861000027201, -0.86397285612158647, -0.87008699110871135, -0.87607009419540671, -0.88192126434835494, -0.88763962040285405, -0.89322430119551521, -0.89867446569395382, -0.90398929312344312, -0.90916798309052238, -0.91420975570353047, -0.91911385169005766, -0.92387953251128652, -0.92850608047321548, -0.93299279883473896, -0.93733901191257485, -0.94154406518302081, -0.94560732538052117, -0.94952818059303667, -0.95330604035419375, -0.95694033573220882, -0.96043051941556568, -0.96377606579543984, -0.96697647104485218, -0.97003125319454397, -0.97293995220556018, -0.97570213003852846, -0.97831737071962765, -0.98078528040323032, -0.98310548743121629, -0.98527764238894111, -0.98730141815785832, -0.9891765099647809, -0.99090263542778001, -0.99247953459871008, -0.99390697000235606, -0.99518472667219693, -0.996312612182778, -0.99729045667869021, -0.99811811290014918, -0.99879545620517241, -0.99932238458834943, -0.99969881869620425, -0.9999247018391445, -1.0, -0.9999247018391445, -0.99969881869620425, -0.99932238458834954, -0.99879545620517241, -0.99811811290014918, -0.99729045667869021, -0.996312612182778, -0.99518472667219693, -0.99390697000235606, -0.99247953459871008, -0.99090263542778001, -0.9891765099647809, -0.98730141815785843, -0.98527764238894122, -0.9831054874312164, -0.98078528040323043, -0.97831737071962777, -0.97570213003852857, -0.97293995220556029, -0.97003125319454397, -0.96697647104485229, -0.96377606579543995, -0.96043051941556579, -0.95694033573220894, -0.95330604035419375, -0.94952818059303679, -0.94560732538052128, -0.94154406518302092, -0.93733901191257496, -0.93299279883473907, -0.92850608047321559, -0.92387953251128663, -0.91911385169005788, -0.91420975570353058, -0.90916798309052249, -0.90398929312344334, -0.89867446569395404, -0.89322430119551532, -0.88763962040285416, -0.88192126434835505, -0.87607009419540693, -0.87008699110871146, -0.8639728561215867, -0.85772861000027223, -0.85135519310526508, -0.84485356524970734, -0.83822470555483797, -0.83146961230254557, -0.82458930278502529, -0.81758481315158404, -0.81045719825259488, -0.80320753148064528, -0.79583690460888368, -0.78834642762660612, -0.78073722857209471, -0.77301045336273688, -0.76516726562245918, -0.75720884650648457, -0.7491363945234597, -0.74095112535495922, -0.73265427167241315, -0.72424708295146711, -0.71573082528381904, -0.70710678118654768, -0.69837624940897269, -0.68954054473706716, -0.68060099779545302, -0.67155895484701866, -0.66241577759017178, -0.65317284295377709, -0.6438315428897915, -0.63439328416364593, -0.62485948814238645, -0.61523159058062737, -0.60551104140432566, -0.59569930449243325, -0.58579785745643909, -0.57580819141784523, -0.56573181078361356, -0.55557023301960218, -0.5453249884220468, -0.53499761988709726, -0.52458968267846939, -0.51410274419322188, -0.50353838372571813, -0.49289819222978426, -0.48218377207912261, -0.47139673682599792, -0.46053871095823995, -0.44961132965460698, -0.43861623853852766, -0.42755509343028253, -0.41642956009763726, -0.40524131400499042, -0.39399204006104827, -0.38268343236509039, -0.37131719395183777, -0.359895036534988, -0.3484186802494349, -0.33688985339222, -0.32531029216226331, -0.31368174039889152, -0.30200594931922853, -0.29028467725446244, -0.27851968938505367, -0.26671275747489859, -0.25486565960451435, -0.24298017990326418, -0.23105810828067103, -0.21910124015687016, -0.20711137619221853, -0.19509032201612872, -0.18303988795514103, -0.17096188876030177, -0.15885814333386158, -0.14673047445536239, -0.13458070850712642, -0.12241067519921603, -0.11022220729388338, -0.09801714032956052, -0.085797312344440282, -0.073564563599667426, -0.06132073630220905, -0.049067674327418091, -0.036807222941359394, -0.024541228522912451, -0.012271538285720572, 0.0};
29
30 /* center delay time, delay time deviation, lfo frequency */
31 static const MYFLT chorusParams[8][3] =
32 {
33 { 384.0, 44.0, 1.879 },
34 { 450.0, 53.0, 1.654 },
35 { 489.0, 57.0, 1.342 },
36 { 553.0, 62.0, 1.231 },
37 { 591.0, 66.0, 0.879 },
38 { 662.0, 71.0, 0.657 },
39 { 753.0, 88.0, 0.465 },
40 { 785.0, 101.0, 0.254 }
41 };
42
43 typedef struct
44 {
45 pyo_audio_HEAD
46 PyObject *input;
47 Stream *input_stream;
48 PyObject *feedback;
49 Stream *feedback_stream;
50 PyObject *depth;
51 Stream *depth_stream;
52 PyObject *mix;
53 Stream *mix_stream;
54 void (*mix_func_ptr)();
55 int modebuffer[5];
56 MYFLT total_signal;
57 MYFLT delays[8];
58 MYFLT delay_devs[8];
59 long size[8];
60 long in_count[8];
61 MYFLT *buffer[8];
62 // jitters
63 MYFLT pointerPos[8];
64 MYFLT inc[8];
65 } Chorus;
66
67 static void
68 Chorus_process_ii(Chorus *self)
69 {
70 MYFLT lfo, pos, val, fpart, inval;
71 int i, j, ipart;
72
73 MYFLT *in = Stream_getData((Stream *)self->input_stream);
74 MYFLT dpth = PyFloat_AS_DOUBLE(self->depth);
75 MYFLT feed = PyFloat_AS_DOUBLE(self->feedback);
76
77 if (dpth < 0)
78 dpth = 0;
79 else if (dpth > 5)
80 dpth = 5;
81
82 if (feed < 0)
83 feed = 0;
84 else if (feed > 1)
85 feed = 1;
86
87 for (i = 0; i < self->bufsize; i++)
88 {
89 inval = in[i];
90
91 self->total_signal = 0.0;
92
93 for (j = 0; j < 8; j++)
94 {
95 if (self->pointerPos[j] < 0.0)
96 self->pointerPos[j] += 512.0;
97 else if (self->pointerPos[j] >= 512.0)
98 self->pointerPos[j] -= 512.0;
99
100 ipart = (int)self->pointerPos[j];
101 fpart = self->pointerPos[j] - ipart;
102 lfo = self->delay_devs[j] * dpth * (LFO_ARRAY[ipart] + (LFO_ARRAY[ipart + 1] - LFO_ARRAY[ipart]) * fpart) + self->delays[j];
103 self->pointerPos[j] += self->inc[j];
104
105 pos = self->in_count[j] - lfo;
106
107 if (pos < 0)
108 pos += self->size[j];
109
110 ipart = (int)pos;
111 fpart = pos - ipart;
112 val = self->buffer[j][ipart] + (self->buffer[j][ipart + 1] - self->buffer[j][ipart]) * fpart;
113 self->total_signal += val;
114
115 self->buffer[j][self->in_count[j]] = inval + val * feed;
116
117 if (self->in_count[j] == 0)
118 self->buffer[j][self->size[j]] = self->buffer[j][self->in_count[j]];
119
120 self->in_count[j]++;
121
122 if (self->in_count[j] >= self->size[j])
123 self->in_count[j] = 0;
124 }
125
126 self->data[i] = self->total_signal * 0.25;
127 }
128 }
129
130 static void
131 Chorus_process_ai(Chorus *self)
132 {
133 MYFLT lfo, pos, val, fpart, inval, dpth;
134 int i, j, ipart;
135
136 MYFLT *in = Stream_getData((Stream *)self->input_stream);
137 MYFLT *depth = Stream_getData((Stream *)self->depth_stream);
138 MYFLT feed = PyFloat_AS_DOUBLE(self->feedback);
139
140 for (i = 0; i < self->bufsize; i++)
141 {
142 inval = in[i];
143 dpth = depth[i];
144
145 if (dpth < 0)
146 dpth = 0;
147 else if (dpth > 5)
148 dpth = 5;
149
150 self->total_signal = 0.0;
151
152 for (j = 0; j < 8; j++)
153 {
154 if (self->pointerPos[j] < 0.0)
155 self->pointerPos[j] += 512.0;
156 else if (self->pointerPos[j] >= 512.0)
157 self->pointerPos[j] -= 512.0;
158
159 ipart = (int)self->pointerPos[j];
160 fpart = self->pointerPos[j] - ipart;
161 lfo = self->delay_devs[j] * dpth * (LFO_ARRAY[ipart] + (LFO_ARRAY[ipart + 1] - LFO_ARRAY[ipart]) * fpart) + self->delays[j];
162 self->pointerPos[j] += self->inc[j];
163
164 pos = self->in_count[j] - lfo;
165
166 if (pos < 0)
167 pos += self->size[j];
168
169 ipart = (int)pos;
170 fpart = pos - ipart;
171 val = self->buffer[j][ipart] + (self->buffer[j][ipart + 1] - self->buffer[j][ipart]) * fpart;
172 self->total_signal += val;
173
174 self->buffer[j][self->in_count[j]] = inval + val * feed;
175
176 if (self->in_count[j] == 0)
177 self->buffer[j][self->size[j]] = self->buffer[j][self->in_count[j]];
178
179 self->in_count[j]++;
180
181 if (self->in_count[j] >= self->size[j])
182 self->in_count[j] = 0;
183 }
184
185 self->data[i] = self->total_signal * 0.25;
186 }
187 }
188
189 static void
190 Chorus_process_ia(Chorus *self)
191 {
192 MYFLT lfo, pos, val, fpart, inval, feed;
193 int i, j, ipart;
194
195 MYFLT *in = Stream_getData((Stream *)self->input_stream);
196 MYFLT dpth = PyFloat_AS_DOUBLE(self->depth);
197 MYFLT *feedback = Stream_getData((Stream *)self->feedback_stream);
198
199 for (i = 0; i < self->bufsize; i++)
200 {
201 inval = in[i];
202 feed = feedback[i];
203
204 if (feed < 0)
205 feed = 0;
206 else if (feed > 1)
207 feed = 1;
208
209 self->total_signal = 0.0;
210
211 for (j = 0; j < 8; j++)
212 {
213 if (self->pointerPos[j] < 0.0)
214 self->pointerPos[j] += 512.0;
215 else if (self->pointerPos[j] >= 512.0)
216 self->pointerPos[j] -= 512.0;
217
218 ipart = (int)self->pointerPos[j];
219 fpart = self->pointerPos[j] - ipart;
220 lfo = self->delay_devs[j] * dpth * (LFO_ARRAY[ipart] + (LFO_ARRAY[ipart + 1] - LFO_ARRAY[ipart]) * fpart) + self->delays[j];
221 self->pointerPos[j] += self->inc[j];
222
223 pos = self->in_count[j] - lfo;
224
225 if (pos < 0)
226 pos += self->size[j];
227
228 ipart = (int)pos;
229 fpart = pos - ipart;
230 val = self->buffer[j][ipart] + (self->buffer[j][ipart + 1] - self->buffer[j][ipart]) * fpart;
231 self->total_signal += val;
232
233 self->buffer[j][self->in_count[j]] = inval + val * feed;
234
235 if (self->in_count[j] == 0)
236 self->buffer[j][self->size[j]] = self->buffer[j][self->in_count[j]];
237
238 self->in_count[j]++;
239
240 if (self->in_count[j] >= self->size[j])
241 self->in_count[j] = 0;
242 }
243
244 self->data[i] = self->total_signal * 0.25;
245 }
246 }
247
248 static void
249 Chorus_process_aa(Chorus *self)
250 {
251 MYFLT lfo, pos, val, fpart, inval, dpth, feed;
252 int i, j, ipart;
253
254 MYFLT *in = Stream_getData((Stream *)self->input_stream);
255 MYFLT *depth = Stream_getData((Stream *)self->depth_stream);
256 MYFLT *feedback = Stream_getData((Stream *)self->feedback_stream);
257
258 for (i = 0; i < self->bufsize; i++)
259 {
260 inval = in[i];
261 dpth = depth[i];
262 feed = feedback[i];
263
264 if (dpth < 0)
265 dpth = 0;
266 else if (dpth > 5)
267 dpth = 5;
268
269 if (feed < 0)
270 feed = 0;
271 else if (feed > 1)
272 feed = 1;
273
274 self->total_signal = 0.0;
275
276 for (j = 0; j < 8; j++)
277 {
278 if (self->pointerPos[j] < 0.0)
279 self->pointerPos[j] += 512.0;
280 else if (self->pointerPos[j] >= 512.0)
281 self->pointerPos[j] -= 512.0;
282
283 ipart = (int)self->pointerPos[j];
284 fpart = self->pointerPos[j] - ipart;
285 lfo = self->delay_devs[j] * dpth * (LFO_ARRAY[ipart] + (LFO_ARRAY[ipart + 1] - LFO_ARRAY[ipart]) * fpart) + self->delays[j];
286 self->pointerPos[j] += self->inc[j];
287
288 pos = self->in_count[j] - lfo;
289
290 if (pos < 0)
291 pos += self->size[j];
292
293 ipart = (int)pos;
294 fpart = pos - ipart;
295 val = self->buffer[j][ipart] + (self->buffer[j][ipart + 1] - self->buffer[j][ipart]) * fpart;
296 self->total_signal += val;
297
298 self->buffer[j][self->in_count[j]] = inval + val * feed;
299
300 if (self->in_count[j] == 0)
301 self->buffer[j][self->size[j]] = self->buffer[j][self->in_count[j]];
302
303 self->in_count[j]++;
304
305 if (self->in_count[j] >= self->size[j])
306 self->in_count[j] = 0;
307 }
308
309 self->data[i] = self->total_signal * 0.25;
310 }
311 }
312
313 static void
314 Chorus_mix_i(Chorus *self)
315 {
316 int i;
317 MYFLT val;
318
319 MYFLT mix = PyFloat_AS_DOUBLE(self->mix);
320 MYFLT *in = Stream_getData((Stream *)self->input_stream);
321
322 if (mix < 0.0)
323 mix = 0.0;
324 else if (mix > 1.0)
325 mix = 1.0;
326
327 for (i = 0; i < self->bufsize; i++)
328 {
329 val = in[i] * (1.0 - mix) + self->data[i] * mix;
330 self->data[i] = val;
331 }
332 }
333
334 static void
335 Chorus_mix_a(Chorus *self)
336 {
337 int i;
338 MYFLT mix, val;
339
340 MYFLT *mi = Stream_getData((Stream *)self->mix_stream);
341 MYFLT *in = Stream_getData((Stream *)self->input_stream);
342
343 for (i = 0; i < self->bufsize; i++)
344 {
345 mix = mi[i];
346
347 if (mix < 0.0)
348 mix = 0.0;
349 else if (mix > 1.0)
350 mix = 1.0;
351
352 val = in[i] * (1.0 - mix) + self->data[i] * mix;
353 self->data[i] = val;
354 }
355 }
356
357 static void Chorus_postprocessing_ii(Chorus *self) { POST_PROCESSING_II };
358 static void Chorus_postprocessing_ai(Chorus *self) { POST_PROCESSING_AI };
359 static void Chorus_postprocessing_ia(Chorus *self) { POST_PROCESSING_IA };
360 static void Chorus_postprocessing_aa(Chorus *self) { POST_PROCESSING_AA };
361 static void Chorus_postprocessing_ireva(Chorus *self) { POST_PROCESSING_IREVA };
362 static void Chorus_postprocessing_areva(Chorus *self) { POST_PROCESSING_AREVA };
363 static void Chorus_postprocessing_revai(Chorus *self) { POST_PROCESSING_REVAI };
364 static void Chorus_postprocessing_revaa(Chorus *self) { POST_PROCESSING_REVAA };
365 static void Chorus_postprocessing_revareva(Chorus *self) { POST_PROCESSING_REVAREVA };
366
367 static void
368 Chorus_setProcMode(Chorus *self)
369 {
370 int procmode, muladdmode, mixmode;
371 procmode = self->modebuffer[2] + self->modebuffer[3] * 10;
372 muladdmode = self->modebuffer[0] + self->modebuffer[1] * 10;
373 mixmode = self->modebuffer[4];
374
375 switch (procmode)
376 {
377 case 0:
378 self->proc_func_ptr = Chorus_process_ii;
379 break;
380
381 case 1:
382 self->proc_func_ptr = Chorus_process_ai;
383 break;
384
385 case 10:
386 self->proc_func_ptr = Chorus_process_ia;
387 break;
388
389 case 11:
390 self->proc_func_ptr = Chorus_process_aa;
391 break;
392 }
393
394 switch (mixmode)
395 {
396 case 0:
397 self->mix_func_ptr = Chorus_mix_i;
398 break;
399
400 case 1:
401 self->mix_func_ptr = Chorus_mix_a;
402 break;
403 }
404
405 switch (muladdmode)
406 {
407 case 0:
408 self->muladd_func_ptr = Chorus_postprocessing_ii;
409 break;
410
411 case 1:
412 self->muladd_func_ptr = Chorus_postprocessing_ai;
413 break;
414
415 case 2:
416 self->muladd_func_ptr = Chorus_postprocessing_revai;
417 break;
418
419 case 10:
420 self->muladd_func_ptr = Chorus_postprocessing_ia;
421 break;
422
423 case 11:
424 self->muladd_func_ptr = Chorus_postprocessing_aa;
425 break;
426
427 case 12:
428 self->muladd_func_ptr = Chorus_postprocessing_revaa;
429 break;
430
431 case 20:
432 self->muladd_func_ptr = Chorus_postprocessing_ireva;
433 break;
434
435 case 21:
436 self->muladd_func_ptr = Chorus_postprocessing_areva;
437 break;
438
439 case 22:
440 self->muladd_func_ptr = Chorus_postprocessing_revareva;
441 break;
442 }
443 }
444
445 static void
446 Chorus_compute_next_data_frame(Chorus *self)
447 {
448 (*self->proc_func_ptr)(self);
449 (*self->mix_func_ptr)(self);
450 (*self->muladd_func_ptr)(self);
451 }
452
453 static int
454 Chorus_traverse(Chorus *self, visitproc visit, void *arg)
455 {
456 pyo_VISIT
457 Py_VISIT(self->input);
458 Py_VISIT(self->feedback);
459 Py_VISIT(self->depth);
460 Py_VISIT(self->mix);
461 return 0;
462 }
463
464 static int
465 Chorus_clear(Chorus *self)
466 {
467 pyo_CLEAR
468 Py_CLEAR(self->input);
469 Py_CLEAR(self->feedback);
470 Py_CLEAR(self->depth);
471 Py_CLEAR(self->mix);
472 return 0;
473 }
474
475 static void
476 Chorus_dealloc(Chorus* self)
477 {
478 int i;
479 pyo_DEALLOC
480
481 for (i = 0; i < 8; i++)
482 {
483 PyMem_RawFree(self->buffer[i]);
484 }
485
486 Chorus_clear(self);
487 Py_TYPE(self->stream)->tp_free((PyObject*)self->stream);
488 Py_TYPE(self)->tp_free((PyObject*)self);
489 }
490
491 static PyObject *
492 Chorus_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
493 {
494 int i;
495 long j;
496 MYFLT srfac;
497 PyObject *inputtmp, *input_streamtmp, *depthtmp = NULL, *feedbacktmp = NULL, *mixtmp = NULL, *multmp = NULL, *addtmp = NULL;
498 Chorus *self;
499 self = (Chorus *)type->tp_alloc(type, 0);
500
501 self->feedback = PyFloat_FromDouble(0.5);
502 self->depth = PyFloat_FromDouble(1.0);
503 self->mix = PyFloat_FromDouble(0.5);
504
505 self->total_signal = 0.0;
506 self->modebuffer[0] = 0;
507 self->modebuffer[1] = 0;
508 self->modebuffer[2] = 0;
509 self->modebuffer[3] = 0;
510 self->modebuffer[4] = 0;
511
512 INIT_OBJECT_COMMON
513 Stream_setFunctionPtr(self->stream, Chorus_compute_next_data_frame);
514 self->mode_func_ptr = Chorus_setProcMode;
515
516 srfac = self->sr / 44100.0;
517
518 for (i = 0; i < 8; i++)
519 {
520 self->in_count[i] = 0;
521 self->delays[i] = chorusParams[i][0] * srfac;
522 self->delay_devs[i] = chorusParams[i][1] * srfac;
523 self->inc[i] = chorusParams[i][2] * 512 / self->sr;
524 }
525
526 static char *kwlist[] = {"input", "depth", "feedback", "mix", "mul", "add", NULL};
527
528 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O|OOOOO", kwlist, &inputtmp, &depthtmp, &feedbacktmp, &mixtmp, &multmp, &addtmp))
529 Py_RETURN_NONE;
530
531 INIT_INPUT_STREAM
532
533 if (depthtmp)
534 {
535 PyObject_CallMethod((PyObject *)self, "setDepth", "O", depthtmp);
536 }
537
538 if (feedbacktmp)
539 {
540 PyObject_CallMethod((PyObject *)self, "setFeedback", "O", feedbacktmp);
541 }
542
543 if (mixtmp)
544 {
545 PyObject_CallMethod((PyObject *)self, "setMix", "O", mixtmp);
546 }
547
548 if (multmp)
549 {
550 PyObject_CallMethod((PyObject *)self, "setMul", "O", multmp);
551 }
552
553 if (addtmp)
554 {
555 PyObject_CallMethod((PyObject *)self, "setAdd", "O", addtmp);
556 }
557
558 PyObject_CallMethod(self->server, "addStream", "O", self->stream);
559
560 for (i = 0; i < 8; i++)
561 {
562 self->size[i] = (long)(chorusParams[i][0] * srfac * 2 + 0.5);
563 self->buffer[i] = (MYFLT *)PyMem_RawRealloc(self->buffer[i], (self->size[i] + 1) * sizeof(MYFLT));
564
565 for (j = 0; j < (self->size[i] + 1); j++)
566 {
567 self->buffer[i][j] = 0.;
568 }
569 }
570
571 (*self->mode_func_ptr)(self);
572
573 return (PyObject *)self;
574 }
575
576 static PyObject * Chorus_getServer(Chorus* self) { GET_SERVER };
577 static PyObject * Chorus_getStream(Chorus* self) { GET_STREAM };
578 static PyObject * Chorus_setMul(Chorus *self, PyObject *arg) { SET_MUL };
579 static PyObject * Chorus_setAdd(Chorus *self, PyObject *arg) { SET_ADD };
580 static PyObject * Chorus_setSub(Chorus *self, PyObject *arg) { SET_SUB };
581 static PyObject * Chorus_setDiv(Chorus *self, PyObject *arg) { SET_DIV };
582
583 static PyObject * Chorus_play(Chorus *self, PyObject *args, PyObject *kwds) { PLAY };
584 static PyObject * Chorus_out(Chorus *self, PyObject *args, PyObject *kwds) { OUT };
585 static PyObject * Chorus_stop(Chorus *self, PyObject *args, PyObject *kwds) { STOP };
586
587 static PyObject * Chorus_multiply(Chorus *self, PyObject *arg) { MULTIPLY };
588 static PyObject * Chorus_inplace_multiply(Chorus *self, PyObject *arg) { INPLACE_MULTIPLY };
589 static PyObject * Chorus_add(Chorus *self, PyObject *arg) { ADD };
590 static PyObject * Chorus_inplace_add(Chorus *self, PyObject *arg) { INPLACE_ADD };
591 static PyObject * Chorus_sub(Chorus *self, PyObject *arg) { SUB };
592 static PyObject * Chorus_inplace_sub(Chorus *self, PyObject *arg) { INPLACE_SUB };
593 static PyObject * Chorus_div(Chorus *self, PyObject *arg) { DIV };
594 static PyObject * Chorus_inplace_div(Chorus *self, PyObject *arg) { INPLACE_DIV };
595
596 static PyObject *
597 Chorus_reset(Chorus *self)
598 {
599 int i, j;
600
601 for (i = 0; i < 8; i++)
602 {
603 for (j = 0; j < (self->size[i] + 1); j++)
604 {
605 self->buffer[i][j] = 0.;
606 }
607 }
608
609 Py_RETURN_NONE;
610 }
611
612 static PyObject * Chorus_setDepth(Chorus *self, PyObject *arg) { SET_PARAM(self->depth, self->depth_stream, 2); }
613 static PyObject * Chorus_setFeedback(Chorus *self, PyObject *arg) { SET_PARAM(self->feedback, self->feedback_stream, 3); }
614 static PyObject * Chorus_setMix(Chorus *self, PyObject *arg) {SET_PARAM(self->mix, self->mix_stream, 4); }
615
616 static PyMemberDef Chorus_members[] =
617 {
618 {"server", T_OBJECT_EX, offsetof(Chorus, server), 0, "Pyo server."},
619 {"stream", T_OBJECT_EX, offsetof(Chorus, stream), 0, "Stream object."},
620 {"input", T_OBJECT_EX, offsetof(Chorus, input), 0, "Input sound object."},
621 {"feedback", T_OBJECT_EX, offsetof(Chorus, feedback), 0, "Feedback value."},
622 {"depth", T_OBJECT_EX, offsetof(Chorus, depth), 0, "Chorus depth."},
623 {"mix", T_OBJECT_EX, offsetof(Chorus, mix), 0, "Balance between dry and wet signals."},
624 {"mul", T_OBJECT_EX, offsetof(Chorus, mul), 0, "Mul factor."},
625 {"add", T_OBJECT_EX, offsetof(Chorus, add), 0, "Add factor."},
626 {NULL} /* Sentinel */
627 };
628
629 static PyMethodDef Chorus_methods[] =
630 {
631 {"getServer", (PyCFunction)Chorus_getServer, METH_NOARGS, "Returns server object."},
632 {"_getStream", (PyCFunction)Chorus_getStream, METH_NOARGS, "Returns stream object."},
633 {"play", (PyCFunction)Chorus_play, METH_VARARGS | METH_KEYWORDS, "Starts computing without sending sound to soundcard."},
634 {"out", (PyCFunction)Chorus_out, METH_VARARGS | METH_KEYWORDS, "Starts computing and sends sound to soundcard channel speficied by argument."},
635 {"stop", (PyCFunction)Chorus_stop, METH_VARARGS | METH_KEYWORDS, "Stops computing."},
636 {"reset", (PyCFunction)Chorus_reset, METH_NOARGS, "Reset the delay line."},
637 {"setFeedback", (PyCFunction)Chorus_setFeedback, METH_O, "Sets feedback value between 0 -> 1."},
638 {"setDepth", (PyCFunction)Chorus_setDepth, METH_O, "Sets chorus depth."},
639 {"setMix", (PyCFunction)Chorus_setMix, METH_O, "Sets balance between dry and wet signals."},
640 {"setMul", (PyCFunction)Chorus_setMul, METH_O, "Sets oscillator mul factor."},
641 {"setAdd", (PyCFunction)Chorus_setAdd, METH_O, "Sets oscillator add factor."},
642 {"setSub", (PyCFunction)Chorus_setSub, METH_O, "Sets inverse add factor."},
643 {"setDiv", (PyCFunction)Chorus_setDiv, METH_O, "Sets inverse mul factor."},
644 {NULL} /* Sentinel */
645 };
646
647 static PyNumberMethods Chorus_as_number =
648 {
649 (binaryfunc)Chorus_add, /*nb_add*/
650 (binaryfunc)Chorus_sub, /*nb_subtract*/
651 (binaryfunc)Chorus_multiply, /*nb_multiply*/
652 0, /*nb_remainder*/
653 0, /*nb_divmod*/
654 0, /*nb_power*/
655 0, /*nb_neg*/
656 0, /*nb_pos*/
657 0, /*(unaryfunc)array_abs,*/
658 0, /*nb_nonzero*/
659 0, /*nb_invert*/
660 0, /*nb_lshift*/
661 0, /*nb_rshift*/
662 0, /*nb_and*/
663 0, /*nb_xor*/
664 0, /*nb_or*/
665 0, /*nb_int*/
666 0, /*nb_long*/
667 0, /*nb_float*/
668 (binaryfunc)Chorus_inplace_add, /*inplace_add*/
669 (binaryfunc)Chorus_inplace_sub, /*inplace_subtract*/
670 (binaryfunc)Chorus_inplace_multiply, /*inplace_multiply*/
671 0, /*inplace_remainder*/
672 0, /*inplace_power*/
673 0, /*inplace_lshift*/
674 0, /*inplace_rshift*/
675 0, /*inplace_and*/
676 0, /*inplace_xor*/
677 0, /*inplace_or*/
678 0, /*nb_floor_divide*/
679 (binaryfunc)Chorus_div, /*nb_true_divide*/
680 0, /*nb_inplace_floor_divide*/
681 (binaryfunc)Chorus_inplace_div, /*nb_inplace_true_divide*/
682 0, /* nb_index */
683 };
684
685 PyTypeObject ChorusType =
686 {
687 PyVarObject_HEAD_INIT(NULL, 0)
688 "_pyo.Chorus_base", /*tp_name*/
689 sizeof(Chorus), /*tp_basicsize*/
690 0, /*tp_itemsize*/
691 (destructor)Chorus_dealloc, /*tp_dealloc*/
692 0, /*tp_print*/
693 0, /*tp_getattr*/
694 0, /*tp_setattr*/
695 0, /*tp_as_async (tp_compare in Python 2)*/
696 0, /*tp_repr*/
697 &Chorus_as_number, /*tp_as_number*/
698 0, /*tp_as_sequence*/
699 0, /*tp_as_mapping*/
700 0, /*tp_hash */
701 0, /*tp_call*/
702 0, /*tp_str*/
703 0, /*tp_getattro*/
704 0, /*tp_setattro*/
705 0, /*tp_as_buffer*/
706 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
707 "Chorus objects. 8 delay lines chorus.", /* tp_doc */
708 (traverseproc)Chorus_traverse, /* tp_traverse */
709 (inquiry)Chorus_clear, /* tp_clear */
710 0, /* tp_richcompare */
711 0, /* tp_weaklistoffset */
712 0, /* tp_iter */
713 0, /* tp_iternext */
714 Chorus_methods, /* tp_methods */
715 Chorus_members, /* tp_members */
716 0, /* tp_getset */
717 0, /* tp_base */
718 0, /* tp_dict */
719 0, /* tp_descr_get */
720 0, /* tp_descr_set */
721 0, /* tp_dictoffset */
722 0, /* tp_init */
723 0, /* tp_alloc */
724 Chorus_new, /* tp_new */
725 };