1 /***************************************************************************
2 * Copyright (C) 2010 by Simon Andreas Eugster (simon.eu@gmail.com) *
3 * This file is part of kdenlive. See www.kdenlive.org. *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 ***************************************************************************/
15 //#define DEBUG_FFTTOOLS
24 // http://cplusplus.syntaxerrors.info/index.php?title=Cannot_declare_member_function_%E2%80%98static_int_Foo::bar%28%29%E2%80%99_to_have_static_linkage
25 const QVector<float> FFTTools::window(WindowType windowType, const int size, const float param)
27 // Deliberately avoid converting size to a float
28 // to keep mid an integer.
29 float mid = (size-1)/2;
31 QVector<float> window;
35 return QVector<float>(size+1, 1);
38 window = QVector<float>(size+1);
40 for (int x = 0; x < mid; x++) {
41 window[x] = x/mid + (mid-x)/mid*param;
43 for (int x = mid; x < size; x++) {
44 window[x] = (x-mid)/(max-mid) * param + (max-x)/(max-mid);
46 window[size] = .5 + param/2;
49 qDebug() << "Triangle window (factor " << window[size] << "):";
50 for (int i = 0; i < size; i++) {
51 qDebug() << window[i];
53 qDebug() << "Triangle window end.";
59 // Use a quick version of the Hamming window here: Instead of
60 // interpolating values between (-max/2) and (max/2)
61 // we use integer values instead, ranging from -mid to (max-mid).
62 window = QVector<float>(size+1);
64 for (int x = 0; x < size; x++) {
65 window[x] = .54 + .46 * cos( 2*M_PI*(x-mid) / size );
68 // Integrating the cosine over the window function results in
69 // an area of 0; So only the constant factor 0.54 counts.
73 qDebug() << "Hanning window (factor " << window[size] << "):";
74 for (int i = 0; i < size; i++) {
75 qDebug() << window[i];
77 qDebug() << "Hanning window end.";
84 return QVector<float>();