Skip to content

Commit

Permalink
Updates for Julia 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wookay committed Sep 15, 2018
1 parent 830c086 commit 829f1e1
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 84 deletions.
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ os:
- linux
- osx
julia:
- 0.6
- 0.7
- 1.0
- nightly
notifications:
email: false
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia --check-bounds=yes -e 'Pkg.init(); Pkg.clone(pwd()); Pkg.build("WORLD"); Pkg.test("WORLD", coverage=true)'
- julia --check-bounds=yes -e 'using Pkg; Pkg.init(); Pkg.clone(pwd()); Pkg.build("WORLD"); Pkg.test("WORLD", coverage=true)'
after_success:
- julia -e 'cd(Pkg.dir("WORLD")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
- julia -e 'Pkg.add("Documenter");'
- julia -e 'cd(Pkg.dir("WORLD")); include(joinpath("docs", "make.jl"))'
- julia -e 'using Pkg; cd(Pkg.dir("WORLD")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
- julia -e 'using Pkg; Pkg.add("Documenter");'
- julia -e 'using Pkg; cd(Pkg.dir("WORLD")); include(joinpath("docs", "make.jl"))'
4 changes: 2 additions & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
julia 0.6
julia 0.7
BinDeps
DocStringExtensions 0.2
DocStringExtensions 0.5.0
FFTW
13 changes: 6 additions & 7 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
environment:
matrix:
# - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/1.0/julia-1.0.0-win64.exe"

branches:
only:
Expand All @@ -28,8 +26,9 @@ install:
build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"WORLD\"); Pkg.build(\"WORLD\")"
- C:\projects\julia\bin\julia -e "
using InteractiveUtils; versioninfo();
using Pkg; Pkg.clone(pwd(), \"WORLD\"); Pkg.build(\"WORLD\")"

test_script:
- C:\projects\julia\bin\julia --check-bounds=yes -e "Pkg.test(\"WORLD\")"
- C:\projects\julia\bin\julia -e "using Pkg; Pkg.test(\"WORLD\")"
2 changes: 1 addition & 1 deletion deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ world = library_dependency("libworld", aliases=["libworld", "world-0"])
const version = "0.3.1"

# TODO
if is_windows() && Sys.WORD_SIZE == 32
if Sys.iswindows() && Sys.WORD_SIZE == 32
error("Your platform isn't supported yet.")
end

Expand Down
1 change: 0 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ makedocs(
)

deploydocs(
julia = "0.5",
target = "build",
deps = nothing,
make = nothing,
Expand Down
10 changes: 3 additions & 7 deletions src/WORLD.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
__precompile__()

"""
A lightweitht julia wrapper for [WORLD](https://github.com/mmorise/World),
a high-quality speech analysis, manipulation and synthesis system.
Expand All @@ -13,8 +11,7 @@ and re-synthesize a speech signal from these paramters. Please see the project
page for more details on the WORLD.
!!! note
WORLD.jl is based on a fork of WORLD ([r9y9/World-cmake](\
https://github.com/r9y9/World-cmake)).
WORLD.jl is based on a fork of WORLD ([r9y9/World-cmake](https://github.com/r9y9/World-cmake)).
[https://github.com/r9y9/WORLD.jl](https://github.com/r9y9/WORLD.jl)
Expand Down Expand Up @@ -123,8 +120,7 @@ decoded_aperiodicity = decode_aperiodicity(coded_aperiodicity, fs)
![](assets/decoded_aperiodicity.png)
For the complete code of visualizations shown above, please check
[the IJulia notebook](\
http://nbviewer.jupyter.org/github/r9y9/WORLD.jl/blob/master/docs/src/assets/WORLD-demo.ipynb).
[the IJulia notebook](http://nbviewer.jupyter.org/github/r9y9/WORLD.jl/blob/master/docs/src/assets/WORLD-demo.ipynb).
## Exports
Expand Down Expand Up @@ -156,7 +152,7 @@ try
# function GetWORLDVersion was added in v0.2.1-2
versionstr = unsafe_string(convert(Ptr{UInt8},
ccall((:GetWORLDVersion, libworld), Ptr{Cchar}, ())))
global const version = convert(VersionNumber, versionstr)
global const version = VersionNumber(versionstr)
catch e
try
ccall((:GetFFTSizeForStar, libworld), Cint, (Cint,), 48000)
Expand Down
48 changes: 24 additions & 24 deletions src/bridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ mutable struct CheapTrickOption
fftsize::Cint
function CheapTrickOption(fs; q1=-0.15, f0floor=71.0)
p = new()
ccall((:InitializeCheapTrickOption, libworld), Void,
(Cint, Ptr{CheapTrickOption},), fs, &p)
ccall((:InitializeCheapTrickOption, libworld), Cvoid,
(Cint, Ptr{CheapTrickOption},), fs, Ref(p))
p.q1 = q1
p.f0floor = f0floor
p.fftsize = get_fftsize_for_cheaptrick(Int(fs), p)
Expand Down Expand Up @@ -135,9 +135,9 @@ Dio estimates F0 trajectory given a monoral input signal.
"""
function dio(x::StridedVector{Cdouble}, fs::Real, opt::DioOption=DioOption())
expectedlen = get_samples_for_dio(fs, length(x), opt.period)
f0 = Array{Cdouble}(expectedlen)
timeaxis = Array{Cdouble}(expectedlen)
ccall((:Dio, libworld), Void,
f0 = Array{Cdouble}(undef, expectedlen)
timeaxis = Array{Cdouble}(undef, expectedlen)
ccall((:Dio, libworld), Cvoid,
(Ptr{Cdouble}, Cint, Cint, Ref{DioOption}, Ptr{Cdouble}, Ptr{Cdouble}),
x, length(x), fs, opt, timeaxis, f0)
f0, timeaxis
Expand All @@ -161,9 +161,9 @@ Harvest estimates F0 trajectory given a monoral input signal.
"""
function harvest(x::StridedVector{Cdouble}, fs::Real, opt::HarvestOption=HarvestOption())
expectedlen = get_samples_for_harvest(fs, length(x), opt.period)
f0 = Array{Cdouble}(expectedlen)
timeaxis = Array{Cdouble}(expectedlen)
ccall((:Harvest, libworld), Void,
f0 = Array{Cdouble}(undef, expectedlen)
timeaxis = Array{Cdouble}(undef, expectedlen)
ccall((:Harvest, libworld), Cvoid,
(Ptr{Cdouble}, Cint, Cint, Ref{HarvestOption}, Ptr{Cdouble}, Ptr{Cdouble}),
x, length(x), fs, opt, timeaxis, f0)
f0, timeaxis
Expand All @@ -188,16 +188,16 @@ StoneMask refines the estimated F0 by Dio,
function stonemask(x::StridedVector{Cdouble}, fs::Integer,
timeaxis::StridedVector{Cdouble},
f0::StridedVector{Cdouble})
refinedF0 = Array{Cdouble}(length(f0))
ccall((:StoneMask, libworld), Void,
refinedF0 = Array{Cdouble}(undef, length(f0))
ccall((:StoneMask, libworld), Cvoid,
(Ptr{Cdouble}, Cint, Cint, Ptr{Cdouble}, Ptr{Cdouble}, Cint,
Ptr{Cdouble}),
x, length(x), fs, timeaxis, f0, length(f0), refinedF0)
refinedF0
end

# Array{T,2} -> Array{Ptr{T}}
function ptrarray2d!{T<:Real}(dst::Array{Ptr{T},1}, src::Array{T,2})
function ptrarray2d!(dst::Array{Ptr{T},1}, src::Array{T,2}) where {T<:Real}
for i=1:size(src, 2)
@inbounds dst[i] = pointer(view(src, 1:size(src, 1), i), 1)
end
Expand All @@ -221,7 +221,7 @@ frequency and the lower limit of f0 (It is defined in world.h).
function get_fftsize_for_cheaptrick(fs::Integer,
opt::CheapTrickOption=CheapTrickOption(fs))
fftsize = ccall((:GetFFTSizeForCheapTrick, libworld), Cint,
(Cint,Ptr{CheapTrickOption}), fs, &opt)
(Cint,Ptr{CheapTrickOption}), fs, Ref(opt))
convert(Int, fftsize)
end

Expand Down Expand Up @@ -249,16 +249,16 @@ function cheaptrick(x::StridedVector{Cdouble}, fs::Integer,
opt::CheapTrickOption=CheapTrickOption(fs)
)
freqbins = get_fftsize_for_cheaptrick(fs, opt)>>1 + 1
spectrogram = Array{Cdouble}(freqbins, length(f0))
spectrogram = Array{Cdouble}(undef, freqbins, length(f0))

# Array{Cdouble,2} -> Array{Ptr{Cdouble}}
cspectrogram = Array{Ptr{Cdouble}}(size(spectrogram, 2))
cspectrogram = Array{Ptr{Cdouble}}(undef, size(spectrogram, 2))
ptrarray2d!(cspectrogram, spectrogram)

ccall((:CheapTrick, libworld), Void,
ccall((:CheapTrick, libworld), Cvoid,
(Ptr{Cdouble}, Cint, Cint, Ptr{Cdouble}, Ptr{Cdouble}, Cint,
Ptr{CheapTrickOption}, Ptr{Ptr{Cdouble}}),
x, length(x), fs, timeaxis, f0, length(f0), &opt, cspectrogram)
x, length(x), fs, timeaxis, f0, length(f0), Ref(opt), cspectrogram)

# Array{Cdouble,2} <- Array{Ptr{Cdouble}}
for i=1:length(f0), j=1:freqbins
Expand Down Expand Up @@ -293,13 +293,13 @@ function d4c(x::StridedVector{Cdouble}, fs::Integer,
aperiodicity = zeros(Cdouble, freqbins, length(f0))

# Array{Cdouble,2} -> Array{Ptr{Cdouble}}
caperiodicity = Array{Ptr{Cdouble}}(size(aperiodicity, 2))
caperiodicity = Array{Ptr{Cdouble}}(undef, size(aperiodicity, 2))
ptrarray2d!(caperiodicity, aperiodicity)

ccall((:D4C, libworld), Void,
ccall((:D4C, libworld), Cvoid,
(Ptr{Cdouble}, Cint, Cint, Ptr{Cdouble}, Ptr{Cdouble}, Cint, Cint,
Ptr{D4COption}, Ptr{Ptr{Cdouble}}),
x, length(x), fs, timeaxis, f0, length(f0), fftsize, &opt,
x, length(x), fs, timeaxis, f0, length(f0), fftsize, Ref(opt),
caperiodicity)

# Array{Cdouble,2} <- Array{Ptr{Cdouble}}
Expand Down Expand Up @@ -336,14 +336,14 @@ function synthesis(f0::StridedVector{Cdouble},
fftsize = get_fftsize_for_cheaptrick(fs, CheapTrickOption(fs))

# Array{Cdouble,2} -> Array{Ptr{Cdouble}}
cspectrogram = Array{Ptr{Cdouble}}(size(spectrogram, 2))
cspectrogram = Array{Ptr{Cdouble}}(undef, size(spectrogram, 2))
ptrarray2d!(cspectrogram, spectrogram)

caperiodicity = Array{Ptr{Cdouble}}(size(aperiodicity, 2))
caperiodicity = Array{Ptr{Cdouble}}(undef, size(aperiodicity, 2))
ptrarray2d!(caperiodicity, aperiodicity)

synthesized = Array{Cdouble}(len)
ccall((:Synthesis, libworld), Void,
synthesized = Array{Cdouble}(undef, len)
ccall((:Synthesis, libworld), Cvoid,
(Ptr{Cdouble}, Cint, Ptr{Ptr{Cdouble}}, Ptr{Ptr{Cdouble}},
Cint, Cdouble, Cint, Cint, Ptr{Cdouble}),
f0, length(f0), cspectrogram, caperiodicity, fftsize, period, fs, len,
Expand Down Expand Up @@ -372,7 +372,7 @@ function interp1!(x::StridedVector{Cdouble},
yi::StridedVector{Cdouble})
@assert length(x) == length(y)
@assert length(xi) == length(yi)
ccall((:interp1, libworld), Void,
ccall((:interp1, libworld), Cvoid,
(Ptr{Cdouble}, Ptr{Cdouble}, Cint, Ptr{Cdouble}, Cint, Ptr{Cdouble}),
x, y, length(x), xi, length(xi), yi)
yi
Expand Down
24 changes: 12 additions & 12 deletions src/codec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ function code_aperiodicity(aperiodicity, fs,
coded_aperiodicity = zeros(Cdouble, n, f0_length)

# Array{Cdouble,2} -> Array{Ptr{Cdouble}}
ccoded_aperiodicity = Array{Ptr{Cdouble}}(f0_length)
ccoded_aperiodicity = Array{Ptr{Cdouble}}(undef, f0_length)
ptrarray2d!(ccoded_aperiodicity, coded_aperiodicity)

# Array{Cdouble,2} -> Array{Ptr{Cdouble}}
caperiodicity = Array{Ptr{Cdouble}}(f0_length)
caperiodicity = Array{Ptr{Cdouble}}(undef, f0_length)
ptrarray2d!(caperiodicity, aperiodicity)

ccall((:CodeAperiodicity, libworld), Void,
ccall((:CodeAperiodicity, libworld), Cvoid,
(Ptr{Ptr{Cdouble}}, Cint, Cint, Cint, Ptr{Ptr{Cdouble}}),
caperiodicity, f0_length, fs, fftsize, ccoded_aperiodicity)

Expand Down Expand Up @@ -80,14 +80,14 @@ function decode_aperiodicity(coded_aperiodicity, fs,
aperiodicity = zeros(Cdouble, freqbins, f0_length)

# Array{Cdouble,2} -> Array{Ptr{Cdouble}}
ccoded_aperiodicity = Array{Ptr{Cdouble}}(f0_length)
ccoded_aperiodicity = Array{Ptr{Cdouble}}(undef, f0_length)
ptrarray2d!(ccoded_aperiodicity, coded_aperiodicity)

# Array{Cdouble,2} -> Array{Ptr{Cdouble}}
caperiodicity = Array{Ptr{Cdouble}}(f0_length)
caperiodicity = Array{Ptr{Cdouble}}(undef, f0_length)
ptrarray2d!(caperiodicity, aperiodicity)

ccall((:DecodeAperiodicity, libworld), Void,
ccall((:DecodeAperiodicity, libworld), Cvoid,
(Ptr{Ptr{Cdouble}}, Cint, Cint, Cint, Ptr{Ptr{Cdouble}}),
ccoded_aperiodicity, f0_length, fs, fftsize, caperiodicity)

Expand Down Expand Up @@ -123,14 +123,14 @@ function code_spectral_envelope(spectrogram, fs,
coded_spectral_envelope = zeros(Cdouble, nd, f0_length)

# Array{Cdouble,2} -> Array{Ptr{Cdouble}}
ccoded_spectral_envelope = Array{Ptr{Cdouble}}(f0_length)
ccoded_spectral_envelope = Array{Ptr{Cdouble}}(undef, f0_length)
ptrarray2d!(ccoded_spectral_envelope, coded_spectral_envelope)

# Array{Cdouble,2} -> Array{Ptr{Cdouble}}
cspectrogram = Array{Ptr{Cdouble}}(f0_length)
cspectrogram = Array{Ptr{Cdouble}}(undef, f0_length)
ptrarray2d!(cspectrogram, spectrogram)

ccall((:CodeSpectralEnvelope, libworld), Void,
ccall((:CodeSpectralEnvelope, libworld), Cvoid,
(Ptr{Ptr{Cdouble}}, Cint, Cint, Cint, Cint, Ptr{Ptr{Cdouble}}),
cspectrogram, f0_length, fs, fftsize, nd, ccoded_spectral_envelope)

Expand Down Expand Up @@ -164,14 +164,14 @@ function decode_spectral_envelope(coded_spectral_envelope, fs, fftsize)
spectrogram = zeros(Cdouble, freqbins, f0_length)

# Array{Cdouble,2} -> Array{Ptr{Cdouble}}
ccoded_spectral_envelope = Array{Ptr{Cdouble}}(f0_length)
ccoded_spectral_envelope = Array{Ptr{Cdouble}}(undef, f0_length)
ptrarray2d!(ccoded_spectral_envelope, coded_spectral_envelope)

# Array{Cdouble,2} -> Array{Ptr{Cdouble}}
cspectrogram = Array{Ptr{Cdouble}}(f0_length)
cspectrogram = Array{Ptr{Cdouble}}(undef, f0_length)
ptrarray2d!(cspectrogram, spectrogram)

ccall((:DecodeSpectralEnvelope, libworld), Void,
ccall((:DecodeSpectralEnvelope, libworld), Cvoid,
(Ptr{Ptr{Cdouble}}, Cint, Cint, Cint, Cint, Ptr{Ptr{Cdouble}}),
ccoded_spectral_envelope, f0_length, fs, fftsize, nd, cspectrogram)

Expand Down
18 changes: 9 additions & 9 deletions src/mcep.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ using FFTW
# TODO(ryuichi) import from MelGeneralizedCepstrums or SPTK
# copied from r9y9/MelGeneralizedCepstrums.jl
function freqt!(wc::AbstractVector, c::AbstractVector, α;
prev=Array{eltype(wc)}(length(wc)))
prev=Array{eltype(wc)}(undef, length(wc)))
fill!(wc, zero(eltype(wc)))
dst_order = length(wc) - 1

m1 = length(c)-1
for i in -m1:0
copy!(prev, wc)
copyto!(prev, wc)
if dst_order >= 0
@inbounds wc[1] = c[-i+1] + α*prev[1]
end
Expand All @@ -27,7 +27,7 @@ function freqt!(wc::AbstractVector, c::AbstractVector, α;
end

function freqt(c::AbstractVector, order=25, α=0.35)
wc = Array{eltype(c)}(order+1)
wc = Array{eltype(c)}(undef, order+1)
freqt!(wc, c, α)
end

Expand All @@ -37,7 +37,7 @@ $(SIGNATURES)
sp2mc converts power spectrum envelope to mel-cepstrum
``
|X(\\omega)|^{2} -> c\_{\\alpha}(m)
|X(\\omega)|^{2} -> c\\_{\\alpha}(m)
``
"""
function sp2mc(powerspec::AbstractVector,
Expand All @@ -63,20 +63,20 @@ $(SIGNATURES)
mc2sp converts mel-cepstrum to power spectrum envelope.
``
c\_{\\alpha}(m) -> |X(\\omega)|^{2}
c\\_{\\alpha}(m) -> |X(\\omega)|^{2}
``
equivalent: `exp(2real(MelGeneralizedCepstrums.mgc2sp(mc, α, 0.0, fftlen)))`
Note that `MelGeneralizedCepstrums.mgc2sp` returns log magnitude spectrum.
"""
function mc2sp{T}(mc::AbstractVector{T}, α, fftlen)
function mc2sp(mc::AbstractVector{T}, α, fftlen) where T
# back to cepstrum from mel-cesptrum
# cₐ(m) -> c(m)
c = freqt(mc, fftlen>>1, -α)
c[1] *= 2.0

symc = zeros(T, fftlen)
copy!(symc, c)
copyto!(symc, c)
for i=1:length(c)-1
symc[end-i+1] = symc[i+1]
end
Expand All @@ -93,8 +93,8 @@ for f in [:sp2mc,
@eval begin
function $f(x::AbstractMatrix, args...; kargs...)
outbuf = $f(view(x, :, 1), args...; kargs...)
ret = Array{eltype(outbuf)}(length(outbuf), size(x, 2))
copy!(ret, 1, outbuf, 1, length(outbuf))
ret = Array{eltype(outbuf)}(undef, length(outbuf), size(x, 2))
copyto!(ret, 1, outbuf, 1, length(outbuf))
for i = 2:size(x, 2)
@inbounds ret[:, i] = $f(view(x, :, i), args...; kargs...)
end
Expand Down

0 comments on commit 829f1e1

Please sign in to comment.