Forums > MaxMSP

MIDI control of floating point values

February 25, 2007 | 6:06 pm

Hello Everyone-

If I want to use a midi fader (which sends integers between 0-127) to
control the speed of an LFO (which receives floating point values
between 0.0 and 20.0 Hz), what is the best way to make the 2 data types
"match"? I would like the fader to yield a smooth transition between
values (i.e. no zipper/quantization noise)….

Thank you,

-Tim


February 25, 2007 | 6:28 pm

There are lots of ways to do this in max and your chosen method will depend upon how your LFO works and if you want a linear response.

I suggest the humble "*" object with the value 0.157480314961
(when you save and reload the patch this number will be truncated to 0.15748) This will scale your input to between 0. 20. It’s easy to calculate the number needed for other ranges.

hi output / hi input = scaling factor

If you want more options you could always check out the scale object and help file and search through the tutorials it has all this info and much more!

As for eliminating zipping noises it depends on your lfo you could investigate line or line~

j.


February 25, 2007 | 6:49 pm

Here’s an easy way to do it – adjust to suit particulars.

On Feb 25, 2007, at 11:06 AM, Tim Flood wrote:

> Hello Everyone-
>
> If I want to use a midi fader (which sends integers between 0-127)
> to control the speed of an LFO (which receives floating point
> values between 0.0 and 20.0 Hz), what is the best way to make the 2
> data types "match"? I would like the fader to yield a smooth
> transition between values (i.e. no zipper/quantization noise)….
>

max v2;
#N vpatcher 10 59 610 459;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 104 228 53 196617 line 0. 1;
#P newex 125 209 27 196617 i 7;
#P newex 104 190 31 196617 t f b;
#P newex 104 139 105 196617 scale 0 127 0. 20.;
#P flonum 104 270 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 104 105 35 9 0 127 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 2;
#P user com 213 139 159 196617 28;
#K set 0 29539 24940 25888 26990 28789 29728 29281 28263 25888 29807
8303 30068 28789 29728 29281 28263 25900 8291 28526 30309 29300 8297
28276 8308 28448 26220 28513 29696;
#K end;
#P window linecount 3;
#P user com 162 190 261 196617 73;
#K set 0 26990 29797 29296 28524 24948 25888 26990 28789 29728 28534
25970 8270 8301 29486 8232 26990 8308 26729 29472 25441 29541 11296
14112 28019 11808 11552 29810 31008 25448 24942 26473 28263 8308
26729 29472 28277 28002 25970 8308 28448 25185 27745 28259 25888
29285 29552 28526 29545 30309 28261 29555 8232 27749 29555 8308 26989
25897 8311 26996 26656 29549 28527 29800 28261 29555 8232 28015 29285
8308 26989 25897 10542 8192;
#K end;
#P window linecount 1;
#P user com 146 105 119 196617 13;
#K set 0 26990 29797 26469 29216 26990 28789 29728 26226 28525 8291
29804 26990 3328;
#K end;
#P window linecount 5;
#P user com 145 270 120 196617 51;
#K set 0 26220 28513 29728 28533 29808 30068 8308 28448 19526 20256
25455 25701 15136 26982 8313 28533 8302 25957 25632 29545 26478 24940
8303 30068 8306 24948 26725 29216 29800 24942 8294 27759 24948 11296
29559 24944 8303 30068 8308 26725 8283 27753 28261 23840 30569 29800
8289 8283 27753 28261 32349;
#K end;
#P connect 4 0 6 0;
#P connect 6 0 7 0;
#P connect 7 0 9 0;
#P connect 9 0 5 0;
#P connect 7 1 8 0;
#P connect 8 0 9 1;
#P pop;

—-
Steven M. Miller

Home < http://pubweb.csf.edu/~smill>
SFIFEM <
http://sfifem.csf.edu>
Atrium Sound Space <
http://atrium.csf.edu>
OVOS <
http://pubweb.csf.edu/~smill/ovos.html>


February 25, 2007 | 7:06 pm

At 1:06 PM -0500 2/25/07, Tim Flood wrote:
>If I want to use a midi fader (which sends integers between 0-127) to control the speed of an LFO (which receives floating point values between 0.0 and 20.0 Hz), what is the best way to make the 2 data types "match"? I would like the fader to yield a smooth transition between values (i.e. no zipper/quantization noise)….

This doesn’t address any quantitization/zipper issues, but I don’t think that those are really an issue when controlling LFO speed, anyway.

#P window setfont "Sans Serif" 9.;
#P flonum 69 117 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 69 95 105 196617 scale 0 127 0. 20.;
#P number 69 77 35 9 0 127 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P connect 0 0 1 0;
#P connect 1 0 2 0;
#P window clipboard copycount 3;


Chris Muir | "There are many futures and only one status quo.
cbm@well.com | This is why conservatives mostly agree,
http://www.xfade.com | and radicals always argue." – Brian Eno


February 25, 2007 | 7:10 pm

On Feb 25, 2007, at 6:28 PM, Leafcutter John wrote:

> I suggest the humble "*" object with the value 0.157480314961
> (when you save and reload the patch this number will be truncated
> to 0.15748) This will scale your input to between 0. 20. It’s easy
> to calculate the number needed for other ranges.
>
> hi output / hi input = scaling factor

This only works when the low limits are equal in both the input &
output ranges, otherwise it’s a little more complicated.

In the case where they’re not equal, an algorithm is:
1) subtract lower limit from input (remove input offset)

2) divide this result by ((input upper limit – input lower limit)*
(output upper limit – output lower limit))
(i.e., divide by (input range * output range))

3) add output lower limit (add output offset)

in other words, in Max-land:
[expr ($f1 - $f2)/($f3-$f2)*($f5-$f4)+$f4]

where $f1 = input; $f2 = input lower limit; $f3 = input upper limit;
$f4 = output lower limit; $f5 = output upper limit

—-
Steven M. Miller

Home < http://pubweb.csf.edu/~smill>
SFIFEM <
http://sfifem.csf.edu>
Atrium Sound Space <
http://atrium.csf.edu>
OVOS <
http://pubweb.csf.edu/~smill/ovos.html>


February 25, 2007 | 7:27 pm

Two things. First, your 0-127 control will create only 128 different values
and even though the final output this patch is float, there will be only 128
different floats. This is perhaps not fine enough. Some stepping may be
heard although less likely in an LFO. Second, your output is frequency so
you should be using an exponential interpolation. Of course your minimum
can’t be zero. You can figure out a value for the last arg of scale to
create the right shape or use this cludge that does its computations with
midi key numbers with fractional parts. (MIDI is a logarithm of frequency.)

My sliders are scaled to 1000 steps to get a finer resolution.

#P window setfont "Sans Serif" 9.;
#P flonum 527 309 126 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 526 282 35 196617 * 20.;
#P newex 526 247 29 196617 * 1.;
#P newex 526 216 99 196617 scale 0. 1000. 0. 1.;
#P user hslider 526 189 18 128 1001 1 0 0;
#P comment 526 165 100 196617 get info on this;
#P flonum 358 143 68 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 221 59 54 196617 loadbang;
#P message 222 84 37 196617 0.001;
#P newex 222 107 51 196617 ftom 0.;
#P flonum 173 252 126 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 173 225 31 196617 mtof;
#P user hslider 54 146 18 128 1001 1 0 0;
#P newex 172 197 110 196617 scale 0. 1000. -24. 0.;
#P flonum 359 119 93 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 271 28 48 196617 loadbang;
#P message 312 61 20 196617 20;
#P newex 310 83 43 196617 ftom 0.;
#P comment 54 122 100 196617 get info on this;
#P window linecount 2;
#P comment 567 246 100 196617 squaring makes an exponential curve;
#P window setfont "Sans Serif" 14.;
#P comment 525 115 194 196622 This is a good approximation too.;
#P window setfont "Sans Serif" 9.;
#P comment 173 275 100 196617 MIDI is a logarithm of frequency.;
#P window linecount 5;
#P comment 22 204 100 196617 remember that snakes bred more easily if you
put your adders on a log table.;
#P window linecount 1;
#P comment 381 85 74 196617 midi values;
#P window linecount 2;
#P comment 104 80 100 196617 1/1000. cps is close enough to 0.;
#P connect 12 0 11 0;
#P connect 11 0 13 0;
#P connect 13 0 14 0;
#P connect 9 0 17 0;
#P connect 17 0 16 0;
#P connect 16 0 15 0;
#P connect 15 0 11 3;
#P connect 7 0 11 4;
#P connect 8 0 7 0;
#P connect 9 0 8 0;
#P connect 15 0 18 0;
#P connect 7 0 10 0;
#P connect 20 0 21 0;
#P connect 21 0 22 0;
#P connect 22 0 23 0;
#P connect 23 0 24 0;
#P connect 21 0 22 1;
#P window clipboard copycount 25;

Cheers
Gary Lee Nelson
Oberlin College
http://www.timara.oberlin.edu/GaryLeeNelson


February 25, 2007 | 7:47 pm

Two things. First, your 0-127 control will create only 128 different values
and even though the final output this patch is float, there will be only 128
different floats. This is perhaps not fine enough. Some stepping may be
heard although less likely in an LFO. Second, your output is frequency so
you should be using an exponential interpolation. Of course your minimum
can’t be zero. You can figure out a value for the last arg of scale to
create the right shape or use this cludge that does its computations with
midi key numbers with fractional parts. (MIDI is a logarithm of frequency.)

My sliders are scaled to 1000 steps to get a finer resolution.

#P window setfont "Sans Serif" 9.;
#P flonum 527 309 126 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 526 282 35 196617 * 20.;
#P newex 526 247 29 196617 * 1.;
#P newex 526 216 99 196617 scale 0. 1000. 0. 1.;
#P user hslider 526 189 18 128 1001 1 0 0;
#P comment 526 165 100 196617 get info on this;
#P flonum 358 143 68 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 221 59 54 196617 loadbang;
#P message 222 84 37 196617 0.001;
#P newex 222 107 51 196617 ftom 0.;
#P flonum 173 252 126 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 173 225 31 196617 mtof;
#P user hslider 54 146 18 128 1001 1 0 0;
#P newex 172 197 110 196617 scale 0. 1000. -24. 0.;
#P flonum 359 119 93 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 271 28 48 196617 loadbang;
#P message 312 61 20 196617 20;
#P newex 310 83 43 196617 ftom 0.;
#P comment 54 122 100 196617 get info on this;
#P window linecount 2;
#P comment 567 246 100 196617 squaring makes an exponential curve;
#P window setfont "Sans Serif" 14.;
#P comment 525 115 194 196622 This is a good approximation too.;
#P window setfont "Sans Serif" 9.;
#P comment 173 275 100 196617 MIDI is a logarithm of frequency.;
#P window linecount 5;
#P comment 22 204 100 196617 remember that snakes bred more easily if you
put your adders on a log table.;
#P window linecount 1;
#P comment 381 85 74 196617 midi values;
#P window linecount 2;
#P comment 104 80 100 196617 1/1000. cps is close enough to 0.;
#P connect 12 0 11 0;
#P connect 11 0 13 0;
#P connect 13 0 14 0;
#P connect 9 0 17 0;
#P connect 17 0 16 0;
#P connect 16 0 15 0;
#P connect 15 0 11 3;
#P connect 7 0 11 4;
#P connect 8 0 7 0;
#P connect 9 0 8 0;
#P connect 15 0 18 0;
#P connect 7 0 10 0;
#P connect 20 0 21 0;
#P connect 21 0 22 0;
#P connect 22 0 23 0;
#P connect 23 0 24 0;
#P connect 21 0 22 1;
#P window clipboard copycount 25;

Cheers
Gary Lee Nelson
Oberlin College
http://www.timara.oberlin.edu/GaryLeeNelson


February 25, 2007 | 7:59 pm

Since the frequency in this case is perceived not as pitch but as
rhythm/speed/tempo/whatever, is the log interpolation necessary?
Given that time is perceived linearly rather than logarithmically,
this seems to be an extra unneeded step, doesn’t it?

On Feb 25, 2007, at 12:27 PM, Gary Lee Nelson wrote:

> Second, your output is frequency so
> you should be using an exponential interpolation. Of course your
> minimum
> can’t be zero. You can figure out a value for the last arg of
> scale to
> create the right shape or use this cludge that does its
> computations with
> midi key numbers with fractional parts. (MIDI is a logarithm of
> frequency.)
>

—-
Steven M. Miller

Home < http://pubweb.csf.edu/~smill>
SFIFEM <
http://sfifem.csf.edu>
Atrium Sound Space <
http://atrium.csf.edu>
OVOS <
http://pubweb.csf.edu/~smill/ovos.html>


February 25, 2007 | 8:50 pm

Tempo IS a frequency and is perceived logarithmically. 120 is twice as fast
as 60 bmp (2/1 an octave) but add 60 again to get 180 and the speed
increases by 3/2 – the third harmonic of 60.

Here is an expression/technique that I use for tempo. 0 is 60, 12 is 120
(up an octave) and -12 is 30 (down 8va).

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 43 75 166 196617 expr 60.*exp(.057762265 * $f1);
#P flonum 43 101 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 43 50 80 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P connect 2 0 1 0;
#P connect 0 0 2 0;
#P window clipboard copycount 3;

On 2/25/07 2:59 PM, "Steven Miller" wrote:

> Since the frequency in this case is perceived not as pitch but as
> rhythm/speed/tempo/whatever, is the log interpolation necessary?
> Given that time is perceived linearly rather than logarithmically,
> this seems to be an extra unneeded step, doesn’t it?

Cheers
Gary Lee Nelson
Oberlin College
http://www.timara.oberlin.edu/GaryLeeNelson


February 25, 2007 | 8:57 pm

Well not really – I don’t know exactly how you are using it, but –
1Hz vibrato to 2Hz is twice as fast – 2Hz vibrato to 4Hz vibrato is
twice as fast as that – ie if 1Hz is a quarter note, then 2Hz will be
an eighth note and 4Hz will be a quarter note. The ratios are what
counts, just as with pitches. If you slowly increase your LFO
frequency to make an accellerando, the speed increase will actually
be perceived logarithmically. You might be doing something where this
doesn’t matter, but I rather doubt it.

Best

L

On 25 Feb 2007, at 19:59, Steven Miller wrote:

> Since the frequency in this case is perceived not as pitch but as
> rhythm/speed/tempo/whatever, is the log interpolation necessary?
> Given that time is perceived linearly rather than logarithmically,
> this seems to be an extra unneeded step, doesn’t it?

Lawrence Casserley – lawrence@lcasserley.co.uk
Lawrence Electronic Operations – http://www.lcasserley.co.uk
Colourscape Music Festivals – http://www.colourscape.org.uk


February 25, 2007 | 9:08 pm

You’re right – I hadn’t really thought of it that way. Thanks!

On Feb 25, 2007, at 1:50 PM, Gary Lee Nelson wrote:

> Tempo IS a frequency and is perceived logarithmically. 120 is
> twice as fast
> as 60 bmp (2/1 an octave) but add 60 again to get 180 and the speed
> increases by 3/2 – the third harmonic of 60.
>

—-
Steven M. Miller

Home < http://pubweb.csf.edu/~smill>
SFIFEM <
http://sfifem.csf.edu>
Atrium Sound Space <
http://atrium.csf.edu>
OVOS <
http://pubweb.csf.edu/~smill/ovos.html>


February 25, 2007 | 9:12 pm

Yeah, good point. I was thinking about LFO speed as generally faster-
slower, not synchronized to a tempo per se.

On Feb 25, 2007, at 1:57 PM, lawrence casserley wrote:

> Well not really – I don’t know exactly how you are using it, but –
> 1Hz vibrato to 2Hz is twice as fast – 2Hz vibrato to 4Hz vibrato is
> twice as fast as that – ie if 1Hz is a quarter note, then 2Hz will
> be an eighth note and 4Hz will be a quarter note. The ratios are
> what counts, just as with pitches. If you slowly increase your LFO
> frequency to make an accellerando, the speed increase will actually
> be perceived logarithmically. You might be doing something where
> this doesn’t matter, but I rather doubt it.
>

—-
Steven M. Miller

Home < http://pubweb.csf.edu/~smill>
SFIFEM <
http://sfifem.csf.edu>
Atrium Sound Space <
http://atrium.csf.edu>
OVOS <
http://pubweb.csf.edu/~smill/ovos.html>


February 25, 2007 | 9:41 pm


February 25, 2007 | 10:02 pm

Hmmm, now we’re getting some sophisticated LFO control going on! And
to think I’d been happy with the plain old knob on that analog
modular system all this time… ;)

On Feb 25, 2007, at 2:41 PM, Peter McCulloch wrote:

> Also, you might want to consider using the left inlet of function
> to remap the signal before sending it to the pack and line~
> controlling the LFO speed. Function will allow you better
> resolution where you need it (and less where you don’t) than just
> standard arithmetic means, and it’s significantly easier than
> finding the appropriate power scaling coefficient. Also, you can
> do things like ease-in and ease-out for your faders, etc.
>
> Peter McCulloch
>
>

—-
Steven M. Miller

Home < http://pubweb.csf.edu/~smill>
SFIFEM <
http://sfifem.csf.edu>
Atrium Sound Space <
http://atrium.csf.edu>
OVOS <
http://pubweb.csf.edu/~smill/ovos.html>


February 27, 2007 | 1:38 am

As said, the function / bpfunction would be helpful, as you can set the domain (x range) to 128 total points, then draw in your desired values (y values) that you want your 0-127 input values to access. Graphical representation of your scaling function, very nice, not to mention that preset works with bpfunction… as does pattr (with lots of interpolation!) etc…

The same goes for the almighty Multislider… use a 128-point one and just draw in your data. You could also use a divisor of 128, like 16… then you’d have only 16 different values that your 0-127 maps to, which would give some "stepping", but this may be interesting too (and can be smoothed by line on the output anyway). Also presettable, and pattr-able.

Table will do this for you too, though I personally don’t like dealing with external table files, would rather use a bpfunction or a multislider, with presets / pattrs.

Don’t forget *mtr*! Hook one up to the desired values and record your changes until your heart’s content (which seems to be never in limitless Max land).

-CJ


Viewing 15 posts - 1 through 15 (of 15 total)