-
Notifications
You must be signed in to change notification settings - Fork 0
Redesign as a complete STFT/ISTFT toolkit (0.4, breaking) #3
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
|
|
||
| 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 | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.