Repository navigation
A major release with some breaking changes: the library no longer panics on
input it can check, and the types say more about the values they carry. Nothing
about the analysis itself changed, so the numbers you get out stay the same.
Documentation improved a lot.
Migrating
- The two lookups return an
Optionnow, so add a?or anunwrap():
spectrum.freq_val_exact(1000.0)andfreq_val_closest(1000.0)give
Nonefor a frequency outside the spectrum instead of panicking. FrequencyandFrequencyValueare different types now. Both compare and
calculate withf32directly, soassert!(value > 0.85)works and most
val()calls can go.- Build a frequency limit with
FrequencyLimit::{min,max,range}instead of
the variants, which hold aNonNegF32now. - Gone for good:
scaling::combined(use a closure),
FrequencySpectrum::{median,to_map,to_mel_map,mel_val}(usedata()or
to_vec()),FrequencyLimit::{min,max}as getters (usemaybe_min()and
maybe_max()),FrequencySpectrum::newand itsDefaultimplementation
(a spectrum comes fromsamples_fft_to_spectrum). - Errors moved around:
TooFewSamplesandSamplesLengthNotAPowerOfTwo
becameInvalidLengthOfSamples, andInvalidSamplingRateis new.
Fewer panics
- BREAKING
FrequencySpectrum::{freq_val_exact,freq_val_closest}return
Nonefor a frequency outside the spectrum, and forNaN, which slipped
through the bounds check before - BREAKING more than 32768 samples is an error instead of a panic
- BREAKING a sampling rate of zero is rejected with the new
SpectrumAnalyzerError::InvalidSamplingRate, instead of producing a
spectrum in which every frequency is0 Hz - BREAKING removed
FrequencyLimit::{min,max}, which panicked for
variants without that bound - BREAKING
FrequencySpectrum::newis internal and theDefault
implementation is gone; the empty spectrum it produced made every getter
panic
Frequencies and values have their own types
- BREAKING a
Frequencyis aNonNegF32and aFrequencyValuea
FiniteF32, so the two cannot be mixed up. The difference is real: a
frequency is never negative, a value turns negative as soon as
scale_20_times_log10touches it - BREAKING
FrequencyLimit::{Min,Max,Range}hold aNonNegF32, which
makes a negative or non-regular limit impossible to build.
FrequencyLimitError::{NotARegularNumber,ValueBelowMinimum}are gone with
it - BREAKING
FrequencySpectrum::frequency_resolution,
scaling::SpectrumDataStats::{min,max,average}and
FrequencyLimitError::{ValueAboveNyquist,InvalidRange}carry those types
as well.SpectrumDataStats::nstays anf32, since it is there to
divide by
A thinner spectrum
- BREAKING removed
scaling::combined; it handed every function the
statistics of the unscaled spectrum, so chaining two of them gave wrong
results. A closure does the same job correctly - BREAKING removed
FrequencySpectrum::medianand
SpectrumDataStats::median; nothing in the library used them - BREAKING removed
FrequencySpectrum::{to_map,to_mel_map}; both used
u32keys, so bins that shared a key silently overwrote each other - BREAKING removed
FrequencySpectrum::mel_val; such calculations are
easy to do ondata(), and the spectrum stays thin and unopinionated
Fixed
- the Hamming and Blackman-Harris windows used the symmetric form (dividing
byN - 1) while the Hann window used the periodic one (dividing byN).
All of them use the periodic form now, which is the right one for FFT
analysis. The coefficients change marginally and the coherent gains are
exact scale_20_times_log10mapped0.0to0 dB, which ranked silence above
every quieter bin. Values are clamped to-100 dBat minimum now- the descriptions of
FrequencyLimit::MinandFrequencyLimit::Maxwere
swapped
Performance
- spectrum creation no longer allocates and scans a working buffer for the
median, which makes it 20-30% faster depending on the number of samples
Documentation
- explained what the frequency values are and how they relate to the input
signal, including the expected range of the samples - added guidance on which window function and which scaling function to pick
- documented the coherent gain of each window, and the difference between the
periodic and the symmetric form - clarified
divide_by_Nagainstdivide_by_N_sqrt, and the statistics a
scaling function receives - fixed the frequency resolution formula; it is
sample_rate / N, not
sample_rate / (N / 2)
What's Changed
- docs: clarify frequency values, scaling, and windows by @phip1611 in #85
- scaling: simplify the API and add guidance on picking settings by @phip1611 in #86
- spectrum: remove the map conversions and fix doc statements by @phip1611 in #87
- windows: use the periodic form and misc doc fixes by @phip1611 in #88
- spectrum: tighten the public API and fix the CI setup by @phip1611 in #89
- doc: streamline and remove outdated by @phip1611 in #90
- lib: replace the remaining panics with Option and Result by @phip1611 in #91
- document the expected range of samples and FiniteF32 helper by @phip1611 in #92
- lib: say what the one remaining panic means by @phip1611 in #93
Full Changelog: v1.9.0...v2.0.0