# Keyboard tracking!



## EvilDragon (May 31, 2010)

How does the "key position" modulator correlate to filter cutoff frequency? I can't seem to get normal pitch tracking of the filters, and I could use it a fair bit! Seems to me like NI totally screwed up this function, because I can't get a 100% pitch tracking for the life of me.

Try setting up a group effect holding a LP4 filter with cutoff at 440 Hz and a fair amount of resonance. Use a short percussive sample which will trigger filter oscillation. Now try to get it to scale linearly! I tried for hours to no avail.

Help?


----------



## EvilDragon (Jun 17, 2010)

Gotta bump this. Anyone has any info?


----------



## polypx (Jun 17, 2010)

I can't make it track exactly at the same rate as the notes on a keyboard (is that what you're trying to do?)

The value 12 seems to be "close" to a chromatic tracking, but not exact. Also, different filters seem to behave differently, perhaps because the cutoff range of each of the fllters is different too.


----------



## Thonex (Jun 17, 2010)

I got pretty close with:

4 pole BP with Cutoff at 524.1 and reso at 100%
Key Position modulating Cutoff Freq and Slider set to 12% (use mouse +shift for fine tuning).

Back in the old days (K2) I think you had to run the modulation through Key Position twice to get this. Since NI changed the their NI values... I'm not sure anymore.

I hope this helps.... but probably not.

Cheers,

Andrew K


----------



## EvilDragon (Jun 18, 2010)

It is just SO weird, I'd like to have a Keytrack knob with +/- 100% range, just as on more elaborate synthesizers.

I just can't fathom the correct values that need to be used. Which values is Key Position modulator sending out? How do they relate to the modulation amount slider and filters?

I hope Big Bob gets some free time to resolve this in the best of his manner - by implementing a function to his math lib 


Thanks for replies, everyone, let's keep this issue alive!


----------



## Big Bob (Jun 18, 2010)

> I hope Big Bob gets some free time to resolve this in the best of his manner - by implementing a function to his math lib



I hope so too, I'm just itching to 'get back in the saddle' :lol: . But, in the meantime, I've made a mental note of it.

God Bless,

Bob


----------



## EvilDragon (Jun 19, 2010)

Yeah, just didn't thought of testing it that way


----------



## EvilDragon (Jun 19, 2010)

OK guys, I figured it out in a simple way (oh god the facepalm I made when I discovered it!)

Try this: disable Tracking in the Source module, then add Key Position as a modulator, and set Intensity to 12 semitones. You now have full tracking! XD

The Intensity slider is per-octave. So, if you set it to 1 semitone, you will have 12 microtonal steps in one octave.

So basically, Key Position just sends out values from 0 to 12 (divided by Intensity) per octave, and starting point of keytracking seems to be C3.

OF COURSE the filter wouldn't track well, it's in Hz! It seems that we need to script our own keytracking. Once again, NI proves that they can't make things easy for their users... >_>


----------



## Big Bob (Sep 2, 2010)

Sorry for the long delay but, I'll try to take a crack at this now (I think I'm finally starting to get a little free time). But, because my time is still somewhat restricted, I'll have to work on this in stages.

The first step I think will be to discover the relationship between the ep and the corresponding cutoff frequency. I took a quick look at this and, unfortunately, NI seems to have used a different function than they did for EQ frequency. For one thing, cutoff frequency covers the range from 43.6Hz to 21,800Hz (for the LP filters) whereas the EQ frequency range is from 20Hz to 20KHz. But, the relationship between EQ frequency and its corresponding *ep* pretty well tracks a simple log function:

* f = 20*2**(ep/K) where K = 100343*

Thinking perhaps they had simply changed the frequency range, the first thing to try was:

*f = 43.6*2**(ep/K2) where K2 would be about 111535*

But, alas, the actual cutoff frequency versus *ep* (at least as reported by the *_get_engine_par_disp *function seems to deviate noticeably from a simple log function. I can't for the life of me figure out why NI would use something more complex than a log function (nor can I figure out why they even used anything different than what they used for EQ frequency). Perhaps they found some clever polynomial that doesn't perfectly track the log function but is for some reason easier to calculate?

The best fit I've come up with so far is:

* f = 1225*2**(4.155*N) - 25 where N = (ep - 500000)/500000*

But, this tracks NI's function rather poorly (deviations are as much as 6 or 7% across the full range).

So, it looks like we have another 'reverse engineering' job on our hands *unless someone has already obtained the formula from NI*. So before I spend a lot of time trying to deduce NI's function, *if any of you happen to know the mathematical relationship, please post it to this thread*.

If any of you are developers that might have some 'clout' with NI, please put pressure on them to publish the entire set of formulae they used to relate the engine parms to their corresponding parameters. There is certainly no reason to keep that kind of information secret and everyone using *ep*s needs it. It seems absurd to me that we are forced to 'reverse engineer' all these relationships that must be well known by someone at NI. I will gladly add more format conversion functions to the Math Library for every formula that NI makes available. That part is easy, it's the unnecessary reverse engineering that is a royal pain!

*I'm going to wait a while before continuing with this just on the off-chance that one of you happens to have NI's formula for filter cutoff versus its ep*.

To be continued ....

God Bless,

Bob


----------



## Big Bob (Sep 3, 2010)

While I'm waiting to see if anyone has the cutoff frequency formula (probably not too likely), let's take a look at the other half of the problem. Namely, how the key position modulator controls the cutoff frequency. There are several ways we could express this but I think the simplest is to view the cutoff frequency, *fc*, in terms of the engine parameter value that controls it. As the engine parameter swings from 0 to 1000000, the value of *fc *swings from 43.6Hz to 21,800Hz (possibly following some sort of pseudo log function).

The key position modulator seems to add a value (*epm*) to the *ep* which is given by:


```
(1)  epm/1000000 = (m - 60)/12*I/100     where m is the MIDI note number played and I is the Intensity slider value in percent.
```

As already discovered by Mario, this simply means that the *ep* is modulated by 1000000**I*/100 per octave deviation from C3 (m=60). Thus, if* I* is set to 100%, playing C4 will add 1000000 to the current *ep* and playing C2 will subtract 1000000 from the current *ep*. Of course, the resulting net *ep* is always clamped between 0 and 1000000. If *I = 50%*, playing C4 will add 500000 to the current ep and playing C5 will add 1000000, etc.

If an instrument is mapped like a piano (using an equi-tempered scale and where A3 = 440Hz), then the frequency of any given MIDI note, *fn*, will be given by:

```
(2)   fn = 440*2**(m - 69)/12
```

Now, if the cutoff frequency, *fc*, is related to the controlling *ep* by a simple log function (like we would expect), we could write:

```
(3)   fc = 43.6*2**(4.48*N)    where N = ep /500000
```
The above formula yields about 43.6Hz when *ep = 0* and 21800Hz when *ep = 1000000*. Of course, as I indicated in my prior post, the cutoff frequency versus the corresponding *ep* doesn't seem to be implemented as a pure log function, but, perhaps it actually is internally and the displayed frequency is calculated some other way (and thus appears to deviate somewhat).

The cutoff frequency range is just about 500:1 (ie 21800/43.6) and thus at an Intensity setting of 100%, one octave of key position change will attempt to produce a 500:1 change in the cutoff frequency. 500:1 expressed in terms of octaves is about 8.96 octaves. Thus, if we want the the cutoff frequency to actually follow the played key's frequency, we need to have a one octave key position change correspond with 1/8.96 of the total 500:1 range. Therefore, we should set Intensity to about 11.2%. If we do that, key position will change the *ep* by about 111535 per octave (above or below C3), per equation (1). The last thing we need to do is set the initial *fc* to the frequency of C3. If A3 is to be tuned to 440Hz, then C3 will have a fundamental frequency of 261.6Hz.

So, if we set the filter's cutoff to 261.6Hz, it will be set to the frequency of C3 and if we set Intensity to 11.2%, *fc* will track the played key's frequency one to one. If you want the cutoff to be somewhat above the played key's fundamental frequency then you would set the initial cutoff accordingly. Note that the values that Andrew detemined by ear was an *Intensity of 12%* and an *fc* just about twice the fundamental frequency of the played key. This could either be that the keyboard mapping was shifted an octave or that Andrew wanted the cutoff frequency to suppress only the harmonics.

Finally, we need to deal with the fact that the cutoff frequency's relationship to its *ep* may not be a simple log function. If that actually is the case, then to achieve perfect tracking across the filters entire range, we will need to obtain or deduce the actual function that NI used. Then, because the key position modulator follows a simple log curve, we would have to abandon it and instead 'script control' the filter's *fc* as a function of the key played. The general idea would be to use equation (2) to compute the frequency of the played note and then use the inverse of the 'final' version of equation (3) to determine the corresponding *ep* value to control the filter.

Unless someone actually has the formula used by NI (if so please post it soon), I think I am going to assume that the internal relationship *is just a simple logarithmic one *(because it just doesn't make sense any other way). When I get a little more time, I will cobble together a script that will be able to control the filter cutoff frequency to precisely track the keyboard (assuming the *eq* to *fc* relationship is a simple log function). Then those of you with better hearing than mine can try to determine if the tracking is accurate enough or if we need to further refine equation (3) to better fit the *fc* relationship to *ep* (as displayed by Kontakt). 

Is any of this understandable or has everyone lost interest in this? :lol: 

To be continued ...

God Bless,

Bob

*****EDIT*****
Whoops! I just realized that Andrew was using a Band Pass filter, not a Low Pass. The BP filters seem to cover a different frequency range (from 36.1 to 18100Hz) but also about a 500:1 range so the same logic will still apply.

*****EDIT #2****
I'm getting ready to make my final post on this topic. But, in reviewing this post, I noticed that I had indicated that N in equation (3) was given as (ep -500000)/500000. Actually equation (3) represents the situation for when N = ep/500000. If we use (ep - 500000)/500000, the leading exponential factor needs to about 974.9 (the geometric mean of the min and max frequencies of the filter). I'm surprised no one challenged equation (3) :o Could it be that everyone has lost interest in this topic :lol: Oh well, I'm going to finish it up now anyway because maybe someone will benefit from the summary findings. :roll: *


----------



## snapshot (Sep 4, 2010)

wow ,this is really interesting and helpful , i think i gonna PDF it just in case of not to lost it . Thaaanks for your time on this stuff .


----------



## chimuelo (Sep 4, 2010)

I totally agree.
I use the SDK in Scope DSP enviroment.
While my programming skills are limited I have several SDK developers who can create whatever custom work I need. They have over a decade of DSP programming skills. 
Having access to such intellectual property rights is crucial.
I would love to see keyboard tracking using BiPolar values like modern synths have.


----------



## Big Bob (Sep 8, 2010)

Rather than post a 'final' installment of my investigation of keyboard tracking of filters, I decided it might be more useful to put it all together in a single post by starting a new thread. So, if there is anyone still following this thread, please read the new thread titled, 'Key Position Modulation'

http://www.vi-control.net/forum/viewtopic.php?p=235535


----------

