View Single Post
Old 06-12-2017, 11:30 AM   #4
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,960
Default

Thanks to Eugen27771 found a solution!
It is sample offset compensation:

Code:
desc:MPL_CV to MIDI

in_pin:left input
in_pin:right input

@init
  threshold_dB = -80;
  threshold = 10^(threshold_dB/20); // Gate threshold
@block
  spl_cnt = 0;
@sample
  spl_cnt+=1;
  pitch = floor(spl0*120); 
  cur_smpl = abs(spl1);
  cur_smpl > threshold ? (gate = 1 ):( gate = 0);   
  (gate == 1 && last_gate != 1 && pitch > 0) ? 
    midisend(spl_cnt, $x90, pitch, 127); // send MIDI Note On
  (gate == 0 && last_gate == 1)  ?
    pitch == 0 ? midisend(spl_cnt, $x80, last_pitch):midisend(spl_cnt, $x80, pitch); // send MIDI Note Off
  last_gate = gate;
  last_pitch = pitch;
mpl is offline   Reply With Quote