DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
Loading...
Searching...
No Matches
SpectralProcessor.h File Reference

Zero-allocation streaming STFT framework for spectral processing. More...

#include "FFT.h"
#include "WindowFunctions.h"
#include "AudioSpec.h"
#include "AudioBuffer.h"
#include "DenormalGuard.h"
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstddef>
#include <memory>
#include <vector>
Include dependency graph for SpectralProcessor.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  dspark::SpectralProcessor< T >
 High-performance STFT analysis-modification-synthesis pipeline. More...
 

Namespaces

namespace  dspark
 Main namespace for the DSPark framework.
 

Detailed Description

Zero-allocation streaming STFT framework for spectral processing.

Provides a WOLA (Weighted Overlap-Add) STFT pipeline: input ring -> analysis window -> FFT -> user inline callback -> IFFT -> synthesis window -> overlap-add -> output. Analysis and synthesis both use a periodic sqrt-Hann window, so the round-trip window product is Hann and the constant-overlap-add condition holds exactly for every divisor hop.

The processing callback is a template parameter, so the compiler inlines the frequency-domain modification directly into the hop loop: no std::function allocation and no virtual dispatch on the audio thread.

Latency is exactly fftSize samples and is independent of the caller's block sizes: every STFT frame is anchored to its absolute position in the sample stream, so chopping the stream into arbitrary (even 1-sample) blocks produces bit-identical output.

Threading: owner-managed. prepare()/reset() from a setup thread while idle; processBlock() from the audio thread. No cross-thread setters.

Dependencies: FFT.h, WindowFunctions.h, AudioSpec.h, AudioBuffer.h, DenormalGuard.h.

sp.prepare(spec, 2048);
// Real-time processing in the audio thread using a lambda:
sp.processBlock(buffer, [](float* freqData, int numBins) {
// freqData is interleaved [re0, im0, re1, im1, ...]
// Modify magnitudes/phases here directly.
});
High-performance STFT analysis-modification-synthesis pipeline.
void prepare(const AudioSpec &spec, int fftSize=2048, int hopSize=0)
Allocates buffers and prepares the WOLA processing state.
void processBlock(AudioBufferView< T > buffer, Func &&processFunc) noexcept
Processes a block of audio through the STFT pipeline.

Definition in file SpectralProcessor.h.