Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: cargo
directory: "/"
schedule:
interval: weekly
open-pull-requests-limit: 5
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: weekly
95 changes: 95 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]
Comment thread
sunsided marked this conversation as resolved.

env:
CARGO_TERM_COLOR: always
RUSTFLAGS: "-D warnings"

jobs:
fmt:
name: rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- run: cargo fmt --all --check

clippy:
name: clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- uses: Swatinem/rust-cache@v2
- run: cargo clippy --all-targets --all-features
# The FFT processors (and thus examples/tests/benches) need `std`, so
# lint only the library for the no_std subsets.
- run: cargo clippy --lib --no-default-features
- run: cargo clippy --lib --no-default-features --features mel,serde

test:
name: test (${{ matrix.rust }})
runs-on: ubuntu-latest
strategy:
matrix:
rust: [stable, "1.85"]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- uses: Swatinem/rust-cache@v2
- run: cargo test --all-features
- run: cargo test # default features

no_std:
name: no_std build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: thumbv7em-none-eabihf
- run: cargo build --no-default-features --features mel,serde --target thumbv7em-none-eabihf

docs:
name: doc
runs-on: ubuntu-latest
env:
RUSTDOCFLAGS: "-D warnings --cfg docsrs"
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- run: cargo doc --all-features --no-deps

deny:
name: cargo-deny
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: EmbarkStudios/cargo-deny-action@v2

coverage:
name: coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools-preview
- uses: taiki-e/install-action@cargo-llvm-cov
- uses: Swatinem/rust-cache@v2
- run: cargo llvm-cov --all-features --lcov --output-path lcov.info
- uses: codecov/codecov-action@v4
with:
files: lcov.info
fail_ci_if_error: false
24 changes: 0 additions & 24 deletions .github/workflows/rust.yml

This file was deleted.

30 changes: 0 additions & 30 deletions .travis.yml

This file was deleted.

48 changes: 48 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Changelog

All notable changes to this project are documented here. The format is based
on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.4.0]

This is a ground-up redesign with a clean, encapsulated API. The old `STFT`
type, `WindowType` enum, `FromF64` trait and `log10_positive` free function
have been removed.

### Added

- `Istft` / `IstftBuilder`: inverse STFT with weighted overlap-add for perfect
reconstruction, plus `Stft::inverse()` to mirror a forward transform.
- One-shot batch processing: `Stft::spectrogram()` returning a `Spectrogram`,
with optional centered framing (`reflect`/`edge`/`zero` padding) and optional
`rayon` parallelism.
- A full window library (`Window`, `WindowFunction`, `Symmetry`): rectangular,
Hann, Hamming, Blackman, Blackman-Harris, Nuttall, flat-top, Bartlett,
triangular, Welch, cosine, Tukey, Kaiser and Gaussian, in periodic and
symmetric variants.
- Coefficient scaling modes (`Scaling`: none, magnitude, density).
- `spectrum` helpers: magnitude, power, phase, and decibel conversions.
- `mel` feature: mel filterbank, mel scale conversions, and an orthonormal
DCT-II for MFCCs (librosa-compatible defaults).
- Optional integrations: `ndarray` (`Array2` output), `rayon` (parallel batch),
`serde` (config (de)serialization).
- `no_std` support (with `alloc`) for the window, spectrum and mel math.
- `#![forbid(unsafe_code)]` across the crate.

### Changed

- Switched the FFT backend to `realfft`, roughly halving time and memory for
real-valued input.

### Fixed

- The number of frequency bins is now `fft_size / 2 + 1`, correctly including
the Nyquist bin (previously `fft_size / 2`, which dropped it).
- Bin center frequencies are now `k · fs / fft_size` (previously
`k · fs / (2·(n_freqs − 1))`, which was off).

[Unreleased]: https://github.com/sunsided/stft/compare/v0.4.0...HEAD
[0.4.0]: https://github.com/sunsided/stft/compare/v0.3.1...v0.4.0
59 changes: 49 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,65 @@
[package]
authors = ["Maximilian Krüger <kruemaxi@gmail.com>", "Markus Mayer <widemeadows@gmail.com>"]
description = "computes the short-time fourier transform on streaming data"
authors = [
"Maximilian Krüger <kruemaxi@gmail.com>",
"Markus Mayer <widemeadows@gmail.com>",
]
categories = ["science", "multimedia::audio", "mathematics", "no-std"]
description = "Short-time Fourier transform (STFT) and inverse STFT: streaming and batch spectrograms, a rich window library, mel spectrograms and MFCCs."
documentation = "https://docs.rs/ruststft"
edition = "2021"
homepage = "https://github.com/sunsided/stft"
keywords = ["dsp", "fft", "stream", "data", "fourier"]
keywords = ["dsp", "fft", "stft", "spectrogram", "mfcc"]
license = "MIT OR Apache-2.0"
name = "ruststft"
readme = "README.md"
repository = "https://github.com/sunsided/stft.git"
version = "0.3.1"
edition = "2021"
rust-version = "1.85"
version = "0.4.0"

[features]
default = ["std"]
# Enables the FFT-backed processors (forward/inverse STFT, batch spectrograms).
# Required because the `realfft`/`rustfft` backend depends on `std`.
std = ["dep:realfft", "num-traits/std", "num-complex/std"]
# Mel filterbank, (log-)mel spectrogram and MFCC. Pure math, `no_std`-capable.
mel = []
# `Array2` input/output for batch spectrograms. Pulls in `std`.
ndarray = ["dep:ndarray", "std"]
# Parallel per-frame batch STFT. Pulls in `std`.
rayon = ["dep:rayon", "std"]
# `serde` derives on the configuration and window-specification types.
serde = ["dep:serde"]
# Enable the WASM SIMD (`simd128`) FFT kernels. Implies `std`. Only takes
# effect on `wasm32` targets built with `-C target-feature=+simd128`.
wasm_simd = ["std", "realfft/wasm_simd"]

[dependencies]
apodize = "1.0.0"
num = "0.4.0"
rustfft = "6.1.0"
strider = "0.1.3"
num-complex = { version = "0.4.6", default-features = false, features = ["libm"] }
num-traits = { version = "0.2.19", default-features = false, features = ["libm"] }
realfft = { version = "3.4.0", optional = true }
ndarray = { version = "0.16.1", optional = true, default-features = false, features = ["std"] }
rayon = { version = "1.10.0", optional = true }
serde = { version = "1.0", optional = true, default-features = false, features = ["derive", "alloc"] }

[dev-dependencies]
criterion = "0.5.1"
approx = "0.5.1"
criterion = "0.5.1"
proptest = "1.6.0"

[[bench]]
name = "lib"
harness = false

[[example]]
name = "mfcc"
required-features = ["mel"]

[lints.rust]
unsafe_code = "forbid"

[lints.clippy]
all = "deny"

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
Loading
Loading