Mercurial > hg > gpsynth
view 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 |
line wrap: on
line source
// Copyright 2011, Ian Hobson. // // This file is part of gpsynth. // // gpsynth is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // gpsynth is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with gpsynth in the file COPYING. // If not, see http://www.gnu.org/licenses/. #pragma once #include <cmath> #include <iterator> namespace dsp { template<typename OutputIterator> void BlackmanWindow(int size, OutputIterator output) { typedef typename std::iterator_traits<OutputIterator>::value_type T; T m1 = (M_PI * 2.0) / (size - 1.0); T m2 = (M_PI * 4.0) / (size - 1.0); for (T i = 0; i < size; i++) { *output++ = 0.42 - 0.5 * std::cos(i * m1) + 0.08 * std::cos(i * m2); } } template<typename OutputIterator> void HannWindow(int size, OutputIterator output) { typedef typename std::iterator_traits<OutputIterator>::value_type T; T m = (M_PI * 2.0) / (size - 1.0); for (T i = 0; i < size; i++) { *output++ = 0.5 - 0.5 * std::cos(i * m); } } template<typename OutputIterator> void HammingWindow(int size, OutputIterator output) { typedef typename std::iterator_traits<OutputIterator>::value_type T; T m = (M_PI * 2.0) / (size - 1.0); for (T i = 0; i < size; i++) { *output++ = 0.54 - 0.46 * std::cos(i * m); } } };