Skip to content

Commit 790438d

Browse files
committed
Merge pull request #14 from r9y9/tighten-type-for-ccall-wrapper-function
Tighten allowed types for ccall wrapper functions
2 parents da54c7e + ea6fb1f commit 790438d

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

src/bridge.jl

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function get_samples_for_dio(fs::Real, len::Integer, period::Real)
6767
(Cint, Cint, Cdouble), fs, len, period)
6868
end
6969

70-
function dio(x::AbstractVector{Cdouble}, fs::Real, opt::DioOption=DioOption())
70+
function dio(x::StridedVector{Cdouble}, fs::Real, opt::DioOption=DioOption())
7171
expectedlen = get_samples_for_dio(fs, length(x), opt.period)
7272
f0 = Array(Cdouble, expectedlen)
7373
timeaxis = Array(Cdouble, expectedlen)
@@ -78,9 +78,9 @@ function dio(x::AbstractVector{Cdouble}, fs::Real, opt::DioOption=DioOption())
7878
f0, timeaxis
7979
end
8080

81-
function stonemask(x::AbstractVector{Cdouble}, fs::Integer,
82-
timeaxis::AbstractVector{Cdouble},
83-
f0::AbstractVector{Cdouble})
81+
function stonemask(x::StridedVector{Cdouble}, fs::Integer,
82+
timeaxis::StridedVector{Cdouble},
83+
f0::StridedVector{Cdouble})
8484
refinedF0 = Array(Cdouble, length(f0))
8585
ccall((:StoneMask, libworld), Void,
8686
(Ptr{Cdouble}, Cint, Cint, Ptr{Cdouble}, Ptr{Cdouble}, Cint,
@@ -101,9 +101,9 @@ function get_fftsize_for_cheaptrick(fs::Integer)
101101
convert(Int, fftsize)
102102
end
103103

104-
function cheaptrick(x::AbstractVector{Cdouble}, fs::Integer,
105-
timeaxis::AbstractVector{Cdouble},
106-
f0::AbstractVector{Cdouble})
104+
function cheaptrick(x::StridedVector{Cdouble}, fs::Integer,
105+
timeaxis::StridedVector{Cdouble},
106+
f0::StridedVector{Cdouble})
107107
freqbins = get_fftsize_for_cheaptrick(fs)>>1 + 1
108108
spectrogram = Array(Cdouble, freqbins, length(f0))
109109

@@ -124,9 +124,9 @@ function cheaptrick(x::AbstractVector{Cdouble}, fs::Integer,
124124
spectrogram
125125
end
126126

127-
function d4c(x::AbstractVector{Cdouble}, fs::Integer,
128-
timeaxis::AbstractVector{Cdouble},
129-
f0::AbstractVector{Cdouble})
127+
function d4c(x::StridedVector{Cdouble}, fs::Integer,
128+
timeaxis::StridedVector{Cdouble},
129+
f0::StridedVector{Cdouble})
130130
fftsize = get_fftsize_for_cheaptrick(fs)
131131
freqbins = fftsize>>1 + 1
132132
aperiodicity = zeros(Cdouble, freqbins, length(f0))
@@ -148,9 +148,9 @@ function d4c(x::AbstractVector{Cdouble}, fs::Integer,
148148
aperiodicity
149149
end
150150

151-
function synthesis(f0::AbstractVector{Cdouble},
152-
spectrogram::AbstractMatrix{Cdouble},
153-
aperiodicity::AbstractMatrix{Cdouble},
151+
function synthesis(f0::StridedVector{Cdouble},
152+
spectrogram::StridedMatrix{Cdouble},
153+
aperiodicity::StridedMatrix{Cdouble},
154154
period::Real, fs::Integer, len::Integer)
155155
fftsize = get_fftsize_for_cheaptrick(fs)
156156

@@ -173,10 +173,10 @@ end
173173

174174
# matlabfunctions
175175

176-
function interp1!(x::AbstractVector{Cdouble},
177-
y::AbstractVector{Cdouble},
178-
xi::AbstractVector{Cdouble},
179-
yi::AbstractVector{Cdouble})
176+
function interp1!(x::StridedVector{Cdouble},
177+
y::StridedVector{Cdouble},
178+
xi::StridedVector{Cdouble},
179+
yi::StridedVector{Cdouble})
180180
@assert length(x) == length(y)
181181
@assert length(xi) == length(yi)
182182
ccall((:interp1, libworld), Void,
@@ -185,9 +185,9 @@ function interp1!(x::AbstractVector{Cdouble},
185185
yi
186186
end
187187

188-
function interp1(x::AbstractVector{Cdouble},
189-
y::AbstractVector{Cdouble},
190-
xi::AbstractVector{Cdouble})
188+
function interp1(x::StridedVector{Cdouble},
189+
y::StridedVector{Cdouble},
190+
xi::StridedVector{Cdouble})
191191
yi = similar(xi)
192192
interp1!(x, y, xi, yi)
193193
end

src/mcep.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,11 @@ for f in [:sp2mc,
7777
]
7878
@eval begin
7979
function $f(x::AbstractMatrix, args...; kargs...)
80-
r = $f(x[:, 1], args...; kargs...)
81-
ret = Array(eltype(r), size(r, 1), size(x, 2))
82-
for i = 1:length(r)
83-
@inbounds ret[i, 1] = r[i]
84-
end
80+
outbuf = $f(sub(x, :, 1), args...; kargs...)
81+
ret = Array(eltype(outbuf), length(outbuf), size(x, 2))
82+
copy!(ret, 1, outbuf, 1, length(outbuf))
8583
for i = 2:size(x, 2)
86-
@inbounds ret[:, i] = $f(x[:, i], args...; kargs...)
84+
@inbounds ret[:, i] = $f(sub(x, :, i), args...; kargs...)
8785
end
8886
ret
8987
end

0 commit comments

Comments
 (0)