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;