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