# Translating modulation to KSP



## kotori (May 12, 2006)

I would like to understand modulation better in order to be able to translate eg. a velocity rescaling into KSP code.
Say I have two Amplifier modulators, one ahdsr (slider at 100%) and one rescaled velocity modulator (slider at 80%). If I receive a note with incoming velocity _x_ which corresponds to a rescaling value of _y_ percent, then what is the resulting amplitude at a specific point in time if the current amplitude after the ahdsr step is _A_?

I'm trying to come up with some sort of formula to better understand this. Any ideas?

Nils


----------



## Thonex (May 12, 2006)

If I'm understanding you correctly, off the top of my head I's say it's some form of multiplication..... like X * Y = A... because if either X or Y = 0 then there will be no sound. 

Of course I'm just totally guessing here...  

T


----------



## Big Bob (May 12, 2006)

Hi Nils,

I don't know if this will help a little but, way back when I first got K2, I was trying to make some sense out of all the modulation controls and their interaction. I summarized some of what I had investigated in a two-page pdf which I'll try to attach to this post (if the forum will take it). If not, I'll email it to you. I haven't read this in a long time so I'm not sure how helpful it will be.

God Bless,

Bob


----------



## ComposerDude (May 12, 2006)

That PDF is wonderful in its precision. I wish more user documentation were written to that standard of clarity.

-Peter


----------



## kotori (May 12, 2006)

Amazing Bob! :shock:  
Very useful information. Thanks a lot. I guess I was a bit puzzled at first by the fact that positive and negative modulation use different formulae.

I still wonder how to translate the calculated factor into an actual volume, eg. what would a factor of 0.5 mean in terms of the volume argument to change_vol? Anyone who knows?

Nils


----------



## Big Bob (May 12, 2006)

kotori @ Fri May 12 said:


> Amazing Bob! :shock:
> Very useful information. Thanks a lot. I guess I was a bit puzzled at first by the fact that positive and negative modulation use different formulae.
> 
> I still wonder how to translate the calculated factor into an actual volume, eg. what would a factor of 0.5 mean in terms of the volume argument to change_vol? Anyone who knows?
> ...


Hi Nils,
I thought I had written down some info relative to your last question but if I did it was so long ago that I can't find it now. I have a vague memory that I ran some tests and the results indicated a fairly typical db characteristic. By that I mean asking a control for say half volume is roughly equivalent to an attenuation of 6db. But, like I say, my memory isn't what it used to be so take it with a grain of salt.

However, if you have a sampled sine wave, you could hook up a sensitive AC meter to your sound card output, and make some relative measurements. For example you could set the CC for max and then adjust the audio card's volume for some convenient reading on the meter. Then, changing nothing else, set the CC to 10%, 20%, .. 100% and note the output voltage readings. Assuming the CC controls the volume from near silence (at zero) to your reference volume (at 127), I suspect the function will follow something like: Output = (CC/127 - 1)*R where R is around 60db or so. If you come up with some less 'wobbly' data, please let me know.

God Bless,

Bob


----------



## Evan Gamble (May 12, 2006)

thanks for the pdf Bob-Ive been trying to make sense out of the modulators too.


----------



## José Herring (May 12, 2006)

Okay I get it. A cc controller changes the volume of what it's modulating. That makes sense.

Now the tricky part. What is that jagged line thingy in the diagrams? Do those represent potentiometers?


----------



## Big Bob (May 12, 2006)

josejherring @ Fri May 12 said:


> Okay I get it. A cc controller changes the volume of what it's modulating. That makes sense.
> 
> Now the tricky part. What is that jagged line thingy in the diagrams? Do those represent potentiometers?


You got it Jose! I was trying to depict the general situation in terms of ganged, analog potentiometers. It's just my electronics background showing, sorry about that.

God Bless,

Bob

BTW Instead of saying a CC 'changes the volume of what it's modulating', a more general way to say it is that it changes the 'intensity' of what it's modulating. So, if you were modulating frequency, more intensity would mean more frequency change, etc. It doesn't have to be volume, I just used volume for illustration purposes.


----------



## Big Bob (May 13, 2006)




----------



## kotori (Jun 10, 2006)

Big Bob @ Fri May 12 said:


> Assuming the CC controls the volume from near silence (at zero) to your reference volume (at 127), I suspect the function will follow something like: Output = (CC/127 - 1)*R where R is around 60db or so. If you come up with some less 'wobbly' data, please let me know.



Hi Bob,
it seems the excellent PDF you posted above is no longer available so I take the liberty of reposting it. I have done some quick experimenting with this and the response isn't completely linear - there seems to a threshold at CC=0. I think the function looks like something like this (assuming the CC intensity slider is at 100%):
Dampening = log((127-CC)/127 * R) where CC>0
Dampening = ∞ where CC=0
where R is such that the maximum dampening is somewhere around 42 dB.

To use the change_vol to imitate this behaviour this lookup table of log-values seem to work reasonable well:

```
declare voltable[128] := (0,0,-69,-138,-209,-280,-351,-423,-496,-569,-643,-718,-793,-869,-945,-1023,-1100,-1179,-1258,-1338,-1419,-1501,-1583,-1666,-1750,-1835,-1920,-2007,-2094,-2182,-2271,-2361,-2452,-2544,-2637,-2731,-2826,-2922,-3019,-3117,-3217,-3317,-3419,-3521,-3625,-3731,-3837,-3945,-4054,-4165,-4277,-4391,-4506,-4622,-4740,-4860,-4982,-5105,-5230,-5357,-5485,-5616,-5749,-5883,-6020,-6159,-6300,-6444,-6590,-6738,-6889,-7043,-7200,-7359,-7521,-7687,-7856,-8028,-8203,-8382,-8565,-8752,-8943,-9138,-9338,-9542,-9751,-9966,-10186,-10411,-10643,-10881,-11126,-11377,-11637,-11904,-12180,-12464,-12759,-13064,-13380,-13707,-14048,-14403,-14772,-15158,-15563,-15986,-16432,-16901,-17398,-17925,-18485,-19084,-19728,-20423,-21179,-22007,-22922,-23945,-25105,-26444,-28028,-29966,-32464,-35986,-42007)
```
The last value in this array should be changed into something working as -∞.

Nils


----------



## Thonex (Jun 10, 2006)

Thanks Kotori!!!

Very good to know this.. and thanks for typing it out for us!!!! :smile: 

On thing I noticed was "-5485,-561 6,-5749,-5883". I guess it doesn't matter that there is a space in the number... correct? KSP will ignore the space anyway right?

Just thought I'd point it out in case it is a problem.


Thanks,

T


----------

