c@349
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
c@349
|
2
|
c@349
|
3 /*
|
c@349
|
4 QM DSP library
|
c@349
|
5 Centre for Digital Music, Queen Mary, University of London.
|
c@349
|
6
|
c@349
|
7 This program is free software; you can redistribute it and/or
|
c@349
|
8 modify it under the terms of the GNU General Public License as
|
c@349
|
9 published by the Free Software Foundation; either version 2 of the
|
c@349
|
10 License, or (at your option) any later version. See the file
|
c@349
|
11 COPYING included with this distribution for more information.
|
c@349
|
12 */
|
c@349
|
13
|
c@349
|
14 #ifndef KAISER_WINDOW_H
|
c@349
|
15 #define KAISER_WINDOW_H
|
c@349
|
16
|
c@349
|
17 #include <vector>
|
c@349
|
18 #include <cmath>
|
c@349
|
19
|
c@377
|
20 /**
|
c@377
|
21 * Kaiser window: A windower whose bandwidth and sidelobe height
|
c@377
|
22 * (signal-noise ratio) can be specified. These parameters are traded
|
c@377
|
23 * off against the window length.
|
c@377
|
24 */
|
c@349
|
25 class KaiserWindow
|
c@349
|
26 {
|
c@349
|
27 public:
|
c@349
|
28 struct Parameters {
|
c@349
|
29 int length;
|
c@349
|
30 double beta;
|
c@349
|
31 };
|
c@349
|
32
|
c@349
|
33 /**
|
c@349
|
34 * Construct a Kaiser windower with the given length and beta
|
c@349
|
35 * parameter.
|
c@349
|
36 */
|
c@349
|
37 KaiserWindow(Parameters p) : m_length(p.length), m_beta(p.beta) { init(); }
|
c@349
|
38
|
c@349
|
39 /**
|
c@349
|
40 * Construct a Kaiser windower with the given attenuation in dB
|
c@349
|
41 * and transition width in samples.
|
c@349
|
42 */
|
c@349
|
43 static KaiserWindow byTransitionWidth(double attenuation,
|
c@349
|
44 double transition) {
|
c@349
|
45 return KaiserWindow
|
c@349
|
46 (parametersForTransitionWidth(attenuation, transition));
|
c@349
|
47 }
|
c@349
|
48
|
c@349
|
49 /**
|
c@349
|
50 * Construct a Kaiser windower with the given attenuation in dB
|
c@349
|
51 * and transition bandwidth in Hz for the given samplerate.
|
c@349
|
52 */
|
c@349
|
53 static KaiserWindow byBandwidth(double attenuation,
|
c@349
|
54 double bandwidth,
|
c@349
|
55 double samplerate) {
|
c@349
|
56 return KaiserWindow
|
c@349
|
57 (parametersForBandwidth(attenuation, bandwidth, samplerate));
|
c@349
|
58 }
|
c@349
|
59
|
c@349
|
60 /**
|
c@349
|
61 * Obtain the parameters necessary for a Kaiser window of the
|
c@349
|
62 * given attenuation in dB and transition width in samples.
|
c@349
|
63 */
|
c@349
|
64 static Parameters parametersForTransitionWidth(double attenuation,
|
c@349
|
65 double transition);
|
c@349
|
66
|
c@349
|
67 /**
|
c@349
|
68 * Obtain the parameters necessary for a Kaiser window of the
|
c@349
|
69 * given attenuation in dB and transition bandwidth in Hz for the
|
c@349
|
70 * given samplerate.
|
c@349
|
71 */
|
c@349
|
72 static Parameters parametersForBandwidth(double attenuation,
|
c@349
|
73 double bandwidth,
|
c@349
|
74 double samplerate) {
|
c@349
|
75 return parametersForTransitionWidth
|
c@349
|
76 (attenuation, (bandwidth * 2 * M_PI) / samplerate);
|
c@349
|
77 }
|
c@349
|
78
|
c@349
|
79 int getLength() const {
|
c@349
|
80 return m_length;
|
c@349
|
81 }
|
c@349
|
82
|
c@349
|
83 const double *getWindow() const {
|
c@349
|
84 return m_window.data();
|
c@349
|
85 }
|
c@349
|
86
|
c@349
|
87 void cut(double *src) const {
|
c@349
|
88 cut(src, src);
|
c@349
|
89 }
|
c@349
|
90
|
c@349
|
91 void cut(const double *src, double *dst) const {
|
c@349
|
92 for (int i = 0; i < m_length; ++i) {
|
c@349
|
93 dst[i] = src[i] * m_window[i];
|
c@349
|
94 }
|
c@349
|
95 }
|
c@349
|
96
|
c@349
|
97 private:
|
c@349
|
98 int m_length;
|
c@349
|
99 double m_beta;
|
c@349
|
100 std::vector<double> m_window;
|
c@349
|
101
|
c@349
|
102 void init();
|
c@349
|
103 };
|
c@349
|
104
|
c@349
|
105 #endif
|