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