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