linear vs logarithmic
i'm not sure i understand what ur after, but this patch might help if u want to be able to control the curve (log factor):
j
Yes, this is helpful. So what you have done here is take (x/127) to the y power and multiply by 100.
So,
((x/(xn-1))^y
would be a useful equation to use, in general?
I'm also interested in applying this to cycle~, so that cycle~ could output waves logarithmically. How would one go about this?
nevermind
Quote: laotze wrote on Thu, 31 July 2008 16:28
----------------------------------------------------
> I'm also interested in applying this to cycle~, so that cycle~ could output waves logarithmically. How would one go about this?
----------------------------------------------------
i'm sorry i dont understand what u mean by outputting waves logarithmically? what would be the purpose, or try to describe what ur trying to achieve?
j
Jay Bodley schrieb:
> I am wondering how Max computes on a logarithmic scale.
There are a lot of ways to do that, the most universal is expr, but for
musical purposes, there are mtof, ftom, atodb and dbtoa which transform
common human perception curves (loudness/amplitude and pitch/frequency)
Stefan
--
Stefan Tiedje------------x-------
--_____-----------|--------------
--(_|_ ----|-----|-----()-------
-- _|_)----|-----()--------------
----------()--------www.ccmix.com
Using [expr] you can use natural log and log base 10.
However you can use maths laws to translate these to work in any base you want. For example this is helpful if you want to play microtonal music using something other than 12 equal divisions of the octave (12 EDO or 12 TET).
Here are some two [expr]s which show how MIDI pitch number and frequency are related logarithmically. Basically they are equivalent to [mtof] and [ftom] but you can see (and hopefully understand) all the maths going on inside.
There is also a mathematical expression I have worked out that transforms 0-127 linear range into the [filtergraph~] logarithmic range of 20-20000. You might find this helpful for any filter GUIs as you will find that using a standard [num] or [float] box you move through low frequencies quickly and high frequencies really slowly!
I hope this helps in some way.
lh
thanks for your examples! for the sake of deeper understanding - would
you mind telling us what the two values 119.589417 and 15.48682 stand
for in your equation?
p
> There is also a mathematical expression I have worked out that transforms 0-127 linear range into the [filtergraph~] logarithmic range of 20-20000. You might find this helpful for any filter GUIs as you will find that using a standard [num] or [float] box you move through low frequencies quickly and high frequencies really slowly!
>
> I hope this helps in some way.
>
> lh
>
>
>
Of course! Sorry for not explaining it in the original post.
Those numbers are simply there to scale the output of the [mtof] equation to fit the boundaries 20-20000Hz. If you run the MIDI range 0-127 straight into [mtof] then the range is something like 8.2-12553Hz which isn't ideal. You could simply use a [scale] object mapping the values you get straight to the audible audio frequency range. Perhaps try:
[scale 8.1758 12543.85 20. 20000.].
However I decided to do it using maths. To get these numbers I sent 20 and 20000 to my [ftom] equation. In this case using the [ftom] object doesn't work because it only returns integers. The results were:
20Hz = 15.48682
20000Hz = 135.076233
difference = 119.589417
Now to use these in the [mtof] equation we need to take the original input ($i1) and replace it with a new equation. First we scale the 0-127 range to 0-1. Then we multiply this by the difference between our desired range. Finally we add on the minimum value.
$i1/127.*119.589417+15.48682
Substituting this equation in to the original [mtof] gives us the final result. I hope this has helped you understand, I have tried to explain it as clearly as possible. If you'd like to see the equations for [atodb] and [dbtoa] then let me know. They were much simpler to work out.
lh
=)))
ok, i thought its some magic numbers like pi or 1/sqrt(2) or something.
so you simply stretched mtof to 20-20000?
thanks for the demystification!
p
Luke wrote:
> Of course! Sorry for not explaining it in the original post.
>
> Those numbers are simply there to scale the output of the [mtof] equation to fit the boundaries 20-20000Hz. If you run the MIDI range 0-127 straight into [mtof] then the range is something like 8.2-12553Hz which isn't ideal. You could simply use a [scale] object mapping the values you get straight to the audible audio frequency range. Perhaps try:
>
> [scale 8.1758 12543.85 20. 20000.].
>
> However I decided to do it using maths. To get these numbers I sent 20 and 20000 to my [ftom] equation. In this case using the [ftom] object doesn't work because it only returns integers. The results were:
>
> 20Hz = 15.48682
> 20000Hz = 135.076233
> difference = 119.589417
>
> Now to use these in the [mtof] equation we need to take the original input ($i1) and replace it with a new equation. First we scale the 0-127 range to 0-1. Then we multiply this by the difference between our desired range. Finally we add on the minimum value.
>
> $i1/127.*119.589417+15.48682
>
> Substituting this equation in to the original [mtof] gives us the final result. I hope this has helped you understand, I have tried to explain it as clearly as possible. If you'd like to see the equations for [atodb] and [dbtoa] then let me know. They were much simpler to work out.
>
> lh
>
>
>
Luke schrieb:
> In this case using the [ftom] object doesn't work because it only
> returns integers. The results were:
give ftom a float argument and it will spit out floats...
Stefan
--
Stefan Tiedje------------x-------
--_____-----------|--------------
--(_|_ ----|-----|-----()-------
-- _|_)----|-----()--------------
----------()--------www.ccmix.com
Luke (thereishopeforus, for some reason I think your name is luke, am I correct?)
Any chance you could explain your ftom equation? I need to make it work to output numbers from 1-256.
I need to have a logathmic slider, like the one in your example, but the user needs to be able to type in frequency values in the numeric box and have it update the slider position correctly, by using a [float] object and some set $1 messages.
It would be greatly appreciated!
Sure.
The log() bit switches from a linear to logarithmic scale, to be specific using the twelfth root of two which is the equation used to work out frequencies in 12 tone equal temperament (equal divisions of the octave).
The $f1/440 and +69 bits on there are to work this out relative to concert A = 440Hz. This would give you midi note values.
The -15/119*127 bit then scales the midi note value output between 0 and 127 for the pitches 20-20000Hz. I've explained how I got these numbers in a previous post on this topic. Assuming you want to still use this frequency range then all you need to do to get the output value 0-255 is replace the final "127" with "255".
lh (the l is for luke)
Hi Luke.
I just came across you post.
I need to scale 20-20000 to 0-127, so the other way around.
How would the formula look this way around?
I'd appreciate your help a lot.
Thanks, Josef
you probably want to convert Hz to note numbers, this is what [ftom] does.
otherwise you´d scale ranges by
- normalise the input range to base 0
- divide thu input range width
- multiply by output range width
- add output range offset
and do it in floating point, and then round.
- 20
/ 189980
* 127
+ 0.5
int
that would be about what [scale] or [zmap] are doing , too...