Scale object exponent for decibel scale

Myr's icon

Hi,

I'm wondering if anyone knows what exponent to enter into the scale object to have it scale a range with the same logarithmic curve as decibels? Or if could use [expr] to do it instead?

Apologies if i'm missing something or there's a better way.

I'm using the [adsr~] object and sending it float values between 0. and 1. to change the amplitude of the output envelope. By default the output seems to be scaled linearly, so sending 0.5 results in the envelope output maximum being 0.5. I'm trying to scale that output so it's logarithmically scaled the same as decibels. So sending 1. would result in envelope output of 1 with sounds effectively hitting 0db. Then by sending 0.5 in the envelope would be scaled so sounds sent through would hit -6db. Sending 0. would result in envelope output of 0. or just staying off.

Thanks!

double_UG's icon

atodb~ dbtoa~

Myr's icon

using atodb then dbtoa in series doesn't do anything.

0.5 -> [atodb] -> [dbtoa] = 0.5

The idea is to scale amplitude to the same logarithmic curve as decibels but have it remain in the range of 0. to 1.

Myr's icon

i think i may have been a bit dense here. an amplitude of 0.5 does result in a volume of -6db.

so i think i may have been over thinking things, and forgotten something a bit simple eheh

Myr's icon

sorry for the noise!

Roman Thilenius's icon


but to answer the original question: it is always log10() * 20.

Myr's icon

although i was overthinking what was needed for the example above i got close to what i wanted with:

[atodb] -> [scale -70. 0. 0. 1.]

or substitute atodb with an expr with Roman's answer above.

unfortunately this doesn't quite do what i wanted as getting close to 0 goes to -inf (as expected) so would need some clipping or mb an if statement to output 0 whenever it displays -inf. also an input of 1 isn't quite outputting 1 (gets to 0.99) so might need something on that end too.

is there a way to do this without scaling the number to the decibel range and then scaling it back into the 0 - 1 range? just mapping the 0 - 1 to the correct logrithmic curve without shifting the range? and possibly cleanly done within 1 expr object?

times like this i really wish my understanding of math was better.

here's a snippet of the atodb and scale example showing live.gain being set in db and a slider being set with the output db scaled to the 0 - 1 range seeming to match

Max Patch
Copy patch and select New From Clipboard in Max.

Roman Thilenius's icon


that is why there is nothig wrong with creating your own patch when you dont know if there is an object: that is how you learn.

and indeed, you must clip it at the low end. (you wouldnt on the high end. feel free to allow an infinite headroom.)

before atodb existed, i used this.

the "90." is arbitrarily set. it is a pretty good compromise (and i dont think that the latest cycling breed uses a higher limit.)

dbtoa atodb

Roman Thilenius's icon


dont expect that live.gain follows math (or any kind of logic for that matter.) in live objects, alwas look into their inspector what they actually output.

§2
you can trust only number conversions you made yourself.