Skip to content

Commit 4d7ccc8

Browse files
committed
FFTWindows avoid double constants
1 parent 6ffad11 commit 4d7ccc8

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

src/AudioLibs/FFT/FFTWindows.h

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ class WindowFunction {
3131

3232
inline float ratio(int idx) {
3333
float result = (static_cast<float>(idx)) / samples_minus_1;
34-
return result>1.0 ? 1.0 : result;
34+
return result>1.0f ? 1.0f : result;
3535
}
3636

3737
inline int samples() { return i_samples; }
3838
virtual float factor(int idx) = 0;
3939

4040
protected:
41-
float samples_minus_1 = 0;
41+
float samples_minus_1 = 0.0f;
4242
int i_samples = 0;
43-
const float twoPi = 6.28318531;
44-
const float fourPi = 12.56637061;
45-
const float sixPi = 18.84955593;
43+
const float twoPi = 6.28318531f;
44+
const float fourPi = 12.56637061f;
45+
const float sixPi = 18.84955593f;
4646
};
4747

4848
/**
@@ -93,7 +93,7 @@ class BufferedWindow : public WindowFunction {
9393
class Rectange : public WindowFunction {
9494
public:
9595
Rectange() = default;
96-
float factor(int idx) { return 1.0; }
96+
float factor(int idx) { return 1.0f; }
9797
};
9898

9999
/**
@@ -105,7 +105,7 @@ class Hamming : public WindowFunction {
105105
public:
106106
Hamming() = default;
107107
float factor(int idx) {
108-
return 0.54 - (0.46 * cos(twoPi * ratio(idx)));
108+
return 0.54f - (0.46f * cos(twoPi * ratio(idx)));
109109
}
110110
};
111111

@@ -118,7 +118,7 @@ class Hann : public WindowFunction {
118118
public:
119119
Hann() = default;
120120
float factor(int idx) {
121-
return 0.54 * (1.0 - cos(twoPi * ratio(idx)));
121+
return 0.54f * (1.0f - cos(twoPi * ratio(idx)));
122122
}
123123
};
124124

@@ -131,8 +131,8 @@ class Triangle : public WindowFunction {
131131
public:
132132
Triangle() = default;
133133
float factor(int idx) {
134-
return 1.0 - ((2.0 * fabs((idx - 1) -
135-
(static_cast<float>(i_samples - 1) / 2.0))) /
134+
return 1.0f - ((2.0f * fabs((idx - 1) -
135+
(static_cast<float>(i_samples - 1) / 2.0f))) /
136136
samples_minus_1);
137137
}
138138
};
@@ -148,8 +148,8 @@ class Nuttall : public WindowFunction {
148148
Nuttall() = default;
149149
float factor(int idx) {
150150
float r = ratio(idx);
151-
return 0.355768 - (0.487396 * (cos(twoPi * r))) +
152-
(0.144232 * (cos(fourPi * r))) - (0.012604 * (cos(sixPi * r)));
151+
return 0.355768f - (0.487396f * (cos(twoPi * r))) +
152+
(0.144232f * (cos(fourPi * r))) - (0.012604f * (cos(sixPi * r)));
153153
}
154154
};
155155

@@ -164,8 +164,8 @@ class Blackman : public WindowFunction {
164164
Blackman() = default;
165165
float factor(int idx) {
166166
float r = ratio(idx);
167-
return 0.42323 - (0.49755 * (cos(twoPi * r))) +
168-
(0.07922 * (cos(fourPi * r)));
167+
return 0.42323f - (0.49755f * (cos(twoPi * r))) +
168+
(0.07922f * (cos(fourPi * r)));
169169
}
170170
};
171171

@@ -179,8 +179,8 @@ class BlackmanNuttall : public WindowFunction {
179179
BlackmanNuttall() = default;
180180
float factor(int idx) {
181181
float r = ratio(idx);
182-
return 0.3635819 - (0.4891775 * (cos(twoPi * r))) +
183-
(0.1365995 * (cos(fourPi * r))) - (0.0106411 * (cos(sixPi * r)));
182+
return 0.3635819f - (0.4891775f * (cos(twoPi * r))) +
183+
(0.1365995f * (cos(fourPi * r))) - (0.0106411f * (cos(sixPi * r)));
184184
}
185185
};
186186

@@ -194,8 +194,8 @@ class BlackmanHarris : public WindowFunction {
194194
BlackmanHarris() = default;
195195
float factor(int idx) {
196196
float r = ratio(idx);
197-
return 0.35875 - (0.48829 * (cos(twoPi * r))) +
198-
(0.14128 * (cos(fourPi * r))) - (0.01168 * (cos(sixPi * r)));
197+
return 0.35875f - (0.48829f * (cos(twoPi * r))) +
198+
(0.14128f * (cos(fourPi * r))) - (0.01168f * (cos(sixPi * r)));
199199
}
200200
};
201201

@@ -209,8 +209,8 @@ class FlatTop : public WindowFunction {
209209
FlatTop() = default;
210210
float factor(int idx) {
211211
float r = ratio(idx);
212-
return 0.2810639 - (0.5208972 * cos(twoPi * r)) +
213-
(0.1980399 * cos(fourPi * r));
212+
return 0.2810639f - (0.5208972f * cos(twoPi * r)) +
213+
(0.1980399f * cos(fourPi * r));
214214
}
215215
};
216216

@@ -223,8 +223,8 @@ class Welch : public WindowFunction {
223223
public:
224224
Welch() = default;
225225
float factor(int idx) {
226-
float tmp = (((idx - 1) - samples_minus_1 / 2.0) / (samples_minus_1 / 2.0));
227-
return 1.0 - (tmp*tmp);
226+
float tmp = (((idx - 1) - samples_minus_1 / 2.0f) / (samples_minus_1 / 2.0f));
227+
return 1.0f - (tmp*tmp);
228228
}
229229
};
230230

0 commit comments

Comments
 (0)