univrsal / spectralizer

Audio visualizer plugin for obs-studio
GNU General Public License v2.0
591 stars 58 forks source link

Implement v1 of logarithmic frequency scale display #39

Closed lookeypl closed 3 years ago

lookeypl commented 3 years ago

This is more of a v1 of these changes. After I tinkered with code a little bit I found an issue which was already mentioned in obs_internal_source::update, which made the "quality" switch for log display unuseable. I decided to PR the code as it is anyway and then play around with some other changes and tweaks I have in mind cause I'm not even 100% sure it will help anything or be worth submitting in the end.

With that said, here's first implementation of displaying audio spectrum in logarithmic frequency scale. It's useful to display audio spectrum in a way that's more relatable to how humans percieve audio frequencies. Implementation is done by taking FFTW results (which are in linear frequency space), calculating magnitudes for each frequency and interpolating between them using Lanczos interpolation.

This is most useable on larger details (I've mostly implemented and tested it in 64 bins and above). At lower detail logspace conversion makes most of the spectrum display low frequencies only (this is less of a bug and more of a drawback of calculating frequencies for specific bins).

New controls:

There also was a "quality" control added, but I decided to hide it for now. Current implementation requires having sample_size = sample_rate / fps at most (as described by obs_internal_source::update) and increasing it made the spectrum broken. Higher detail would make the interpolation more precise so I looked through the code and I think I know what the issue is with this - I highlighted it more in visualizer_source.cpp at get_properties_for_visualiser function where the control is hidden. I'll try looking into it more now and see if my idea on how to fix this is worth including in the code.

univrsal commented 3 years ago

Thank you again for the time you put into this, I think this has to be one of the first code contributions I've gotten on any of my projects, so that's cool. I hope you didn't have too many issues deciphering my code :P. I'll try to test this tomorrow and then get CI going.