-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from phip1611/dev
Release v1.3
- Loading branch information
Showing
27 changed files
with
680 additions
and
402 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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,10 +1,10 @@ | ||
[package] | ||
name = "spectrum-analyzer" | ||
description = """ | ||
A simple and fast `no_std` library to get the frequency spectrum of a digital signal (e.g. audio) using FFT. | ||
It follows the KISS principle and consists of simple building blocks/optional features. | ||
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.2.6" | ||
version = "1.3.0" | ||
authors = ["Philipp Schuster <[email protected]>"] | ||
edition = "2021" | ||
keywords = ["fft", "spectrum", "frequencies", "audio", "dsp"] | ||
|
@@ -20,6 +20,10 @@ exclude = [ | |
".github" | ||
] | ||
|
||
[[bench]] | ||
name = "fft_spectrum_bench" | ||
harness = false | ||
|
||
[features] | ||
# by default we use microfft-real: it's the fastest and totally fit's our needs. | ||
# As of version 0.5.0 there is no advantage by using other implementations. | ||
|
@@ -47,12 +51,14 @@ minimp3 = "0.5" | |
# visualize spectrum in tests and examples | ||
audio-visualizer = "0.3" | ||
# get audio input in examples | ||
cpal = "0.13" | ||
cpal = "0.15.0" | ||
# audio data buffering | ||
ringbuffer = "0.8" # REQUIRES Rust Stable 1.55 because it uses "ringbuffer v0.8" | ||
ringbuffer = "0.12.0" | ||
rand = "0.8" # for benchmark | ||
# exit in examples | ||
ctrlc = "3.2" | ||
# for benchmark | ||
criterion = "0.4" | ||
|
||
|
||
# otherwise FFT and other code is too slow | ||
|
This file contains 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
This file contains 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
This file contains 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,57 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use spectrum_analyzer::{ | ||
samples_fft_to_spectrum, scaling, windows, FrequencyLimit, FrequencySpectrum, | ||
}; | ||
|
||
fn spectrum_without_scaling(samples: &[f32]) -> FrequencySpectrum { | ||
samples_fft_to_spectrum(samples, 44100, FrequencyLimit::All, None).unwrap() | ||
} | ||
|
||
fn spectrum_with_scaling(samples: &[f32]) -> FrequencySpectrum { | ||
samples_fft_to_spectrum( | ||
samples, | ||
44100, | ||
FrequencyLimit::All, | ||
Some(&scaling::divide_by_N_sqrt), | ||
) | ||
.unwrap() | ||
} | ||
|
||
fn spectrum_with_multiple_scaling(samples: &[f32]) -> FrequencySpectrum { | ||
let mut spectrum = spectrum_with_scaling(samples); | ||
|
||
let mut working_buffer = vec![(0.0.into(), 0.0.into()); spectrum.data().len()]; | ||
|
||
spectrum | ||
.apply_scaling_fn(&scaling::divide_by_N_sqrt, &mut working_buffer) | ||
.unwrap(); | ||
spectrum | ||
.apply_scaling_fn(&scaling::divide_by_N_sqrt, &mut working_buffer) | ||
.unwrap(); | ||
spectrum | ||
.apply_scaling_fn(&scaling::divide_by_N_sqrt, &mut working_buffer) | ||
.unwrap(); | ||
spectrum | ||
} | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
// create 2048 random samples | ||
let samples = (0..2048) | ||
.map(|_| rand::random::<i16>()) | ||
.map(|x| x as f32) | ||
.collect::<Vec<_>>(); | ||
let hann_window = windows::hann_window(&samples); | ||
|
||
c.bench_function("spectrum without scaling", |b| { | ||
b.iter(|| spectrum_without_scaling(black_box(&hann_window))) | ||
}); | ||
c.bench_function("spectrum with scaling", |b| { | ||
b.iter(|| spectrum_without_scaling(black_box(&hann_window))) | ||
}); | ||
c.bench_function("spectrum with multiple scaling steps", |b| { | ||
b.iter(|| spectrum_with_multiple_scaling(black_box(&hann_window))) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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,16 @@ | ||
{ pkgs ? import <nixpkgs> {} }: | ||
pkgs.mkShell rec { | ||
nativeBuildInputs = with pkgs; [ | ||
pkg-config | ||
]; | ||
|
||
buildInputs = with pkgs; [ | ||
alsa-lib | ||
fontconfig | ||
libxkbcommon | ||
xorg.libXcursor | ||
xorg.libX11 | ||
]; | ||
|
||
LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath buildInputs}"; | ||
} |
This file contains 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
Oops, something went wrong.