#include "gen_exported.h" namespace gen_exported { /******************************************************************************************************************* 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 (at) 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. *******************************************************************************************************************/ // global noise generator Noise noise; static const int GENLIB_LOOPCOUNT_BAIL = 100000; // The State struct contains all the state and procedures for the gendsp kernel typedef struct State { CommonState __commonstate; Delay m_delay_11; Delay m_delay_10; Delay m_delay_12; Delay m_delay_6; Delay m_delay_7; Delay m_delay_8; Delay m_delay_13; Delay m_delay_15; Delay m_delay_14; Delay m_delay_17; Delay m_delay_16; Delay m_delay_9; int __exception; int vectorsize; t_sample m_revtime_20; t_sample m_roomsize_19; t_sample m_dry_24; t_sample m_early_21; t_sample m_spread_23; t_sample m_bandwidth_22; t_sample m_history_5; t_sample m_tail_18; t_sample m_history_1; t_sample m_history_4; t_sample samplerate; t_sample m_history_3; t_sample m_history_2; t_sample m_damping_25; // re-initialize all member variables; inline void reset(t_param __sr, int __vs) { __exception = 0; vectorsize = __vs; samplerate = __sr; m_history_1 = ((int)0); m_history_2 = ((int)0); m_history_3 = ((int)0); m_history_4 = ((int)0); m_history_5 = ((int)0); m_delay_6.reset("m_delay_6", ((int)7000)); m_delay_7.reset("m_delay_7", ((int)5000)); m_delay_8.reset("m_delay_8", ((int)16000)); m_delay_9.reset("m_delay_9", ((int)6000)); m_delay_10.reset("m_delay_10", ((int)15000)); m_delay_11.reset("m_delay_11", ((int)12000)); m_delay_12.reset("m_delay_12", ((int)48000)); m_delay_13.reset("m_delay_13", ((int)10000)); m_delay_14.reset("m_delay_14", ((int)48000)); m_delay_15.reset("m_delay_15", ((int)48000)); m_delay_16.reset("m_delay_16", ((int)48000)); m_delay_17.reset("m_delay_17", ((int)48000)); m_tail_18 = ((t_sample)0.25); m_roomsize_19 = ((int)75); m_revtime_20 = ((int)11); m_early_21 = ((t_sample)0.25); m_bandwidth_22 = ((t_sample)0.5); m_spread_23 = ((int)23); m_dry_24 = ((int)1); m_damping_25 = ((t_sample)0.7); genlib_reset_complete(this); }; // the signal processing routine; inline int perform(t_sample ** __ins, t_sample ** __outs, int __n) { vectorsize = __n; const t_sample * __in1 = __ins[0]; const t_sample * __in2 = __ins[1]; t_sample * __out1 = __outs[0]; t_sample * __out2 = __outs[1]; if (__exception) { return __exception; } else if (( (__in1 == 0) || (__in2 == 0) || (__out1 == 0) || (__out2 == 0) )) { __exception = GENLIB_ERR_NULL_BUFFER; return __exception; }; t_sample expr_335 = ((m_roomsize_19 * samplerate) * ((t_sample)0.0029411764705882)); t_sample expr_334 = safepow(((t_sample)0.001), safediv(((int)1), (m_revtime_20 * samplerate))); t_sample mul_314 = (expr_335 * ((t_sample)0.7071)); t_sample expr_327 = (-safepow(expr_334, mul_314)); t_sample mul_313 = (expr_335 * ((t_sample)0.63245)); t_sample expr_326 = (-safepow(expr_334, mul_313)); t_sample add_239 = (expr_335 + ((int)5)); t_sample expr_329 = safepow(expr_334, add_239); t_sample mul_315 = (expr_335 * ((t_sample)0.81649)); t_sample expr_328 = (-safepow(expr_334, mul_315)); t_sample mul_316 = (expr_335 * ((int)1)); t_sample expr_333 = (-safepow(expr_334, mul_316)); t_sample mul_243 = (expr_335 * ((t_sample)0.155)); t_sample add_240 = (mul_243 + ((int)5)); t_sample expr_330 = safepow(expr_334, add_240); t_sample mul_245 = (expr_335 * ((t_sample)0.41)); t_sample add_242 = (mul_245 + ((int)5)); t_sample expr_332 = safepow(expr_334, add_242); t_sample mul_244 = (expr_335 * ((t_sample)0.3)); t_sample add_241 = (mul_244 + ((int)5)); t_sample expr_331 = safepow(expr_334, add_241); t_sample rsub_324 = (((int)1) - m_bandwidth_22); t_sample mul_310 = (expr_335 * ((t_sample)0.000527)); int int_309 = int(mul_310); t_sample mul_278 = (m_spread_23 * ((t_sample)0.376623)); t_sample add_277 = (mul_278 + ((int)931)); t_sample rsub_274 = (((int)1341) - add_277); t_sample mul_285 = (int_309 * rsub_274); t_sample mul_250 = (m_spread_23 * (-0.380445)); t_sample add_249 = (mul_250 + ((int)931)); t_sample rsub_246 = (((int)1341) - add_249); t_sample mul_259 = (int_309 * rsub_246); t_sample mul_294 = (m_spread_23 * ((t_sample)0.125541)); t_sample add_276 = (mul_294 + ((int)369)); t_sample rsub_275 = (add_277 - add_276); t_sample mul_292 = (int_309 * rsub_275); t_sample mul_308 = (expr_335 * ((t_sample)0.110732)); t_sample mul_252 = (m_spread_23 * (-0.568366)); t_sample add_248 = (mul_252 + ((int)369)); t_sample rsub_247 = (add_249 - add_248); t_sample mul_266 = (int_309 * rsub_247); t_sample add_293 = (mul_294 + ((int)159)); t_sample mul_301 = (int_309 * add_293); t_sample add_251 = (mul_252 + ((int)159)); t_sample mul_273 = (int_309 * add_251); // the main sample loop; while ((__n--)) { const t_sample in1 = (*(__in1++)); const t_sample in2 = (*(__in2++)); t_sample mul_183 = (in1 * m_dry_24); t_sample mul_171 = (in2 * m_dry_24); t_sample mul_173 = ((in1 + in2) * ((t_sample)0.707)); t_sample mix_777 = (mul_173 + (rsub_324 * (m_history_5 - mul_173))); t_sample mix_323 = mix_777; t_sample tap_219 = m_delay_17.read_linear(mul_314); t_sample mul_215 = (tap_219 * expr_327); t_sample mix_778 = (mul_215 + (m_damping_25 * (m_history_4 - mul_215))); t_sample mix_217 = mix_778; t_sample tap_213 = m_delay_16.read_linear(mul_313); t_sample mul_209 = (tap_213 * expr_326); t_sample mix_779 = (mul_209 + (m_damping_25 * (m_history_3 - mul_209))); t_sample mix_211 = mix_779; t_sample tap_225 = m_delay_15.read_linear(mul_315); t_sample mul_221 = (tap_225 * expr_328); t_sample mix_780 = (mul_221 + (m_damping_25 * (m_history_2 - mul_221))); t_sample mix_223 = mix_780; t_sample tap_321 = m_delay_14.read_linear(mul_316); t_sample mul_312 = (tap_321 * expr_333); t_sample mix_781 = (mul_312 + (m_damping_25 * (m_history_1 - mul_312))); t_sample mix_319 = mix_781; t_sample tap_284 = m_delay_13.read_linear(mul_285); t_sample mul_282 = (tap_284 * ((t_sample)0.625)); t_sample tap_227 = m_delay_12.read_linear(add_242); t_sample tap_228 = m_delay_12.read_linear(add_241); t_sample tap_229 = m_delay_12.read_linear(add_240); t_sample tap_230 = m_delay_12.read_linear(add_239); t_sample mul_233 = (tap_229 * expr_330); t_sample mul_231 = (tap_230 * expr_329); t_sample mul_235 = (tap_228 * expr_331); t_sample mul_237 = (tap_227 * expr_332); t_sample tap_258 = m_delay_11.read_linear(mul_259); t_sample mul_256 = (tap_258 * ((t_sample)0.625)); t_sample add_203 = (mix_319 + mix_223); t_sample add_201 = (mix_217 + mix_211); t_sample add_196 = (add_203 + add_201); t_sample mul_179 = (add_196 * ((t_sample)0.5)); t_sample add_204 = (mul_179 + mul_231); t_sample sub_200 = (add_203 - add_201); t_sample mul_182 = (sub_200 * ((t_sample)0.5)); t_sample add_207 = (mul_182 + mul_237); t_sample sub_202 = (mix_319 - mix_223); t_sample sub_199 = (mix_217 - mix_211); t_sample sub_198 = (sub_202 - sub_199); t_sample mul_181 = (sub_198 * ((t_sample)0.5)); t_sample add_206 = (mul_181 + mul_235); t_sample add_197 = (sub_202 + sub_199); t_sample rsub_195 = (((int)0) - add_197); t_sample mul_180 = (rsub_195 * ((t_sample)0.5)); t_sample add_205 = (mul_180 + mul_233); t_sample tap_291 = m_delay_10.read_linear(mul_292); t_sample mul_289 = (tap_291 * ((t_sample)0.625)); t_sample tap_307 = m_delay_9.read_linear(mul_308); t_sample tap_265 = m_delay_8.read_linear(mul_266); t_sample mul_263 = (tap_265 * ((t_sample)0.625)); t_sample tap_300 = m_delay_7.read_linear(mul_301); t_sample mul_298 = (tap_300 * ((t_sample)0.75)); t_sample mul_305 = (tap_307 * ((t_sample)0.75)); t_sample sub_304 = (mix_323 - mul_305); t_sample mul_303 = (sub_304 * ((t_sample)0.75)); t_sample add_302 = (mul_303 + tap_307); t_sample tap_272 = m_delay_6.read_linear(mul_273); t_sample mul_270 = (tap_272 * ((t_sample)0.75)); t_sample mul_194 = (mul_182 * m_tail_18); t_sample mul_192 = (mul_180 * m_tail_18); t_sample add_178 = (mul_194 + mul_192); t_sample mul_193 = (mul_181 * m_tail_18); t_sample mul_191 = (mul_179 * m_tail_18); t_sample add_177 = (mul_193 + mul_191); t_sample sub_186 = (add_178 - add_177); t_sample mul_190 = (mul_237 * m_early_21); t_sample mul_188 = (mul_233 * m_early_21); t_sample add_176 = (mul_190 + mul_188); t_sample mul_189 = (mul_235 * m_early_21); t_sample mul_187 = (mul_231 * m_early_21); t_sample add_175 = (mul_189 + mul_187); t_sample sub_185 = (add_176 - add_175); t_sample add_172 = (sub_186 + sub_185); t_sample add_184 = (add_172 + in1); t_sample sub_297 = (add_184 - mul_298); t_sample mul_296 = (sub_297 * ((t_sample)0.75)); t_sample add_295 = (mul_296 + tap_300); t_sample sub_288 = (add_295 - mul_289); t_sample mul_287 = (sub_288 * ((t_sample)0.625)); t_sample add_286 = (mul_287 + tap_291); t_sample sub_281 = (add_286 - mul_282); t_sample mul_280 = (sub_281 * ((t_sample)0.625)); t_sample add_279 = (mul_280 + tap_284); t_sample out1 = (mul_183 + add_279); t_sample add_174 = (add_172 + in2); t_sample sub_269 = (add_174 - mul_270); t_sample mul_268 = (sub_269 * ((t_sample)0.75)); t_sample add_267 = (mul_268 + tap_272); t_sample sub_262 = (add_267 - mul_263); t_sample mul_261 = (sub_262 * ((t_sample)0.625)); t_sample add_260 = (mul_261 + tap_265); t_sample sub_255 = (add_260 - mul_256); t_sample mul_254 = (sub_255 * ((t_sample)0.625)); t_sample add_253 = (mul_254 + tap_258); t_sample out2 = (mul_171 + add_253); t_sample history_322_next_336 = fixdenorm(mix_323); t_sample history_216_next_337 = fixdenorm(mix_217); t_sample history_210_next_338 = fixdenorm(mix_211); t_sample history_222_next_339 = fixdenorm(mix_223); t_sample history_318_next_340 = fixdenorm(mix_319); m_delay_17.write(add_205); m_delay_16.write(add_204); m_delay_15.write(add_206); m_delay_14.write(add_207); m_delay_13.write(sub_281); m_delay_12.write(add_302); m_delay_11.write(sub_255); m_delay_10.write(sub_288); m_delay_9.write(sub_304); m_delay_8.write(sub_262); m_delay_7.write(sub_297); m_delay_6.write(sub_269); m_history_5 = history_322_next_336; m_history_4 = history_216_next_337; m_history_3 = history_210_next_338; m_history_2 = history_222_next_339; m_history_1 = history_318_next_340; m_delay_6.step(); m_delay_7.step(); m_delay_8.step(); m_delay_9.step(); m_delay_10.step(); m_delay_11.step(); m_delay_12.step(); m_delay_13.step(); m_delay_14.step(); m_delay_15.step(); m_delay_16.step(); m_delay_17.step(); // assign results to output buffer; (*(__out1++)) = out1; (*(__out2++)) = out2; }; return __exception; }; inline void set_tail(t_param _value) { m_tail_18 = (_value < 0 ? 0 : (_value > 1 ? 1 : _value)); }; inline void set_roomsize(t_param _value) { m_roomsize_19 = (_value < 0.1 ? 0.1 : (_value > 300 ? 300 : _value)); }; inline void set_revtime(t_param _value) { m_revtime_20 = (_value < 0.1 ? 0.1 : (_value > 360 ? 360 : _value)); }; inline void set_early(t_param _value) { m_early_21 = (_value < 0 ? 0 : (_value > 1 ? 1 : _value)); }; inline void set_bandwidth(t_param _value) { m_bandwidth_22 = (_value < 0 ? 0 : (_value > 1 ? 1 : _value)); }; inline void set_spread(t_param _value) { m_spread_23 = (_value < 0 ? 0 : (_value > 100 ? 100 : _value)); }; inline void set_dry(t_param _value) { m_dry_24 = (_value < 0 ? 0 : (_value > 1 ? 1 : _value)); }; inline void set_damping(t_param _value) { m_damping_25 = (_value < 0 ? 0 : (_value > 1 ? 1 : _value)); }; } State; /// /// Configuration for the genlib API /// /// Number of signal inputs and outputs int gen_kernel_numins = 2; int gen_kernel_numouts = 2; int num_inputs() { return gen_kernel_numins; } int num_outputs() { return gen_kernel_numouts; } int num_params() { return 8; } /// Assistive lables for the signal inputs and outputs const char *gen_kernel_innames[] = { "in1", "in2" }; const char *gen_kernel_outnames[] = { "out1", "out2" }; /// Invoke the signal process of a State object int perform(CommonState *cself, t_sample **ins, long numins, t_sample **outs, long numouts, long n) { State* self = (State *)cself; return self->perform(ins, outs, n); } /// Reset all parameters and stateful operators of a State object void reset(CommonState *cself) { State* self = (State *)cself; self->reset(cself->sr, cself->vs); } /// Set a parameter of a State object void setparameter(CommonState *cself, long index, t_param value, void *ref) { State *self = (State *)cself; switch (index) { case 0: self->set_bandwidth(value); break; case 1: self->set_damping(value); break; case 2: self->set_dry(value); break; case 3: self->set_early(value); break; case 4: self->set_revtime(value); break; case 5: self->set_roomsize(value); break; case 6: self->set_spread(value); break; case 7: self->set_tail(value); break; default: break; } } /// Get the value of a parameter of a State object void getparameter(CommonState *cself, long index, t_param *value) { State *self = (State *)cself; switch (index) { case 0: *value = self->m_bandwidth_22; break; case 1: *value = self->m_damping_25; break; case 2: *value = self->m_dry_24; break; case 3: *value = self->m_early_21; break; case 4: *value = self->m_revtime_20; break; case 5: *value = self->m_roomsize_19; break; case 6: *value = self->m_spread_23; break; case 7: *value = self->m_tail_18; break; default: break; } } /// Get the name of a parameter of a State object const char *getparametername(CommonState *cself, long index) { if (index >= 0 && index < cself->numparams) { return cself->params[index].name; } return 0; } /// Get the minimum value of a parameter of a State object t_param getparametermin(CommonState *cself, long index) { if (index >= 0 && index < cself->numparams) { return cself->params[index].outputmin; } return 0; } /// Get the maximum value of a parameter of a State object t_param getparametermax(CommonState *cself, long index) { if (index >= 0 && index < cself->numparams) { return cself->params[index].outputmax; } return 0; } /// Get parameter of a State object has a minimum and maximum value char getparameterhasminmax(CommonState *cself, long index) { if (index >= 0 && index < cself->numparams) { return cself->params[index].hasminmax; } return 0; } /// Get the units of a parameter of a State object const char *getparameterunits(CommonState *cself, long index) { if (index >= 0 && index < cself->numparams) { return cself->params[index].units; } return 0; } /// Get the size of the state of all parameters of a State object size_t getstatesize(CommonState *cself) { return genlib_getstatesize(cself, &getparameter); } /// Get the state of all parameters of a State object short getstate(CommonState *cself, char *state) { return genlib_getstate(cself, state, &getparameter); } /// set the state of all parameters of a State object short setstate(CommonState *cself, const char *state) { return genlib_setstate(cself, state, &setparameter); } /// Allocate and configure a new State object and it's internal CommonState: void *create(t_param sr, long vs) { State *self = new State; self->reset(sr, vs); ParamInfo *pi; self->__commonstate.inputnames = gen_kernel_innames; self->__commonstate.outputnames = gen_kernel_outnames; self->__commonstate.numins = gen_kernel_numins; self->__commonstate.numouts = gen_kernel_numouts; self->__commonstate.sr = sr; self->__commonstate.vs = vs; self->__commonstate.params = (ParamInfo *)genlib_sysmem_newptr(8 * sizeof(ParamInfo)); self->__commonstate.numparams = 8; // initialize parameter 0 ("m_bandwidth_22") pi = self->__commonstate.params + 0; pi->name = "bandwidth"; pi->paramtype = GENLIB_PARAMTYPE_FLOAT; pi->defaultvalue = self->m_bandwidth_22; pi->defaultref = 0; pi->hasinputminmax = false; pi->inputmin = 0; pi->inputmax = 1; pi->hasminmax = true; pi->outputmin = 0; pi->outputmax = 1; pi->exp = 0; pi->units = ""; // no units defined // initialize parameter 1 ("m_damping_25") pi = self->__commonstate.params + 1; pi->name = "damping"; pi->paramtype = GENLIB_PARAMTYPE_FLOAT; pi->defaultvalue = self->m_damping_25; pi->defaultref = 0; pi->hasinputminmax = false; pi->inputmin = 0; pi->inputmax = 1; pi->hasminmax = true; pi->outputmin = 0; pi->outputmax = 1; pi->exp = 0; pi->units = ""; // no units defined // initialize parameter 2 ("m_dry_24") pi = self->__commonstate.params + 2; pi->name = "dry"; pi->paramtype = GENLIB_PARAMTYPE_FLOAT; pi->defaultvalue = self->m_dry_24; pi->defaultref = 0; pi->hasinputminmax = false; pi->inputmin = 0; pi->inputmax = 1; pi->hasminmax = true; pi->outputmin = 0; pi->outputmax = 1; pi->exp = 0; pi->units = ""; // no units defined // initialize parameter 3 ("m_early_21") pi = self->__commonstate.params + 3; pi->name = "early"; pi->paramtype = GENLIB_PARAMTYPE_FLOAT; pi->defaultvalue = self->m_early_21; pi->defaultref = 0; pi->hasinputminmax = false; pi->inputmin = 0; pi->inputmax = 1; pi->hasminmax = true; pi->outputmin = 0; pi->outputmax = 1; pi->exp = 0; pi->units = ""; // no units defined // initialize parameter 4 ("m_revtime_20") pi = self->__commonstate.params + 4; pi->name = "revtime"; pi->paramtype = GENLIB_PARAMTYPE_FLOAT; pi->defaultvalue = self->m_revtime_20; pi->defaultref = 0; pi->hasinputminmax = false; pi->inputmin = 0; pi->inputmax = 1; pi->hasminmax = true; pi->outputmin = 0.1; pi->outputmax = 360; pi->exp = 0; pi->units = ""; // no units defined // initialize parameter 5 ("m_roomsize_19") pi = self->__commonstate.params + 5; pi->name = "roomsize"; pi->paramtype = GENLIB_PARAMTYPE_FLOAT; pi->defaultvalue = self->m_roomsize_19; pi->defaultref = 0; pi->hasinputminmax = false; pi->inputmin = 0; pi->inputmax = 1; pi->hasminmax = true; pi->outputmin = 0.1; pi->outputmax = 300; pi->exp = 0; pi->units = ""; // no units defined // initialize parameter 6 ("m_spread_23") pi = self->__commonstate.params + 6; pi->name = "spread"; pi->paramtype = GENLIB_PARAMTYPE_FLOAT; pi->defaultvalue = self->m_spread_23; pi->defaultref = 0; pi->hasinputminmax = false; pi->inputmin = 0; pi->inputmax = 1; pi->hasminmax = true; pi->outputmin = 0; pi->outputmax = 100; pi->exp = 0; pi->units = ""; // no units defined // initialize parameter 7 ("m_tail_18") pi = self->__commonstate.params + 7; pi->name = "tail"; pi->paramtype = GENLIB_PARAMTYPE_FLOAT; pi->defaultvalue = self->m_tail_18; pi->defaultref = 0; pi->hasinputminmax = false; pi->inputmin = 0; pi->inputmax = 1; pi->hasminmax = true; pi->outputmin = 0; pi->outputmax = 1; pi->exp = 0; pi->units = ""; // no units defined return self; } /// Release all resources and memory used by a State object: void destroy(CommonState *cself) { State *self = (State *)cself; genlib_sysmem_freeptr(cself->params); delete self; } } // gen_exported::