Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NaN gradient in spectrogram #617

Merged
merged 2 commits into from
Dec 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/audio/spectrogram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ See [`stft`](@ref) for other arguments.
Spectrogram in the shape `(T, F, B)`, where
`T` is the number of window hops and `F = n_fft ÷ 2 + 1`.
"""
function spectrogram(waveform;
function spectrogram(waveform::AbstractArray{T};
pad::Int = 0, n_fft::Int, hop_length::Int, window,
center::Bool = true, power::Real = 2.0,
normalized::Bool = false, window_normalized::Bool = false,
)
) where T
pad > 0 && (waveform = pad_zeros(waveform, pad; dims=1);)

# Pack batch dimensions.
Expand All @@ -41,8 +41,8 @@ function spectrogram(waveform;
window_normalized && (spec = spec .* inv(norm(window));)

if power > 0
p = eltype(waveform)(power)
spec = abs.(spec).^p
p = T(power)
spec = abs.(spec .+ eps(T)).^p
end
return spec
end
Expand Down
Loading