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@349: class KaiserWindow c@349: { c@349: public: c@349: struct Parameters { c@349: int length; c@349: 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, c@349: double transition) { c@349: return KaiserWindow c@349: (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, c@349: double bandwidth, c@349: double samplerate) { c@349: return KaiserWindow c@349: (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, c@349: 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, c@349: double bandwidth, c@349: double samplerate) { c@349: return parametersForTransitionWidth c@349: (attenuation, (bandwidth * 2 * M_PI) / samplerate); c@349: } c@349: c@349: int getLength() const { c@349: return m_length; c@349: } c@349: c@349: const double *getWindow() const { c@349: return m_window.data(); c@349: } c@349: c@349: void cut(double *src) const { c@349: cut(src, src); c@349: } c@349: c@349: void cut(const double *src, double *dst) const { c@349: for (int i = 0; i < m_length; ++i) { c@349: dst[i] = src[i] * m_window[i]; c@349: } 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