// ----
// ---- file   : osc_noise_voice_1.cpp
// ---- author : bsp
// ---- legal  : Distributed under terms of the MIT license (https://opensource.org/licenses/MIT)
// ----
// ----          Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 
// ----          associated documentation files (the "Software"), to deal in the Software without restriction, including 
// ----          without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
// ----          copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to 
// ----          the following conditions:
// ----  
// ----          The above copyright notice and this permission notice shall be included in all copies or substantial 
// ----          portions of the Software.
// ----
// ----          THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
// ----          NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// ----          IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// ----          WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
// ----          SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ----
// ---- info   : auto-generated by "Cycle"
// ----           $ g++ -Wall -Wno-unused-function -Wno-unused-variable -I../../tksampler -c osc_noise_voice_1.cpp -o osc_noise_voice_1.o
// ---- created: 08Aug2023 12:10:41
// ----
// ----
// ----

#include <plugin.h>

#include <stdlib.h>
#include <math.h>
#include <string.h>


#define OVERSAMPLE_FACTOR  2.0f

#define PARAM_CUTOFF_1           0
#define PARAM_CUTOFF_2           1
#define PARAM_CUTOFF_3           2
#define PARAM_RES_1              3
#define PARAM_RES_2              4
#define PARAM_RES_3              5
#define NUM_PARAMS               6
static const char *loc_param_names[NUM_PARAMS] = {
   "cutoff_1",                // 0: CUTOFF_1
   "cutoff_2",                // 1: CUTOFF_2
   "cutoff_3",                // 2: CUTOFF_3
   "res_1",                   // 3: RES_1
   "res_2",                   // 4: RES_2
   "res_3",                   // 5: RES_3

};
static float loc_param_resets[NUM_PARAMS] = {
   0.5f,                      // 0: CUTOFF_1
   0.5f,                      // 1: CUTOFF_2
   0.5f,                      // 2: CUTOFF_3
   0.3f,                      // 3: RES_1
   0.3f,                      // 4: RES_2
   0.3f,                      // 5: RES_3

};

#define MOD_CUTOFF_1             0
#define MOD_CUTOFF_2             1
#define MOD_CUTOFF_3             2
#define MOD_LEVEL_1              3
#define MOD_LEVEL_2              4
#define MOD_LEVEL_3              5
#define MOD_W_1                  6
#define NUM_MODS                 7
static const char *loc_mod_names[NUM_MODS] = {
   "cutoff_1",     // 0: CUTOFF_1
   "cutoff_2",     // 1: CUTOFF_2
   "cutoff_3",     // 2: CUTOFF_3
   "level_1",      // 3: LEVEL_1
   "level_2",      // 4: LEVEL_2
   "level_3",      // 5: LEVEL_3
   "w_1",          // 6: W_1

};

typedef struct osc_noise_voice_1_info_s {
   st_plugin_info_t base;
} osc_noise_voice_1_info_t;

typedef struct osc_noise_voice_1_shared_s {
   st_plugin_shared_t base;
   float params[NUM_PARAMS];

} osc_noise_voice_1_shared_t;

typedef struct osc_noise_voice_1_voice_s {
   st_plugin_voice_t base;
   float             sample_rate;
   float             note_speed_fixed;
   float             note_speed_cur;
   float             note_speed_inc;
   float             note_cur;
   float             note_inc;
   float             mods[NUM_MODS];
   float mod_cutoff_1_cur;
   float mod_cutoff_1_inc;
   float mod_cutoff_2_cur;
   float mod_cutoff_2_inc;
   float mod_cutoff_3_cur;
   float mod_cutoff_3_inc;
   float mod_level_1_cur;
   float mod_level_1_inc;
   float mod_level_2_cur;
   float mod_level_2_inc;
   float mod_level_3_cur;
   float mod_level_3_inc;
   float mod_w_1_cur;
   float mod_w_1_inc;

   float tmp1_kbd;
   float tmp2_off;
   float tmp3_seq;
   float tmp4_kbd;
   float tmp5_off;
   float tmp6_seq;
   float tmp7_seq;
   float tmp8_seq;
   float tmp9_seq;
   float tmp10_seq;
   float tmp11_seq;
   float tmp12_seq;
   float tmp13_seq;
   float tmp14_kbd;
   float tmp15_off;
   float tmp16_seq;
   float tmp17_kbd;
   float tmp18_off;
   float tmp19_seq;
   float tmp20_seq;
   float tmp21_seq;
   float tmp22_seq;
   float tmp23_seq;
   float tmp24_seq;
   float tmp25_seq;
   float tmp26_seq;
   float tmp27_kbd;
   float tmp28_off;
   float tmp29_seq;
   float tmp30_kbd;
   float tmp31_off;
   float tmp32_seq;
   float tmp33_seq;
   float tmp34_seq;
   float tmp35_seq;
   float tmp36_seq;
   float tmp37_seq;
   float tmp38_seq;
   float tmp39_seq;
   short tmp40_i2f;
   unsigned short tmp41_lfsr_state;
   short tmp42_lfsr_state_signed;
   float tmp43_svf_lp;
   float tmp44_svf_hp;
   float tmp45_svf_bp;
   float tmp46_freq;
   float tmp47_svf_lp;
   float tmp48_svf_hp;
   float tmp49_svf_bp;
   float tmp50_freq;
   float tmp51_svf_lp;
   float tmp52_svf_hp;
   float tmp53_svf_bp;
   float tmp54_freq;
   float tmp55_svf_lp;
   float tmp56_svf_hp;
   float tmp57_svf_bp;
   float tmp58_freq;
   float tmp59_svf_lp;
   float tmp60_svf_hp;
   float tmp61_svf_bp;
   float tmp62_res;
   float tmp63_freq;
   float tmp64_svf_lp;
   float tmp65_svf_hp;
   float tmp66_svf_bp;
   float tmp67_res;
   float tmp68_freq;
   float tmp69_svf_lp;
   float tmp70_svf_hp;
   float tmp71_svf_bp;
   float tmp72_res;
   float tmp73_freq;
   float tmp74_svf_lp;
   float tmp75_svf_hp;
   float tmp76_svf_bp;
   float tmp77_res;
   float tmp78_freq;
   float tmp79_svf_lp;
   float tmp80_svf_hp;
   float tmp81_svf_bp;
   float tmp82_res;
   float tmp83_freq;
   float tmp84_svf_lp;
   float tmp85_svf_hp;
   float tmp86_svf_bp;
   float tmp87_res;
   float tmp88_freq;
   float tmp89_svf_lp;
   float tmp90_svf_hp;
   float tmp91_svf_bp;
   float tmp92_res;
   float tmp93_freq;
   short tmp94_i2f;
   unsigned short tmp95_lfsr_state;
   short tmp96_lfsr_state_signed;
   float tmp97_svf_lp;
   float tmp98_svf_hp;
   float tmp99_svf_bp;
   float tmp100_freq;
   float tmp101_svf_lp;
   float tmp102_svf_hp;
   float tmp103_svf_bp;
   float tmp104_freq;
   float tmp105_svf_lp;
   float tmp106_svf_hp;
   float tmp107_svf_bp;
   float tmp108_freq;
   float tmp109_svf_lp;
   float tmp110_svf_hp;
   float tmp111_svf_bp;
   float tmp112_freq;
   float tmp113_svf_lp;
   float tmp114_svf_hp;
   float tmp115_svf_bp;
   float tmp116_res;
   float tmp117_freq;
   float tmp118_svf_lp;
   float tmp119_svf_hp;
   float tmp120_svf_bp;
   float tmp121_res;
   float tmp122_freq;
   float tmp123_svf_lp;
   float tmp124_svf_hp;
   float tmp125_svf_bp;
   float tmp126_res;
   float tmp127_freq;
   float tmp128_svf_lp;
   float tmp129_svf_hp;
   float tmp130_svf_bp;
   float tmp131_res;
   float tmp132_freq;
   float tmp133_svf_lp;
   float tmp134_svf_hp;
   float tmp135_svf_bp;
   float tmp136_res;
   float tmp137_freq;
   float tmp138_svf_lp;
   float tmp139_svf_hp;
   float tmp140_svf_bp;
   float tmp141_res;
   float tmp142_freq;
   float tmp143_svf_lp;
   float tmp144_svf_hp;
   float tmp145_svf_bp;
   float tmp146_res;
   float tmp147_freq;
   short tmp148_i2f;
   unsigned short tmp149_lfsr_state;
   short tmp150_lfsr_state_signed;
   float tmp151_svf_lp;
   float tmp152_svf_hp;
   float tmp153_svf_bp;
   float tmp154_freq;
   float tmp155_svf_lp;
   float tmp156_svf_hp;
   float tmp157_svf_bp;
   float tmp158_freq;
   float tmp159_svf_lp;
   float tmp160_svf_hp;
   float tmp161_svf_bp;
   float tmp162_freq;
   float tmp163_svf_lp;
   float tmp164_svf_hp;
   float tmp165_svf_bp;
   float tmp166_freq;
   float tmp167_svf_lp;
   float tmp168_svf_hp;
   float tmp169_svf_bp;
   float tmp170_res;
   float tmp171_freq;
   float tmp172_svf_lp;
   float tmp173_svf_hp;
   float tmp174_svf_bp;
   float tmp175_res;
   float tmp176_freq;
   float tmp177_svf_lp;
   float tmp178_svf_hp;
   float tmp179_svf_bp;
   float tmp180_res;
   float tmp181_freq;
   float tmp182_svf_lp;
   float tmp183_svf_hp;
   float tmp184_svf_bp;
   float tmp185_res;
   float tmp186_freq;
   float tmp187_svf_lp;
   float tmp188_svf_hp;
   float tmp189_svf_bp;
   float tmp190_res;
   float tmp191_freq;
   float tmp192_svf_lp;
   float tmp193_svf_hp;
   float tmp194_svf_bp;
   float tmp195_res;
   float tmp196_freq;
   float tmp197_svf_lp;
   float tmp198_svf_hp;
   float tmp199_svf_bp;
   float tmp200_res;
   float tmp201_freq;
   float tmp202_seq;
   float tmp203_seq;
   float tmp204_seq;
   float tmp205_seq;
   float tmp206_seq;
   float var_x;
   float var_v_cutoff_1l;
   float var_v_cutoff_1h;
   float var_v_cutoff_2l;
   float var_v_cutoff_2h;
   float var_v_cutoff_3l;
   float var_v_cutoff_3h;
   float var_v_res_1;
   float var_v_res_1h;
   float var_v_res_1h2;
   float var_v_res_2;
   float var_v_res_2h;
   float var_v_res_2h2;
   float var_v_res_3;
   float var_v_res_3h;
   float var_v_res_3h2;
   float var_v_1;
   float var_v_2;
   float var_v_3;

} osc_noise_voice_1_voice_t;

#define loop(X)  for(unsigned int i = 0u; i < (X); i++)
#define clamp(a,b,c) (((a)<(b))?(b):(((a)>(c))?(c):(a)))

static inline float mathLerpf(float _a, float _b, float _t) { return _a + (_b - _a) * _t; }
static inline float mathClampf(float a, float b, float c) { return (((a)<(b))?(b):(((a)>(c))?(c):(a))); }
static inline float mathMinf(float a, float b) { return (a<b)?a:b; }
static inline float mathMaxf(float a, float b) { return (a>b)?a:b; }
static inline float mathAbsMaxf(float _x, float _y) { return ( ( (_x<0.0f)?-_x:_x)>((_y<0.0f)?-_y:_y)?_x:_y ); }
static inline float mathAbsMinf(float _x, float _y) { return ( ((_x<0.0f)?-_x:_x)<((_y<0.0f)?-_y:_y)?_x:_y ); }

static inline float winLinear(const float *_s, float _index) {
   int idx = (int)_index;
   float r = _index - (float)idx;
   return mathLerpf(_s[idx], _s[idx+1], r);
}

static float ffrac_s(float _f) { int i; if(_f >= 0.0f) { i = (int)_f; return _f - (float)i; } else { i = (int)-_f; return 1.0f - (-_f - (float)i); } }

static float mathPowerf(float _x, float _y) {
   float r;
   if(_y != 0.0f)
   {
      if(_x < 0.0f)
      {
         r = (float)( -expf(_y*logf(-_x)) );
      }
      else if(_x > 0.0f)
      {
         r = (float)( expf(_y*logf(_x)) );
      }
      else
      {
         r = 0.0f;
      }
   }
   else
   {
      r = 1.0f;
   }
   return Dstplugin_fix_denorm_32(r);
}

static void loc_prepare(st_plugin_voice_t *_voice);

void loc_prepare(st_plugin_voice_t *_voice) {
   ST_PLUGIN_VOICE_CAST(osc_noise_voice_1_voice_t);
   ST_PLUGIN_VOICE_SHARED_CAST(osc_noise_voice_1_shared_t);

   float out = 0.0f;
   // -------- lane "prepare" modIdx=0
   
   // -- mod="$m_cutoff_1" dstVar=out
   out = voice->mod_cutoff_1_cur;
   
   // -- mod="p2s" dstVar=out
   out  = (mathPowerf(2.0f, out * 7.0f) - 1.0f);
   
   // ---- mod="p2s" input "kbd" seq 1/1
   
   // -- mod="$KBD" dstVar=voice->tmp1_kbd
   voice->tmp1_kbd = 1.0f;
   
   // ---- mod="p2s" input "off" seq 1/1
   
   // -- mod="$m_w_1" dstVar=voice->tmp2_off
   voice->tmp2_off = voice->mod_w_1_cur;
   
   // -- mod="neg" dstVar=voice->tmp2_off
   voice->tmp2_off = -voice->tmp2_off;
   out += (voice->note_cur + (voice->tmp2_off * 12.0f) - 64.0f) * voice->tmp1_kbd;
   #ifdef OVERSAMPLE_FACTOR
   out = ((440.0f/32.0f)*expf( ((out-9.0f)/12.0f)*logf(2.0f) )) / (voice->sample_rate * OVERSAMPLE_FACTOR);
   #else
   out = ((440.0f/32.0f)*expf( ((out-9.0f)/12.0f)*logf(2.0f) )) / voice->sample_rate;
   #endif
   
   // -- mod="clp" dstVar=out
   if(out > 1.0f) out = 1.0f;
   else if(out < 0.02f) out = 0.02f;
   
   // -- mod="0.5" dstVar=out
   voice->tmp3_seq = 0.5f;
   out *= voice->tmp3_seq;
   
   // -- mod="sto v_cutoff_1l" dstVar=out
   voice->var_v_cutoff_1l = out;
   
   // -- mod="$m_cutoff_1" dstVar=out
   out = voice->mod_cutoff_1_cur;
   
   // -- mod="p2s" dstVar=out
   out  = (mathPowerf(2.0f, out * 7.0f) - 1.0f);
   
   // ---- mod="p2s" input "kbd" seq 1/1
   
   // -- mod="$KBD" dstVar=voice->tmp4_kbd
   voice->tmp4_kbd = 1.0f;
   
   // ---- mod="p2s" input "off" seq 1/1
   
   // -- mod="$m_w_1" dstVar=voice->tmp5_off
   voice->tmp5_off = voice->mod_w_1_cur;
   out += (voice->note_cur + (voice->tmp5_off * 12.0f) - 64.0f) * voice->tmp4_kbd;
   #ifdef OVERSAMPLE_FACTOR
   out = ((440.0f/32.0f)*expf( ((out-9.0f)/12.0f)*logf(2.0f) )) / (voice->sample_rate * OVERSAMPLE_FACTOR);
   #else
   out = ((440.0f/32.0f)*expf( ((out-9.0f)/12.0f)*logf(2.0f) )) / voice->sample_rate;
   #endif
   
   // -- mod="clp" dstVar=out
   if(out > 1.0f) out = 1.0f;
   else if(out < 0.02f) out = 0.02f;
   
   // -- mod="0.5" dstVar=out
   voice->tmp6_seq = 0.5f;
   out *= voice->tmp6_seq;
   
   // -- mod="sto v_cutoff_1h" dstVar=out
   voice->var_v_cutoff_1h = out;
   
   // -- mod="1" dstVar=out
   out = 1.0f;
   
   // -- mod="$p_res_1" dstVar=out
   voice->tmp7_seq = shared->params[PARAM_RES_1];
   out -= voice->tmp7_seq;
   
   // -- mod="sto v_res_1" dstVar=out
   voice->var_v_res_1 = out;
   
   // -- mod="0.5" dstVar=out
   voice->tmp8_seq = 0.5f;
   out *= voice->tmp8_seq;
   
   // -- mod="0.5" dstVar=out
   voice->tmp9_seq = 0.5f;
   out += voice->tmp9_seq;
   
   // -- mod="sto v_res_1h" dstVar=out
   voice->var_v_res_1h = out;
   
   // -- mod="0.5" dstVar=out
   voice->tmp10_seq = 0.5f;
   out *= voice->tmp10_seq;
   
   // -- mod="0.5" dstVar=out
   voice->tmp11_seq = 0.5f;
   out += voice->tmp11_seq;
   
   // -- mod="0.5" dstVar=out
   voice->tmp12_seq = 0.5f;
   out *= voice->tmp12_seq;
   
   // -- mod="0.5" dstVar=out
   voice->tmp13_seq = 0.5f;
   out += voice->tmp13_seq;
   
   // -- mod="sto v_res_1h2" dstVar=out
   voice->var_v_res_1h2 = out;
   
   // -- mod="$m_cutoff_2" dstVar=out
   out = voice->mod_cutoff_2_cur;
   
   // -- mod="p2s" dstVar=out
   out  = (mathPowerf(2.0f, out * 7.0f) - 1.0f);
   
   // ---- mod="p2s" input "kbd" seq 1/1
   
   // -- mod="$KBD" dstVar=voice->tmp14_kbd
   voice->tmp14_kbd = 1.0f;
   
   // ---- mod="p2s" input "off" seq 1/1
   
   // -- mod="$m_w_1" dstVar=voice->tmp15_off
   voice->tmp15_off = voice->mod_w_1_cur;
   
   // -- mod="neg" dstVar=voice->tmp15_off
   voice->tmp15_off = -voice->tmp15_off;
   out += (voice->note_cur + (voice->tmp15_off * 12.0f) - 64.0f) * voice->tmp14_kbd;
   #ifdef OVERSAMPLE_FACTOR
   out = ((440.0f/32.0f)*expf( ((out-9.0f)/12.0f)*logf(2.0f) )) / (voice->sample_rate * OVERSAMPLE_FACTOR);
   #else
   out = ((440.0f/32.0f)*expf( ((out-9.0f)/12.0f)*logf(2.0f) )) / voice->sample_rate;
   #endif
   
   // -- mod="clp" dstVar=out
   if(out > 1.0f) out = 1.0f;
   else if(out < 0.02f) out = 0.02f;
   
   // -- mod="0.5" dstVar=out
   voice->tmp16_seq = 0.5f;
   out *= voice->tmp16_seq;
   
   // -- mod="sto v_cutoff_2l" dstVar=out
   voice->var_v_cutoff_2l = out;
   
   // -- mod="$m_cutoff_2" dstVar=out
   out = voice->mod_cutoff_2_cur;
   
   // -- mod="p2s" dstVar=out
   out  = (mathPowerf(2.0f, out * 7.0f) - 1.0f);
   
   // ---- mod="p2s" input "kbd" seq 1/1
   
   // -- mod="$KBD" dstVar=voice->tmp17_kbd
   voice->tmp17_kbd = 1.0f;
   
   // ---- mod="p2s" input "off" seq 1/1
   
   // -- mod="$m_w_1" dstVar=voice->tmp18_off
   voice->tmp18_off = voice->mod_w_1_cur;
   out += (voice->note_cur + (voice->tmp18_off * 12.0f) - 64.0f) * voice->tmp17_kbd;
   #ifdef OVERSAMPLE_FACTOR
   out = ((440.0f/32.0f)*expf( ((out-9.0f)/12.0f)*logf(2.0f) )) / (voice->sample_rate * OVERSAMPLE_FACTOR);
   #else
   out = ((440.0f/32.0f)*expf( ((out-9.0f)/12.0f)*logf(2.0f) )) / voice->sample_rate;
   #endif
   
   // -- mod="clp" dstVar=out
   if(out > 1.0f) out = 1.0f;
   else if(out < 0.02f) out = 0.02f;
   
   // -- mod="0.5" dstVar=out
   voice->tmp19_seq = 0.5f;
   out *= voice->tmp19_seq;
   
   // -- mod="sto v_cutoff_2h" dstVar=out
   voice->var_v_cutoff_2h = out;
   
   // -- mod="1" dstVar=out
   out = 1.0f;
   
   // -- mod="$p_res_2" dstVar=out
   voice->tmp20_seq = shared->params[PARAM_RES_2];
   out -= voice->tmp20_seq;
   
   // -- mod="sto v_res_2" dstVar=out
   voice->var_v_res_2 = out;
   
   // -- mod="0.5" dstVar=out
   voice->tmp21_seq = 0.5f;
   out *= voice->tmp21_seq;
   
   // -- mod="0.5" dstVar=out
   voice->tmp22_seq = 0.5f;
   out += voice->tmp22_seq;
   
   // -- mod="sto v_res_2h" dstVar=out
   voice->var_v_res_2h = out;
   
   // -- mod="0.5" dstVar=out
   voice->tmp23_seq = 0.5f;
   out *= voice->tmp23_seq;
   
   // -- mod="0.5" dstVar=out
   voice->tmp24_seq = 0.5f;
   out += voice->tmp24_seq;
   
   // -- mod="0.5" dstVar=out
   voice->tmp25_seq = 0.5f;
   out *= voice->tmp25_seq;
   
   // -- mod="0.5" dstVar=out
   voice->tmp26_seq = 0.5f;
   out += voice->tmp26_seq;
   
   // -- mod="sto v_res_2h2" dstVar=out
   voice->var_v_res_2h2 = out;
   
   // -- mod="$m_cutoff_3" dstVar=out
   out = voice->mod_cutoff_3_cur;
   
   // -- mod="p2s" dstVar=out
   out  = (mathPowerf(2.0f, out * 7.0f) - 1.0f);
   
   // ---- mod="p2s" input "kbd" seq 1/1
   
   // -- mod="$KBD" dstVar=voice->tmp27_kbd
   voice->tmp27_kbd = 1.0f;
   
   // ---- mod="p2s" input "off" seq 1/1
   
   // -- mod="$m_w_1" dstVar=voice->tmp28_off
   voice->tmp28_off = voice->mod_w_1_cur;
   
   // -- mod="neg" dstVar=voice->tmp28_off
   voice->tmp28_off = -voice->tmp28_off;
   out += (voice->note_cur + (voice->tmp28_off * 12.0f) - 64.0f) * voice->tmp27_kbd;
   #ifdef OVERSAMPLE_FACTOR
   out = ((440.0f/32.0f)*expf( ((out-9.0f)/12.0f)*logf(2.0f) )) / (voice->sample_rate * OVERSAMPLE_FACTOR);
   #else
   out = ((440.0f/32.0f)*expf( ((out-9.0f)/12.0f)*logf(2.0f) )) / voice->sample_rate;
   #endif
   
   // -- mod="clp" dstVar=out
   if(out > 1.0f) out = 1.0f;
   else if(out < 0.02f) out = 0.02f;
   
   // -- mod="0.5" dstVar=out
   voice->tmp29_seq = 0.5f;
   out *= voice->tmp29_seq;
   
   // -- mod="sto v_cutoff_3l" dstVar=out
   voice->var_v_cutoff_3l = out;
   
   // -- mod="$m_cutoff_3" dstVar=out
   out = voice->mod_cutoff_3_cur;
   
   // -- mod="p2s" dstVar=out
   out  = (mathPowerf(2.0f, out * 7.0f) - 1.0f);
   
   // ---- mod="p2s" input "kbd" seq 1/1
   
   // -- mod="$KBD" dstVar=voice->tmp30_kbd
   voice->tmp30_kbd = 1.0f;
   
   // ---- mod="p2s" input "off" seq 1/1
   
   // -- mod="$m_w_1" dstVar=voice->tmp31_off
   voice->tmp31_off = voice->mod_w_1_cur;
   out += (voice->note_cur + (voice->tmp31_off * 12.0f) - 64.0f) * voice->tmp30_kbd;
   #ifdef OVERSAMPLE_FACTOR
   out = ((440.0f/32.0f)*expf( ((out-9.0f)/12.0f)*logf(2.0f) )) / (voice->sample_rate * OVERSAMPLE_FACTOR);
   #else
   out = ((440.0f/32.0f)*expf( ((out-9.0f)/12.0f)*logf(2.0f) )) / voice->sample_rate;
   #endif
   
   // -- mod="clp" dstVar=out
   if(out > 1.0f) out = 1.0f;
   else if(out < 0.02f) out = 0.02f;
   
   // -- mod="0.5" dstVar=out
   voice->tmp32_seq = 0.5f;
   out *= voice->tmp32_seq;
   
   // -- mod="sto v_cutoff_3h" dstVar=out
   voice->var_v_cutoff_3h = out;
   
   // -- mod="1" dstVar=out
   out = 1.0f;
   
   // -- mod="$p_res_3" dstVar=out
   voice->tmp33_seq = shared->params[PARAM_RES_3];
   out -= voice->tmp33_seq;
   
   // -- mod="sto v_res_3" dstVar=out
   voice->var_v_res_3 = out;
   
   // -- mod="0.5" dstVar=out
   voice->tmp34_seq = 0.5f;
   out *= voice->tmp34_seq;
   
   // -- mod="0.5" dstVar=out
   voice->tmp35_seq = 0.5f;
   out += voice->tmp35_seq;
   
   // -- mod="sto v_res_3h" dstVar=out
   voice->var_v_res_3h = out;
   
   // -- mod="0.5" dstVar=out
   voice->tmp36_seq = 0.5f;
   out *= voice->tmp36_seq;
   
   // -- mod="0.5" dstVar=out
   voice->tmp37_seq = 0.5f;
   out += voice->tmp37_seq;
   
   // -- mod="0.5" dstVar=out
   voice->tmp38_seq = 0.5f;
   out *= voice->tmp38_seq;
   
   // -- mod="0.5" dstVar=out
   voice->tmp39_seq = 0.5f;
   out += voice->tmp39_seq;
   
   // -- mod="sto v_res_3h2" dstVar=out
   voice->var_v_res_3h2 = out;
} /* end prepare */

static const char *ST_PLUGIN_API loc_get_param_name(st_plugin_info_t *_info,
                                                    unsigned int      _paramIdx
                                                    ) {
   (void)_info;
   return loc_param_names[_paramIdx];
}

static float ST_PLUGIN_API loc_get_param_reset(st_plugin_info_t *_info,
                                               unsigned int      _paramIdx
                                               ) {
   (void)_info;
   return loc_param_resets[_paramIdx];
}

static float ST_PLUGIN_API loc_get_param_value(st_plugin_shared_t *_shared,
                                               unsigned int        _paramIdx
                                               ) {
   ST_PLUGIN_SHARED_CAST(osc_noise_voice_1_shared_t);
   return shared->params[_paramIdx];
}

static void ST_PLUGIN_API loc_set_param_value(st_plugin_shared_t *_shared,
                                              unsigned int        _paramIdx,
                                              float               _value
                                              ) {
   ST_PLUGIN_SHARED_CAST(osc_noise_voice_1_shared_t);
   shared->params[_paramIdx] = _value;
}

static const char *ST_PLUGIN_API loc_get_mod_name(st_plugin_info_t *_info,
                                                  unsigned int      _modIdx
                                                  ) {
   (void)_info;
   return loc_mod_names[_modIdx];
}

static void ST_PLUGIN_API loc_set_sample_rate(st_plugin_voice_t *_voice,
                                              float              _sampleRate
                                              ) {
   ST_PLUGIN_VOICE_CAST(osc_noise_voice_1_voice_t);
   voice->sample_rate = _sampleRate;
}

static void ST_PLUGIN_API loc_note_on(st_plugin_voice_t  *_voice,
                                      int                 _bGlide,
                                      unsigned char       _note,
                                      float               _vel
                                      ) {
   ST_PLUGIN_VOICE_CAST(osc_noise_voice_1_voice_t);
   ST_PLUGIN_VOICE_SHARED_CAST(osc_noise_voice_1_shared_t);
   (void)_bGlide;
   (void)_note;
   (void)_vel;
   if(!_bGlide)
   {
      memset((void*)voice->mods, 0, sizeof(voice->mods));
#ifdef OVERSAMPLE_FACTOR
      voice->note_speed_fixed = (0.5f / (voice->sample_rate * OVERSAMPLE_FACTOR));
#else
      voice->note_speed_fixed = (0.5f / voice->sample_rate);
#endif // OVERSAMPLE_FACTOR


      voice->tmp42_lfsr_state_signed = 0;
      voice->tmp43_svf_lp = 0.0f;
      voice->tmp44_svf_hp = 0.0f;
      voice->tmp45_svf_bp = 0.0f;
      voice->tmp47_svf_lp = 0.0f;
      voice->tmp48_svf_hp = 0.0f;
      voice->tmp49_svf_bp = 0.0f;
      voice->tmp51_svf_lp = 0.0f;
      voice->tmp52_svf_hp = 0.0f;
      voice->tmp53_svf_bp = 0.0f;
      voice->tmp55_svf_lp = 0.0f;
      voice->tmp56_svf_hp = 0.0f;
      voice->tmp57_svf_bp = 0.0f;
      voice->tmp59_svf_lp = 0.0f;
      voice->tmp60_svf_hp = 0.0f;
      voice->tmp61_svf_bp = 0.0f;
      voice->tmp64_svf_lp = 0.0f;
      voice->tmp65_svf_hp = 0.0f;
      voice->tmp66_svf_bp = 0.0f;
      voice->tmp69_svf_lp = 0.0f;
      voice->tmp70_svf_hp = 0.0f;
      voice->tmp71_svf_bp = 0.0f;
      voice->tmp74_svf_lp = 0.0f;
      voice->tmp75_svf_hp = 0.0f;
      voice->tmp76_svf_bp = 0.0f;
      voice->tmp79_svf_lp = 0.0f;
      voice->tmp80_svf_hp = 0.0f;
      voice->tmp81_svf_bp = 0.0f;
      voice->tmp84_svf_lp = 0.0f;
      voice->tmp85_svf_hp = 0.0f;
      voice->tmp86_svf_bp = 0.0f;
      voice->tmp89_svf_lp = 0.0f;
      voice->tmp90_svf_hp = 0.0f;
      voice->tmp91_svf_bp = 0.0f;
      voice->tmp96_lfsr_state_signed = 0;
      voice->tmp97_svf_lp = 0.0f;
      voice->tmp98_svf_hp = 0.0f;
      voice->tmp99_svf_bp = 0.0f;
      voice->tmp101_svf_lp = 0.0f;
      voice->tmp102_svf_hp = 0.0f;
      voice->tmp103_svf_bp = 0.0f;
      voice->tmp105_svf_lp = 0.0f;
      voice->tmp106_svf_hp = 0.0f;
      voice->tmp107_svf_bp = 0.0f;
      voice->tmp109_svf_lp = 0.0f;
      voice->tmp110_svf_hp = 0.0f;
      voice->tmp111_svf_bp = 0.0f;
      voice->tmp113_svf_lp = 0.0f;
      voice->tmp114_svf_hp = 0.0f;
      voice->tmp115_svf_bp = 0.0f;
      voice->tmp118_svf_lp = 0.0f;
      voice->tmp119_svf_hp = 0.0f;
      voice->tmp120_svf_bp = 0.0f;
      voice->tmp123_svf_lp = 0.0f;
      voice->tmp124_svf_hp = 0.0f;
      voice->tmp125_svf_bp = 0.0f;
      voice->tmp128_svf_lp = 0.0f;
      voice->tmp129_svf_hp = 0.0f;
      voice->tmp130_svf_bp = 0.0f;
      voice->tmp133_svf_lp = 0.0f;
      voice->tmp134_svf_hp = 0.0f;
      voice->tmp135_svf_bp = 0.0f;
      voice->tmp138_svf_lp = 0.0f;
      voice->tmp139_svf_hp = 0.0f;
      voice->tmp140_svf_bp = 0.0f;
      voice->tmp143_svf_lp = 0.0f;
      voice->tmp144_svf_hp = 0.0f;
      voice->tmp145_svf_bp = 0.0f;
      voice->tmp150_lfsr_state_signed = 0;
      voice->tmp151_svf_lp = 0.0f;
      voice->tmp152_svf_hp = 0.0f;
      voice->tmp153_svf_bp = 0.0f;
      voice->tmp155_svf_lp = 0.0f;
      voice->tmp156_svf_hp = 0.0f;
      voice->tmp157_svf_bp = 0.0f;
      voice->tmp159_svf_lp = 0.0f;
      voice->tmp160_svf_hp = 0.0f;
      voice->tmp161_svf_bp = 0.0f;
      voice->tmp163_svf_lp = 0.0f;
      voice->tmp164_svf_hp = 0.0f;
      voice->tmp165_svf_bp = 0.0f;
      voice->tmp167_svf_lp = 0.0f;
      voice->tmp168_svf_hp = 0.0f;
      voice->tmp169_svf_bp = 0.0f;
      voice->tmp172_svf_lp = 0.0f;
      voice->tmp173_svf_hp = 0.0f;
      voice->tmp174_svf_bp = 0.0f;
      voice->tmp177_svf_lp = 0.0f;
      voice->tmp178_svf_hp = 0.0f;
      voice->tmp179_svf_bp = 0.0f;
      voice->tmp182_svf_lp = 0.0f;
      voice->tmp183_svf_hp = 0.0f;
      voice->tmp184_svf_bp = 0.0f;
      voice->tmp187_svf_lp = 0.0f;
      voice->tmp188_svf_hp = 0.0f;
      voice->tmp189_svf_bp = 0.0f;
      voice->tmp192_svf_lp = 0.0f;
      voice->tmp193_svf_hp = 0.0f;
      voice->tmp194_svf_bp = 0.0f;
      voice->tmp197_svf_lp = 0.0f;
      voice->tmp198_svf_hp = 0.0f;
      voice->tmp199_svf_bp = 0.0f;

      voice->var_x = 0.0f;
      voice->var_v_cutoff_1l = 0.0f;
      voice->var_v_cutoff_1h = 0.0f;
      voice->var_v_cutoff_2l = 0.0f;
      voice->var_v_cutoff_2h = 0.0f;
      voice->var_v_cutoff_3l = 0.0f;
      voice->var_v_cutoff_3h = 0.0f;
      voice->var_v_res_1 = 0.0f;
      voice->var_v_res_1h = 0.0f;
      voice->var_v_res_1h2 = 0.0f;
      voice->var_v_res_2 = 0.0f;
      voice->var_v_res_2h = 0.0f;
      voice->var_v_res_2h2 = 0.0f;
      voice->var_v_res_3 = 0.0f;
      voice->var_v_res_3h = 0.0f;
      voice->var_v_res_3h2 = 0.0f;
      voice->var_v_1 = 0.0f;
      voice->var_v_2 = 0.0f;
      voice->var_v_3 = 0.0f;


   }
}

static void ST_PLUGIN_API loc_set_mod_value(st_plugin_voice_t *_voice,
                                            unsigned int       _modIdx,
                                            float              _value,
                                            unsigned           _frameOffset
                                            ) {
   ST_PLUGIN_VOICE_CAST(osc_noise_voice_1_voice_t);
   (void)_frameOffset;
   voice->mods[_modIdx] = _value;
}

static void ST_PLUGIN_API loc_prepare_block(st_plugin_voice_t *_voice,
                                            unsigned int       _numFrames,
                                            float              _freqHz,
                                            float              _note,
                                            float              _vol,
                                            float              _pan
                                            ) {
   ST_PLUGIN_VOICE_CAST(osc_noise_voice_1_voice_t);
   ST_PLUGIN_VOICE_SHARED_CAST(osc_noise_voice_1_shared_t);
   (void)_note;
   (void)_vol;
   (void)_pan;

#ifdef OVERSAMPLE_FACTOR
   float noteSpeed = _freqHz / (voice->sample_rate * OVERSAMPLE_FACTOR);
#else
   float noteSpeed = _freqHz / voice->sample_rate;
#endif // OVERSAMPLE_FACTOR

   float modcutoff_1     = shared->params[PARAM_CUTOFF_1    ]                       + voice->mods[MOD_CUTOFF_1     ];
   float modcutoff_2     = shared->params[PARAM_CUTOFF_2    ]                       + voice->mods[MOD_CUTOFF_2     ];
   float modcutoff_3     = shared->params[PARAM_CUTOFF_3    ]                       + voice->mods[MOD_CUTOFF_3     ];
   float modlevel_1      = voice->mods[MOD_LEVEL_1      ];
   float modlevel_2      = voice->mods[MOD_LEVEL_2      ];
   float modlevel_3      = voice->mods[MOD_LEVEL_3      ];
   float modw_1          = voice->mods[MOD_W_1          ];

   if(_numFrames > 0u)
   {
      // lerp
      float recBlockSize = (1.0f / _numFrames);
      voice->note_speed_inc = (noteSpeed - voice->note_speed_cur) * recBlockSize;
      voice->note_inc       = (_note - voice->note_cur) * recBlockSize;
      voice->mod_cutoff_1_inc     = (modcutoff_1        - voice->mod_cutoff_1_cur      ) * recBlockSize;
      voice->mod_cutoff_2_inc     = (modcutoff_2        - voice->mod_cutoff_2_cur      ) * recBlockSize;
      voice->mod_cutoff_3_inc     = (modcutoff_3        - voice->mod_cutoff_3_cur      ) * recBlockSize;
      voice->mod_level_1_inc      = (modlevel_1         - voice->mod_level_1_cur       ) * recBlockSize;
      voice->mod_level_2_inc      = (modlevel_2         - voice->mod_level_2_cur       ) * recBlockSize;
      voice->mod_level_3_inc      = (modlevel_3         - voice->mod_level_3_cur       ) * recBlockSize;
      voice->mod_w_1_inc          = (modw_1             - voice->mod_w_1_cur           ) * recBlockSize;

      loc_prepare(&voice->base);
   }
   else
   {
      // initial params/modulation (first block, not rendered)
      voice->note_speed_cur = noteSpeed;
      voice->note_speed_inc = 0.0f;
      voice->note_cur       = _note;
      voice->note_inc       = 0.0f;
      voice->mod_cutoff_1_cur     = modcutoff_1;
      voice->mod_cutoff_1_inc     = 0.0f;
      voice->mod_cutoff_2_cur     = modcutoff_2;
      voice->mod_cutoff_2_inc     = 0.0f;
      voice->mod_cutoff_3_cur     = modcutoff_3;
      voice->mod_cutoff_3_inc     = 0.0f;
      voice->mod_level_1_cur      = modlevel_1;
      voice->mod_level_1_inc      = 0.0f;
      voice->mod_level_2_cur      = modlevel_2;
      voice->mod_level_2_inc      = 0.0f;
      voice->mod_level_3_cur      = modlevel_3;
      voice->mod_level_3_inc      = 0.0f;
      voice->mod_w_1_cur          = modw_1;
      voice->mod_w_1_inc          = 0.0f;

      loc_prepare(&voice->base);
   }

   // printf("xxx note_cur=%f\n", voice->note_cur);
}

static void ST_PLUGIN_API loc_process_replace(st_plugin_voice_t  *_voice,
                                              int                 _bMonoIn,
                                              const float        *_samplesIn,
                                              float              *_samplesOut, 
                                              unsigned int        _numFrames
                                              ) {
   (void)_bMonoIn;
   (void)_samplesIn;

   ST_PLUGIN_VOICE_CAST(osc_noise_voice_1_voice_t);
   ST_PLUGIN_VOICE_SHARED_CAST(osc_noise_voice_1_shared_t);

   // Mono output (replicate left to right channel)
   unsigned int j = 0u;
   unsigned int jStep = _bMonoIn ? 1u : 2u;
   unsigned int k = 0u;
   for(unsigned int i = 0u; i < _numFrames; i++)
   {
      float out = _samplesIn[j];
      j += jStep;
#ifdef OVERSAMPLE_FACTOR
      float outOS = 0.0f;
#endif // OVERSAMPLE_FACTOR

#ifdef OVERSAMPLE_FACTOR
      for(unsigned int osi = 0u; osi < OVERSAMPLE_FACTOR; osi++)
#endif // OVERSAMPLE_FACTOR
      {
         float tmp_f;
         float tmp2_f;
         
         // ========
         // ======== lane "out" modIdx=0
         // ========
         
         // -- mod="fsr" dstVar=out
         voice->tmp40_i2f = (int)(out * 2048);  // IntFallback: F2I
         voice->tmp41_lfsr_state ^= voice->tmp41_lfsr_state >> 7;
         voice->tmp41_lfsr_state ^= voice->tmp41_lfsr_state << 9;
         voice->tmp41_lfsr_state ^= voice->tmp41_lfsr_state >> 13;
         voice->tmp42_lfsr_state_signed = (voice->tmp41_lfsr_state & 65520);
         voice->tmp40_i2f = voice->tmp42_lfsr_state_signed >> 4;
         out = voice->tmp40_i2f / ((float)(2048));  // IntFallback: I2F
         
         // -- mod="rep" dstVar=out
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_1h" dstVar=voice->tmp46_freq
         voice->tmp46_freq = voice->var_v_cutoff_1h;
         voice->tmp43_svf_lp = voice->tmp43_svf_lp + (voice->tmp45_svf_bp * voice->tmp46_freq);
         voice->tmp44_svf_hp = out - voice->tmp43_svf_lp - (voice->tmp45_svf_bp * 1.0f);
         voice->tmp45_svf_bp = voice->tmp45_svf_bp + (voice->tmp44_svf_hp * voice->tmp46_freq);
         out = voice->tmp44_svf_hp;
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_1h" dstVar=voice->tmp50_freq
         voice->tmp50_freq = voice->var_v_cutoff_1h;
         voice->tmp47_svf_lp = voice->tmp47_svf_lp + (voice->tmp49_svf_bp * voice->tmp50_freq);
         voice->tmp48_svf_hp = out - voice->tmp47_svf_lp - (voice->tmp49_svf_bp * 1.0f);
         voice->tmp49_svf_bp = voice->tmp49_svf_bp + (voice->tmp48_svf_hp * voice->tmp50_freq);
         out = voice->tmp48_svf_hp;
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_1h" dstVar=voice->tmp54_freq
         voice->tmp54_freq = voice->var_v_cutoff_1h;
         voice->tmp51_svf_lp = voice->tmp51_svf_lp + (voice->tmp53_svf_bp * voice->tmp54_freq);
         voice->tmp52_svf_hp = out - voice->tmp51_svf_lp - (voice->tmp53_svf_bp * 1.0f);
         voice->tmp53_svf_bp = voice->tmp53_svf_bp + (voice->tmp52_svf_hp * voice->tmp54_freq);
         out = voice->tmp52_svf_hp;
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_1h" dstVar=voice->tmp58_freq
         voice->tmp58_freq = voice->var_v_cutoff_1h;
         voice->tmp55_svf_lp = voice->tmp55_svf_lp + (voice->tmp57_svf_bp * voice->tmp58_freq);
         voice->tmp56_svf_hp = out - voice->tmp55_svf_lp - (voice->tmp57_svf_bp * 1.0f);
         voice->tmp57_svf_bp = voice->tmp57_svf_bp + (voice->tmp56_svf_hp * voice->tmp58_freq);
         out = voice->tmp56_svf_hp;
         
         // -- mod="rep" dstVar=out
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "res" seq 1/1
         
         // -- mod="$v_res_1" dstVar=voice->tmp62_res
         voice->tmp62_res = voice->var_v_res_1;
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_1l" dstVar=voice->tmp63_freq
         voice->tmp63_freq = voice->var_v_cutoff_1l;
         voice->tmp59_svf_lp = voice->tmp59_svf_lp + (voice->tmp61_svf_bp * voice->tmp63_freq);
         voice->tmp60_svf_hp = out - voice->tmp59_svf_lp - (voice->tmp61_svf_bp * voice->tmp62_res);
         voice->tmp61_svf_bp = voice->tmp61_svf_bp + (voice->tmp60_svf_hp * voice->tmp63_freq);
         out = voice->tmp59_svf_lp;
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "res" seq 1/1
         
         // -- mod="$v_res_1" dstVar=voice->tmp67_res
         voice->tmp67_res = voice->var_v_res_1;
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_1l" dstVar=voice->tmp68_freq
         voice->tmp68_freq = voice->var_v_cutoff_1l;
         voice->tmp64_svf_lp = voice->tmp64_svf_lp + (voice->tmp66_svf_bp * voice->tmp68_freq);
         voice->tmp65_svf_hp = out - voice->tmp64_svf_lp - (voice->tmp66_svf_bp * voice->tmp67_res);
         voice->tmp66_svf_bp = voice->tmp66_svf_bp + (voice->tmp65_svf_hp * voice->tmp68_freq);
         out = voice->tmp64_svf_lp;
         
         // -- mod="rep" dstVar=out
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "res" seq 1/1
         
         // -- mod="$v_res_1h" dstVar=voice->tmp72_res
         voice->tmp72_res = voice->var_v_res_1h;
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_1l" dstVar=voice->tmp73_freq
         voice->tmp73_freq = voice->var_v_cutoff_1l;
         voice->tmp69_svf_lp = voice->tmp69_svf_lp + (voice->tmp71_svf_bp * voice->tmp73_freq);
         voice->tmp70_svf_hp = out - voice->tmp69_svf_lp - (voice->tmp71_svf_bp * voice->tmp72_res);
         voice->tmp71_svf_bp = voice->tmp71_svf_bp + (voice->tmp70_svf_hp * voice->tmp73_freq);
         out = voice->tmp69_svf_lp;
         
         // -- mod="rep" dstVar=out
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "res" seq 1/1
         
         // -- mod="$v_res_1h2" dstVar=voice->tmp77_res
         voice->tmp77_res = voice->var_v_res_1h2;
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_1l" dstVar=voice->tmp78_freq
         voice->tmp78_freq = voice->var_v_cutoff_1l;
         voice->tmp74_svf_lp = voice->tmp74_svf_lp + (voice->tmp76_svf_bp * voice->tmp78_freq);
         voice->tmp75_svf_hp = out - voice->tmp74_svf_lp - (voice->tmp76_svf_bp * voice->tmp77_res);
         voice->tmp76_svf_bp = voice->tmp76_svf_bp + (voice->tmp75_svf_hp * voice->tmp78_freq);
         out = voice->tmp74_svf_lp;
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "res" seq 1/1
         
         // -- mod="$v_res_1h2" dstVar=voice->tmp82_res
         voice->tmp82_res = voice->var_v_res_1h2;
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_1l" dstVar=voice->tmp83_freq
         voice->tmp83_freq = voice->var_v_cutoff_1l;
         voice->tmp79_svf_lp = voice->tmp79_svf_lp + (voice->tmp81_svf_bp * voice->tmp83_freq);
         voice->tmp80_svf_hp = out - voice->tmp79_svf_lp - (voice->tmp81_svf_bp * voice->tmp82_res);
         voice->tmp81_svf_bp = voice->tmp81_svf_bp + (voice->tmp80_svf_hp * voice->tmp83_freq);
         out = voice->tmp79_svf_lp;
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "res" seq 1/1
         
         // -- mod="$v_res_1h2" dstVar=voice->tmp87_res
         voice->tmp87_res = voice->var_v_res_1h2;
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_1l" dstVar=voice->tmp88_freq
         voice->tmp88_freq = voice->var_v_cutoff_1l;
         voice->tmp84_svf_lp = voice->tmp84_svf_lp + (voice->tmp86_svf_bp * voice->tmp88_freq);
         voice->tmp85_svf_hp = out - voice->tmp84_svf_lp - (voice->tmp86_svf_bp * voice->tmp87_res);
         voice->tmp86_svf_bp = voice->tmp86_svf_bp + (voice->tmp85_svf_hp * voice->tmp88_freq);
         out = voice->tmp84_svf_lp;
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "res" seq 1/1
         
         // -- mod="$v_res_1h2" dstVar=voice->tmp92_res
         voice->tmp92_res = voice->var_v_res_1h2;
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_1l" dstVar=voice->tmp93_freq
         voice->tmp93_freq = voice->var_v_cutoff_1l;
         voice->tmp89_svf_lp = voice->tmp89_svf_lp + (voice->tmp91_svf_bp * voice->tmp93_freq);
         voice->tmp90_svf_hp = out - voice->tmp89_svf_lp - (voice->tmp91_svf_bp * voice->tmp92_res);
         voice->tmp91_svf_bp = voice->tmp91_svf_bp + (voice->tmp90_svf_hp * voice->tmp93_freq);
         out = voice->tmp89_svf_lp;
         
         // -- mod="sto v_1" dstVar=out
         voice->var_v_1 = out;
         
         // -- mod="fsr" dstVar=out
         voice->tmp94_i2f = (int)(out * 2048);  // IntFallback: F2I
         voice->tmp95_lfsr_state ^= voice->tmp95_lfsr_state >> 7;
         voice->tmp95_lfsr_state ^= voice->tmp95_lfsr_state << 9;
         voice->tmp95_lfsr_state ^= voice->tmp95_lfsr_state >> 13;
         voice->tmp96_lfsr_state_signed = (voice->tmp95_lfsr_state & 65520);
         voice->tmp94_i2f = voice->tmp96_lfsr_state_signed >> 4;
         out = voice->tmp94_i2f / ((float)(2048));  // IntFallback: I2F
         
         // -- mod="rep" dstVar=out
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_2h" dstVar=voice->tmp100_freq
         voice->tmp100_freq = voice->var_v_cutoff_2h;
         voice->tmp97_svf_lp = voice->tmp97_svf_lp + (voice->tmp99_svf_bp * voice->tmp100_freq);
         voice->tmp98_svf_hp = out - voice->tmp97_svf_lp - (voice->tmp99_svf_bp * 1.0f);
         voice->tmp99_svf_bp = voice->tmp99_svf_bp + (voice->tmp98_svf_hp * voice->tmp100_freq);
         out = voice->tmp98_svf_hp;
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_2h" dstVar=voice->tmp104_freq
         voice->tmp104_freq = voice->var_v_cutoff_2h;
         voice->tmp101_svf_lp = voice->tmp101_svf_lp + (voice->tmp103_svf_bp * voice->tmp104_freq);
         voice->tmp102_svf_hp = out - voice->tmp101_svf_lp - (voice->tmp103_svf_bp * 1.0f);
         voice->tmp103_svf_bp = voice->tmp103_svf_bp + (voice->tmp102_svf_hp * voice->tmp104_freq);
         out = voice->tmp102_svf_hp;
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_2h" dstVar=voice->tmp108_freq
         voice->tmp108_freq = voice->var_v_cutoff_2h;
         voice->tmp105_svf_lp = voice->tmp105_svf_lp + (voice->tmp107_svf_bp * voice->tmp108_freq);
         voice->tmp106_svf_hp = out - voice->tmp105_svf_lp - (voice->tmp107_svf_bp * 1.0f);
         voice->tmp107_svf_bp = voice->tmp107_svf_bp + (voice->tmp106_svf_hp * voice->tmp108_freq);
         out = voice->tmp106_svf_hp;
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_2h" dstVar=voice->tmp112_freq
         voice->tmp112_freq = voice->var_v_cutoff_2h;
         voice->tmp109_svf_lp = voice->tmp109_svf_lp + (voice->tmp111_svf_bp * voice->tmp112_freq);
         voice->tmp110_svf_hp = out - voice->tmp109_svf_lp - (voice->tmp111_svf_bp * 1.0f);
         voice->tmp111_svf_bp = voice->tmp111_svf_bp + (voice->tmp110_svf_hp * voice->tmp112_freq);
         out = voice->tmp110_svf_hp;
         
         // -- mod="rep" dstVar=out
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "res" seq 1/1
         
         // -- mod="$v_res_2" dstVar=voice->tmp116_res
         voice->tmp116_res = voice->var_v_res_2;
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_2l" dstVar=voice->tmp117_freq
         voice->tmp117_freq = voice->var_v_cutoff_2l;
         voice->tmp113_svf_lp = voice->tmp113_svf_lp + (voice->tmp115_svf_bp * voice->tmp117_freq);
         voice->tmp114_svf_hp = out - voice->tmp113_svf_lp - (voice->tmp115_svf_bp * voice->tmp116_res);
         voice->tmp115_svf_bp = voice->tmp115_svf_bp + (voice->tmp114_svf_hp * voice->tmp117_freq);
         out = voice->tmp113_svf_lp;
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "res" seq 1/1
         
         // -- mod="$v_res_2" dstVar=voice->tmp121_res
         voice->tmp121_res = voice->var_v_res_2;
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_2l" dstVar=voice->tmp122_freq
         voice->tmp122_freq = voice->var_v_cutoff_2l;
         voice->tmp118_svf_lp = voice->tmp118_svf_lp + (voice->tmp120_svf_bp * voice->tmp122_freq);
         voice->tmp119_svf_hp = out - voice->tmp118_svf_lp - (voice->tmp120_svf_bp * voice->tmp121_res);
         voice->tmp120_svf_bp = voice->tmp120_svf_bp + (voice->tmp119_svf_hp * voice->tmp122_freq);
         out = voice->tmp118_svf_lp;
         
         // -- mod="rep" dstVar=out
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "res" seq 1/1
         
         // -- mod="$v_res_2h" dstVar=voice->tmp126_res
         voice->tmp126_res = voice->var_v_res_2h;
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_2l" dstVar=voice->tmp127_freq
         voice->tmp127_freq = voice->var_v_cutoff_2l;
         voice->tmp123_svf_lp = voice->tmp123_svf_lp + (voice->tmp125_svf_bp * voice->tmp127_freq);
         voice->tmp124_svf_hp = out - voice->tmp123_svf_lp - (voice->tmp125_svf_bp * voice->tmp126_res);
         voice->tmp125_svf_bp = voice->tmp125_svf_bp + (voice->tmp124_svf_hp * voice->tmp127_freq);
         out = voice->tmp123_svf_lp;
         
         // -- mod="rep" dstVar=out
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "res" seq 1/1
         
         // -- mod="$v_res_2h2" dstVar=voice->tmp131_res
         voice->tmp131_res = voice->var_v_res_2h2;
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_2l" dstVar=voice->tmp132_freq
         voice->tmp132_freq = voice->var_v_cutoff_2l;
         voice->tmp128_svf_lp = voice->tmp128_svf_lp + (voice->tmp130_svf_bp * voice->tmp132_freq);
         voice->tmp129_svf_hp = out - voice->tmp128_svf_lp - (voice->tmp130_svf_bp * voice->tmp131_res);
         voice->tmp130_svf_bp = voice->tmp130_svf_bp + (voice->tmp129_svf_hp * voice->tmp132_freq);
         out = voice->tmp128_svf_lp;
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "res" seq 1/1
         
         // -- mod="$v_res_2h2" dstVar=voice->tmp136_res
         voice->tmp136_res = voice->var_v_res_2h2;
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_2l" dstVar=voice->tmp137_freq
         voice->tmp137_freq = voice->var_v_cutoff_2l;
         voice->tmp133_svf_lp = voice->tmp133_svf_lp + (voice->tmp135_svf_bp * voice->tmp137_freq);
         voice->tmp134_svf_hp = out - voice->tmp133_svf_lp - (voice->tmp135_svf_bp * voice->tmp136_res);
         voice->tmp135_svf_bp = voice->tmp135_svf_bp + (voice->tmp134_svf_hp * voice->tmp137_freq);
         out = voice->tmp133_svf_lp;
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "res" seq 1/1
         
         // -- mod="$v_res_2h2" dstVar=voice->tmp141_res
         voice->tmp141_res = voice->var_v_res_2h2;
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_2l" dstVar=voice->tmp142_freq
         voice->tmp142_freq = voice->var_v_cutoff_2l;
         voice->tmp138_svf_lp = voice->tmp138_svf_lp + (voice->tmp140_svf_bp * voice->tmp142_freq);
         voice->tmp139_svf_hp = out - voice->tmp138_svf_lp - (voice->tmp140_svf_bp * voice->tmp141_res);
         voice->tmp140_svf_bp = voice->tmp140_svf_bp + (voice->tmp139_svf_hp * voice->tmp142_freq);
         out = voice->tmp138_svf_lp;
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "res" seq 1/1
         
         // -- mod="$v_res_2h2" dstVar=voice->tmp146_res
         voice->tmp146_res = voice->var_v_res_2h2;
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_2l" dstVar=voice->tmp147_freq
         voice->tmp147_freq = voice->var_v_cutoff_2l;
         voice->tmp143_svf_lp = voice->tmp143_svf_lp + (voice->tmp145_svf_bp * voice->tmp147_freq);
         voice->tmp144_svf_hp = out - voice->tmp143_svf_lp - (voice->tmp145_svf_bp * voice->tmp146_res);
         voice->tmp145_svf_bp = voice->tmp145_svf_bp + (voice->tmp144_svf_hp * voice->tmp147_freq);
         out = voice->tmp143_svf_lp;
         
         // -- mod="sto v_2" dstVar=out
         voice->var_v_2 = out;
         
         // -- mod="fsr" dstVar=out
         voice->tmp148_i2f = (int)(out * 2048);  // IntFallback: F2I
         voice->tmp149_lfsr_state ^= voice->tmp149_lfsr_state >> 7;
         voice->tmp149_lfsr_state ^= voice->tmp149_lfsr_state << 9;
         voice->tmp149_lfsr_state ^= voice->tmp149_lfsr_state >> 13;
         voice->tmp150_lfsr_state_signed = (voice->tmp149_lfsr_state & 65520);
         voice->tmp148_i2f = voice->tmp150_lfsr_state_signed >> 4;
         out = voice->tmp148_i2f / ((float)(2048));  // IntFallback: I2F
         
         // -- mod="rep" dstVar=out
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_3h" dstVar=voice->tmp154_freq
         voice->tmp154_freq = voice->var_v_cutoff_3h;
         voice->tmp151_svf_lp = voice->tmp151_svf_lp + (voice->tmp153_svf_bp * voice->tmp154_freq);
         voice->tmp152_svf_hp = out - voice->tmp151_svf_lp - (voice->tmp153_svf_bp * 1.0f);
         voice->tmp153_svf_bp = voice->tmp153_svf_bp + (voice->tmp152_svf_hp * voice->tmp154_freq);
         out = voice->tmp152_svf_hp;
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_3h" dstVar=voice->tmp158_freq
         voice->tmp158_freq = voice->var_v_cutoff_3h;
         voice->tmp155_svf_lp = voice->tmp155_svf_lp + (voice->tmp157_svf_bp * voice->tmp158_freq);
         voice->tmp156_svf_hp = out - voice->tmp155_svf_lp - (voice->tmp157_svf_bp * 1.0f);
         voice->tmp157_svf_bp = voice->tmp157_svf_bp + (voice->tmp156_svf_hp * voice->tmp158_freq);
         out = voice->tmp156_svf_hp;
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_3h" dstVar=voice->tmp162_freq
         voice->tmp162_freq = voice->var_v_cutoff_3h;
         voice->tmp159_svf_lp = voice->tmp159_svf_lp + (voice->tmp161_svf_bp * voice->tmp162_freq);
         voice->tmp160_svf_hp = out - voice->tmp159_svf_lp - (voice->tmp161_svf_bp * 1.0f);
         voice->tmp161_svf_bp = voice->tmp161_svf_bp + (voice->tmp160_svf_hp * voice->tmp162_freq);
         out = voice->tmp160_svf_hp;
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_3h" dstVar=voice->tmp166_freq
         voice->tmp166_freq = voice->var_v_cutoff_3h;
         voice->tmp163_svf_lp = voice->tmp163_svf_lp + (voice->tmp165_svf_bp * voice->tmp166_freq);
         voice->tmp164_svf_hp = out - voice->tmp163_svf_lp - (voice->tmp165_svf_bp * 1.0f);
         voice->tmp165_svf_bp = voice->tmp165_svf_bp + (voice->tmp164_svf_hp * voice->tmp166_freq);
         out = voice->tmp164_svf_hp;
         
         // -- mod="rep" dstVar=out
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "res" seq 1/1
         
         // -- mod="$v_res_3" dstVar=voice->tmp170_res
         voice->tmp170_res = voice->var_v_res_3;
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_3l" dstVar=voice->tmp171_freq
         voice->tmp171_freq = voice->var_v_cutoff_3l;
         voice->tmp167_svf_lp = voice->tmp167_svf_lp + (voice->tmp169_svf_bp * voice->tmp171_freq);
         voice->tmp168_svf_hp = out - voice->tmp167_svf_lp - (voice->tmp169_svf_bp * voice->tmp170_res);
         voice->tmp169_svf_bp = voice->tmp169_svf_bp + (voice->tmp168_svf_hp * voice->tmp171_freq);
         out = voice->tmp167_svf_lp;
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "res" seq 1/1
         
         // -- mod="$v_res_3" dstVar=voice->tmp175_res
         voice->tmp175_res = voice->var_v_res_3;
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_3l" dstVar=voice->tmp176_freq
         voice->tmp176_freq = voice->var_v_cutoff_3l;
         voice->tmp172_svf_lp = voice->tmp172_svf_lp + (voice->tmp174_svf_bp * voice->tmp176_freq);
         voice->tmp173_svf_hp = out - voice->tmp172_svf_lp - (voice->tmp174_svf_bp * voice->tmp175_res);
         voice->tmp174_svf_bp = voice->tmp174_svf_bp + (voice->tmp173_svf_hp * voice->tmp176_freq);
         out = voice->tmp172_svf_lp;
         
         // -- mod="rep" dstVar=out
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "res" seq 1/1
         
         // -- mod="$v_res_3h" dstVar=voice->tmp180_res
         voice->tmp180_res = voice->var_v_res_3h;
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_3l" dstVar=voice->tmp181_freq
         voice->tmp181_freq = voice->var_v_cutoff_3l;
         voice->tmp177_svf_lp = voice->tmp177_svf_lp + (voice->tmp179_svf_bp * voice->tmp181_freq);
         voice->tmp178_svf_hp = out - voice->tmp177_svf_lp - (voice->tmp179_svf_bp * voice->tmp180_res);
         voice->tmp179_svf_bp = voice->tmp179_svf_bp + (voice->tmp178_svf_hp * voice->tmp181_freq);
         out = voice->tmp177_svf_lp;
         
         // -- mod="rep" dstVar=out
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "res" seq 1/1
         
         // -- mod="$v_res_3h2" dstVar=voice->tmp185_res
         voice->tmp185_res = voice->var_v_res_3h2;
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_3l" dstVar=voice->tmp186_freq
         voice->tmp186_freq = voice->var_v_cutoff_3l;
         voice->tmp182_svf_lp = voice->tmp182_svf_lp + (voice->tmp184_svf_bp * voice->tmp186_freq);
         voice->tmp183_svf_hp = out - voice->tmp182_svf_lp - (voice->tmp184_svf_bp * voice->tmp185_res);
         voice->tmp184_svf_bp = voice->tmp184_svf_bp + (voice->tmp183_svf_hp * voice->tmp186_freq);
         out = voice->tmp182_svf_lp;
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "res" seq 1/1
         
         // -- mod="$v_res_3h2" dstVar=voice->tmp190_res
         voice->tmp190_res = voice->var_v_res_3h2;
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_3l" dstVar=voice->tmp191_freq
         voice->tmp191_freq = voice->var_v_cutoff_3l;
         voice->tmp187_svf_lp = voice->tmp187_svf_lp + (voice->tmp189_svf_bp * voice->tmp191_freq);
         voice->tmp188_svf_hp = out - voice->tmp187_svf_lp - (voice->tmp189_svf_bp * voice->tmp190_res);
         voice->tmp189_svf_bp = voice->tmp189_svf_bp + (voice->tmp188_svf_hp * voice->tmp191_freq);
         out = voice->tmp187_svf_lp;
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "res" seq 1/1
         
         // -- mod="$v_res_3h2" dstVar=voice->tmp195_res
         voice->tmp195_res = voice->var_v_res_3h2;
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_3l" dstVar=voice->tmp196_freq
         voice->tmp196_freq = voice->var_v_cutoff_3l;
         voice->tmp192_svf_lp = voice->tmp192_svf_lp + (voice->tmp194_svf_bp * voice->tmp196_freq);
         voice->tmp193_svf_hp = out - voice->tmp192_svf_lp - (voice->tmp194_svf_bp * voice->tmp195_res);
         voice->tmp194_svf_bp = voice->tmp194_svf_bp + (voice->tmp193_svf_hp * voice->tmp196_freq);
         out = voice->tmp192_svf_lp;
         
         // -- mod="svf" dstVar=out
         
         // ---- mod="svf" input "res" seq 1/1
         
         // -- mod="$v_res_3h2" dstVar=voice->tmp200_res
         voice->tmp200_res = voice->var_v_res_3h2;
         
         // ---- mod="svf" input "freq" seq 1/1
         
         // -- mod="$v_cutoff_3l" dstVar=voice->tmp201_freq
         voice->tmp201_freq = voice->var_v_cutoff_3l;
         voice->tmp197_svf_lp = voice->tmp197_svf_lp + (voice->tmp199_svf_bp * voice->tmp201_freq);
         voice->tmp198_svf_hp = out - voice->tmp197_svf_lp - (voice->tmp199_svf_bp * voice->tmp200_res);
         voice->tmp199_svf_bp = voice->tmp199_svf_bp + (voice->tmp198_svf_hp * voice->tmp201_freq);
         out = voice->tmp197_svf_lp;
         
         // -- mod="sto v_3" dstVar=out
         voice->var_v_3 = out;
         
         // -- mod="$v_1" dstVar=out
         out = voice->var_v_1;
         
         // -- mod="$m_level_1" dstVar=out
         voice->tmp202_seq = voice->mod_level_1_cur;
         out *= voice->tmp202_seq;
         
         // -- mod="$v_2" dstVar=out
         voice->tmp203_seq = voice->var_v_2;
         
         // -- mod="$m_level_2" dstVar=voice->tmp203_seq
         voice->tmp204_seq = voice->mod_level_2_cur;
         voice->tmp203_seq *= voice->tmp204_seq;
         out += voice->tmp203_seq;
         
         // -- mod="$v_3" dstVar=out
         voice->tmp205_seq = voice->var_v_3;
         
         // -- mod="$m_level_3" dstVar=voice->tmp205_seq
         voice->tmp206_seq = voice->mod_level_3_cur;
         voice->tmp205_seq *= voice->tmp206_seq;
         out += voice->tmp205_seq;
   
         /* end calc */

#ifdef OVERSAMPLE_FACTOR
         outOS += out;
#endif // OVERSAMPLE_FACTOR
      }
#ifdef OVERSAMPLE_FACTOR
      // Apply lowpass filter before downsampling
      //   (note) normalized Fc = F/Fs = 0.442947 / sqrt(oversample_factorČ - 1)
      out = outOS * (1.0f / OVERSAMPLE_FACTOR);
#endif // OVERSAMPLE_FACTOR
      _samplesOut[k]      = out;
      _samplesOut[k + 1u] = out;

      // Next frame
      k += 2u;
      voice->note_speed_cur += voice->note_speed_inc;
      voice->mod_cutoff_1_cur      += voice->mod_cutoff_1_inc;
      voice->mod_cutoff_2_cur      += voice->mod_cutoff_2_inc;
      voice->mod_cutoff_3_cur      += voice->mod_cutoff_3_inc;
      voice->mod_level_1_cur       += voice->mod_level_1_inc;
      voice->mod_level_2_cur       += voice->mod_level_2_inc;
      voice->mod_level_3_cur       += voice->mod_level_3_inc;
      voice->mod_w_1_cur           += voice->mod_w_1_inc;
   } /* loop numFrames */
}

static st_plugin_shared_t *ST_PLUGIN_API loc_shared_new(st_plugin_info_t *_info) {
   osc_noise_voice_1_shared_t *ret = (osc_noise_voice_1_shared_t *)malloc(sizeof(osc_noise_voice_1_shared_t));
   if(NULL != ret)
   {
      memset((void*)ret, 0, sizeof(*ret));
      ret->base.info  = _info;
      memcpy((void*)ret->params, (void*)loc_param_resets, NUM_PARAMS * sizeof(float));
   }
   return &ret->base;
}

static void ST_PLUGIN_API loc_shared_delete(st_plugin_shared_t *_shared) {
   free((void*)_shared);
}

static st_plugin_voice_t *ST_PLUGIN_API loc_voice_new(st_plugin_info_t *_info, unsigned int _voiceIdx) {
   osc_noise_voice_1_voice_t *voice = (osc_noise_voice_1_voice_t *)malloc(sizeof(osc_noise_voice_1_voice_t));
   if(NULL != voice)
   {
      memset((void*)voice, 0, sizeof(*voice));
      voice->base.info = _info;
      voice->tmp41_lfsr_state = 17545;
      voice->tmp95_lfsr_state = 56265;
      voice->tmp149_lfsr_state = 52693;
   }
   return &voice->base;
}

static void ST_PLUGIN_API loc_voice_delete(st_plugin_voice_t *_voice) {
   ST_PLUGIN_VOICE_CAST(osc_noise_voice_1_voice_t);

   free((void*)_voice);
}

static void ST_PLUGIN_API loc_plugin_exit(st_plugin_info_t *_info) {
   free((void*)_info);
}

#ifdef USE_CYCLE_SINE_TBL
static void loc_calc_sine_tbl(void) {
#define QCOS_BITS 16
#define QCOS_ONE  (1 << QCOS_BITS)
#define QCOS_MASK (QCOS_ONE - 1)
   // (note) same as in TSR "C" implementation
   float *qcos = cycle_sine_tbl_f + 4096; // quarter cos tbl

   // calc quarter cos tbl
   int k = 0;
   for(int a = 0; a < (QCOS_ONE/4); a += (QCOS_ONE/16384)/*4*/)  // 4096 elements
   {
      int x = a - ((int)(QCOS_ONE * 0.25 + 0.5)) + ((a + ((int)(QCOS_ONE * 0.25 + 0.5)))&~QCOS_MASK);
      x = ((x * ((x<0?-x:x) - ((int)(QCOS_ONE * 0.5 + 0.5)))) >> QCOS_BITS) << 4;
      x += (((((int)(QCOS_ONE * 0.225 + 0.5)) * x) >> QCOS_BITS) * ((x<0?-x:x) - QCOS_ONE)) >> QCOS_BITS;
      qcos[k++] = x / float(QCOS_ONE);
   }

   // 0°..90° (rev qtbl)
   int j = 4096;
   k = 0;
   loop(4096)
      cycle_sine_tbl_f[k++] = qcos[--j];

   // 90..180° = cos tbl
   k += 4096;

   // 180°..360° (y-flip first half of tbl)
   j = 0;
   loop(8192)
      cycle_sine_tbl_f[k++] = -cycle_sine_tbl_f[j++];

#ifdef USE_CYCLE_SINE_TBL_I
   loop(16384)
      cycle_sine_tbl_i[i] = (short)(cycle_sine_tbl_f[i] * 2048.0f/*FX_ONE*/);
#endif // USE_CYCLE_SINE_TBL_I
}
#endif // USE_CYCLE_SINE_TBL

extern "C" {
st_plugin_info_t *osc_noise_voice_1_init(void) {
   osc_noise_voice_1_info_t *ret = (osc_noise_voice_1_info_t *)malloc(sizeof(osc_noise_voice_1_info_t));

   if(NULL != ret)
   {
      memset(ret, 0, sizeof(*ret));

      ret->base.api_version = ST_PLUGIN_API_VERSION;
      ret->base.id          = "osc_noise_voice_1";  // unique id. don't change this in future builds.
      ret->base.author      = "bsp";
      ret->base.name        = "noise voice osc 1";
      ret->base.short_name  = "noise voice osc 1";
      ret->base.flags       = ST_PLUGIN_FLAG_OSC;
      ret->base.category    = ST_PLUGIN_CAT_UNKNOWN;
      ret->base.num_params  = NUM_PARAMS;
      ret->base.num_mods    = NUM_MODS;

      ret->base.shared_new       = &loc_shared_new;
      ret->base.shared_delete    = &loc_shared_delete;
      ret->base.voice_new        = &loc_voice_new;
      ret->base.voice_delete     = &loc_voice_delete;
      ret->base.get_param_name   = &loc_get_param_name;
      ret->base.get_param_reset  = &loc_get_param_reset;
      ret->base.get_param_value  = &loc_get_param_value;
      ret->base.set_param_value  = &loc_set_param_value;
      ret->base.get_mod_name     = &loc_get_mod_name;
      ret->base.set_sample_rate  = &loc_set_sample_rate;
      ret->base.note_on          = &loc_note_on;
      ret->base.set_mod_value    = &loc_set_mod_value;
      ret->base.prepare_block    = &loc_prepare_block;
      ret->base.process_replace  = &loc_process_replace;
      ret->base.plugin_exit      = &loc_plugin_exit;

#ifdef USE_CYCLE_SINE_TBL
      loc_calc_sine_tbl();
#endif // USE_CYCLE_SINE_TBL
   }

   return &ret->base;
}

#ifndef STFX_SKIP_MAIN_INIT
ST_PLUGIN_APICALL st_plugin_info_t *ST_PLUGIN_API st_plugin_init(unsigned int _pluginIdx) {
   switch(_pluginIdx)
   {
      case 0u:
         return osc_noise_voice_1_init();
   }
   return NULL;
}
#endif // STFX_SKIP_MAIN_INIT

} // extern "C"
