Skip to content

Commit aee2d7d

Browse files
committed
Revert some change to ccall
This reverts commit e843a3a.
1 parent d46c7fa commit aee2d7d

File tree

3 files changed

+70
-93
lines changed

3 files changed

+70
-93
lines changed

Project.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ name = "AppleAccelerate"
22
uuid = "13e28ba4-7ad8-5781-acae-3021b1ed3924"
33
version = "0.3.2"
44

5-
[deps]
6-
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
7-
85
[compat]
96
julia = "1.6"
107

@@ -16,4 +13,4 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1613
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1714

1815
[targets]
19-
test = ["DSP", "Statistics", "LinearAlgebra", "Test", "Random"]
16+
test = [ "DSP", "Statistics", "LinearAlgebra", "Test", "Random"]

src/Array.jl

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ for (T, suff) in ((Float64, ""), (Float32, "f"))
2727

2828
# In-place mutating variant
2929
function ($f!)(out::Array{$T}, X::Array{$T})
30-
fptr = get_fptr($(string("vv", fa, suff)))
31-
ccall(fptr, Cvoid,
32-
(Ptr{$T}, Ptr{$T}, Ref{Cint}), out, X, length(X))
30+
ccall(($(string("vv",fa,suff)),libacc),Cvoid,
31+
(Ptr{$T},Ptr{$T},Ref{Cint}),out,X,length(X))
3332
out
3433
end
3534
end
@@ -53,9 +52,8 @@ for (T, suff) in ((Float64, ""), (Float32, "f"))
5352
($f!)(out, X, Y)
5453
end
5554
function ($f!)(out::Array{$T}, X::Array{$T}, Y::Array{$T})
56-
fptr = get_fptr($(string("vv", fa, suff)))
57-
ccall(fptr, Cvoid,
58-
(Ptr{$T}, Ptr{$T}, Ptr{$T}, Ref{Cint}), out, X, Y, length(X))
55+
ccall(($(string("vv",fa,suff)),libacc),Cvoid,
56+
(Ptr{$T},Ptr{$T},Ptr{$T},Ref{Cint}),out,X,Y,length(X))
5957
out
6058
end
6159
end
@@ -71,9 +69,8 @@ for (T, suff) in ((Float64, ""), (Float32, "f"))
7169
($f!)(out, X, Y)
7270
end
7371
function ($f!)(out::Array{$T}, X::Array{$T}, Y::Array{$T})
74-
fptr = get_fptr($(string("vv", fa, suff)))
75-
ccall(fptr, Cvoid,
76-
(Ptr{$T}, Ptr{$T}, Ptr{$T}, Ref{Cint}), out, Y, X, length(X))
72+
ccall(($(string("vv",fa,suff)),libacc),Cvoid,
73+
(Ptr{$T},Ptr{$T},Ptr{$T},Ref{Cint}),out,Y,X,length(X))
7774
out
7875
end
7976
end
@@ -89,9 +86,8 @@ for (T, suff) in ((Float64, ""), (Float32, "f"))
8986
($f!)(out1, out2, X)
9087
end
9188
function ($f!)(out1::Array{$T}, out2::Array{$T}, X::Array{$T})
92-
fptr = get_fptr($(string("vv", f, suff)))
93-
ccall(fptr, Cvoid,
94-
(Ptr{$T}, Ptr{$T}, Ptr{$T}, Ref{Cint}), out1, out2, X, length(X))
89+
ccall(($(string("vv",f,suff)),libacc),Cvoid,
90+
(Ptr{$T},Ptr{$T},Ptr{$T},Ref{Cint}),out1,out2,X,length(X))
9591
out1, out2
9692
end
9793
end
@@ -106,9 +102,8 @@ for (T, suff) in ((Float64, ""), (Float32, "f"))
106102
($f!)(out, X)
107103
end
108104
function ($f!)(out::Array{Complex{$T}}, X::Array{$T})
109-
fptr = get_fptr($(string("vv", fa, suff)))
110-
ccall(fptr, Cvoid,
111-
(Ptr{Complex{$T}}, Ptr{$T}, Ref{Cint}), out, X, length(X))
105+
ccall(($(string("vv",fa,suff)),libacc),Cvoid,
106+
(Ptr{Complex{$T}},Ptr{$T},Ref{Cint}),out,X,length(X))
112107
out
113108
end
114109
end
@@ -140,10 +135,9 @@ for (T, suff) in ((Float32, ""), (Float64, "D"))
140135
@eval begin
141136
function ($f)(X::Vector{$T})
142137
val = Ref{$T}(0.0)
143-
fptr = get_fptr($(string("vDSP_", fa, suff)))
144-
ccall(fptr, Cvoid,
145-
(Ptr{$T}, Int64, Ref{$T}, UInt64),
146-
X, 1, val, length(X))
138+
ccall(($(string("vDSP_", fa, suff), libacc)), Cvoid,
139+
(Ptr{$T}, Int64, Ref{$T}, UInt64),
140+
X, 1, val, length(X))
147141
return val[]
148142
end
149143
end
@@ -154,11 +148,10 @@ for (T, suff) in ((Float32, ""), (Float64, "D"))
154148
function ($f)(X::Vector{$T})
155149
index = Ref{Int}(0)
156150
val = Ref{$T}(0.0)
157-
fptr = get_fptr($(string("vDSP_", fa, suff)))
158-
ccall(fptr, Cvoid,
159-
(Ptr{$T}, Int64, Ref{$T}, Ref{Int}, UInt64),
160-
X, 1, val, index, length(X))
161-
return (val[], index[] + 1)
151+
ccall(($(string("vDSP_", fa, suff), libacc)), Cvoid,
152+
(Ptr{$T}, Int64, Ref{$T}, Ref{Int}, UInt64),
153+
X, 1, val, index, length(X))
154+
return (val[], index[]+1)
162155
end
163156
end
164157
end
@@ -179,8 +172,7 @@ for (T, suff) in ((Float32, ""), (Float64, "D"))
179172
the result vector with computed value. *Returns:* **Vector{$($T)}** `result`
180173
""" ->
181174
function ($f!)(result::Vector{$T}, X::Vector{$T}, Y::Vector{$T})
182-
fptr = get_fptr($(string("vDSP_", f, suff)))
183-
ccall(fptr, Cvoid,
175+
ccall(($(string("vDSP_", f, suff), libacc)), Cvoid,
184176
(Ptr{$T}, Int64, Ptr{$T}, Int64, Ptr{$T}, Int64, UInt64),
185177
Y, 1, X, 1, result, 1, length(result))
186178
return result

src/DSP.jl

Lines changed: 51 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ for (T, suff) in ((Float64, "D"), (Float32, ""))
4040
if (rsize < xsize + ksize - 1)
4141
error("'result' must have at least length(X) + length(K) - 1 elements")
4242
end
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)
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)
4847
return result
4948
end
5049
end
@@ -88,11 +87,10 @@ for (T, suff) in ((Float64, "D"), (Float32, ""))
8887
if (rsize < xsize + ysize - 1)
8988
error("'result' must have at least length(X) + length(Y) - 1 elements")
9089
end
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)
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)
9694
return result
9795
end
9896
end
@@ -136,7 +134,7 @@ for (T, suff) in ((Float64, "D"), (Float32, ""))
136134
end
137135

138136
## == Biquadratic/IIR filtering
139-
for (T, suff) in ((Float64, "D"),)
137+
for (T, suff) in ((Float64, "D"), )
140138

141139
"""
142140
Initializes a vDSP_biquad_setup for use with vDSP_biquad. A multi-section filter
@@ -147,15 +145,14 @@ for (T, suff) in ((Float64, "D"),)
147145
Returns: Biquad{T}
148146
"""
149147
@eval begin
150-
function biquadcreate(coefficients::Vector{$T}, sections::Int)
151-
if length(coefficients) < 5 * sections
148+
function biquadcreate(coefficients::Vector{$T}, sections::Int)
149+
if length(coefficients) < 5*sections
152150
error("Incomplete biquad specification provided - coefficients must
153151
contain 5 elements for each filter section")
154152
end
155-
fptr = get_fptr($(string("vDSP_biquad_CreateSetup", suff)))
156-
setup = ccall(fptr, Ptr{Cvoid},
157-
(Ptr{$T}, UInt64),
158-
coefficients, sections)
153+
setup = ccall(($(string("vDSP_biquad_CreateSetup", suff), libacc)), Ptr{Cvoid},
154+
(Ptr{$T}, UInt64),
155+
coefficients, sections)
159156
return Biquad($T, setup, sections)
160157
end
161158
end
@@ -170,15 +167,14 @@ for (T, suff) in ((Float64, "D"),)
170167
"""
171168
@eval begin
172169
function biquad(X::Vector{$T}, delays::Vector{$T}, numelem::Int, biquad::Biquad{$T})
173-
if length(delays) < (2 * (biquad.sections) + 2)
170+
if length(delays) < (2*(biquad.sections)+2)
174171
error("Incomplete delay specification provided - delays must contain 2*M + 2
175172
values where M is the number of sections in the biquad")
176173
end
177174
result::Vector{$T} = similar(X)
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)
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)
182178
return result
183179
end
184180
end
@@ -193,10 +189,9 @@ for (T, suff) in ((Float64, "D"),)
193189
"""
194190
@eval begin
195191
function biquaddestroy(biquad::Biquad{$T})
196-
fptr = get_fptr($(string("vDSP_biquad_DestroySetup", suff)))
197-
ccall(fptr, Cvoid,
198-
(Ptr{Cvoid},),
199-
biquad.setup)
192+
ccall(($(string("vDSP_biquad_DestroySetup", suff), libacc)), Cvoid,
193+
(Ptr{Cvoid}, ),
194+
biquad.setup)
200195
end
201196
end
202197
end
@@ -210,7 +205,7 @@ Generates a Blackman window of length 'length'. Default return type
210205
is Vector{Float64}, but if rtype=Float32, Vector{Float32}
211206
will be returned.
212207
"""
213-
function blackman(length::Int, rtype::DataType = Float64)
208+
function blackman(length::Int, rtype::DataType=Float64)
214209
result::Vector{rtype} = Array{rtype}(undef, length)
215210
blackman!(result, length, 0)
216211
end
@@ -222,7 +217,7 @@ Generates a Hamming window of length 'length'. Default return type
222217
is Vector{Float64}, but if rtype=Float32, Vector{Float32}
223218
will be returned.
224219
"""
225-
function hamming(length::Int, rtype::DataType = Float64)
220+
function hamming(length::Int, rtype::DataType=Float64)
226221
result::Vector{rtype} = Array{rtype}(undef, length)
227222
hamming!(result, length, 0)
228223
end
@@ -234,15 +229,15 @@ Generates a denormalized Hanning window of length 'length'. Default
234229
return type is Vector{Float64}, but if rtype=Float32, Vector{Float32}
235230
will be returned.
236231
"""
237-
function hanning(length::Int, rtype::DataType = Float64)
232+
function hanning(length::Int, rtype::DataType=Float64)
238233
result::Vector{rtype} = Array{rtype}(undef, length)
239234
hanning!(result, length, 0)
240235
end
241236

242237
"""
243238
Alias function for `hanning`
244239
"""
245-
function hann(length::Int, rtype::DataType = Float64)
240+
function hann(length::Int, rtype::DataType=Float64)
246241
hanning(length, rtype)
247242
end
248243

@@ -256,11 +251,10 @@ for (T, suff) in ((Float32, ""), (Float64, "D"))
256251
Returns: Vector{$T}
257252
"""
258253
@eval begin
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)
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)
264258
return result
265259
end
266260
end
@@ -274,11 +268,10 @@ for (T, suff) in ((Float32, ""), (Float64, "D"))
274268
Returns: Vector{$T}
275269
"""
276270
@eval begin
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)
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)
282275
return result
283276
end
284277
end
@@ -296,11 +289,10 @@ for (T, suff) in ((Float32, ""), (Float64, "D"))
296289
Returns: Vector{$T}
297290
"""
298291
@eval begin
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)
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)
304296
return result
305297
end
306298
end
@@ -311,7 +303,7 @@ for (T, suff) in ((Float32, ""), (Float64, "D"))
311303
Returns: Vector{$T}
312304
"""
313305
@eval begin
314-
function hann!(result::Vector{$T}, length::Int, flag::Int = 0)
306+
function hann!(result::Vector{$T}, length::Int, flag::Int=0)
315307
hanning!(result, length, flag)
316308
end
317309
end
@@ -328,18 +320,17 @@ storage of the previous setup object.
328320
329321
Returns: DFTSetup
330322
"""
331-
function plan_dct(length::Int, dct_type::Int, previous = C_NULL)
323+
function plan_dct(length::Int, dct_type::Int, previous=C_NULL)
332324
n = trailing_zeros(length)
333325
f = length >> n
334-
if dct_type < 2 && dct_type > 4
326+
if dct_type < 2 && dct_type > 4
335327
error("DCT type ", dct_type, " is not supported. Only DCT types 2, 3 and 4 are supported")
336-
elseif !(n >= 4 && f in (1, 3, 5, 15))
328+
elseif !(n >= 4 && f in (1,3,5,15))
337329
error("Invalid DCT length. Length must be equal to f*(2^n) where f = 1,3,5,15 and n >= 4")
338330
end
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)
331+
setup::Ptr{Cvoid} = ccall(("vDSP_DCT_CreateSetup", libacc), Ptr{Cvoid},
332+
(Ptr{Cvoid}, UInt64, UInt64),
333+
previous, length, dct_type)
343334
return DFTSetup(Float32, setup, 0)
344335
end
345336

@@ -352,11 +343,9 @@ Returns: Vector{Float32}
352343
"""
353344
function dct(X::Vector{Float32}, setup::DFTSetup)
354345
result = similar(X)
355-
fptr = get_fptr("vDSP_DCT_Execute")
356-
357-
ccall(fptr, Cvoid,
358-
(Ptr{Cvoid}, Ptr{Float32}, Ptr{Float32}),
359-
setup.setup, X, result)
346+
ccall(("vDSP_DCT_Execute", libacc), Cvoid,
347+
(Ptr{Cvoid}, Ptr{Float32}, Ptr{Float32}),
348+
setup.setup, X, result)
360349
return result
361350
end
362351

@@ -367,7 +356,7 @@ This function does not require a separate call to dct_setup.
367356
368357
Returns: Vector{Float32}
369358
"""
370-
function dct(X::Vector{Float32}, dct_type::Int = 2)
359+
function dct(X::Vector{Float32}, dct_type::Int=2)
371360
setup = plan_dct(length(X), dct_type)
372361
return dct(X, setup)
373362
end
@@ -377,10 +366,9 @@ end
377366
Deinitializes a DFTSetup object created by plan_dct
378367
"""
379368
function plan_destroy(setup::DFTSetup)
380-
fptr = get_fptr("vDSP_DFT_DestroySetup")
381-
ccall(fptr, Cvoid,
382-
(Ptr{Cvoid},),
383-
setup.setup)
369+
ccall(("vDSP_DFT_DestroySetup", libacc), Cvoid,
370+
(Ptr{Cvoid},),
371+
setup.setup)
384372
end
385373

386374

0 commit comments

Comments
 (0)