1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
5 Centre for Digital Music, Queen Mary, University of London.
6 This file Copyright 2006 Chris Cannam.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version. See the file
12 COPYING included with this distribution for more information.
37 * Construct a windower of the given type.
39 Window(WindowType type, size_t size) : m_type(type), m_size(size) { encache(); }
40 Window(const Window &w) : m_type(w.m_type), m_size(w.m_size) { encache(); }
41 Window &operator=(const Window &w) {
42 if (&w == this) return *this;
48 virtual ~Window() { delete[] m_cache; }
50 void cut(T *src) const { cut(src, src); }
51 void cut(const T *src, T *dst) const {
52 for (size_t i = 0; i < m_size; ++i) dst[i] = src[i] * m_cache[i];
55 WindowType getType() const { return m_type; }
56 size_t getSize() const { return m_size; }
67 void Window<T>::encache()
72 for (i = 0; i < n; ++i) mult[i] = 1.0;
76 case RectangularWindow:
77 for (i = 0; i < n; ++i) {
78 mult[i] = mult[i] * 0.5;
83 for (i = 0; i < n/2; ++i) {
84 mult[i] = mult[i] * (i / T(n/2));
85 mult[i + n/2] = mult[i + n/2] * (1.0 - (i / T(n/2)));
90 for (i = 0; i < n; ++i) {
91 mult[i] = mult[i] * (0.54 - 0.46 * cos(2 * M_PI * i / n));
96 for (i = 0; i < n; ++i) {
97 mult[i] = mult[i] * (0.50 - 0.50 * cos(2 * M_PI * i / n));
102 for (i = 0; i < n; ++i) {
103 mult[i] = mult[i] * (0.42 - 0.50 * cos(2 * M_PI * i / n)
104 + 0.08 * cos(4 * M_PI * i / n));
109 for (i = 0; i < n; ++i) {
110 mult[i] = mult[i] * exp((-1.0 / (n*n)) * ((T(2*i) - n) *
116 for (i = 0; i < n; ++i) {
117 mult[i] = mult[i] * (1.0 - fabs((T(2*i) - n) / T(n + 1)));