Solved! a new algorithm to resolve the tilt pitching problem

ajaym
Posts: 11
Joined: Sat Jun 07, 2014 10:22 am

Solved! a new algorithm to resolve the tilt pitching problem

Postby ajaym » Sat Jun 07, 2014 10:50 am

A couple of weeks ago I picked up a Qunexus during a trip to central London. Tomorrow I plan to return and buy a second one. I've always dreamed of being able to carry a playable keyboard in a backpack and was astonished at how actually playable this tiny little gadget is.

But, my dream of using keyboard tilt to add natural vibrato was rudely shattered when I got terrible pitching issues with keyboard tilt turned on. I am, however, a software engineer as well as a musician, so I had a look at what was happening using Midi OX to log events from the qunexus. It turns out there are actually two contributory factors to the problem. The good news is that these are solvable. In fact, if, like me, you use Cockos Reaper as your DAW, then you can use the amazing JS plugin functionality in Reaper to simply write any kind of audio or MIDI plugin you want just using notepad. I'll come back to this in a minute

So here are the problems
(a) When you press a key, there's a built-in time delay in the firmware before tilt is activated. At that point, around about 0.4 seconds after the key is pressed, any slight movement of the key will immediately cause pitch to jump to the absolute position of the tilt. Unfortunately this is not an optimal algorithm. I thought about this for a little while and decided an alternate algorithm would likely be much better.

This alternate algorithm dispenses with the time delay entirely. Since that's currently built into the firmware I have to live with it, but I can still test it (see below). The alternative algorithm works like this

When a key is pressed, measure the absolute tilt. Note the value. Now, don't output any pitch bend events until the tilt crosses the neutral (untilted) point. After that, start outputting pitch bend events.

I used Reaper's JS functionality to write a few lines of code to test this and simply inserted the plugin as the first MIDI plugin in the chain. Immediately the pitching problems were (almost) solved and I could add natural vibrato to notes as I had planned.

There were, however, still some pitching issues, albeit a lot less severe. After a bit more research I discovered a second issue. If you tilt a key, pitch bend events are emitted and if you release that key a pitch bend value of 64 (neutral) is emitted. But if you play legato that event is not emitted. Indeed, it seems not to be emitted when all keys are subsequently released either.

So the second part of the fix is to emit a neutral pitch bend event when a second note on occurs, on the basis that you are almost certainly using tilt to bend individual notes and want the next note played to be on pitch.

I am just about to test this second fix with my JS plugin. I will post tomorrow with the three or four lines of code that are required to fix this issue in Reaper. It could, for non-Reaper hosts, be coded into a simple VST plugin. Unfortunately I can't remove the time delay; that requires a firmware change.

If any of the KMI engineers are reading this, Reaper is a great way to experiment with alternative algorithms without tedious firmware modifications. I believe this algorithm works much better than the current one and urge you to investigate it.

The second issue I see in this thread is the ongoing concerns over inconsistent key velocity and pressure response. I can certainly confirm this is so in the unit that I have. Indeed, one key is significantly less sensitive than others but ironically if I increase the key sensitivity using the editor, the key will start triggering note events randomly. But in general key sensitivity is not completely consistent, though not, to my mind, unplayably so. I have found an overall gain of 0.75 and a logarithmic keyboard curve to give pretty good results with demanding instruments such as acoustic piano.

However to further even up response I am planning further mods to my Reaper JS plugin to allow individual notes to be compensated. This should allow a calibration curve for each note on the device, separate from the overall key sensitivity adjustment in the qunexus editor.

I will post further when I have had the opportunity to do a bit more testing but the news is looking positive at this stage.
ajaym
Posts: 11
Joined: Sat Jun 07, 2014 10:22 am

Re: Solved! a new algorithm to resolve the tilt pitching pro

Postby ajaym » Tue Jun 10, 2014 11:15 am

Ok, here is the JS plugin code to demonstrate the new tilt algorithm.

1. Copy the code below into a text file using Notepad

@block
while(midirecv(ts,msg1,msg2,msg3))
(
// if we sent pitchbend event, reset to neutral on note on event
(tilt_neutral != 0 && msg1 == 0x90 && msg3 !=0x00) ? midisend(ts,0xe0,0x00,0x40);
// reset tilt flags on note on event
(msg1 == 0x90 && msg3 != 0x00)? tilt_neutral= 0;
(msg1 == 0x90) ? initial_tilt=0;
// capture initial tilt value from first pitchbend event after note on
(msg1 == 0xe0 && initial_tilt == 0) ? initial_tilt=msg3;
// set tilt flag when we get a pitchbend event that crosses the neutral zone.
((msg1 == 0xe0) && ((msg3 >= 0x40 && initial_tilt <= 0x40) || (msg3 <= 0x40 && initial_tilt >= 0x40)) && (tilt_neutral == 0)) ? tilt_neutral=1; // set when tilt reaches neutral
// send pitchbend events if we are now allowed to
(tilt_neutral != 0 || msg1 != 0xe0) ? midisend(ts,msg1,msg2,msg3);
);

2. Download a copy of Reaper from the Cockos web site if you're not already a Reaper convert. Note that the evaluation copy is not crippled or time expired in any way, it will just nag you at startup.

3. Place the text file in step 1 into Reaper's plugin directory for JS scripts which will typically be

C:\Users\admin\AppData\Roaming\REAPER\Effects\MIDI

4. Set up your audio output device and MIDI input device from Options/Preferences

5. Insert a new track using track/insert

6. ensure that audio arm (round red button) is enabled and that the qunexus is selected as midi input device, and click the little arrow to enable record monitoring.

7. Insert a plugin by clicking the FX button. For the demo, I'll use the supplied ReaSynth VST which will produce a simple sinewave as its default patch.

8. Using a Qunexus patch with tilt enabled and a reasonable pitch bend range, say 4 semitones, to make the issues more obvious, play some notes.Use tilt to add vibrato as you play. Note that pitching errors are not uncommon if notes are held and subsequent notes played legato, although they occur otherwise as well.

9. Insert the JS plugin by clicking on the plugin button again, selecting Add and the JS folder, in which you should find your plugin.

10. Drag the plugin to the top of the list of two plugins so that it filters MIDI first before ReaSynth gets it

11. Ensure the checkbox to the left of the plugin is enabled and repeat step 8. Observe that pitch errors do not occur but you can still use tilt to bend or impose vibrato. Unfortunately the KMI firmware has an inbuilt time delay before which these become active. Hopefully I can convince KMI's engineers to make this delay configurable.

12. Uncheck the checkbox and repeat step 8. Note that pitching errors reoccur.

How it works: we record the initial tilt position and then require tilt to cross the neutral point before allowing pitch bend events to pass through. Additionally, on a note on, if the previous note had sent pitchbend events, we sent a pitch neutral event to ensure that subsequent notes are not pitchbent, since in most cases, particularly with legato playing, we do not want any previous pitchbend to affect subsequent notes.

It should be simple to implement this as a VST for other hosts but Reaper's JS functionality obviously makes testing this sort of thing really simple.

I am now returning to the keyboard calibration part of the problem and will post a new JS script which should also address this problem shortly. Hopefully KMI might be willing to remove the tilt timedelay and possibly implement this (and the calibration functionality) in a VST, unless of course their engineers think this would be appropriately implemented in firmware.

Please try this and let me know what you think. If you like it, please tell KMI.

Return to “QuNexus General Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest

cron