noriah / catnip

terminal audio visualizer for linux/unix/macOS/windblows*
MIT License
226 stars 13 forks source link

[feature request] option to visualize on logarithmic scale #15

Open josephdong1000 opened 2 years ago

josephdong1000 commented 2 years ago

It'd also be cool to have a toggle/setting that flips between logarithmic and linear axis scales, since right now I think the low frequencies are being squished together.

For reference, here's what an audio spectrum with a logarithmic scale looks like:

image

, versus a linear scale like

image

, which is what the visualizer looks like right now.

noriah commented 2 years ago

I actually want to look into this. I had originally tried to do something logarithmic, but I am not too well versed in the magic of audio analysis. I had done a logarithmic scale before, but the output was very sparse. I believe I need to fill out the missing bars with some smoothing algorithm that will follow the existing bars.

If you check out the code, it was supposed to be an attempt at some sort of non-linear distribution, but it ends up just being linear with a lot of wasted work.

This is definitely something I will be working on.

josephdong1000 commented 2 years ago

I think it should just be a matter of transforming the linear datapoints with a log function, but you would also have to decrease the spacing of samples for lower frequencies. I haven't taken a look at the code tho, and I don't really know how to program in go lol

Something I found that could help with the sampling frequency issue: https://stackoverflow.com/questions/32320028/convert-linear-audio-frequency-distribution-to-logarithmic-perceptual-distributi