I wanted to post this in tutorials but that is apparently for special users so I'll just deposit this information here and hope some of you might like it.
I present to you this information as a university student of electrical engineer and a maths fanatic. Perhaps this knowledge is less obvious for some of you which might help out with your programming.
In the audio world our human perception is much more exponential than it is linear. Volume levels dictated in the digital domain (values between 0 and 1 or 0 and 255 (or more) depending on the data format) is the language every computer understands. Once this value is converted into a voltage and amplified by an amp the speaker will hopefully deviate its rest position accordingly and hence audio is produces. The human ear however doesn't work like this at all.
Values between 0 and 1 do not scale linearly in our perception. Besides the fact that our brain compresses audio volume to become more sensitive in silent situations, sound levels are perceived exponentially or (logarithmically depending on what you like). Its the same thing. Equal steps in volume occur with exponential steps in volume. So if you make a sound twice as loud, you add about 6dB of volume on a linear scale. Double it again and you only notice a 6dB increace etc.
In programming audio, you might notice that the audio sensitivity does not respond like you expect it at all. That might be due to the fact that you aren't using a logarithmic scale for your audio, especially if you use specific frequency ranges and you have to amplify your signal even more.
The best way to make the software respond more realistically is by adding a logarithmic function. Experiment with this. Inside your modifier, put the expression unit and type:
A*log10(B*x)
Here A and B can be set by yourself. Generally I pick B close to 10 and then A between 1 and 10 depending on the frequencies I select for. So something like 3*log10(10*x) is very common. The problem with logarithmic functions however is that values close to 0 become negative. Therefor you do need some form of capping. I suggest using a gate after this to limit the value on the lower bound to 0. You could also use a clamp for a similar problem on the high values especially if you use the smooth feature which might blow up to infinite values over longer periods of time.
The usage of the log10 function will make your effects respond much more naturally to audio compared to linear sensitivity. I hope this information will be helpful to some of you! In the subforum on videos made by magic you can find one video I created to show of something that essentially uses only logarithmic values to change the behavior of shader speeds, colours and much more.
I hope you enjoyed! Questions are always welcome and I'm sorry if this is such obvious information that no one really cares.
I apologize for putting this in the wrong forum.
With kind regards,
Robert
[Lesson] On the math of audio
Re: [Lesson] On the math of audio
Very useful. As a musician and sound tech, i'm aware of this, but I suck at math and didn't know how to achieve this. Thanks for the formula!
Re: [Lesson] On the math of audio
Personally, I like the way things look without any logarithmic scaling. The default linear scaling emphasizes the loud sounds, such as the drum beats, which looks nicer to me. But, everyone's different 
-
RobertFennis
- Posts: 6
- Joined: Fri Dec 16, 2016 10:36 am
Re: [Lesson] On the math of audio
Dude I totally aggree. It depends on what you want the visuals to represent. For example, for GLSL shaders I like to base the speed on a logarithmic version of the 20 to 80Hz range. Then gate it at 0, subtract 0.5 and then smooth it. It will usually let the shaders go very quickly when the drop of a song comes and it also responds very well to basslines. It tends to ignore kicks a little bit because I want it to be a representation of what the music is doing kind of like how trackmania works. Then again, If I want something to trigger on a kick drum, I'll use a different function. Its great that you mention it because it should totally depend on 'what' you are trying to achieve! Good point.Eric wrote:Personally, I like the way things look without any logarithmic scaling. The default linear scaling emphasizes the loud sounds, such as the drum beats, which looks nicer to me. But, everyone's different