一个易于使用且快速的 `no_std` 库 (带有 `alloc`),用于使用 FFT 来获取数字信号 (例如音频) 的频率频谱。
一个易于使用且快速的 `no_std` 库 (带有 `alloc`),用于使用 FFT 来获取数字信号 (例如音频) 的频率频谱。
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.
The base library supports all standard and non-standard targets: Linux, macOS, and Windows, but also embedded systems running custom software.
Please see file /EDUCATIONAL.md.
no_std-contexts)The crate is no_std and only needs alloc, so there is no feature to
enable and nothing to turn off. The most basic usage looks like this:
[dependencies]
spectrum-analyzer = ""…The example above is a good default: a Hann window, divide_by_N, and a
block of 2048 samples. Which window and which scaling function to pick, how
many samples to use, and what the resulting values mean is documented in the
crate documentation, including the
windows and scaling modules.
I've tested multiple FFT implementations and settled on microfft::real. It
was not only the fastest, but is also the only one that works in no_std
contexts.
Run cargo bench for numbers on your machine.
In the following examples you can see a basic visualization of the spectrum from 0 to 4000Hz for
a layered signal of sine waves of 50, 1000, and 3777Hz @ 44100Hz sampling rate. The peaks for the
given frequencies are clearly visible. Each calculation was done with 2048 samples, i.e. ≈46ms of audio signal.
Peaks (50, 1000, 3777 Hz) are clearly visible but also some noise. are clearly visible but also some noise.")
Peaks (50, 1000, 3777 Hz) are clearly visible and Hann window reduces noise a little. Because this example has little noise, you don't see much difference. are clearly visible and Hann window reduces noise a little bit. Because this example has few noise, you don't see much difference.")
Execute example $ cargo run --release --example live-visualization. It will
show you how you can visualize audio data in realtime + the current spectrum.
Tests and examples pull in audio-visualizer, which needs native libraries
for audio input and for the window of the live example. On Ubuntu/Debian
these are libasound2-dev, libgl1-mesa-dev, libx11-dev,
libxcursor-dev, libxi-dev, libxkbcommon-dev, libxrandr-dev, and
libwayland-dev. The flake.nix in this repository provides the same set.
Note that not all tests are "automatic unit tests" but also tests that you need to check visually, by looking at the generated diagram of the spectrum.
The MSRV (minimum supported Rust version) of the library is 1.85.1. To
run benchmarks, tests, and examples you may need a more recent version.
I tested f64 but the additional accuracy doesn't pay out the ~40% calculation overhead (on x86_64).
Apply a window function. The windows module documents which one to pick.
Also check out my blog post.
MIT, see LICENSE.
暂无开放 Issues,或尚未同步最近议题。