From 94ddf9d531f380c62040e3d8f3478668e5269ff1 Mon Sep 17 00:00:00 2001 From: haberdashpi Date: Tue, 22 Oct 2019 18:05:35 -0400 Subject: [PATCH] `dB` quantities maintain floating point precision Adds tests for handling `Float32` numbers without promoting to `Float64` unless necessary. --- src/numbers.jl | 4 ++-- test/runtests.jl | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/numbers.jl b/src/numbers.jl index d5a5417..cba6f12 100644 --- a/src/numbers.jl +++ b/src/numbers.jl @@ -22,8 +22,8 @@ sample rate. """ signal(val::Number,::Nothing,fs) = NumberSignal(val,inHz(Float64,fs)) -signal(val::Unitful.Gain,::Nothing,fs) = - NumberSignal(uconvertrp(NoUnits,val),inHz(Float64,fs),dB=true) +signal(val::Unitful.Gain{<:Any,<:Any,T},::Nothing,fs) where T = + NumberSignal(float(T)(uconvertrp(NoUnits,val)),inHz(Float64,fs),dB=true) SignalTrait(::Type{<:NumberSignal{T,S}}) where {T,S} = IsSignal{T,S,InfiniteLength}() diff --git a/test/runtests.jl b/test/runtests.jl index abd9350..a40f14d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -614,13 +614,13 @@ progress = Progress(total_test_groups,desc="Running tests...") @test x |> append(y) |> until(13s) |> sink |> eltype == Float32 @test x |> pad(zero) |> until(15s) |> sink |> eltype == Float32 @test x |> lowpass(3Hz) |> sink |> eltype == Float32 - @test x |> normpower |> amplify(-10dB) |> sink |> eltype == Float32 + @test x |> normpower |> amplify(-10f0*dB) |> sink |> eltype == Float32 @test x |> mix(y) |> sink(samplerate=10Hz) |> eltype == Float32 @test x |> addchannel(y) |> sink(samplerate=10Hz) |> eltype == Float32 @test x |> channel(1) |> sink(samplerate=10Hz) |> eltype == Float32 - @test_throws x |> ramp |> sink |> eltype == Float32 - @test_throws x |> fadeto(y) |> sink |> eltype == Float32 + @test x |> ramp |> sink |> eltype == Float32 + @test x |> fadeto(y) |> sink |> eltype == Float32 end next!(progress)