-
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.
- Loading branch information
Showing
19 changed files
with
1,184 additions
and
279 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ 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. | ||
""" | ||
version = "0.5.2" | ||
version = "1.0.0" | ||
authors = ["Philipp Schuster <[email protected]>"] | ||
edition = "2018" | ||
keywords = ["fft", "spectrum", "frequencies", "audio", "dsp"] | ||
|
@@ -33,16 +33,27 @@ microfft-complex = ["microfft"] | |
microfft-real = ["microfft"] | ||
|
||
[dependencies] | ||
rustfft = { version = "6.0.0", optional = true } | ||
microfft = { version = "0.4.0", optional = true } | ||
rustfft = { version = "6.0", optional = true } | ||
microfft = { version = "0.4", optional = true } | ||
# approx. compare floats; not only in tests but also during runtime | ||
float-cmp = "0.8.0" | ||
float-cmp = "0.9.0" | ||
# sin() cos() log10() etc for no_std-environments; these are not part of Core library | ||
libm = "0.2.1" | ||
|
||
[dev-dependencies] | ||
# readmp3 files in tests and examples | ||
minimp3 = "0.5.1" | ||
# visualize spectrum in tests and examples | ||
audio-visualizer = "0.2.2" | ||
# get audio input in examples | ||
cpal = "0.13.4" | ||
# CLI example | ||
tui = { version = "0.16", default-features = false, features = ['crossterm'] } | ||
crossterm = "0.21.0" | ||
# audio data buffering | ||
ringbuffer = "0.7.1" | ||
rand = "0.8.4" | ||
|
||
|
||
# otherwise FFT and other code is too slow | ||
[profile.dev] | ||
|
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,99 @@ | ||
/* | ||
MIT License | ||
Copyright (c) 2021 Philipp Schuster | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
|
||
#![deny( | ||
clippy::all, | ||
clippy::cargo, | ||
clippy::nursery, | ||
// clippy::restriction, | ||
// clippy::pedantic | ||
)] | ||
// now allow a few rules which are denied by the above statement | ||
// --> they are ridiculous and not necessary | ||
#![allow( | ||
clippy::suboptimal_flops, | ||
clippy::redundant_pub_crate, | ||
clippy::fallible_impl_from | ||
)] | ||
#![deny(missing_debug_implementations)] | ||
#![deny(rustdoc::all)] | ||
|
||
use std::time::Instant; | ||
|
||
use spectrum_analyzer::*; | ||
|
||
/// Benchmark can be used to check how changes effect the performance. | ||
/// Always execute with release flag! | ||
fn main() { | ||
// 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); | ||
|
||
let bench_res_without_scaling = bench_without_scaling(hann_window.clone()); | ||
let bench_res_with_scaling = bench_with_scaling(hann_window); | ||
|
||
println!( | ||
"Bench without scaling: avg = {}us per Iteration", | ||
bench_res_without_scaling | ||
); | ||
println!( | ||
"Bench with scaling: avg = {}us per Iteration", | ||
bench_res_with_scaling | ||
); | ||
} | ||
|
||
fn bench_without_scaling(samples: Vec<f32>) -> u64 { | ||
let fnc = move || samples_fft_to_spectrum(&samples, 44100, FrequencyLimit::All, None).unwrap(); | ||
bench_fnc(Box::new(fnc)) | ||
} | ||
|
||
fn bench_with_scaling(samples: Vec<f32>) -> u64 { | ||
let fnc = move || { | ||
samples_fft_to_spectrum( | ||
&samples, | ||
44100, | ||
FrequencyLimit::All, | ||
Some(&scaling::divide_by_N), | ||
) | ||
.unwrap() | ||
}; | ||
bench_fnc(Box::new(fnc)) | ||
} | ||
|
||
fn bench_fnc(fnc: Box<dyn Fn() -> FrequencySpectrum>) -> u64 { | ||
// warm-up | ||
for _ in 0..10 { | ||
let _ = fnc(); | ||
} | ||
let now = Instant::now(); | ||
let runs = 10000; | ||
for _ in 0..runs { | ||
let _ = fnc(); | ||
} | ||
let duration = now.elapsed(); | ||
(duration.as_micros() / runs) as u64 | ||
} |
Oops, something went wrong.