#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_5; Delta __m_delta_14; Delta __m_delta_11; Delta __m_delta_20; Delta __m_delta_17; Phasor __m_phasor_10; Sah __m_sah_13; Sah __m_sah_12; Sah __m_sah_15; Sah __m_sah_16; Sah __m_sah_21; Sah __m_sah_19; Sah __m_sah_18; Sah __m_sah_22; int __exception; int vectorsize; t_sample m_window_8; t_sample m_history_1; t_sample samplerate; t_sample m_xfade_9; t_sample m_history_2; t_sample m_history_4; t_sample m_history_3; t_sample m_ratio_7; t_sample m_blur_6; t_sample samples_to_seconds; // re-initialize all member variables; inline void reset(t_param __sr, int __vs) { __exception = 0; vectorsize = __vs; samplerate = __sr; m_history_1 = 0; m_history_2 = 0; m_history_3 = 0; m_history_4 = 0; m_delay_5.reset("m_delay_5", 88200); m_blur_6 = 0; m_ratio_7 = 0; m_window_8 = 100; m_xfade_9 = 1; samples_to_seconds = (1 / samplerate); __m_phasor_10.reset(0); __m_delta_11.reset(0); __m_sah_12.reset(0); __m_sah_13.reset(0); __m_delta_14.reset(0); __m_sah_15.reset(0); __m_sah_16.reset(0); __m_delta_17.reset(0); __m_sah_18.reset(0); __m_sah_19.reset(0); __m_delta_20.reset(0); __m_sah_21.reset(0); __m_sah_22.reset(0); 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]; t_sample * __out1 = __outs[0]; t_sample * __out2 = __outs[1]; if (__exception) { return __exception; } else if (( (__in1 == 0) || (__out1 == 0) || (__out2 == 0) )) { __exception = GENLIB_ERR_NULL_BUFFER; return __exception; }; t_sample mstosamps_138 = (m_window_8 * (samplerate * 0.001)); t_sample rsub_124 = (1 - m_ratio_7); t_sample mul_123 = (rsub_124 * 1000); t_sample div_122 = safediv(mul_123, m_window_8); samples_to_seconds = (1 / samplerate); // the main sample loop; while ((__n--)) { const t_sample in1 = (*(__in1++)); t_sample noise_76 = noise(); t_sample abs_94 = fabs(noise_76); t_sample mul_104 = (abs_94 * m_blur_6); t_sample noise_74 = noise(); t_sample abs_92 = fabs(noise_74); t_sample mul_98 = (abs_92 * m_blur_6); t_sample noise_75 = noise(); t_sample abs_93 = fabs(noise_75); t_sample mul_101 = (abs_93 * m_blur_6); t_sample noise_73 = noise(); t_sample abs_91 = fabs(noise_73); t_sample mul_95 = (abs_91 * m_blur_6); t_sample phasor_144 = __m_phasor_10(div_122, samples_to_seconds); t_sample add_143 = ((m_history_4 + phasor_144) + 0); t_sample mod_142 = safemod(add_143, 1); t_sample delta_84 = __m_delta_11(mod_142); t_sample sah_83 = __m_sah_12(mul_104, delta_84, 0); t_sample sah_105 = __m_sah_13(mstosamps_138, delta_84, 0); t_sample mul_90 = (sah_105 * mod_142); t_sample sub_141 = (mod_142 - 0.5); t_sample mul_140 = (sub_141 * 3.1415926535898); t_sample cos_139 = cos(mul_140); t_sample mul_109 = (cos_139 * cos_139); t_sample add_121 = ((m_history_3 + phasor_144) + 0.5); t_sample mod_120 = safemod(add_121, 1); t_sample delta_100 = __m_delta_14(mod_120); t_sample sah_79 = __m_sah_15(mul_98, delta_100, 0); t_sample sah_99 = __m_sah_16(mstosamps_138, delta_100, 0); t_sample mul_88 = (sah_99 * mod_120); t_sample sub_119 = (mod_120 - 0.5); t_sample mul_118 = (sub_119 * 3.1415926535898); t_sample cos_117 = cos(mul_118); t_sample mul_107 = (cos_117 * cos_117); t_sample add_137 = ((m_history_2 + phasor_144) + 0.25); t_sample mod_136 = safemod(add_137, 1); t_sample delta_103 = __m_delta_17(mod_136); t_sample sah_81 = __m_sah_18(mul_101, delta_103, 0); t_sample sah_102 = __m_sah_19(mstosamps_138, delta_103, 0); t_sample mul_89 = (sah_102 * mod_136); t_sample sub_135 = (mod_136 - 0.5); t_sample mul_134 = (sub_135 * 3.1415926535898); t_sample cos_133 = cos(mul_134); t_sample mul_108 = (cos_133 * cos_133); t_sample add_115 = ((m_history_1 + phasor_144) + 0.75); t_sample mod_114 = safemod(add_115, 1); t_sample delta_97 = __m_delta_20(mod_114); t_sample sah_77 = __m_sah_21(mul_95, delta_97, 0); t_sample sah_96 = __m_sah_22(mstosamps_138, delta_97, 0); t_sample mul_87 = (sah_96 * mod_114); t_sample tap_129 = m_delay_5.read_linear(mul_90); t_sample tap_130 = m_delay_5.read_linear(mul_89); t_sample tap_131 = m_delay_5.read_linear(mul_88); t_sample tap_132 = m_delay_5.read_linear(mul_87); t_sample mul_126 = (tap_130 * mul_108); t_sample mul_127 = (tap_129 * mul_109); t_sample mul_116 = (tap_131 * mul_107); t_sample add_150 = (mul_116 + mul_127); t_sample mix_149 = (in1 + (m_xfade_9 * (add_150 - in1))); t_sample out1 = mix_149; t_sample sub_113 = (mod_114 - 0.5); t_sample mul_112 = (sub_113 * 3.1415926535898); t_sample cos_111 = cos(mul_112); t_sample mul_106 = (cos_111 * cos_111); t_sample mul_110 = (tap_132 * mul_106); t_sample add_152 = (mul_110 + mul_126); t_sample mix_151 = (in1 + (m_xfade_9 * (add_152 - in1))); t_sample out2 = mix_151; t_sample history_85_next_145 = fixdenorm(sah_83); t_sample history_80_next_146 = fixdenorm(sah_79); t_sample history_82_next_147 = fixdenorm(sah_81); t_sample history_78_next_148 = fixdenorm(sah_77); m_delay_5.write(in1); m_history_4 = history_85_next_145; m_history_3 = history_80_next_146; m_history_2 = history_82_next_147; m_history_1 = history_78_next_148; m_delay_5.step(); // assign results to output buffer; (*(__out1++)) = out1; (*(__out2++)) = out2; }; return __exception; }; inline void set_blur(t_param _value) { m_blur_6 = (_value < 0 ? 0 : (_value > 0.25 ? 0.25 : _value)); }; inline void set_ratio(t_param _value) { m_ratio_7 = (_value < 0.25 ? 0.25 : (_value > 4 ? 4 : _value)); }; inline void set_window(t_param _value) { m_window_8 = (_value < 0.1 ? 0.1 : (_value > 1000 ? 1000 : _value)); }; inline void set_xfade(t_param _value) { m_xfade_9 = (_value < 0 ? 0 : (_value > 1 ? 1 : _value)); }; } State; /// /// Configuration for the genlib API /// /// Number of signal inputs and outputs int gen_kernel_numins = 1; int gen_kernel_numouts = 2; int num_inputs() { return gen_kernel_numins; } int num_outputs() { return gen_kernel_numouts; } int num_params() { return 4; } /// Assistive lables for the signal inputs and outputs const char *gen_kernel_innames[] = { "in1" }; 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_blur(value); break; case 1: self->set_ratio(value); break; case 2: self->set_window(value); break; case 3: self->set_xfade(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_blur_6; break; case 1: *value = self->m_ratio_7; break; case 2: *value = self->m_window_8; break; case 3: *value = self->m_xfade_9; 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(4 * sizeof(ParamInfo)); self->__commonstate.numparams = 4; // initialize parameter 0 ("m_blur_6") pi = self->__commonstate.params + 0; pi->name = "blur"; pi->paramtype = GENLIB_PARAMTYPE_FLOAT; pi->defaultvalue = self->m_blur_6; pi->defaultref = 0; pi->hasinputminmax = false; pi->inputmin = 0; pi->inputmax = 1; pi->hasminmax = true; pi->outputmin = 0; pi->outputmax = 0.25; pi->exp = 0; pi->units = ""; // no units defined // initialize parameter 1 ("m_ratio_7") pi = self->__commonstate.params + 1; pi->name = "ratio"; pi->paramtype = GENLIB_PARAMTYPE_FLOAT; pi->defaultvalue = self->m_ratio_7; pi->defaultref = 0; pi->hasinputminmax = false; pi->inputmin = 0; pi->inputmax = 1; pi->hasminmax = true; pi->outputmin = 0.25; pi->outputmax = 4; pi->exp = 0; pi->units = ""; // no units defined // initialize parameter 2 ("m_window_8") pi = self->__commonstate.params + 2; pi->name = "window"; pi->paramtype = GENLIB_PARAMTYPE_FLOAT; pi->defaultvalue = self->m_window_8; pi->defaultref = 0; pi->hasinputminmax = false; pi->inputmin = 0; pi->inputmax = 1; pi->hasminmax = true; pi->outputmin = 0.1; pi->outputmax = 1000; pi->exp = 0; pi->units = ""; // no units defined // initialize parameter 3 ("m_xfade_9") pi = self->__commonstate.params + 3; pi->name = "xfade"; pi->paramtype = GENLIB_PARAMTYPE_FLOAT; pi->defaultvalue = self->m_xfade_9; 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::