|
|
|
10-13-2018, 09:18 AM
|
#1
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
How to convert an FX parameter value from formatted to normalized?
Hello!
I am trying to set the frequency of MAutoDynamicEQ with TrackFX_SetParam. The plugins formatted values are 20 - 20000 (Hz) but Reaper expects a value from 0 to 1. If I use (freq-20)/(20000-20) I get the wrong number. How can I find the formula used?
Thanks!
|
|
|
10-13-2018, 09:21 AM
|
#2
|
Human being with feelings
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
|
If it's a VST2(*) plugin, bad news : there is no standard way to get the normalized value from a mapped value or text string. You will just have to somehow reverse engineer the mapping formula used inside the plugin. (That is, for example set various frequencies manually in the plugin GUI and examine what the normalized parameter value exposed to the host is. You could put those values in a spreadsheet, graph it, etc and try to discover the mapping formula used.)
(*) And this may be the case for VST3 plugins too...
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
|
|
|
10-13-2018, 09:31 AM
|
#3
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
:O:O:O:O
Holy shit! Why no standard way? Who is to blame? :S
Here are some values:
Code:
20 -> 0
28.25 -> 0.05
39.91 -> 0.1
79.62 -> 0.2
158.9 -> 0.3
317 -> 0.4
632.5 -> 0.5
1262 -> 0.6
2518 -> 0.7
5024 -> 0.8
10000 -> 0.9
20000 -> 1
I'll see what I can do...
Last edited by amagalma; 10-13-2018 at 10:05 AM.
|
|
|
10-13-2018, 11:26 AM
|
#4
|
Human being with feelings
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,984
|
I`m not good at math, but maybe this works:
Code:
value = 0.1*math.log(frequency / 20, 2)
I got it from MIDI pitch:
Code:
actial_midi_pitch = 69+ 12*math.log(x/440, 2)
lowest_note_MIDI_pitch = 69+ 12*math.log(20/440, 2 )
pitch_range = 120
value = (actial_midi_pitch -lowest_note_MIDI_pitch) / pitch_range
Otherwise I can only recommend to try brutforce method like
Quote:
ReaPack/mpl_Set last touched parameter value (via deductive brutforce).lua
|
Last edited by mpl; 10-13-2018 at 01:52 PM.
|
|
|
10-13-2018, 01:55 PM
|
#5
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
Thanks mpl!
It is quite close! Not exactly but pretty close!
|
|
|
10-13-2018, 02:08 PM
|
#6
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
Ok, after some tests... This is it exactly! No any error at all!
Code:
value = 0.1003433*math.log(frequency / 20, 2)
Yay!!
Thank you so much mpl!! But how did you thought to use that formula? How did you come up with it?
|
|
|
10-13-2018, 02:16 PM
|
#7
|
Human being with feelings
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,984
|
I`m not sure if the plugin itself doesnt quantize values inside. Maybe try bigger coefficient
Code:
0.1003433318888889*math.log(frequency / 20, 2)
>
20 -> 0.0
28.25 -> 0.049996152164271
39.91 -> 0.10001724404091
79.62 -> 0.19999739252982
158.9 -> 0.30003130051714
317 -> 0.40000975552149
632.5 -> 0.50001017806575
1262 -> 0.60000978642006
2518 -> 0.70000857670887
5024 -> 0.80000654502886
10000 -> 0.89965666812003
20000 -> 1.0000000000089
Quote:
Originally Posted by amagalma
how did you thought to use that formula? How did you come up with it?
|
Well, I tried powered thigs like y=x^0.3, but any frequency stuff usually smells logarithm. So I use relation beetween linear and log (MIDI Pitch and frequency) values, then convert to 0..1 values, based on standart pitch range (not full MIDI range 0-127).
Code:
actial_midi_pitch = 69+ 12*math.log(x/440, 2)
lowest_note_MIDI_pitch = 69+ 12*math.log(20/440, 2 )
pitch_range = 120
value = (actial_midi_pitch -lowest_note_MIDI_pitch) / pitch_range
value = (69+ 12*math.log(x/440, 2)-69- 12*math.log(20/440, 2 )) / 120
value = 12*(math.log(x/440, 2)+ math.log(20/440, 2 )) / 120
value = 0.1*(math.log(x/440, 2)+ math.log(20/440, 2 ))
value = 0.1*(math.log((x/440) / (20/440), 2))
value = 0.1*math.log(x/ 20, 2)
Last edited by mpl; 10-13-2018 at 03:05 PM.
|
|
|
10-13-2018, 03:21 PM
|
#8
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
Brilliant!
But why did you choose as the lowest note the note 20 (G#0) and 120 as the pitch range?
P.S. 0.1003433 is enough to give me 1Hz resolution so I can dial 9999Hz or 10KHz, which is more resolution than I could need up there!
|
|
|
10-13-2018, 03:33 PM
|
#9
|
Human being with feelings
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,984
|
120 is a standard range for linear convertion. 20 is not lowest note, but lowest frequency (you mentioned 20-20000Hz range). Also , just in case, resolution is different for different frequencies (bigger frequency mean lower resolution), since we are at non-linear scale.
|
|
|
10-13-2018, 04:20 PM
|
#10
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
But if my lowest frequency was 16Hz? Then the math would not be correct. It is the combination of 20 and 120 that gets close. But still it is not 100% correct. And I don't know how mathematically 0.1003433 (that works better) can be justified...
Anyway!.. What it matters is that we got there!
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 02:28 PM.
|