Skip to content

Commit

Permalink
remove deprecated type World and related methods
Browse files Browse the repository at this point in the history
  • Loading branch information
r9y9 committed May 30, 2015
1 parent 074d04b commit 7880b9c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 81 deletions.
41 changes: 0 additions & 41 deletions src/WORLD.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,45 +32,4 @@ end
include("bridge.jl")
include("mcep.jl")

# World is a composite type that holds common settings that can be used during
# analysis
immutable World
fs::Int # Sample frequency
period::Float64 # Frame period [ms]
end

# will be deprecated
World(;fs::Real=44100, period::Float64=5.0) = World(fs, period)

function dio(w::World, x::AbstractVector{Float64}; opt::DioOption=DioOption())
w.period == opt.period ||
throw(ArgmentError("Inconsistent frame period: $(w.period) != $(opt.period)"))
dio(x, w.fs, opt)
end

function stonemask(w::World, x::AbstractVector{Float64},
timeaxis::AbstractVector{Float64},
f0::AbstractVector{Float64})
stonemask(x, w.fs, timeaxis, f0)
end

function cheaptrick(w::World, x::AbstractVector{Float64},
timeaxis::AbstractVector{Float64},
f0::AbstractVector{Float64})
cheaptrick(x, w.fs, timeaxis, f0)
end

function d4c(w::World, x::AbstractVector{Float64},
timeaxis::AbstractVector{Float64},
f0::AbstractVector{Float64})
d4c(x, w.fs, timeaxis, f0)
end

function synthesis(w::World, f0::AbstractVector{Float64},
spectrogram::AbstractMatrix{Float64},
residual::AbstractMatrix{Float64},
len::Integer)
synthesis(f0, spectrogram, residual, w.period, w.fs, len)
end

end # module WORLD
8 changes: 4 additions & 4 deletions src/bridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ end
# Note that the default options assume that the sampling frequency of a input
# speech signal is 44.1 kHz.
function DioOption(;
f0floor::Float64=80.0,
f0ceil::Float64=640.0,
f0floor::Float64=71.0,
f0ceil::Float64=800.0,
channels_in_octave::Float64=2.0,
period::Float64=5.0,
speed::Integer=11
speed::Integer=1
)
DioOption(f0floor, f0ceil, channels_in_octave, period, speed)
end
Expand All @@ -42,7 +42,7 @@ function get_samples_for_dio(fs::Real, len::Integer, period::Real)
(Int, Int, Float64), fs, len, period)
end

function dio(x::AbstractVector{Float64}, fs::Real, opt::DioOption)
function dio(x::AbstractVector{Float64}, fs::Real, opt::DioOption=DioOption())
expectedlen = get_samples_for_dio(fs, length(x), opt.period)
f0 = Array(Float64, expectedlen)
timeaxis = Array(Float64, expectedlen)
Expand Down
11 changes: 5 additions & 6 deletions test/consistency.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,41 @@ x = vec(readdlm(joinpath(dirname(@__FILE__), "data", "x.txt")))

fs = 16000
period = 5.0
w = World(fs, period)
opt = DioOption(71.0, 800.0, 2, period, 1)

# Fundamental frequency (f0) estimation by DIO
f0, timeaxis = dio(w, x; opt=opt)
f0, timeaxis = dio(x, fs, opt)
f0_org = vec(readdlm(joinpath(dirname(@__FILE__), "data", "f0.txt")))

println("Maximum error in DIO is $(maximum(abs(f0-f0_org)))")
@test length(f0) == length(f0_org)
@test_approx_eq_eps f0 f0_org 1.0e-10

# F0 refienment by StoneMask
f0 = stonemask(w, x, timeaxis, f0)
f0 = stonemask(x, fs, timeaxis, f0)
f0_refined_org = vec(readdlm(joinpath(dirname(@__FILE__), "data", "f0_refined.txt")))

println("Maximum error in StoneMask is $(maximum(abs(f0-f0_refined_org)))")
@test length(f0) == length(f0_refined_org)
@test_approx_eq_eps f0 f0_refined_org 1.0e-10

# Spectral envelope estimation by CheapTrick
spectrogram = cheaptrick(w, x, timeaxis, f0)
spectrogram = cheaptrick(x, fs, timeaxis, f0)
spectrogram_org = readdlm(joinpath(dirname(@__FILE__), "data", "spectrogram.txt"))'

println("Maximum error in CheapTrick is $(maximum(abs(spectrogram - spectrogram_org)))")
@test size(spectrogram) == size(spectrogram_org)
@test_approx_eq_eps spectrogram spectrogram_org 1.0e-10

aperiodicity = d4c(w, x, timeaxis, f0)
aperiodicity = d4c(x, fs, timeaxis, f0)
aperiodicity_org = readdlm(joinpath(dirname(@__FILE__), "data", "aperiodicity.txt"))'
println("Maximum error in D4C is $(maximum(abs(aperiodicity-aperiodicity_org)))")
@test size(aperiodicity) == size(aperiodicity)
@test_approx_eq_eps aperiodicity aperiodicity_org 1.0e-10

# Synthesis
y_length = convert(Int, ((length(f0)-1)*period/1000 * fs) + 1)
y = synthesis(w, f0, spectrogram, aperiodicity, y_length)
y = synthesis(f0, spectrogram, aperiodicity, period, fs, y_length)
y_org = vec(readdlm(joinpath(dirname(@__FILE__), "data", "x_synthesized.txt")))
println("Maximum error in Synthesis is $(maximum(abs(y-y_org)))")
@test length(y) == length(y_org)
Expand Down
48 changes: 18 additions & 30 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,37 @@ using WAV

function test_dio(x, fs::Int=44100, period::Float64=5.0)
println("test_dio: fs=$(fs), period=$(period)")
w = World(fs, period)
opt = DioOption(71.0, 800.0, 2, period, 1)
f0, timeaxis = dio(w, x; opt=opt)
f0, timeaxis = dio(x, fs, opt)
@test !any(isnan(f0))
@test all(f0 .>= 0.0)
@test !any(isnan(timeaxis))
end

function test_stonemask(x, fs::Int=44100, period::Float64=5.0)
println("test_stonemask: fs=$(fs), period=$(period)")
w = World(fs, period)
opt = DioOption(71.0, 800.0, 2, period, 1)
f0, timeaxis = dio(w, x; opt=opt)
f0 = stonemask(w, x, timeaxis, f0)
f0, timeaxis = dio(x, fs, opt)
f0 = stonemask(x, fs, timeaxis, f0)
@test !any(isnan(f0))
@test all(f0 .>= 0.0)
end

function test_cheaptrick(x, fs::Int=44100, period::Float64=5.0)
println("test_cheaptrick: fs=$(fs), period=$(period)")
w = World(fs, period)
opt = DioOption(71.0, 800.0, 2, period, 1)
f0, timeaxis = dio(w, x; opt=opt)
f0 = stonemask(w, x, timeaxis, f0)
spectrogram = cheaptrick(w, x, timeaxis, f0)
f0, timeaxis = dio(x, fs, opt)
f0 = stonemask(x, fs, timeaxis, f0)
spectrogram = cheaptrick(x, fs, timeaxis, f0)
@test !any(isnan(spectrogram))
end

function test_d4c(x, fs::Int=44100, period::Float64=5.0)
println("test_d4c: fs=$(fs), period=$(period)")
w = World(fs, period)
opt = DioOption(71.0, 800.0, 2, period, 1)
f0, timeaxis = dio(w, x; opt=opt)
f0 = stonemask(w, x, timeaxis, f0)
aperiodicity = d4c(w, x, timeaxis, f0)
f0, timeaxis = dio(x, fs, opt)
f0 = stonemask(x, fs, timeaxis, f0)
aperiodicity = d4c(x, fs, timeaxis, f0)
@test !any(isnan(aperiodicity))
end

Expand All @@ -53,29 +49,28 @@ function test_synthesis(x::AbstractArray, fs::Int=44100,
tol::Float64=0.1)
println("test_synthesis: fs=$(fs), period=$(period), tol=$(tol)")

w = World(fs, period)
opt = DioOption(71.0, 800.0, 2, period, 1)

# Fundamental frequency (f0) estimation by DIO
f0, timeaxis = dio(w, x; opt=opt)
f0, timeaxis = dio(x, fs, opt)
@test !any(isnan(f0))
@test !any(isnan(timeaxis))

# F0 re-estimation by StoneMask
f0 = stonemask(w, x, timeaxis, f0)
f0 = stonemask(x, fs, timeaxis, f0)
@test !any(isnan(f0))

# Spectral envelope estimation
spectrogram = cheaptrick(w, x, timeaxis, f0)
spectrogram = cheaptrick(x, fs, timeaxis, f0)
@test !any(isnan(spectrogram))

# Aperiodicity ratio estimation by D4C
aperiodicity = d4c(w, x, timeaxis, f0)
aperiodicity = d4c(x, fs, timeaxis, f0)
@test !any(isnan(aperiodicity))

# Sysnthesis from f0, spectral envelope and aperiodicity ratio.
y_length = convert(Int, (length(f0)-1)*period/1000 * fs + 1)
y = synthesis(w, f0, spectrogram, aperiodicity, length(x))
y = synthesis(f0, spectrogram, aperiodicity, period, fs, length(x))
@test !any(isnan(y))

minlen = min(length(x), length(y))
Expand All @@ -102,7 +97,7 @@ for period in [5.0, 7.0, 10.0]
end

# Test WORLD speech decomposition and re-synthesis
for (period, tol) in ([5.0, 0.14],[10.0, 0.16])
for (period, tol) in ([5.0, 0.15],[10.0, 0.16])
test_synthesis(x, fs, period, tol)
end

Expand All @@ -112,10 +107,9 @@ println("WORLD decomposition and re-synthesis tests passed.")

let
@assert fs == 16000
w = World(fs, 5.0)
f0, timeaxis = dio(w, x)
f0 = stonemask(w, x, timeaxis, f0)
spectrogram = cheaptrick(w, x, timeaxis, f0)
f0, timeaxis = dio(x, fs)
f0 = stonemask(x, fs, timeaxis, f0)
spectrogram = cheaptrick(x, fs, timeaxis, f0)
spec = spectrogram[:,30]

α = 0.41
Expand Down Expand Up @@ -145,12 +139,6 @@ end

# get_fftsize

let
w1 = World(44100, 5.0)
w2 = World(fs=44100, period=5.0)
@test w1 == w2
end

for fs in [16000, 20000]
c = get_fftsize_for_cheaptrick(fs)
@test c == 1024
Expand Down

0 comments on commit 7880b9c

Please sign in to comment.