annotate src/window_makers.hpp @ 0:add35537fdbb tip

Initial import
author irh <ian.r.hobson@gmail.com>
date Thu, 25 Aug 2011 11:05:55 +0100
parents
children
rev   line source
ian@0 1 // Copyright 2011, Ian Hobson.
ian@0 2 //
ian@0 3 // This file is part of gpsynth.
ian@0 4 //
ian@0 5 // gpsynth is free software: you can redistribute it and/or modify
ian@0 6 // it under the terms of the GNU General Public License as published by
ian@0 7 // the Free Software Foundation, either version 3 of the License, or
ian@0 8 // (at your option) any later version.
ian@0 9 //
ian@0 10 // gpsynth is distributed in the hope that it will be useful,
ian@0 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
ian@0 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ian@0 13 // GNU General Public License for more details.
ian@0 14 //
ian@0 15 // You should have received a copy of the GNU General Public License
ian@0 16 // along with gpsynth in the file COPYING.
ian@0 17 // If not, see http://www.gnu.org/licenses/.
ian@0 18
ian@0 19 #pragma once
ian@0 20
ian@0 21 #include <cmath>
ian@0 22 #include <iterator>
ian@0 23
ian@0 24 namespace dsp {
ian@0 25
ian@0 26 template<typename OutputIterator>
ian@0 27 void BlackmanWindow(int size, OutputIterator output) {
ian@0 28 typedef typename std::iterator_traits<OutputIterator>::value_type T;
ian@0 29 T m1 = (M_PI * 2.0) / (size - 1.0);
ian@0 30 T m2 = (M_PI * 4.0) / (size - 1.0);
ian@0 31 for (T i = 0; i < size; i++) {
ian@0 32 *output++ = 0.42 - 0.5 * std::cos(i * m1) + 0.08 * std::cos(i * m2);
ian@0 33 }
ian@0 34 }
ian@0 35
ian@0 36 template<typename OutputIterator>
ian@0 37 void HannWindow(int size, OutputIterator output) {
ian@0 38 typedef typename std::iterator_traits<OutputIterator>::value_type T;
ian@0 39 T m = (M_PI * 2.0) / (size - 1.0);
ian@0 40 for (T i = 0; i < size; i++) {
ian@0 41 *output++ = 0.5 - 0.5 * std::cos(i * m);
ian@0 42 }
ian@0 43 }
ian@0 44
ian@0 45 template<typename OutputIterator>
ian@0 46 void HammingWindow(int size, OutputIterator output) {
ian@0 47 typedef typename std::iterator_traits<OutputIterator>::value_type T;
ian@0 48 T m = (M_PI * 2.0) / (size - 1.0);
ian@0 49 for (T i = 0; i < size; i++) {
ian@0 50 *output++ = 0.54 - 0.46 * std::cos(i * m);
ian@0 51 }
ian@0 52 }
ian@0 53
ian@0 54 };