1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
//! FFT on real inputs (RFFT)
//!
//! This implementation takes advantage of the symmetry properties of
//! the FFT to compute an `N`-point RFFT by internally invoking an
//! `N/2`-point CFFT, roughly doubling the computation speed compared
//! to used a full `N`-point CFFT.
//!
//! The produced output is the first half out the output returned by
//! the corresponding `N`-point CFFT, i.e. the real DC value and
//! `N/2 - 1` positive-frequency terms. The negative-frequency terms
//! are not computed, since they can be calculated from the
//! positive-frequency terms and are therefore redundant.

use crate::rfft::*;
use num_complex::Complex32;

/// Perform an in-place 2-point RFFT.
///
/// # Example
///
/// ```
/// use microfft::real::rfft_2;
///
/// let mut input = [0.; 2];
/// let result = rfft_2(&mut input);
/// ```
///
/// # Panics
///
/// Panics if `input` has a length other than `2`.
#[inline]
pub fn rfft_2(input: &mut [f32]) -> &mut [Complex32] {
    assert_eq!(input.len(), 2);
    RFftN2::transform(input)
}

/// Perform an in-place 4-point RFFT.
///
/// # Example
///
/// ```
/// use microfft::real::rfft_4;
///
/// let mut input = [0.; 4];
/// let result = rfft_4(&mut input);
/// ```
///
/// # Panics
///
/// Panics if `input` has a length other than `4`.
#[inline]
pub fn rfft_4(input: &mut [f32]) -> &mut [Complex32] {
    assert_eq!(input.len(), 4);
    RFftN4::transform(input)
}

/// Perform an in-place 8-point RFFT.
///
/// # Example
///
/// ```
/// use microfft::real::rfft_8;
///
/// let mut input = [0.; 8];
/// let result = rfft_8(&mut input);
/// ```
///
/// # Panics
///
/// Panics if `input` has a length other than `8`.
#[cfg(any(
    feature = "maxn-8",
    feature = "maxn-16",
    feature = "maxn-32",
    feature = "maxn-64",
    feature = "maxn-128",
    feature = "maxn-256",
    feature = "maxn-512",
    feature = "maxn-1024",
    feature = "maxn-2048",
    feature = "maxn-4096",
))]
#[inline]
pub fn rfft_8(input: &mut [f32]) -> &mut [Complex32] {
    assert_eq!(input.len(), 8);
    RFftN8::transform(input)
}

/// Perform an in-place 16-point RFFT.
///
/// # Example
///
/// ```
/// use microfft::real::rfft_16;
///
/// let mut input = [0.; 16];
/// let result = rfft_16(&mut input);
/// ```
///
/// # Panics
///
/// Panics if `input` has a length other than `16`.
#[cfg(any(
    feature = "maxn-16",
    feature = "maxn-32",
    feature = "maxn-64",
    feature = "maxn-128",
    feature = "maxn-256",
    feature = "maxn-512",
    feature = "maxn-1024",
    feature = "maxn-2048",
    feature = "maxn-4096",
))]
#[inline]
pub fn rfft_16(input: &mut [f32]) -> &mut [Complex32] {
    assert_eq!(input.len(), 16);
    RFftN16::transform(input)
}

/// Perform an in-place 32-point RFFT.
///
/// # Example
///
/// ```
/// use microfft::real::rfft_32;
///
/// let mut input = [0.; 32];
/// let result = rfft_32(&mut input);
/// ```
///
/// # Panics
///
/// Panics if `input` has a length other than `32`.
#[cfg(any(
    feature = "maxn-32",
    feature = "maxn-64",
    feature = "maxn-128",
    feature = "maxn-256",
    feature = "maxn-512",
    feature = "maxn-1024",
    feature = "maxn-2048",
    feature = "maxn-4096",
))]
#[inline]
pub fn rfft_32(input: &mut [f32]) -> &mut [Complex32] {
    assert_eq!(input.len(), 32);
    RFftN32::transform(input)
}

/// Perform an in-place 64-point RFFT.
///
/// # Example
///
/// ```
/// use microfft::real::rfft_64;
///
/// let mut input = [0.; 64];
/// let result = rfft_64(&mut input);
/// ```
///
/// # Panics
///
/// Panics if `input` has a length other than `64`.
#[cfg(any(
    feature = "maxn-64",
    feature = "maxn-128",
    feature = "maxn-256",
    feature = "maxn-512",
    feature = "maxn-1024",
    feature = "maxn-2048",
    feature = "maxn-4096",
))]
#[inline]
pub fn rfft_64(input: &mut [f32]) -> &mut [Complex32] {
    assert_eq!(input.len(), 64);
    RFftN64::transform(input)
}

/// Perform an in-place 128-point RFFT.
///
/// # Example
///
/// ```
/// use microfft::real::rfft_128;
///
/// let mut input = [0.; 128];
/// let result = rfft_128(&mut input);
/// ```
///
/// # Panics
///
/// Panics if `input` has a length other than `128`.
#[cfg(any(
    feature = "maxn-128",
    feature = "maxn-256",
    feature = "maxn-512",
    feature = "maxn-1024",
    feature = "maxn-2048",
    feature = "maxn-4096",
))]
#[inline]
pub fn rfft_128(input: &mut [f32]) -> &mut [Complex32] {
    assert_eq!(input.len(), 128);
    RFftN128::transform(input)
}

/// Perform an in-place 256-point RFFT.
///
/// # Example
///
/// ```
/// use microfft::real::rfft_256;
///
/// let mut input = [0.; 256];
/// let result = rfft_256(&mut input);
/// ```
///
/// # Panics
///
/// Panics if `input` has a length other than `256`.
#[cfg(any(
    feature = "maxn-256",
    feature = "maxn-512",
    feature = "maxn-1024",
    feature = "maxn-2048",
    feature = "maxn-4096",
))]
#[inline]
pub fn rfft_256(input: &mut [f32]) -> &mut [Complex32] {
    assert_eq!(input.len(), 256);
    RFftN256::transform(input)
}

/// Perform an in-place 512-point RFFT.
///
/// # Example
///
/// ```
/// use microfft::real::rfft_512;
///
/// let mut input = [0.; 512];
/// let result = rfft_512(&mut input);
/// ```
///
/// # Panics
///
/// Panics if `input` has a length other than `512`.
#[cfg(any(
    feature = "maxn-512",
    feature = "maxn-1024",
    feature = "maxn-2048",
    feature = "maxn-4096",
))]
#[inline]
pub fn rfft_512(input: &mut [f32]) -> &mut [Complex32] {
    assert_eq!(input.len(), 512);
    RFftN512::transform(input)
}

/// Perform an in-place 1024-point RFFT.
///
/// # Example
///
/// ```
/// use microfft::real::rfft_1024;
///
/// let mut input = [0.; 1024];
/// let result = rfft_1024(&mut input);
/// ```
///
/// # Panics
///
/// Panics if `input` has a length other than `1024`.
#[cfg(any(feature = "maxn-1024", feature = "maxn-2048", feature = "maxn-4096"))]
#[inline]
pub fn rfft_1024(input: &mut [f32]) -> &mut [Complex32] {
    assert_eq!(input.len(), 1024);
    RFftN1024::transform(input)
}

/// Perform an in-place 2048-point RFFT.
///
/// # Example
///
/// ```
/// use microfft::real::rfft_2048;
///
/// let mut input = [0.; 2048];
/// let result = rfft_2048(&mut input);
/// ```
///
/// # Panics
///
/// Panics if `input` has a length other than `2048`.
#[cfg(any(feature = "maxn-2048", feature = "maxn-4096"))]
#[inline]
pub fn rfft_2048(input: &mut [f32]) -> &mut [Complex32] {
    assert_eq!(input.len(), 2048);
    RFftN2048::transform(input)
}

/// Perform an in-place 4096-point RFFT.
///
/// # Example
///
/// ```
/// use microfft::real::rfft_4096;
///
/// let mut input = [0.; 4096];
/// let result = rfft_4096(&mut input);
/// ```
///
/// # Panics
///
/// Panics if `input` has a length other than `4096`.
#[cfg(any(feature = "maxn-4096"))]
#[inline]
pub fn rfft_4096(input: &mut [f32]) -> &mut [Complex32] {
    assert_eq!(input.len(), 4096);
    RFftN4096::transform(input)
}