c@119: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ c@119: /* c@119: Constant-Q library c@119: Copyright (c) 2013-2014 Queen Mary, University of London c@119: c@119: Permission is hereby granted, free of charge, to any person c@119: obtaining a copy of this software and associated documentation c@119: files (the "Software"), to deal in the Software without c@119: restriction, including without limitation the rights to use, copy, c@119: modify, merge, publish, distribute, sublicense, and/or sell copies c@119: of the Software, and to permit persons to whom the Software is c@119: furnished to do so, subject to the following conditions: c@119: c@119: The above copyright notice and this permission notice shall be c@119: included in all copies or substantial portions of the Software. c@119: c@119: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, c@119: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF c@119: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND c@119: NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY c@119: CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF c@119: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION c@119: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. c@119: c@119: Except as contained in this notice, the names of the Centre for c@119: Digital Music; Queen Mary, University of London; and Chris Cannam c@119: shall not be used in advertising or otherwise to promote the sale, c@119: use or other dealings in this Software without prior written c@119: authorization. c@119: */ c@119: c@119: #ifndef KAISER_WINDOW_H c@119: #define KAISER_WINDOW_H c@119: c@119: #include c@119: #include c@119: c@179: #include "pi.h" c@179: c@119: /** c@119: * Kaiser window: A windower whose bandwidth and sidelobe height c@119: * (signal-noise ratio) can be specified. These parameters are traded c@119: * off against the window length. c@119: */ c@119: class KaiserWindow c@119: { c@119: public: c@119: struct Parameters { c@119: int length; c@119: double beta; c@119: }; c@119: c@119: /** c@119: * Construct a Kaiser windower with the given length and beta c@119: * parameter. c@119: */ c@119: KaiserWindow(Parameters p) : m_length(p.length), m_beta(p.beta) { init(); } c@119: c@119: /** c@119: * Construct a Kaiser windower with the given attenuation in dB c@119: * and transition width in samples. c@119: */ c@119: static KaiserWindow byTransitionWidth(double attenuation, c@119: double transition) { c@119: return KaiserWindow c@119: (parametersForTransitionWidth(attenuation, transition)); c@119: } c@119: c@119: /** c@119: * Construct a Kaiser windower with the given attenuation in dB c@119: * and transition bandwidth in Hz for the given samplerate. c@119: */ c@119: static KaiserWindow byBandwidth(double attenuation, c@119: double bandwidth, c@119: double samplerate) { c@119: return KaiserWindow c@119: (parametersForBandwidth(attenuation, bandwidth, samplerate)); c@119: } c@119: c@119: /** c@119: * Obtain the parameters necessary for a Kaiser window of the c@119: * given attenuation in dB and transition width in samples. c@119: */ c@119: static Parameters parametersForTransitionWidth(double attenuation, c@119: double transition); c@119: c@119: /** c@119: * Obtain the parameters necessary for a Kaiser window of the c@119: * given attenuation in dB and transition bandwidth in Hz for the c@119: * given samplerate. c@119: */ c@119: static Parameters parametersForBandwidth(double attenuation, c@119: double bandwidth, c@119: double samplerate) { c@119: return parametersForTransitionWidth c@119: (attenuation, (bandwidth * 2 * M_PI) / samplerate); c@119: } c@119: c@119: int getLength() const { c@119: return m_length; c@119: } c@119: c@119: const double *getWindow() const { c@119: return m_window.data(); c@119: } c@119: c@119: void cut(double *src) const { c@119: cut(src, src); c@119: } c@119: c@119: void cut(const double *src, double *dst) const { c@119: for (int i = 0; i < m_length; ++i) { c@119: dst[i] = src[i] * m_window[i]; c@119: } c@119: } c@119: c@119: private: c@119: int m_length; c@119: double m_beta; c@119: std::vector m_window; c@119: c@119: void init(); c@119: }; c@119: c@119: #endif