karawin / Ka-Radio32

esp32 version of Ka-Radio (https://github.com/karawin/Ka-Radio) by jp Cocatrix
525 stars 155 forks source link

volume control #150

Open silver13 opened 4 years ago

silver13 commented 4 years ago

Hi, karadio is a great project, I built both the 8266 and the 32 versions recently, great work

But I notice the volume control is not very linear, and the db values posted seem wrong too, as 1 db is pretty small volume change, but the top db changes are quite noticeable, even 0.5 db is noticeable.

Anyway I had a look at the code and function, and it uses a log function. The human hearing is (approximately) logarithmic, which means if you want to linearize it , you have to multiply it by it's inverse, the exponential function.

In practice I heard x^3 is a suitable approximation, over the 0.0 - 1.0 interval. Also x^4 can be used, this depends on the dynamic range of the system used. X^4 corresponds to a 60dB range.

so something like (( (float) x/256 )^3 )*256.0 for a 0 - 255 volume input

here is a graph of x^3 , x^4 and log

http://fooplot.com/#W3sidHlwZSI6MCwiZXEiOiIoKHgvMjU2KV4yKSoyNTYiLCJjb2xvciI6IiMwMDAwMDAifSx7InR5cGUiOjAsImVxIjoiKGxvZygyNTUvKDI1Ni14KzEpKSoxMDUuNTQ1NzEzMzQpIiwiY29sb3IiOiIjMDAwMDAwIn0seyJ0eXBlIjowLCJlcSI6IigoeC8yNTYpXjQpKjI1NiIsImNvbG9yIjoiIzAwMDAwMCJ9LHsidHlwZSI6MTAwMCwid2luZG93IjpbIi0zMDQuMjAxMTA4NzQ3MjkyNTUiLCI0MTcuNDQzODU3MjU5MDU4MyIsIi0xNDguNzY5ODg1Mjk5NzcwNzgiLCIyOTUuMzE5MzI0NTUwMjkxMyJdfV0-

Unfortunately I cant compile it because msys2 is complicated and I haven't got to that step yet, anyway thanks for reading and sorry about opening a "complaint" , it really is a fine piece of software, I'm listening to it right now

karawin commented 4 years ago

Thanks, i will see it later.