Skip to content

Commit

Permalink
Merge branch 'main' into fft-add-larger-buffer-sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
phip1611 authored Dec 16, 2024
2 parents 1f234cc + 5015895 commit 3df9879
Show file tree
Hide file tree
Showing 15 changed files with 182 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
use nix
use flake
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ updates:
- package-ecosystem: cargo
directory: "/"
schedule:
interval: daily
interval: monthly
open-pull-requests-limit: 10
ignore:
- dependency-name: "*"
update-types: [ "version-update:semver-patch" ]
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
interval: monthly
open-pull-requests-limit: 10
27 changes: 24 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,40 @@ env:
CARGO_TERM_COLOR: always

jobs:
build:
build_library_msrv:
strategy:
matrix:
runs-on:
- macos-latest
- ubuntu-latest
- windows-latest
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.63.0 # MSRV
- uses: Swatinem/rust-cache@v2
- run: cargo build
- run: rustup target add thumbv7em-none-eabihf
- run: cargo build --target thumbv7em-none-eabihf

build_all_targets:
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
- nightly
- 1.63.0 # MSRV
steps:
- uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
components: clippy, rustfmt
- uses: Swatinem/rust-cache@v2
- name: Install required Linux packages for "audio-visualizer"/cpal/minifb
run: sudo apt update && sudo apt -y install libasound2-dev libxkbcommon-dev

Expand All @@ -41,14 +60,16 @@ jobs:
strategy:
matrix:
rust:
- 1.63.0 # MSRV
- stable
- nightly
steps:
- uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
components: clippy, rustfmt
- uses: Swatinem/rust-cache@v2
- name: Install required Linux packages for "audio-visualizer"/cpal/minifb
run: sudo apt update && sudo apt -y install libasound2-dev libxkbcommon-dev
- name: Rustfmt
Expand Down
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# Changelog

# Unreleased
## 1.6.0 (2024-12-16)
- dependency updates
- MSRV bump but only for the tests and examples, not library users
- Added FFT buffer sizes of 32768

# 1.5.0 (2023-09-21)
## 1.5.0 (2023-09-21)
- fixed the build by updating the dependencies
- apart from that, no changes happened
- **BREAKING** MSRV is now `1.63.0`
- internal code improvements

# 1.4.0 (2023-03-04)
## 1.4.0 (2023-03-04)
- dropped all optional FFT features (`microfft-complex`, `microfft-real`,
`rustfft-complex`) and made `microfft::real` the default FFT implementation.
This is breaking but only for a small percentage of users. There was no
Expand Down
39 changes: 18 additions & 21 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ description = """
An easy to use and fast `no_std` library (with `alloc`) to get the frequency
spectrum of a digital signal (e.g. audio) using FFT.
"""
version = "1.5.0"
version = "1.6.0"
authors = ["Philipp Schuster <phip1611@gmail.com>"]
edition = "2021"
keywords = ["fft", "spectrum", "frequencies", "audio", "dsp"]
categories = ["multimedia", "no-std"]
rust-version = "1.63" # MSRV of base library, not examples and benchmarks
readme = "README.md"
license = "MIT"
homepage = "https://github.com/phip1611/spectrum-analyzer"
Expand All @@ -25,29 +26,25 @@ name = "fft_spectrum_bench"
harness = false

[dependencies]
microfft = { version = "0.6.0", features = ["size-32768"] }
# approx. compare floats; not only in tests but also during runtime
float-cmp = "0.9.0"
# sin() cos() log10() etc for no_std-environments; these are not part of Core library
libm = "0.2.7"
paste = "1.0.14"
float-cmp = "~0.10.0"
libm = "~0.2.7"
microfft = { version = "~0.6.0", features = ["size-16384"] }
paste = "~1.0.14"

[dev-dependencies]
# readmp3 files in tests and examples
minimp3 = "0.5.1"
# visualize spectrum in tests and examples
audio-visualizer = "0.4.0"
# get audio input in examples
cpal = "0.15.2"
# audio data buffering
ringbuffer = "0.15.0"
rand = "0.8.5" # for benchmark
# exit in examples
ctrlc = "~3.3.1" # locked because of repo MSRV
# for benchmark
criterion = "~0.4.0" # locked because of repo MSRV
audio-visualizer = "~0.4.0"
minimp3 = "~0.5.1"

# Additional dependencies for: examples
cpal = "~0.15.2"
ctrlc = "~3.4.0"
ringbuffer = "~0.15.0"

# otherwise FFT and other code is too slow
# Additional dependencies for: benchmarks
criterion = "~0.5.0"
rand = "0.8.5"


# Faster code in tests, otherwise FFT is too slow
[profile.dev]
opt-level = 1
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ spectrum of a digital signal (e.g. audio) using FFT.

The **MSRV** (minimum supported Rust version) is `1.63.0`.

## Supported Platforms

The base library supports all standard and non-standard targets, such as
machines running Linux, Ubuntu, Windows, but also embedded systems running
custom software.

## I want to understand how FFT can be used to get a spectrum
Please see file [/EDUCATIONAL.md](/EDUCATIONAL.md).

Expand Down
22 changes: 0 additions & 22 deletions check-build.sh

This file was deleted.

27 changes: 27 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
description = "spectrum-analyzer Rust crate";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
};

outputs =
{ self, nixpkgs }@inputs:
{
devShells.x86_64-linux.default =
let
pkgs = inputs.nixpkgs.legacyPackages.x86_64-linux;

# Mainly runtime deps of the examples, not the base lib.
runtimeDeps = with pkgs; [
alsa-lib
fontconfig
libxkbcommon
xorg.libXcursor
xorg.libX11
];
in
pkgs.mkShell {
packages =
with pkgs;
[
pkg-config
]
++ runtimeDeps;
LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath runtimeDeps}";
};
};
}
17 changes: 0 additions & 17 deletions shell.nix

This file was deleted.

17 changes: 8 additions & 9 deletions src/frequency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ impl Display for OrderableF32 {
impl Ord for OrderableF32 {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
self.partial_cmp(other).unwrap()
if self.val() < other.val() {
Ordering::Less
} else if self.val() == other.val() {
Ordering::Equal
} else {
Ordering::Greater
}
}
}

Expand All @@ -81,14 +87,7 @@ impl PartialOrd for OrderableF32 {
#[allow(clippy::float_cmp)]
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
// self.cmp(other).is_eq()
Some(if self.val() < other.val() {
Ordering::Less
} else if self.val() == other.val() {
Ordering::Equal
} else {
Ordering::Greater
})
Some(self.cmp(other))
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ mod tests;
/// to their magnitude.
///
/// * `samples` raw audio, e.g. 16bit audio data but as f32.
/// You should apply an window function (like Hann) on the data first.
/// You should apply a window function (like Hann) on the data first.
/// The final frequency resolution is `sample_rate / (N / 2)`
/// e.g. `44100/(16384/2) == 5.383Hz`, i.e. more samples =>
/// better accuracy/frequency resolution. The amount of samples must
/// be a power of 2. If you don't have enough data, provide zeroes.
/// * `sampling_rate` sampling_rate, e.g. `44100 [Hz]`
/// * `frequency_limit` Frequency limit. See [`FrequencyLimit´]
/// * `scaling_fn` See [`crate::scaling::SpectrumScalingFunction`] for details.
/// * `sampling_rate` The used sampling_rate, e.g. `44100 [Hz]`.
/// * `frequency_limit` The [`FrequencyLimit`].
/// * `scaling_fn` See [`SpectrumScalingFunction`] for details.
///
/// ## Returns value
/// New object of type [`FrequencySpectrum`].
Expand Down Expand Up @@ -219,9 +219,9 @@ pub fn samples_fft_to_spectrum(
/// derived from `fft_result.len()`. There are for example differences for
/// `fft_result.len()` in real and complex FFT algorithms.
/// * `fft_result` Result buffer from FFT. Has the same length as the samples array.
/// * `sampling_rate` sampling_rate, e.g. `44100 [Hz]`
/// * `frequency_limit` Frequency limit. See [`FrequencyLimit´]
/// * `scaling_fn` See [`crate::scaling::SpectrumScalingFunction`].
/// * `sampling_rate` The used sampling_rate, e.g. `44100 [Hz]`.
/// * `frequency_limit` The [`FrequencyLimit`].
/// * `scaling_fn` See [`SpectrumScalingFunction`] for details.
///
/// ## Return value
/// New object of type [`FrequencySpectrum`].
Expand Down
8 changes: 5 additions & 3 deletions src/limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ SOFTWARE.
*/
//! Module for the struct [`FrequencyLimit`].
/// Can be used to specify a desired frequency limit. If you know that you only
/// need frequencies `f <= 1000Hz`, `1000 <= f <= 6777`, or `10000 <= f`, then this
/// can help you to accelerate overall computation speed and memory usage.
/// Can be used to specify a desired frequency limit.
///
/// If you know that you only need frequencies `f <= 1000Hz`,
/// `1000 <= f <= 6777`, or `10000 <= f`, then this can help you to accelerate
/// overall computation speed and memory usage.
///
/// Please note that due to frequency inaccuracies the FFT result may not contain
/// a value for `1000Hz` but for `998.76Hz`!
Expand Down
Loading

0 comments on commit 3df9879

Please sign in to comment.