//  sample_rate: 16574
//   oversample: 4
//    note_freq: 130.815
//      #frames: 9088


float var_x = 0;
float var_wt_x = 0;
float var_wt_y = 0;
float var_wt_freq = 0;

float tmp_f;
float tmp2_f;
Short tmp_i;
Short tmp2_i;

function ffrac_s(float _f) { return (_f >= 0.0f) ? frac(_f) : (1.0f + frac(_f)); }

function loc_bipolar_to_scale(float _t, float _div, float _mul) {
   // t (-1..1) => /_div .. *_mul
   
   float s;

   if(_t < 0.0f)
   {
      s = (1.0f / _div);
      s = 1.0f + (s - 1.0f) * -_t;
      if(s < 0.0f)
         s = 0.0f;
   }
   else
   {
      s = _mul;
      s = 1.0f + (s - 1.0f) * _t;
   }
   
   return s;
}
Envelope *curve_0;
Envelope *curve_1;
Envelope *curve_2;
Envelope *curve_3;
FloatArray vpl_iobuf;  // interleaved l/r frame
StPluginVoice *vpl_voice_0;
float tmp5_rmp_step;
float tmp11_rmp_step;
float tmp17_rmp_step;
float tmp24_rmp_step;



function Calc(FloatArray _d) {
   vpl_voice_0.noteOn(false/*bGlide*/, 60/*note*/, 1.0/*vel*/);
   float tmp1_sin_phase = 0.0f;
   float tmp2_sin_speed;
   float tmp4_rmp_cur = 0.0f;
   // start=0 end=0.93 #frames=36352:
   float tmp10_rmp_cur = 0.0f;
   // start=0 end=0.93 #frames=36352:
   float tmp13_pul_phase = 0.0f;
   float tmp14_pul_speed;
   float tmp16_rmp_cur = 0.0f;
   // start=0 end=0.93 #frames=36352:
   float tmp21_flt_last = 0.0f;
   float tmp23_rmp_cur = 0.0f;
   // start=0 end=0.93 #frames=36352:
   tmp5_rmp_step = 2.55832e-05f;
   tmp11_rmp_step = 2.55832e-05f;
   tmp17_rmp_step = 2.55832e-05f;
   tmp24_rmp_step = 2.55832e-05f;
   int smpIdx = 0;
   int outIdx = 0;
   loop(36352)
   {
      float out = 0.0f;
      
      // ========
      // ======== lane "out" modIdx=0
      // ========
      
      // -- mod="sin" dstVar=out
      float tmp3_freq;
      
      // ---- mod="sin" input "freq" seq 1/1
      
      // -- mod="rmp" dstVar=tmp3_freq
      tmp3_freq = tmp4_rmp_cur;
      tmp4_rmp_cur = mathMinf(tmp4_rmp_cur+tmp5_rmp_step, 0.93);
      
      // -- mod="lut" dstVar=tmp3_freq
      tmp3_freq = curve_1.valueAtTime(tmp3_freq);
      
      // -- mod="$SIN_RATE_SCL" dstVar=tmp3_freq
      float tmp6_seq;
      tmp6_seq = 0.232602f;
      tmp3_freq *= tmp6_seq;
      
      // -- mod="$SIN_RATE_OFF" dstVar=tmp3_freq
      float tmp7_seq;
      tmp7_seq = 0.511008f;
      tmp3_freq += tmp7_seq;
      tmp2_sin_speed = 0.0019732f * tmp3_freq;
      float tmp8_sin_tmp;
      tmp8_sin_tmp = (tmp1_sin_phase);
      tmp8_sin_tmp = ffrac_s(tmp8_sin_tmp);
      out = sin(2PI * tmp8_sin_tmp);
      tmp1_sin_phase = ffrac_s(tmp1_sin_phase + tmp2_sin_speed);
      
      // -- mod="rmp" dstVar=out
      float tmp9_seq;
      tmp9_seq = tmp10_rmp_cur;
      tmp10_rmp_cur = mathMinf(tmp10_rmp_cur+tmp11_rmp_step, 0.93);
      
      // -- mod="lut" dstVar=tmp9_seq
      tmp9_seq = curve_0.valueAtTime(tmp9_seq);
      out *= tmp9_seq;
      
      // -- mod="pul" dstVar=out
      float tmp12_seq;
      float tmp15_freq;
      
      // ---- mod="pul" input "freq" seq 1/1
      
      // -- mod="rmp" dstVar=tmp15_freq
      tmp15_freq = tmp16_rmp_cur;
      tmp16_rmp_cur = mathMinf(tmp16_rmp_cur+tmp17_rmp_step, 0.93);
      
      // -- mod="lut" dstVar=tmp15_freq
      tmp15_freq = curve_3.valueAtTime(tmp15_freq);
      
      // -- mod="$CLICK_RATE_SCL" dstVar=tmp15_freq
      float tmp18_seq;
      tmp18_seq = 0.28928f;
      tmp15_freq *= tmp18_seq;
      
      // -- mod="$CLICK_RATE_OFF" dstVar=tmp15_freq
      float tmp19_seq;
      tmp19_seq = 0.55625f;
      tmp15_freq += tmp19_seq;
      tmp14_pul_speed = 0.0019732f * tmp15_freq;
      float tmp20_pul_tmp;
      tmp20_pul_tmp = (tmp13_pul_phase);
      tmp20_pul_tmp = ffrac_s(tmp20_pul_tmp);
      tmp12_seq = (tmp20_pul_tmp >= 0.5) ? 1.0f : -1.0f;
      tmp13_pul_phase = ffrac_s(tmp13_pul_phase + tmp14_pul_speed);
      
      // -- mod="flt" dstVar=tmp12_seq
      tmp12_seq = mathLerpf(tmp21_flt_last, tmp12_seq, 0.0421572f);
      tmp21_flt_last = tmp12_seq;
      
      // -- mod="rmp" dstVar=tmp12_seq
      float tmp22_seq;
      tmp22_seq = tmp23_rmp_cur;
      tmp23_rmp_cur = mathMinf(tmp23_rmp_cur+tmp24_rmp_step, 0.93);
      
      // -- mod="lut" dstVar=tmp22_seq
      tmp22_seq = curve_2.valueAtTime(tmp22_seq);
      
      // -- mod="$CLICK_LEVEL" dstVar=tmp22_seq
      float tmp25_seq;
      tmp25_seq = 0.0953125f;
      tmp22_seq *= tmp25_seq;
      tmp12_seq *= tmp22_seq;
      out += tmp12_seq;
      
      // -- mod="vpl" dstVar=out
      vpl_iobuf[0] = out;  // plugin_id="bsp ws smoothstep"
      vpl_iobuf[1] = out;
      vpl_voice_0.processReplace(vpl_iobuf, 1/*numFrames*/);
      out = vpl_iobuf[0];  // plugin_id="bsp ws smoothstep"
      
      // -- mod="$DRIVE" dstVar=out
      float tmp26_seq;
      tmp26_seq = 1.1406f;
      out *= tmp26_seq;
      
      // -- mod="clp" dstVar=out
      if(out > 0.999f) out = 0.999f;
      else if(out < -0.999f) out = -0.999f;

      _d[outIdx++] = out;
   } /* end loop frames */
} /* end calc() */
