@@ -40,10 +40,11 @@ for (T, suff) in ((Float64, "D"), (Float32, ""))
40
40
if (rsize < xsize + ksize - 1 )
41
41
error (" 'result' must have at least length(X) + length(K) - 1 elements" )
42
42
end
43
- xpadded:: Vector{$T} = [zeros ($ T, ksize- 1 ); X; zeros ($ T, ksize)]
44
- ccall (($ (string (" vDSP_conv" , suff), libacc)), Cvoid,
45
- (Ptr{$ T}, Int64, Ptr{$ T}, Int64, Ptr{$ T}, Int64, UInt64, UInt64),
46
- xpadded, 1 , pointer (K, ksize), - 1 , result, 1 , rsize, ksize)
43
+ xpadded:: Vector{$T} = [zeros ($ T, ksize - 1 ); X; zeros ($ T, ksize)]
44
+ fptr = get_fptr ($ (string (" vDSP_conv" , suff)))
45
+ ccall (fptr, Cvoid,
46
+ (Ptr{$ T}, Int64, Ptr{$ T}, Int64, Ptr{$ T}, Int64, UInt64, UInt64),
47
+ xpadded, 1 , pointer (K, ksize), - 1 , result, 1 , rsize, ksize)
47
48
return result
48
49
end
49
50
end
@@ -87,10 +88,11 @@ for (T, suff) in ((Float64, "D"), (Float32, ""))
87
88
if (rsize < xsize + ysize - 1 )
88
89
error (" 'result' must have at least length(X) + length(Y) - 1 elements" )
89
90
end
90
- xpadded:: Vector{$T} = [zeros ($ T, ysize- 1 ); X; zeros ($ T, ysize)]
91
- ccall (($ (string (" vDSP_conv" , suff), libacc)), Cvoid,
92
- (Ptr{$ T}, Int64, Ptr{$ T}, Int64, Ptr{$ T}, Int64, UInt64, UInt64),
93
- xpadded, 1 , Y, 1 , result, 1 , rsize, ysize)
91
+ xpadded:: Vector{$T} = [zeros ($ T, ysize - 1 ); X; zeros ($ T, ysize)]
92
+ fptr = get_fptr ($ (string (" vDSP_conv" , suff)))
93
+ ccall (fptr, Cvoid,
94
+ (Ptr{$ T}, Int64, Ptr{$ T}, Int64, Ptr{$ T}, Int64, UInt64, UInt64),
95
+ xpadded, 1 , Y, 1 , result, 1 , rsize, ysize)
94
96
return result
95
97
end
96
98
end
@@ -134,7 +136,7 @@ for (T, suff) in ((Float64, "D"), (Float32, ""))
134
136
end
135
137
136
138
# # == Biquadratic/IIR filtering
137
- for (T, suff) in ((Float64, " D" ), )
139
+ for (T, suff) in ((Float64, " D" ),)
138
140
139
141
"""
140
142
Initializes a vDSP_biquad_setup for use with vDSP_biquad. A multi-section filter
@@ -145,14 +147,15 @@ for (T, suff) in ((Float64, "D"), )
145
147
Returns: Biquad{T}
146
148
"""
147
149
@eval begin
148
- function biquadcreate (coefficients:: Vector{$T} , sections:: Int )
149
- if length (coefficients) < 5 * sections
150
+ function biquadcreate (coefficients:: Vector{$T} , sections:: Int )
151
+ if length (coefficients) < 5 * sections
150
152
error (" Incomplete biquad specification provided - coefficients must
151
153
contain 5 elements for each filter section" )
152
154
end
153
- setup = ccall (($ (string (" vDSP_biquad_CreateSetup" , suff), libacc)), Ptr{Cvoid},
154
- (Ptr{$ T}, UInt64),
155
- coefficients, sections)
155
+ fptr = get_fptr ($ (string (" vDSP_biquad_CreateSetup" , suff)))
156
+ setup = ccall (fptr, Ptr{Cvoid},
157
+ (Ptr{$ T}, UInt64),
158
+ coefficients, sections)
156
159
return Biquad ($ T, setup, sections)
157
160
end
158
161
end
@@ -167,14 +170,15 @@ for (T, suff) in ((Float64, "D"), )
167
170
"""
168
171
@eval begin
169
172
function biquad (X:: Vector{$T} , delays:: Vector{$T} , numelem:: Int , biquad:: Biquad{$T} )
170
- if length (delays) < (2 * (biquad. sections)+ 2 )
173
+ if length (delays) < (2 * (biquad. sections) + 2 )
171
174
error (" Incomplete delay specification provided - delays must contain 2*M + 2
172
175
values where M is the number of sections in the biquad" )
173
176
end
174
177
result:: Vector{$T} = similar (X)
175
- ccall (($ (string (" vDSP_biquad" , suff), libacc)), Cvoid,
176
- (Ptr{Cvoid}, Ptr{$ T}, Ptr{$ T}, Int64, Ptr{$ T}, Int64, UInt64),
177
- biquad. setup, delays, X, 1 , result, 1 , numelem)
178
+ fptr = get_fptr ($ (string (" vDSP_biquad" , suff)))
179
+ ccall (fptr, Cvoid,
180
+ (Ptr{Cvoid}, Ptr{$ T}, Ptr{$ T}, Int64, Ptr{$ T}, Int64, UInt64),
181
+ biquad. setup, delays, X, 1 , result, 1 , numelem)
178
182
return result
179
183
end
180
184
end
@@ -189,9 +193,10 @@ for (T, suff) in ((Float64, "D"), )
189
193
"""
190
194
@eval begin
191
195
function biquaddestroy (biquad:: Biquad{$T} )
192
- ccall (($ (string (" vDSP_biquad_DestroySetup" , suff), libacc)), Cvoid,
193
- (Ptr{Cvoid}, ),
194
- biquad. setup)
196
+ fptr = get_fptr ($ (string (" vDSP_biquad_DestroySetup" , suff)))
197
+ ccall (fptr, Cvoid,
198
+ (Ptr{Cvoid},),
199
+ biquad. setup)
195
200
end
196
201
end
197
202
end
@@ -205,7 +210,7 @@ Generates a Blackman window of length 'length'. Default return type
205
210
is Vector{Float64}, but if rtype=Float32, Vector{Float32}
206
211
will be returned.
207
212
"""
208
- function blackman (length:: Int , rtype:: DataType = Float64)
213
+ function blackman (length:: Int , rtype:: DataType = Float64)
209
214
result:: Vector{rtype} = Array {rtype} (undef, length)
210
215
blackman! (result, length, 0 )
211
216
end
@@ -217,7 +222,7 @@ Generates a Hamming window of length 'length'. Default return type
217
222
is Vector{Float64}, but if rtype=Float32, Vector{Float32}
218
223
will be returned.
219
224
"""
220
- function hamming (length:: Int , rtype:: DataType = Float64)
225
+ function hamming (length:: Int , rtype:: DataType = Float64)
221
226
result:: Vector{rtype} = Array {rtype} (undef, length)
222
227
hamming! (result, length, 0 )
223
228
end
@@ -229,15 +234,15 @@ Generates a denormalized Hanning window of length 'length'. Default
229
234
return type is Vector{Float64}, but if rtype=Float32, Vector{Float32}
230
235
will be returned.
231
236
"""
232
- function hanning (length:: Int , rtype:: DataType = Float64)
237
+ function hanning (length:: Int , rtype:: DataType = Float64)
233
238
result:: Vector{rtype} = Array {rtype} (undef, length)
234
239
hanning! (result, length, 0 )
235
240
end
236
241
237
242
"""
238
243
Alias function for `hanning`
239
244
"""
240
- function hann (length:: Int , rtype:: DataType = Float64)
245
+ function hann (length:: Int , rtype:: DataType = Float64)
241
246
hanning (length, rtype)
242
247
end
243
248
@@ -251,10 +256,11 @@ for (T, suff) in ((Float32, ""), (Float64, "D"))
251
256
Returns: Vector{$T }
252
257
"""
253
258
@eval begin
254
- function blackman! (result:: Vector{$T} , length:: Int , flag:: Int = 0 )
255
- ccall (($ (string (" vDSP_blkman_window" , suff), libacc)), Cvoid,
256
- (Ptr{$ T}, UInt64, Int64),
257
- result, length, flag)
259
+ function blackman! (result:: Vector{$T} , length:: Int , flag:: Int = 0 )
260
+ fptr = get_fptr ($ (string (" vDSP_blkman_window" , suff)))
261
+ ccall (fptr, Cvoid,
262
+ (Ptr{$ T}, UInt64, Int64),
263
+ result, length, flag)
258
264
return result
259
265
end
260
266
end
@@ -268,10 +274,11 @@ for (T, suff) in ((Float32, ""), (Float64, "D"))
268
274
Returns: Vector{$T }
269
275
"""
270
276
@eval begin
271
- function hamming! (result:: Vector{$T} , length:: Int , flag:: Int = 0 )
272
- ccall (($ (string (" vDSP_hamm_window" , suff), libacc)), Cvoid,
273
- (Ptr{$ T}, UInt64, Int64),
274
- result, length, flag)
277
+ function hamming! (result:: Vector{$T} , length:: Int , flag:: Int = 0 )
278
+ fptr = get_fptr ($ (string (" vDSP_hamm_window" , suff)))
279
+ ccall (fptr, Cvoid,
280
+ (Ptr{$ T}, UInt64, Int64),
281
+ result, length, flag)
275
282
return result
276
283
end
277
284
end
@@ -289,10 +296,11 @@ for (T, suff) in ((Float32, ""), (Float64, "D"))
289
296
Returns: Vector{$T }
290
297
"""
291
298
@eval begin
292
- function hanning! (result:: Vector{$T} , length:: Int , flag:: Int = 0 )
293
- ccall (($ (string (" vDSP_hann_window" , suff), libacc)), Cvoid,
294
- (Ptr{$ T}, UInt64, Int64),
295
- result, length, flag)
299
+ function hanning! (result:: Vector{$T} , length:: Int , flag:: Int = 0 )
300
+ fptr = get_fptr ($ (string (" vDSP_hann_window" , suff)))
301
+ ccall (fptr, Cvoid,
302
+ (Ptr{$ T}, UInt64, Int64),
303
+ result, length, flag)
296
304
return result
297
305
end
298
306
end
@@ -303,7 +311,7 @@ for (T, suff) in ((Float32, ""), (Float64, "D"))
303
311
Returns: Vector{$T }
304
312
"""
305
313
@eval begin
306
- function hann! (result:: Vector{$T} , length:: Int , flag:: Int = 0 )
314
+ function hann! (result:: Vector{$T} , length:: Int , flag:: Int = 0 )
307
315
hanning! (result, length, flag)
308
316
end
309
317
end
@@ -320,17 +328,18 @@ storage of the previous setup object.
320
328
321
329
Returns: DFTSetup
322
330
"""
323
- function plan_dct (length:: Int , dct_type:: Int , previous= C_NULL )
331
+ function plan_dct (length:: Int , dct_type:: Int , previous = C_NULL )
324
332
n = trailing_zeros (length)
325
333
f = length >> n
326
- if dct_type < 2 && dct_type > 4
334
+ if dct_type < 2 && dct_type > 4
327
335
error (" DCT type " , dct_type, " is not supported. Only DCT types 2, 3 and 4 are supported" )
328
- elseif ! (n >= 4 && f in (1 ,3 , 5 , 15 ))
336
+ elseif ! (n >= 4 && f in (1 , 3 , 5 , 15 ))
329
337
error (" Invalid DCT length. Length must be equal to f*(2^n) where f = 1,3,5,15 and n >= 4" )
330
338
end
331
- setup:: Ptr{Cvoid} = ccall ((" vDSP_DCT_CreateSetup" , libacc), Ptr{Cvoid},
332
- (Ptr{Cvoid}, UInt64, UInt64),
333
- previous, length, dct_type)
339
+ fptr = get_fptr (" vDSP_DCT_CreateSetup" )
340
+ setup:: Ptr{Cvoid} = ccall (fptr, Ptr{Cvoid},
341
+ (Ptr{Cvoid}, UInt64, UInt64),
342
+ previous, length, dct_type)
334
343
return DFTSetup (Float32, setup, 0 )
335
344
end
336
345
@@ -343,9 +352,11 @@ Returns: Vector{Float32}
343
352
"""
344
353
function dct (X:: Vector{Float32} , setup:: DFTSetup )
345
354
result = similar (X)
346
- ccall ((" vDSP_DCT_Execute" , libacc), Cvoid,
347
- (Ptr{Cvoid}, Ptr{Float32}, Ptr{Float32}),
348
- setup. setup, X, result)
355
+ fptr = get_fptr (" vDSP_DCT_Execute" )
356
+
357
+ ccall (fptr, Cvoid,
358
+ (Ptr{Cvoid}, Ptr{Float32}, Ptr{Float32}),
359
+ setup. setup, X, result)
349
360
return result
350
361
end
351
362
@@ -356,7 +367,7 @@ This function does not require a separate call to dct_setup.
356
367
357
368
Returns: Vector{Float32}
358
369
"""
359
- function dct (X:: Vector{Float32} , dct_type:: Int = 2 )
370
+ function dct (X:: Vector{Float32} , dct_type:: Int = 2 )
360
371
setup = plan_dct (length (X), dct_type)
361
372
return dct (X, setup)
362
373
end
366
377
Deinitializes a DFTSetup object created by plan_dct
367
378
"""
368
379
function plan_destroy (setup:: DFTSetup )
369
- ccall ((" vDSP_DFT_DestroySetup" , libacc), Cvoid,
370
- (Ptr{Cvoid},),
371
- setup. setup)
380
+ fptr = get_fptr (" vDSP_DFT_DestroySetup" )
381
+ ccall (fptr, Cvoid,
382
+ (Ptr{Cvoid},),
383
+ setup. setup)
372
384
end
373
385
374
386
0 commit comments