Class thl::dsp::fft::StftAnalyser#
-
class StftAnalyser#
Inheritance diagram for thl::dsp::fft::StftAnalyser:
Cuts a stream of samples into overlapping frames and hands each frame’s spectrum to process_spectrum(): the analysis half of a short-time Fourier transform.
push() takes samples in chunks of any size (as they come from a SampleProbe). Every hop_size() samples, once fft_size() have arrived, each channel’s newest fft_size() samples are windowed, transformed (RealFft) and handed to process_spectrum(), channel by channel, the same frame for every channel. The bins are scaled so a sine of amplitude A reads |X| = A at its bin: the window’s coherent gain and the FFT’s N / 2 undone, so a full-scale sine reads 0 dB. DC and Nyquist, which have no mirror image, read their amplitude too.
reset() drops what has been collected: the next frame comes only after fft_size() new samples (after a discontinuity, so no frame spans a gap).
Threads: prepare() allocates; push() and reset() allocate nothing and belong to one thread at a time (a reader thread, not necessarily the audio thread).
Subclassed by thl::dsp::analysis::SpectrumAnalyser
Public Types
Public Functions
-
StftAnalyser() = default#
-
virtual ~StftAnalyser()#
-
StftAnalyser(const StftAnalyser&) = delete#
-
StftAnalyser &operator=(const StftAnalyser&) = delete#
-
bool prepare(size_t fft_size, size_t hop_size, size_t num_channels, Window window = Window::Hann)#
Frames of
fft_size(a power of two RealFft takes), one everyhop_sizesamples (1 to fft_size), fornum_channelschannels.False, and unprepared, otherwise.
-
inline size_t fft_size() const#
-
inline size_t hop_size() const#
-
inline size_t num_bins() const#
-
inline size_t num_channels() const#
-
void push(std::span<const float*const> channels, size_t num_samples)#
Feeds
num_samplesof every channel (channels[c]: channel c; a missing or null one reads as silence).Calls process_spectrum() for every frame that completes.
-
void reset()#
Drops what has been collected: the next frame needs fft_size() new samples.
Protected Functions
-
virtual void process_spectrum(size_t channel, std::span<const std::complex<float>> bins) = 0#
One frame of channel
channel:num_bins() bins, scaled as described above.Called for every channel of a frame in turn.
-
StftAnalyser() = default#