Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::signal::StftT< SampleType > Class Template Reference

Allocation-stable STFT processor with single-thread ownership. More...

#include <stft.hpp>

Public Member Functions

 StftT ()=default
 StftT (const StftConfig &config)
void configure (const StftConfig &config)
 RT contract: configure() allocates FFT/window/ring/frame storage and is not audio-thread safe.
bool push_samples (const SampleType *samples, int count)
 Feed audio samples.
const StftFrameT< SampleType > & latest_frame () const
 Access the latest computed frame.
bool frame_ready () const
 Whether at least one frame has been computed.
int num_bins () const
 Number of frequency bins (fft_size/2 + 1).
SampleType window_sum () const
 Sum of the configured analysis-window coefficients.
int fft_size () const
 Current FFT size.
int hop_size () const
 Current hop size.
std::vector< SampleType > latest_magnitude_db (SampleType floor_db=SampleType{-120.0f}) const
 Get the latest frame magnitudes in dB. Not RT-safe; returns a vector.
void reset ()

Static Public Member Functions

static void to_db (SampleType *magnitudes, int count, SampleType floor_db=SampleType{-120.0f})
 Convert linear magnitudes to dB in-place.

Detailed Description

template<typename SampleType = float>
class pulp::signal::StftT< SampleType >

Allocation-stable STFT processor with single-thread ownership.

Feed samples via push_samples(). When enough samples accumulate for a hop, a complete windowed FFT frame is computed. The latest frame is available via latest_frame().

Intended usage keeps push and read on one thread. For realtime visualization, VisualizationBridge copies audio into fixed SPSC storage in the callback, then its UI-owned poll path calls push_samples(), reads the frame, and publishes a snapshot through TripleBuffer.

The STFT itself is NOT thread-safe for concurrent push/read. A TripleBuffer can publish completed results, but does not make concurrent access to this object safe.

Constructor & Destructor Documentation

◆ StftT() [1/2]

template<typename SampleType = float>
pulp::signal::StftT< SampleType >::StftT ( )
default

◆ StftT() [2/2]

template<typename SampleType = float>
pulp::signal::StftT< SampleType >::StftT ( const StftConfig & config)
inlineexplicit

Member Function Documentation

◆ configure()

template<typename SampleType = float>
void pulp::signal::StftT< SampleType >::configure ( const StftConfig & config)
inline

RT contract: configure() allocates FFT/window/ring/frame storage and is not audio-thread safe.

After configure(), push_samples(), latest_frame(), frame_ready(), accessors, to_db(), and reset() are allocation-free, but FFT cost still makes callback use an explicit product-level decision. latest_magnitude_db() returns a vector copy and is not RT-safe.

◆ fft_size()

template<typename SampleType = float>
int pulp::signal::StftT< SampleType >::fft_size ( ) const
inline

Current FFT size.

◆ frame_ready()

template<typename SampleType = float>
bool pulp::signal::StftT< SampleType >::frame_ready ( ) const
inline

Whether at least one frame has been computed.

◆ hop_size()

template<typename SampleType = float>
int pulp::signal::StftT< SampleType >::hop_size ( ) const
inline

Current hop size.

◆ latest_frame()

template<typename SampleType = float>
const StftFrameT< SampleType > & pulp::signal::StftT< SampleType >::latest_frame ( ) const
inline

Access the latest computed frame.

◆ latest_magnitude_db()

template<typename SampleType = float>
std::vector< SampleType > pulp::signal::StftT< SampleType >::latest_magnitude_db ( SampleType floor_db = SampleType{-120.0f}) const
inline

Get the latest frame magnitudes in dB. Not RT-safe; returns a vector.

◆ num_bins()

template<typename SampleType = float>
int pulp::signal::StftT< SampleType >::num_bins ( ) const
inline

Number of frequency bins (fft_size/2 + 1).

◆ push_samples()

template<typename SampleType = float>
bool pulp::signal::StftT< SampleType >::push_samples ( const SampleType * samples,
int count )
inline

Feed audio samples.

Call from the audio thread. Returns true if a new frame was computed during this call.

◆ reset()

template<typename SampleType = float>
void pulp::signal::StftT< SampleType >::reset ( )
inline

◆ to_db()

template<typename SampleType = float>
void pulp::signal::StftT< SampleType >::to_db ( SampleType * magnitudes,
int count,
SampleType floor_db = SampleType{-120.0f} )
inlinestatic

Convert linear magnitudes to dB in-place.

◆ window_sum()

template<typename SampleType = float>
SampleType pulp::signal::StftT< SampleType >::window_sum ( ) const
inline

Sum of the configured analysis-window coefficients.

Consumers that need absolute amplitude calibration can divide DC/Nyquist magnitudes by this value and other one-sided real-FFT magnitudes by half this value.


The documentation for this class was generated from the following file:
  • /home/runner/work/pulp/pulp/core/signal/include/pulp/signal/stft.hpp