Skip to content

Commit

Permalink
Add c2acr and ic2ir and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
r9y9 committed Jun 18, 2015
1 parent ca95711 commit a601822
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/SPTK.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export
mc2b,
b2mc,
c2ir,
ic2ir,
c2acr,
c2ndps,
ndps2c,
gc2gc,
Expand Down
15 changes: 15 additions & 0 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ function b2mc(b::Vector{Cdouble}, α=0.41)
mc
end

function c2acr(c::Vector{Cdouble}, m2, fftlen)
r = zeros(m2 + 1)
ccall((:c2acr, libSPTK), Void,
(Ptr{Cdouble}, Cint, Ptr{Cdouble}, Cint, Cint),
c, length(c) - 1, r, m2, fftlen)
r
end

# c2ir converts cepstrum to impulse response.
function c2ir(c::Vector{Cdouble}, len)
h = zeros(len)
Expand All @@ -205,6 +213,12 @@ function c2ir(c::Vector{Cdouble}, len)
h
end

function ic2ir(h::Vector{Cdouble}, order)
c = zeros(order+1)
ccall((:ic2ir, libSPTK), Void, (Ptr{Cdouble}, Cint, Ptr{Cdouble}, Cint),
h, length(h), c, length(c))
c
end

# c2ndps converts cepstrum to negative derivative of phase spectrum.
function c2ndps(c::Vector{Cdouble}, fftlen)
Expand All @@ -215,6 +229,7 @@ function c2ndps(c::Vector{Cdouble}, fftlen)
ndps[1:fftlen>>1+1]
end


# c2ndps converts negative derivative of phase spectrum to cepstrum.
function ndps2c(ndps::Vector{Cdouble}, order)
fftlen = (length(ndps)-1)*2 # assuming the length of npds is fftsize/2+1
Expand Down
2 changes: 2 additions & 0 deletions src/extend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ for f in [:mcep,
:mc2b,
:b2mc,
:c2ir,
:ic2ir,
:c2acr,
:c2ndps,
:ndps2c,
:gc2gc,
Expand Down
23 changes: 19 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,26 @@ function test_mgcep_conversions()
cmat = b2mc(dummy_ceps_mat, 0.41)
@test size(cmat) == (length(dummy_ceps), 10)

println("-- test_c2acr")
r = c2acr(dummy_ceps, 20, 512)
@show length(r)
@test length(r) == 21
r = c2acr(dummy_ceps, 25, 512)
@test length(r) == 26
rmat = c2acr(dummy_ceps_mat, 25, 512)
@test size(rmat) == (26, 10)

println("-- test_c2ir")
c = c2ir(dummy_ceps, 512)
@test length(c) == 512
cmat = c2ir(dummy_ceps_mat, 512)
@test size(cmat) == (512, 10)
ir = c2ir(dummy_ceps, 512)
@test length(ir) == 512
irmat = c2ir(dummy_ceps_mat, 512)
@test size(irmat) == (512, 10)

println("-- test_ic2ir invertibility")
c = ic2ir(ir, length(dummy_ceps)-1)
@test_approx_eq c dummy_ceps
cmat = ic2ir(irmat, length(dummy_ceps)-1)
@test_approx_eq cmat dummy_ceps_mat

println("-- test_c2ndps")
ndps = c2ndps(dummy_ceps, 512)
Expand Down

0 comments on commit a601822

Please sign in to comment.