c@349: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ c@349: c@349: /* c@349: QM DSP library c@349: Centre for Digital Music, Queen Mary, University of London. c@349: c@349: This program is free software; you can redistribute it and/or c@349: modify it under the terms of the GNU General Public License as c@349: published by the Free Software Foundation; either version 2 of the c@349: License, or (at your option) any later version. See the file c@349: COPYING included with this distribution for more information. c@349: */ c@349: c@349: #ifndef KAISER_WINDOW_H c@349: #define KAISER_WINDOW_H c@349: c@349: #include c@349: #include c@349: c@377: /** c@377: * Kaiser window: A windower whose bandwidth and sidelobe height c@377: * (signal-noise ratio) can be specified. These parameters are traded c@377: * off against the window length. c@377: */ c@349: class KaiserWindow c@349: { c@349: public: c@349: struct Parameters { cannam@483: int length; cannam@483: double beta; c@349: }; c@349: c@349: /** c@349: * Construct a Kaiser windower with the given length and beta c@349: * parameter. c@349: */ c@349: KaiserWindow(Parameters p) : m_length(p.length), m_beta(p.beta) { init(); } c@349: c@349: /** c@349: * Construct a Kaiser windower with the given attenuation in dB c@349: * and transition width in samples. c@349: */ c@349: static KaiserWindow byTransitionWidth(double attenuation, cannam@483: double transition) { cannam@483: return KaiserWindow cannam@483: (parametersForTransitionWidth(attenuation, transition)); c@349: } c@349: c@349: /** c@349: * Construct a Kaiser windower with the given attenuation in dB c@349: * and transition bandwidth in Hz for the given samplerate. c@349: */ c@349: static KaiserWindow byBandwidth(double attenuation, cannam@483: double bandwidth, cannam@483: double samplerate) { cannam@483: return KaiserWindow cannam@483: (parametersForBandwidth(attenuation, bandwidth, samplerate)); c@349: } c@349: c@349: /** c@349: * Obtain the parameters necessary for a Kaiser window of the c@349: * given attenuation in dB and transition width in samples. c@349: */ c@349: static Parameters parametersForTransitionWidth(double attenuation, cannam@483: double transition); c@349: c@349: /** c@349: * Obtain the parameters necessary for a Kaiser window of the c@349: * given attenuation in dB and transition bandwidth in Hz for the c@349: * given samplerate. c@349: */ c@349: static Parameters parametersForBandwidth(double attenuation, cannam@483: double bandwidth, cannam@483: double samplerate) { cannam@483: return parametersForTransitionWidth cannam@483: (attenuation, (bandwidth * 2 * M_PI) / samplerate); c@349: } c@349: c@349: int getLength() const { cannam@483: return m_length; c@349: } c@349: c@349: const double *getWindow() const { cannam@483: return m_window.data(); c@349: } c@349: c@349: void cut(double *src) const { cannam@483: cut(src, src); c@349: } c@349: c@349: void cut(const double *src, double *dst) const { cannam@483: for (int i = 0; i < m_length; ++i) { cannam@483: dst[i] = src[i] * m_window[i]; cannam@483: } c@349: } c@349: c@349: private: c@349: int m_length; c@349: double m_beta; c@349: std::vector m_window; c@349: c@349: void init(); c@349: }; c@349: c@349: #endif