some minor test file restructuring
This commit is contained in:
parent
89043b80c9
commit
10802a61f3
3 changed files with 11 additions and 46 deletions
|
@ -9,24 +9,6 @@ const TEST_BUF_SIZE = 1024
|
||||||
|
|
||||||
include("testhelpers.jl")
|
include("testhelpers.jl")
|
||||||
|
|
||||||
# convenience function to calculate the mean-squared error
|
|
||||||
function mse(arr1::Array, arr2::Array)
|
|
||||||
@assert length(arr1) == length(arr2)
|
|
||||||
N = length(arr1)
|
|
||||||
err = 0.0
|
|
||||||
for i in 1:N
|
|
||||||
err += (arr2[i] - arr1[i])^2
|
|
||||||
end
|
|
||||||
err /= N
|
|
||||||
end
|
|
||||||
|
|
||||||
mse(X::AbstractArray, thresh=1e-8) = Y::AbstractArray -> begin
|
|
||||||
if size(X) != size(Y)
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
return mse(X, Y) < thresh
|
|
||||||
end
|
|
||||||
|
|
||||||
type TestAudioStream <: AudioIO.AudioStream
|
type TestAudioStream <: AudioIO.AudioStream
|
||||||
root::AudioIO.AudioMixer
|
root::AudioIO.AudioMixer
|
||||||
|
@ -99,27 +81,6 @@ facts("AudioNode Stopping") do
|
||||||
@fact process(test_stream) => zeros(AudioIO.AudioSample, TEST_BUF_SIZE)
|
@fact process(test_stream) => zeros(AudioIO.AudioSample, TEST_BUF_SIZE)
|
||||||
end
|
end
|
||||||
|
|
||||||
facts("WAV file write/read") do
|
|
||||||
fname = Pkg.dir("AudioIO", "test", "sinwave.wav")
|
|
||||||
|
|
||||||
samplerate = 44100
|
|
||||||
freq = 440
|
|
||||||
t = [0 : 2 * samplerate - 1] / samplerate
|
|
||||||
phase = 2 * pi * freq * t
|
|
||||||
reference = int16((2 ^ 15 - 1) * sin(phase))
|
|
||||||
|
|
||||||
AudioIO.open(fname, "w") do f
|
|
||||||
write(f, reference)
|
|
||||||
end
|
|
||||||
|
|
||||||
AudioIO.open(fname) do f
|
|
||||||
@fact f.sfinfo.channels => 1
|
|
||||||
@fact f.sfinfo.frames => 2 * samplerate
|
|
||||||
actual = read(f, 2 * samplerate)
|
|
||||||
@fact reference => mse(actual)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
facts("Audio Device Listing") do
|
facts("Audio Device Listing") do
|
||||||
# there aren't any devices on the Travis machine so just test that this doesn't crash
|
# there aren't any devices on the Travis machine so just test that this doesn't crash
|
||||||
@fact get_audio_devices() => issubtype(Array)
|
@fact get_audio_devices() => issubtype(Array)
|
||||||
|
|
|
@ -2,12 +2,8 @@ module TestAudioIONodes
|
||||||
|
|
||||||
using FactCheck
|
using FactCheck
|
||||||
using AudioIO
|
using AudioIO
|
||||||
import AudioIO.AudioSample
|
import AudioIO: AudioSample, AudioBuf, AudioRenderer, AudioNode
|
||||||
import AudioIO.AudioBuf
|
import AudioIO: DeviceInfo, render
|
||||||
import AudioIO.AudioRenderer
|
|
||||||
import AudioIO.AudioNode
|
|
||||||
import AudioIO.DeviceInfo
|
|
||||||
import AudioIO.render
|
|
||||||
|
|
||||||
include("testhelpers.jl")
|
include("testhelpers.jl")
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# convenience function to calculate the mean-squared error
|
# convenience function to calculate the mean-squared error
|
||||||
function mse(arr1::Array, arr2::Array)
|
function mse(arr1::AbstractArray, arr2::AbstractArray)
|
||||||
@assert length(arr1) == length(arr2)
|
@assert length(arr1) == length(arr2)
|
||||||
N = length(arr1)
|
N = length(arr1)
|
||||||
err = 0.0
|
err = 0.0
|
||||||
|
@ -9,6 +9,14 @@ function mse(arr1::Array, arr2::Array)
|
||||||
err /= N
|
err /= N
|
||||||
end
|
end
|
||||||
|
|
||||||
|
mse(X::AbstractArray, thresh=1e-8) = Y::AbstractArray -> begin
|
||||||
|
if size(X) != size(Y)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
return mse(X, Y) < thresh
|
||||||
|
end
|
||||||
|
|
||||||
issubtype(T::Type) = x -> typeof(x) <: T
|
issubtype(T::Type) = x -> typeof(x) <: T
|
||||||
lessthan(rhs) = lhs -> lhs < rhs
|
lessthan(rhs) = lhs -> lhs < rhs
|
||||||
greaterthan(rhs) = lhs -> lhs > rhs
|
greaterthan(rhs) = lhs -> lhs > rhs
|
||||||
|
|
Loading…
Reference in a new issue