summaryrefslogtreecommitdiff
path: root/gtk2_ardour/fft.cc
diff options
context:
space:
mode:
authorSampo Savolainen <v2@iki.fi>2008-10-20 18:57:34 +0000
committerSampo Savolainen <v2@iki.fi>2008-10-20 18:57:34 +0000
commita75868c767dc5a74f4b7361a6255972bad7f7c61 (patch)
treea9c2d38f35c8f85bc826ca7310f10073e7131539 /gtk2_ardour/fft.cc
parent820acf23009586ef4fe9cfbbfd3eb2f840012634 (diff)
Added facilities into PluginInsert for the GUI to gather parts of the real signal passed through the insert. Also added rudimentary plugin input/output difference analysis in the plugin eq gui for the collected signal.
git-svn-id: svn://localhost/ardour2/branches/3.0@3987 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'gtk2_ardour/fft.cc')
-rw-r--r--gtk2_ardour/fft.cc40
1 files changed, 38 insertions, 2 deletions
diff --git a/gtk2_ardour/fft.cc b/gtk2_ardour/fft.cc
index eda1a96e3f..f78a1e94ad 100644
--- a/gtk2_ardour/fft.cc
+++ b/gtk2_ardour/fft.cc
@@ -26,7 +26,8 @@
FFT::FFT(uint32_t windowSize)
: _window_size(windowSize),
_data_size(_window_size/2),
- _iterations(0)
+ _iterations(0),
+ _hann_window(0)
{
_fftInput = (float *) fftwf_malloc(sizeof(float) * _window_size);
@@ -50,12 +51,19 @@ FFT::reset()
}
void
-FFT::analyze(ARDOUR::Sample *input)
+FFT::analyze(ARDOUR::Sample *input, WindowingType windowing_type)
{
_iterations++;
memcpy(_fftInput, input, sizeof(float) * _window_size);
+ if (windowing_type == HANN) {
+ float *window = get_hann_window();
+ for (uint32_t i = 0; i < _window_size; i++) {
+ _fftInput[i] *= window[i];
+ }
+ }
+
fftwf_execute(_plan);
_power_at_bin[0] += _fftOutput[0] * _fftOutput[0];
@@ -96,9 +104,37 @@ FFT::calculate()
}
}
+float *
+FFT::get_hann_window()
+{
+ if (_hann_window)
+ return _hann_window;
+
+
+ _hann_window = (float *) malloc(sizeof(float) * _window_size);
+
+ double sum = 0.0;
+
+ for (uint32_t i=0; i < _window_size; i++) {
+ _hann_window[i]=0.81f * ( 0.5f - (0.5f * (float) cos(2.0f * M_PI * (float)i / (float)(_window_size))));
+ sum += _hann_window[i];
+ }
+
+ double isum = 1.0 / sum;
+
+ for (uint32_t i=0; i < _window_size; i++) {
+ _hann_window[i] *= isum;
+ }
+
+ return _hann_window;
+}
+
FFT::~FFT()
{
+ if (_hann_window) {
+ free(_hann_window);
+ }
fftwf_destroy_plan(_plan);
free(_power_at_bin);
free(_phase_at_bin);