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
use crate::paste::paste;
use crate::Value;
use ffi::FFI;
macro_rules! gsl_fft_wavetable {
($rust_name:ident, $name:ident, $complex_rust_name:ident, $complex_name:ident, $ty:ident $(, $extra:ident)?) => (
paste! {
ffi_wrapper!(
$rust_name,
*mut sys::[<$name _wavetable $($extra)?>],
[<$name _wavetable $($extra)? _free>]
);
impl $rust_name {
#[doc(alias = $name _wavetable $($extra)? _alloc)]
pub fn new(n: usize) -> Option<Self> {
let tmp = unsafe { sys::[<$name _wavetable $($extra)? _alloc>](n) };
if tmp.is_null() {
None
} else {
Some(Self::wrap(tmp))
}
}
pub fn nf(&self) -> usize {
unsafe { (*self.unwrap_shared()).nf }
}
pub fn factor(&self) -> &[usize] {
unsafe { &(*self.unwrap_shared()).factor }
}
pub fn factor_mut(&mut self) -> &mut [usize] {
unsafe { &mut (*self.unwrap_unique()).factor }
}
}
ffi_wrapper!(
$complex_rust_name,
*mut sys::$complex_name,
[<$complex_name _free>]
);
impl $complex_rust_name {
#[doc(alias = $complex_name _alloc)]
pub fn new(n: usize) -> Option<Self> {
let tmp = unsafe { sys::[<$complex_name _alloc>](n) };
if tmp.is_null() {
None
} else {
Some(Self::wrap(tmp))
}
}
#[doc(alias = $name $($extra)? _forward)]
pub fn forward(
&mut self,
data: &mut [$ty],
stride: usize,
n: usize,
wavetable: &$rust_name,
) -> Value {
Value::from(unsafe {
sys::[<$name $($extra)? _forward>](
data.as_mut_ptr(),
stride,
n,
wavetable.unwrap_shared(),
self.unwrap_unique(),
)
})
}
#[doc(alias = $name $($extra)? _transform)]
pub fn transform(
&mut self,
data: &mut [$ty],
stride: usize,
n: usize,
wavetable: &$rust_name,
sign: ::FftDirection,
) -> Value {
Value::from(unsafe {
sys::[<$name $($extra)? _transform>](
data.as_mut_ptr(),
stride,
n,
wavetable.unwrap_shared(),
self.unwrap_unique(),
sign.into(),
)
})
}
#[doc(alias = $name $($extra)? _backward)]
pub fn backward(
&mut self,
data: &mut [$ty],
stride: usize,
n: usize,
wavetable: &$rust_name,
) -> Value {
Value::from(unsafe {
sys::[<$name $($extra)? _backward>](
data.as_mut_ptr(),
stride,
n,
wavetable.unwrap_shared(),
self.unwrap_unique(),
)
})
}
#[doc(alias = $name $($extra)? _inverse)]
pub fn inverse(
&mut self,
data: &mut [$ty],
stride: usize,
n: usize,
wavetable: &$rust_name,
) -> Value {
Value::from(unsafe {
sys::[<$name $($extra)? _inverse>](
data.as_mut_ptr(),
stride,
n,
wavetable.unwrap_shared(),
self.unwrap_unique(),
)
})
}
}
}
);
}
gsl_fft_wavetable!(
FftComplexF64WaveTable,
gsl_fft_complex,
FftComplexF64Workspace,
gsl_fft_complex_workspace,
f64
);
gsl_fft_wavetable!(
FftComplexF32WaveTable,
gsl_fft_complex,
FftComplexF32Workspace,
gsl_fft_complex_workspace_float,
f32,
_float
);