Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Equalizer plugin, refinement to analysis display #3530

Merged
merged 1 commit into from
Jul 15, 2017
Merged

Equalizer plugin, refinement to analysis display #3530

merged 1 commit into from
Jul 15, 2017

Conversation

curlymorphic
Copy link
Contributor

@curlymorphic curlymorphic commented May 2, 2017

The spectral analysis was using a rectangle window, leading to high spectral leakage.
This pull request uses the Blackman-Harris window to give a display more representative of the audio.

Fixes #2703

@@ -38,6 +38,21 @@ EqAnalyser::EqAnalyser() :
m_inProgress=false;
m_specBuf = ( fftwf_complex * ) fftwf_malloc( ( FFT_BUFFER_SIZE + 1 ) * sizeof( fftwf_complex ) );
m_fftPlan = fftwf_plan_dft_r2c_1d( FFT_BUFFER_SIZE*2, m_buffer, m_specBuf, FFTW_MEASURE );

//initilise BalckmanHarris window, constants taken from
//https://en.wikipedia.org/wiki/Window_function#A_list_of_window_functions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling...

-	//initilise BalckmanHarris window, constants taken from
+	//initialize BlackmanHarris window, constants taken from

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also there's a dash there, Blackman-Harris

@tresf
Copy link
Member

tresf commented May 3, 2017

@michaelgregorius do you have time to test and approve this pull request?

@michaelgregorius
Copy link
Contributor

@tresf, @curlymorphic: I had a look at the changed code and also compiled the branch myself to test it with a simple sine wave at 110Hz again.

First something that I noticed while looking at the code. It might be worthwhile to put the code that generates the window into a separate class in case we decide later to also implement other windowing functions.

As for the practical test it seems that unfortunately the patch doesn't have a big effect in the tested case.

Here's the EQ from master:
3530-sine-from-master

And here's the same signal with the patch applied:
3530-sine-from-branch

For reference here's the same signal shown in the frequency analyzer from REAPER using a buffer size of 2048:
reaper-blackman-harris-2048

Please note that LMMS cuts off the display at around -18 dB FS and that that's the reason why the plots don't look almost identical.

Judging by the plots and looking at the changed code the implementation seems to be correct. However, it seems that the main culprit for the high leakage is the buffer size of 2048 that's used for the FFT. If I set the buffer size to 32768 in the REAPER frequency analyzer the peak for the test signal becomes very sharp and does not spill over.

I think the following features might be interesting for the analyzer:

  • The ability to switch the windowing function.
  • The ability to switch the buffer sizes.
  • The ability to switch the scales from -18 dB to smaller values.

The reason for the last request is that some people mix with signals peaking at around -18 dB to have enough headroom. If you do this in LMMS and send such a channel through the EQ you will likely see almost nothing in the plot window.

Sorry, for requesting all this here. I usually hate pull requests that request more and more features myself. 😉

If you want we can add separate issues for these requests.

@curlymorphic
Copy link
Contributor Author

@michaelgregorius

Thanks for the in-depth report.

I will have to check the range on the display when I'm at my pc, but its alot more than the -18dB, its just squashed vertically when compared to reapers output. The +-18dB is the gain 'for the eq controls. It could be an idea to add the analysis scale on the right hand side.
What I am going to do is write the content of the fft buffer to a csv file and plot the curves, as I want to chech the display when over a larger y axis.

"First something that I noticed while looking at the code. It might be worthwhile to put the code that generates the window into a separate class in case we decide later to also implement other windowing functions"

I would agree. The fft-helper class, but that would cause confusion, as there is already a function there, that's suposed to do the windowing, that iirc is used in the spectrum analyzer plugin. However there are some problems with it. It calculates the window incorrectly, it also calculates the window for each sample played, 2 trig functions and 2 divides per sample is just silly.
I don't want to change the code for another plugin this close to a release.

"I think the following features might be interesting for the analyzer:

The ability to switch the windowing function.
The ability to switch the buffer sizes.
The ability to switch the scales from -18 dB to smaller values."

These are all good ideas, I was tempted to add these to this pull request but i decided againt adding new features at this stage. I do think it would be a good idea to add these suggested features, but in a seperate pr aimed at master. I can do a mock up of the additional features, in the not to distant future, but i would prefer to fix current bugs first.

"If you want we can add separate issues for these requests." Yes please.

@Umcaruje
Copy link
Member

Umcaruje commented May 3, 2017

I think you should try out the von Hann window, it's the default in calf analyzer and works pretty good. When using the blackman-harris windowing in the calf analyzer it added a lot of weird harmonics to the sine waves, while the von Hann window really seemed like the best choice.

@Umcaruje
Copy link
Member

Umcaruje commented May 3, 2017

If I set the buffer size to 32768

Wouldn't that make the latency on the EQ go through the roof?

@curlymorphic
Copy link
Contributor Author

Wouldn't that make the latency on the EQ go through the roof?

Its the trade off between frequency and time resolution.

I think you should try out the von Hann window,

Thats a great idea, maybe for the update aimed after 1.2 release, we should collate a list of what windowing functions users would like, and any additional functionally required then plan and evaluate the expansion. I am keen to do this, could be a nice team project.

@michaelgregorius
Copy link
Contributor

Wouldn't that make the latency on the EQ go through the roof?

Yes, bigger windows definitively introduce some latency. However, I assume that this would only affect the graphical display and not the processing of the signal itself.

I am keen to do this, could be a nice team project.

I agree and I think that LMMS needs more of such team efforts/projects. Right now LMMS seems to be mainly developed by individual developers who contribute with pull requests. Obviously there is a limit to what a single developer can do and this keeps the project from implementing the bigger changes that are needed/wanted like a better separation between the core and GUI classes, realtime safe operations or the single window GUI.

@curlymorphic
Copy link
Contributor Author

@Umcaruje
I have changed the fft window to use a Von Hann function, to see what you prefer?

I will remove the unused windowing function code, when a decision has been made as to what is preferred.

@Umcaruje Umcaruje added this to the 1.2.0 milestone May 14, 2017
@PhysSong
Copy link
Member

PhysSong commented Jun 7, 2017

Maybe it will be better to separate window initializing code to some new functions and implement switching between window functions.
If it is not needed for now, just providing windowing toggle button will be better.

@michaelgregorius
Copy link
Contributor

@curlymorphic I have added #3624, #3625 and #3626 to deal with the aforementioned features separately.

@PhysSong I agree that it would be a good idea to have a class or a collection of functions that can generate different types of windowing functions that can be reused in different places.

@zonkmachine
Copy link
Member

@Umcaruje
I have changed the fft window to use a Von Hann function, to see what you prefer?

I will remove the unused windowing function code, when a decision has been made as to what is preferred.

I have no preferred windowing function myself. I've tested this and it works fine. I think we can merge it as it is with a von Hann window and the commented out Blackman-Harris function and then get back to it after 1.2 is released.

@PhysSong
Copy link
Member

Some windowing functions(Hamming and von Hann) are already implemented in fft_helpers.h, and I think it is possible to reuse them. If someone needs other window functions, simply adds it into fft_helpers.h and use it in plugins.

@zonkmachine
Copy link
Member

Some windowing functions(Hamming and von Hann) are already implemented in fft_helpers.h, and I think it is possible to reuse them. If someone needs other window functions, simply adds it into fft_helpers.h and use it in plugins.

I think that can be fixed later here: #3625
We're pressed to release 1.2.0 and this is a pretty good place to merge this in my opinion.

@LMMS/developers Merge?

@PhysSong
Copy link
Member

PhysSong commented Jul 6, 2017

Someone might want to see not windowed spectrum as before. I think windowing on/off button should exist.

@Umcaruje
Copy link
Member

Umcaruje commented Jul 7, 2017

@zonkmachine I really want to hear from @michaelgregorius on which windowing function is better, so we can clean up the code before merging.

@michaelgregorius
Copy link
Contributor

@Umcaruje I don't think there is something like a "better" function. As can be seen here they all have certain tradeoffs: https://en.wikipedia.org/wiki/Window_function#A_list_of_window_functions

It seems that the main lobe of the FFT is more pronounced with Blackman-Harris. So I'd use Blackman-Harris for now and then implement the switching of windowing functions as part of #3625. One option for the switching should be something like "Off (Rectangular)" so that it can also be turned off.

@curlymorphic
Copy link
Contributor Author

@Umcaruje @michaelgregorius

If we can make a decision I will amend the pull request to suit. My vote would be Blackman-Harris,

I would like to stick with the decision of not changing the fft_helpers class this close to a release. I do plan on implementing the windowing functions in the fft_helper class, but I shall aim that pull request at master due to changes affecting more than just this plugin. Changing the Equalizer plugin to use this code can then be handled in #3625.

@michaelgregorius
Copy link
Contributor

@curlymorphic Sound reasonable and good to me!

@curlymorphic
Copy link
Contributor Author

curlymorphic commented Jul 7, 2017

@PhysSong is already working on updating the fft_helper class for the master branch in #3625
Sorry, I only just noticed

The spectural analysis was using a rectangle window, leading to high spectural leakage.
This pull request uses the Blackman-Harris window to give a display more representative of the audio.
@Umcaruje
Copy link
Member

Umcaruje commented Jul 7, 2017

Yeah, Blackman-Harris gets a 👍 from me as well then, this should be merged

@Umcaruje Umcaruje merged commit b3054fd into LMMS:stable-1.2 Jul 15, 2017
sdasda7777 pushed a commit to sdasda7777/lmms that referenced this pull request Jun 28, 2022
The spectural analysis was using a rectangle window, leading to high spectural leakage.
This pull request uses the Blackman-Harris window to give a display more representative of the audio.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants