Skip to content

Commit

Permalink
Move audio documentation to its own page
Browse files Browse the repository at this point in the history
- Convert examples to doctests or evaluate during build time
-More tests
  • Loading branch information
pxl-th committed Jun 7, 2024
1 parent bd76e9f commit 5460ed7
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 111 deletions.
3 changes: 3 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
FLAC = "abae9e3b-a9a0-4778-b5c6-ca109b507d99"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd"
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
24 changes: 13 additions & 11 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ using Documenter, NNlib
DocMeta.setdocmeta!(NNlib, :DocTestSetup, :(using NNlib); recursive = true)

makedocs(modules = [NNlib],
sitename = "NNlib.jl",
doctest = false,
pages = ["Home" => "index.md",
"Reference" => "reference.md"],
format = Documenter.HTML(
canonical = "https://fluxml.ai/NNlib.jl/stable/",
# analytics = "UA-36890222-9",
assets = ["assets/flux.css"],
prettyurls = get(ENV, "CI", nothing) == "true"),
warnonly=[:missing_docs,]
)
sitename = "NNlib.jl",
doctest = true,
pages = ["Home" => "index.md",
"Reference" => "reference.md",
"Audio" => "audio.md"],
format = Documenter.HTML(
canonical = "https://fluxml.ai/NNlib.jl/stable/",
# analytics = "UA-36890222-9",
assets = ["assets/flux.css"],
prettyurls = get(ENV, "CI", nothing) == "true",
size_threshold=nothing),
warnonly=[:missing_docs,]
)

deploydocs(repo = "github.com/FluxML/NNlib.jl.git",
target = "build",
Expand Down
Binary file added docs/src/assets/jfk.flac
Binary file not shown.
40 changes: 40 additions & 0 deletions docs/src/audio.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Reference

## Window functions

```@docs
hann_window
hamming_window
```

## Spectral

```@docs
stft
istft
NNlib.power_to_db
NNlib.db_to_power
```

## Spectrogram

```@docs
spectrogram
```

Example:

```@example 1
using NNlib
using FileIO
using UnicodePlots
waveform, sampling_rate = load("./assets/jfk.flac")
lineplot(reshape(waveform, :); width=50, color=:white)
```

```@example 1
n_fft = 256
spec = spectrogram(waveform; n_fft, hop_length=n_fft ÷ 4, window=hann_window(n_fft))
heatmap(NNlib.power_to_db(spec)[:, :, 1]; width=80, height=30)
```
12 changes: 0 additions & 12 deletions docs/src/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,3 @@ NNlib.glu
NNlib.within_gradient
bias_act!
```

## Spectral

```@docs
hann_window
hamming_window
stft
istft
spectrogram
NNlib.power_to_db
NNlib.db_to_power
```
28 changes: 9 additions & 19 deletions src/audio/spectrogram.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
"""
spectrogram(waveform;
pad::Int = 0, n_fft::Int, hop_length::Int, window,
center::Bool = true, power::Real = 2.0,
normalized::Bool = false, window_normalized::Bool = false,
)
Create a spectrogram or a batch of spectrograms from a raw audio signal.
# Arguments
- `pad::Int`:
Then amount of padding to apply on both sides.
Default is `0`.
- `window_normalized::Bool`:
Whether to normalize the waveform by the window’s L2 energy.
Default is `false`.
- `power::Real`:
Exponent for the magnitude spectrogram (must be ≥ 0)
e.g., `1` for magnitude, `2` for power, etc.
Expand All @@ -21,19 +24,6 @@ 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`.
# Example
```julia
julia> waveform, sampling_rate = load("test.flac");
julia> spec = spectrogram(waveform;
n_fft=1024, hop_length=128, window=hann_window(1024));
julia> spec_db = NNlib.power_to_db(spec);
julia> Makie.heatmap(spec_db[:, :, 1])
```
"""
function spectrogram(waveform;
pad::Int = 0, n_fft::Int, hop_length::Int, window,
Expand All @@ -48,7 +38,7 @@ function spectrogram(waveform;
n_fft, hop_length, window, center, normalized)
# Unpack batch dimensions.
spec = reshape(spec_, (size(spec_)[1:2]..., sz[2:end]...))
window_normalized && (spec .*= inv(norm(window));)
window_normalized && (spec = spec .* inv(norm(window));)

if power > 0
p = real(eltype(spec)(power))
Expand All @@ -65,10 +55,10 @@ Convert a power spectrogram (amplitude squared) to decibel (dB) units.
# Arguments
- `s`: Input power.
- `ref`: Scalar w.r.t. which the input is scaled. Default is `1`.
- `amin`: Minimum threshold for `s`. Default is `1f-10`.
- `ref`: Scalar w.r.t. which the input is scaled.
- `amin`: Minimum threshold for `s`.
- `top_db`: Threshold the output at `top_db` below the peak:
`max.(s_db, maximum(s_db) - top_db)`. Default is `80`.
`max.(s_db, maximum(s_db) - top_db)`.
# Returns
Expand Down
132 changes: 63 additions & 69 deletions src/audio/stft.jl
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
"""
hann_window(
hamming_window(
window_length::Int, ::Type{T} = Float32; periodic::Bool = true,
α::T = T(0.54), β::T = T(0.46),
) where T <: Real
Hann window function.
Hamming window function
(ref: https://en.wikipedia.org/wiki/Window_function#Hann_and_Hamming_windows).
Generalized version of `hann_window`.
``w[n] = \\frac{1}{2}[1 - cos(\\frac{2 \\pi n}{N - 1})]``
``w[n] = \\alpha - \\beta cos(\\frac{2 \\pi n}{N - 1})``
Where ``N`` is the window length.
```julia
julia> lineplot(hann_window(100))
┌────────────────────────────────────────┐
1 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠎⠉⠉⠉⠣⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠎⠀⠀⠀⠀⠀⠀⠀⠣⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠱⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠱⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠱⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡎⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢣⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡜⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢇⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⡜⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢇⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⡰⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⡆⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⡰⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⡄⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⡠⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⡄⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⡰⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢄⠀⠀⠀⠀│
│⠀⠀⠀⠀⡔⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢆⠀⠀⠀│
0 │⣀⣀⡔⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢆⣀│
└────────────────────────────────────────┘
⠀0⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀100⠀
julia> lineplot(hamming_window(100); width=30, height=10)
┌──────────────────────────────┐
1 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠚⠉⠉⠉⠢⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠎⠁⠀⠀⠀⠀⠀⠈⢢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⢣⡀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⢰⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠱⡀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⣠⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠳⡀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⢰⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠱⡄⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⡰⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠱⡀⠀⠀⠀⠀│
│⠀⠀⠀⢀⠴⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢄⠀⠀⠀│
│⠀⢀⡠⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠳⣀⠀│
0 │⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉│
└──────────────────────────────┘
⠀0⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀100⠀
```
# Arguments:
- `window_length::Int`: Size of the window.
- `::Type{T}`: Elemet type of the window. Default is `Float32`.
- `::Type{T}`: Elemet type of the window.
# Keyword Arguments:
Expand All @@ -43,63 +41,64 @@ julia> lineplot(hann_window(100))
Following always holds:
```julia
hann_window(N; periodic=true) ≈ hann_window(N + 1; periodic=false)[1:end - 1]
```jldoctest
julia> N = 256;
julia> hamming_window(N; periodic=true) ≈ hamming_window(N + 1; periodic=false)[1:end - 1]
true
```
- `α::Real`: Coefficient α in the equation above.
- `β::Real`: Coefficient β in the equation above.
# Returns:
Vector of length `window_length` and eltype `T`.
"""
function hann_window(
function hamming_window(
window_length::Int, ::Type{T} = Float32; periodic::Bool = true,
α::T = T(0.54), β::T = T(0.46),
) where T <: Real
window_length < 1 && throw(ArgumentError(
"`window_length` must be > 0, instead: `$window_length`."))

n::T = ifelse(periodic, window_length, window_length - 1)
scale = T(2) * π / n
[T(0.5) * (T(1) - cos(scale * T(k))) for k in 0:(window_length - 1)]
return- β * cos(scale * T(k)) for k in 0:(window_length - 1)]
end

"""
hamming_window(
hann_window(
window_length::Int, ::Type{T} = Float32; periodic::Bool = true,
α::T = T(0.54), β::T = T(0.46),
) where T <: Real
Hamming window function. Generalized version of `hann_window`.
Hann window function
(ref: https://en.wikipedia.org/wiki/Window_function#Hann_and_Hamming_windows).
``w[n] = \\alpha - \\beta cos(\\frac{2 \\pi n}{N - 1})``
``w[n] = \\frac{1}{2}[1 - cos(\\frac{2 \\pi n}{N - 1})]``
Where ``N`` is the window length.
```julia
julia> lineplot(hamming_window(100))
┌────────────────────────────────────────┐
1 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠊⠉⠉⠉⠓⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠎⠀⠀⠀⠀⠀⠀⠀⠣⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡴⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡰⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡰⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡰⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⡄⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⢠⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⡄⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⣠⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⡄⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⡠⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⡄⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⡰⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢄⠀⠀⠀⠀│
│⠀⠀⠀⢀⠎⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠣⡀⠀⠀│
│⣀⠤⠖⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠢⠤│
0 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
└────────────────────────────────────────┘
⠀0⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀100⠀
julia> lineplot(hann_window(100); width=30, height=10)
┌──────────────────────────────┐
1 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠚⠉⠉⠉⠢⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡔⠁⠀⠀⠀⠀⠀⠘⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠞⠀⠀⠀⠀⠀⠀⠀⠀⠈⢆⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⢀⡎⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢣⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⡎⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢦⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⢀⠞⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢆⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⢀⡜⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢇⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⢀⠎⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢦⠀⠀⠀⠀│
│⠀⠀⠀⢠⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠣⡀⠀⠀│
0 │⣀⣀⠔⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢤⣀│
└──────────────────────────────┘
⠀0⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀100⠀
```
# Arguments:
- `window_length::Int`: Size of the window.
- `::Type{T}`: Elemet type of the window. Default is `Float32`.
- `::Type{T}`: Elemet type of the window.
# Keyword Arguments:
Expand All @@ -108,26 +107,24 @@ julia> lineplot(hamming_window(100))
Following always holds:
```julia
hamming_window(N; periodic=true) ≈ hamming_window(N + 1; periodic=false)[1:end - 1]
```jldoctest
julia> N = 256;
julia> hann_window(N; periodic=true) ≈ hann_window(N + 1; periodic=false)[1:end - 1]
true
julia> hann_window(N) ≈ hamming_window(N; α=0.5f0, β=0.5f0)
true
```
- `α::Real`: Coefficient α in the equation above.
- `β::Real`: Coefficient β in the equation above.
# Returns:
Vector of length `window_length` and eltype `T`.
"""
function hamming_window(
function hann_window(
window_length::Int, ::Type{T} = Float32; periodic::Bool = true,
α::T = T(0.54), β::T = T(0.46),
) where T <: Real
window_length < 1 && throw(ArgumentError(
"`window_length` must be > 0, instead: `$window_length`."))

n::T = ifelse(periodic, window_length, window_length - 1)
scale = T(2) * π / n
- β * cos(scale * T(k)) for k in 0:(window_length - 1)]
hamming_window(window_length, T; periodic, α=T(0.5), β=T(0.5))
end

"""
Expand Down Expand Up @@ -156,14 +153,13 @@ and ``m`` is the index of the sliding window.
- `n_fft::Int`: Size of Fourier transform.
- `hop_length::Int`: Distance between neighboring sliding window frames.
Default is `n_fft ÷ 4`.
- `window`: Optional window function to apply.
Must be 1D vector `0 < length(window) ≤ n_fft`.
If window is shorter than `n_fft`, it is padded with zeros on both sides.
If `nothing` (default), then no window is applied.
- `center::Bool`: Whether to pad input on both sides so that ``t``-th frame
is centered at time ``t \\times \\text{hop length}``.
Default is `true`. Padding is done with `pad_reflect` function.
Padding is done with `pad_reflect` function.
- `normalized::Bool`: Whether to return normalized STFT,
i.e. multiplied with ``\\text{n fft}^{-0.5}``.
Expand Down Expand Up @@ -222,7 +218,7 @@ function stft(x;
use_window && (x = x .* window;)
y = eltype(x) <: Complex ? fft(x, region) : rfft(x, region)

normalized && (y .*= n_fft^-0.5;)
normalized && (y = y .* n_fft^-0.5;)
return y
end

Expand All @@ -247,16 +243,14 @@ Return the least squares estimation of the original signal
- `n_fft::Int`: Size of Fourier transform.
- `hop_length::Int`: Distance between neighboring sliding window frames.
Default is `n_fft ÷ 4`.
- `window`: Window function that was applied to the input of `stft`.
If `nothing` (default), then no window was applied.
- `center::Bool`: Whether input to `stft` was padded on both sides
so that ``t``-th frame is centered at time ``t \\times \\text{hop length}``.
Default is `true`. Padding is done with `pad_reflect` function.
Padding is done with `pad_reflect` function.
- `normalized::Bool`: Whether input to `stft` was normalized.
- `return_complex::Bool`: Whether the output should be complex,
or if the input should be assumed to derive from a real signal and window.
Default `false`.
- `original_length::Union{Nothing, Int}`: Optional size of the first dimension
of the input to `stft`. Helps restoring the exact `stft` input size.
Otherwise, the array might be a bit shorter.
Expand Down
Loading

0 comments on commit 5460ed7

Please sign in to comment.