Skip to content

Commit

Permalink
Avoid divide by 0 in soundsc (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffFessler authored Apr 22, 2024
1 parent f2bc8a9 commit 43504ab
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/soundsc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,8 @@ end
soundsc(x, S::Real = framerate(x), args...; kwargs...)
Call `sound` after scaling `x` to have values in `(-1,1)`.
"""
soundsc(x::AbstractArray, S::Real = framerate(x), args...; kwargs...) =
sound(x * prevfloat(1.0) / maximum(abs, x), S, args...; kwargs...)
function soundsc(x::AbstractArray, S::Real = framerate(x), args...; kwargs...)
smax = maximum(abs, x)
scale = smax == 0 ? 1 : prevfloat(1.0) / smax # do not normalize if all zero
sound(x * scale, S, args...; kwargs...)
end

0 comments on commit 43504ab

Please sign in to comment.