Skip to content

Commit

Permalink
Equalizer plugin, refinement to analysis display (#3530)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
curlymorphic authored and Umcaruje committed Jul 15, 2017
1 parent 0abe0a5 commit b3054fd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
23 changes: 21 additions & 2 deletions plugins/Eq/EqSpectrumView.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/* eqspectrumview.cpp - implementation of EqSpectrumView class.
*
* Copyright (c) 2014 David French <dave/dot/french3/at/googlemail/dot/com>
* Copyright (c) 2014-2017, David French <dave/dot/french3/at/googlemail/dot/com>
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
Expand Down Expand Up @@ -38,6 +37,20 @@ 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 );

//initialize Blackman-Harris window, constants taken from
//https://en.wikipedia.org/wiki/Window_function#A_list_of_window_functions
const float a0 = 0.35875;
const float a1 = 0.48829;
const float a2 = 0.14128;
const float a3 = 0.01168;

for(int i = 0; i < FFT_BUFFER_SIZE; i++)
{
m_fftWindow[i] = ( a0 - a1 * cosf( 2 * F_PI * i / (float)FFT_BUFFER_SIZE - 1 )
+ a2 * cosf( 4 * F_PI * i / (float)FFT_BUFFER_SIZE-1)
- a3 * cos( 6 * F_PI * i / (float)FFT_BUFFER_SIZE - 1.0 ));
}
clear();
}

Expand Down Expand Up @@ -84,6 +97,12 @@ void EqAnalyser::analyze( sampleFrame *buf, const fpp_t frames )
const int LOWEST_FREQ = 0;
const int HIGHEST_FREQ = m_sampleRate / 2;

//apply FFT window
for( int i = 0; i < FFT_BUFFER_SIZE; i++ )
{
m_buffer[i] = m_buffer[i] * m_fftWindow[i];
}

fftwf_execute( m_fftPlan );
absspec( m_specBuf, m_absSpecBuf, FFT_BUFFER_SIZE+1 );

Expand Down
2 changes: 1 addition & 1 deletion plugins/Eq/EqSpectrumView.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@


const int MAX_BANDS = 2048;

class EqAnalyser
{
public:
Expand Down Expand Up @@ -61,6 +60,7 @@ class EqAnalyser
int m_sampleRate;
bool m_active;
bool m_inProgress;
float m_fftWindow[FFT_BUFFER_SIZE];
};


Expand Down

0 comments on commit b3054fd

Please sign in to comment.