Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::FFT< Real >::PartitionedConvolver Class Reference

Uniform partitioned FIR convolver for low-latency streaming. More...

#include <fft.H>

Collaboration diagram for Aleph::FFT< Real >::PartitionedConvolver:
[legend]

Public Member Functions

 PartitionedConvolver (const Array< Real > &kernel, const size_t partition_size=0)
 
 PartitionedConvolver (const PartitionedConvolver &other)=default
 Copy the kernel partitions, the plan and the state of another convolver.
 
 PartitionedConvolver (PartitionedConvolver &&other) noexcept
 Take the state of another convolver, which is left empty.
 
PartitionedConvolver & operator= (const PartitionedConvolver &other)=default
 Copy the kernel partitions, the plan and the state of another convolver.
 
PartitionedConvolver & operator= (PartitionedConvolver &&other) noexcept
 Exchange this convolver with another, which is left with the previous state of this one.
 
void swap (PartitionedConvolver &other) noexcept
 Exchange in O(1) the state of this convolver and another.
 
size_t partition_size () const noexcept
 
size_t fft_size () const noexcept
 
const Array< Real > & kernel () const noexcept
 
void reset ()
 
Array< Real > process_block (const Array< Real > &block)
 Convolve the next samples of a stream, a partition at a time.
 
Array< Real > flush ()
 
Array< Real > convolve (const Array< Real > &signal)
 Convolve a whole signal with the kernel.
 
template<typename Container >
requires Is_Real_Container<Container>
Array< Real > process_block (const Container &block)
 process_block() of the samples of a real container.
 
template<typename Container >
requires Is_Real_Container<Container>
Array< Real > convolve (const Container &signal)
 convolve() of the samples of a real container.
 

Private Member Functions

void clear_state ()
 Rationale: Resets all delay-line history and overlap buffers.
 
Array< Complex > zero_spectrum () const
 implementation helper for creating zero-filled complex spectra.
 
Array< Real > padded_partition (const Array< Real > &chunk) const
 implementation helper for preparing a padded partition.
 
Array< Real > process_partition_impl (const Array< Real > &chunk)
 Rationale: Implements the core frequency-domain partitioned convolution logic:
 

Static Private Member Functions

static size_t default_partition_size (const size_t kernel_size)
 Rationale: Selects a partition size that minimizes latency while maintaining FFT efficiency (capped at 256 for low-latency).
 

Private Attributes

Array< Real > kernel_
 
size_t partition_size_ = 0
 
size_t fft_size_ = 0
 
Plan plan_
 
Array< Array< Complex > > kernel_partitions_
 
Array< Array< Complex > > input_history_
 
size_t head_ = 0
 
Array< Real > overlap_
 
Array< Real > pending_
 
size_t total_input_size_ = 0
 
size_t emitted_output_size_ = 0
 

Detailed Description

template<std::floating_point Real = double>
class Aleph::FFT< Real >::PartitionedConvolver

Uniform partitioned FIR convolver for low-latency streaming.

The partition size controls algorithmic latency directly: each processed partition emits that many time-domain samples.

Definition at line 15521 of file fft.H.

Constructor & Destructor Documentation

◆ PartitionedConvolver() [1/3]

◆ PartitionedConvolver() [2/3]

template<std::floating_point Real = double>
Aleph::FFT< Real >::PartitionedConvolver::PartitionedConvolver ( const PartitionedConvolver &  other)
default

Copy the kernel partitions, the plan and the state of another convolver.

Parameters
[in]otherconvolver to copy.
Exceptions
std::bad_allocif the buffers cannot be allocated.

◆ PartitionedConvolver() [3/3]

template<std::floating_point Real = double>
Aleph::FFT< Real >::PartitionedConvolver::PartitionedConvolver ( PartitionedConvolver &&  other)
inlinenoexcept

Take the state of another convolver, which is left empty.

The implicit move took the kernel partitions, the plan and the buffers but copied the sizes, the head and the counters: the moved-from convolver then transformed partitions with a plan that it no longer had. Now its sizes, head and counters are 0 and it has no kernel: it rejects every block and signal, while reset(), flush() and an assignment to it still work.

Parameters
[in,out]otherconvolver to move from.
Note
Complexity: O(1).

Definition at line 15682 of file fft.H.

Member Function Documentation

◆ clear_state()

◆ convolve() [1/2]

template<std::floating_point Real = double>
Array< Real > Aleph::FFT< Real >::PartitionedConvolver::convolve ( const Array< Real > &  signal)
inline

Convolve a whole signal with the kernel.

Parameters
[in]signalsignal to convolve; the convolver is reset first.
Returns
the linear convolution, with signal.size() + kernel().size() - 1 samples.
Exceptions
std::runtime_errorif the convolver is empty (it was moved from).

Definition at line 15828 of file fft.H.

References ah_runtime_error_if, Aleph::FFT< Real >::append_all(), Aleph::FFT< Real >::PartitionedConvolver::flush(), Aleph::Array< T >::is_empty(), Aleph::FFT< Real >::PartitionedConvolver::kernel_, output, Aleph::FFT< Real >::PartitionedConvolver::process_block(), and Aleph::FFT< Real >::PartitionedConvolver::reset().

Referenced by Aleph::FFT< Real >::PartitionedConvolver::convolve(), and Aleph::FFT< Real >::partitioned_convolution().

◆ convolve() [2/2]

template<std::floating_point Real = double>
template<typename Container >
requires Is_Real_Container<Container>
Array< Real > Aleph::FFT< Real >::PartitionedConvolver::convolve ( const Container &  signal)
inline

convolve() of the samples of a real container.

Template Parameters
Containertype of the container.
Parameters
[in]signalsignal to convolve.
Returns
the linear convolution.
Exceptions
std::runtime_errorif the convolver is empty (it was moved from).

Definition at line 15864 of file fft.H.

References Aleph::FFT< Real >::build_real_input(), and Aleph::FFT< Real >::PartitionedConvolver::convolve().

◆ default_partition_size()

template<std::floating_point Real = double>
static size_t Aleph::FFT< Real >::PartitionedConvolver::default_partition_size ( const size_t  kernel_size)
inlinestaticprivate

Rationale: Selects a partition size that minimizes latency while maintaining FFT efficiency (capped at 256 for low-latency).

Definition at line 15539 of file fft.H.

References ah_invalid_argument_if, and Aleph::FFT< Real >::next_power_of_two().

Referenced by Aleph::FFT< Real >::PartitionedConvolver::PartitionedConvolver().

◆ fft_size()

template<std::floating_point Real = double>
size_t Aleph::FFT< Real >::PartitionedConvolver::fft_size ( ) const
inlinenoexcept

Definition at line 15739 of file fft.H.

References Aleph::FFT< Real >::PartitionedConvolver::fft_size_.

◆ flush()

◆ kernel()

template<std::floating_point Real = double>
const Array< Real > & Aleph::FFT< Real >::PartitionedConvolver::kernel ( ) const
inlinenoexcept

Definition at line 15744 of file fft.H.

References Aleph::FFT< Real >::PartitionedConvolver::kernel_.

◆ operator=() [1/2]

template<std::floating_point Real = double>
PartitionedConvolver & Aleph::FFT< Real >::PartitionedConvolver::operator= ( const PartitionedConvolver &  other)
default

Copy the kernel partitions, the plan and the state of another convolver.

Parameters
[in]otherconvolver to copy.
Returns
this convolver.
Exceptions
std::bad_allocif the buffers cannot be allocated.

◆ operator=() [2/2]

template<std::floating_point Real = double>
PartitionedConvolver & Aleph::FFT< Real >::PartitionedConvolver::operator= ( PartitionedConvolver &&  other)
inlinenoexcept

Exchange this convolver with another, which is left with the previous state of this one.

Parameters
[in,out]otherconvolver to move from.
Returns
this convolver.
Note
Complexity: O(1).

Definition at line 15710 of file fft.H.

References Aleph::FFT< Real >::PartitionedConvolver::swap().

◆ padded_partition()

template<std::floating_point Real = double>
Array< Real > Aleph::FFT< Real >::PartitionedConvolver::padded_partition ( const Array< Real > &  chunk) const
inlineprivate

implementation helper for preparing a padded partition.

Definition at line 15574 of file fft.H.

References Aleph::Array< T >::create(), Aleph::FFT< Real >::PartitionedConvolver::partition_size_, and Aleph::Array< T >::size().

Referenced by Aleph::FFT< Real >::PartitionedConvolver::process_partition_impl().

◆ partition_size()

template<std::floating_point Real = double>
size_t Aleph::FFT< Real >::PartitionedConvolver::partition_size ( ) const
inlinenoexcept

◆ process_block() [1/2]

template<std::floating_point Real = double>
Array< Real > Aleph::FFT< Real >::PartitionedConvolver::process_block ( const Array< Real > &  block)
inline

Convolve the next samples of a stream, a partition at a time.

Parameters
[in]blocknext samples, of any number: they are buffered until a whole partition is available.
Returns
the output of every partition completed so far.
Exceptions
std::runtime_errorif the convolver is empty (it was moved from).

Definition at line 15762 of file fft.H.

References ah_runtime_error_if, Aleph::FFT< Real >::append_all(), Aleph::Array< T >::is_empty(), Aleph::FFT< Real >::PartitionedConvolver::kernel_, Aleph::FFT< Real >::PartitionedConvolver::partition_size_, Aleph::FFT< Real >::PartitionedConvolver::pending_, Aleph::FFT< Real >::PartitionedConvolver::process_partition_impl(), Aleph::Array< T >::size(), Aleph::FFT< Real >::slice_copy(), and Aleph::FFT< Real >::PartitionedConvolver::total_input_size_.

Referenced by Aleph::FFT< Real >::PartitionedConvolver::convolve(), and Aleph::FFT< Real >::PartitionedConvolver::process_block().

◆ process_block() [2/2]

template<std::floating_point Real = double>
template<typename Container >
requires Is_Real_Container<Container>
Array< Real > Aleph::FFT< Real >::PartitionedConvolver::process_block ( const Container &  block)
inline

process_block() of the samples of a real container.

Template Parameters
Containertype of the container.
Parameters
[in]blocknext samples.
Returns
the output of every partition completed so far.
Exceptions
std::runtime_errorif the convolver is empty (it was moved from).

Definition at line 15849 of file fft.H.

References Aleph::FFT< Real >::build_real_input(), and Aleph::FFT< Real >::PartitionedConvolver::process_block().

◆ process_partition_impl()

◆ reset()

template<std::floating_point Real = double>
void Aleph::FFT< Real >::PartitionedConvolver::reset ( )
inline

◆ swap()

◆ zero_spectrum()

template<std::floating_point Real = double>
Array< Complex > Aleph::FFT< Real >::PartitionedConvolver::zero_spectrum ( ) const
inlineprivate

Member Data Documentation

◆ emitted_output_size_

template<std::floating_point Real = double>
size_t Aleph::FFT< Real >::PartitionedConvolver::emitted_output_size_ = 0
private

◆ fft_size_

◆ head_

template<std::floating_point Real = double>
size_t Aleph::FFT< Real >::PartitionedConvolver::head_ = 0
private

◆ input_history_

◆ kernel_

◆ kernel_partitions_

template<std::floating_point Real = double>
Array<Array<Complex> > Aleph::FFT< Real >::PartitionedConvolver::kernel_partitions_
private

◆ overlap_

◆ partition_size_

◆ pending_

template<std::floating_point Real = double>
Array<Real> Aleph::FFT< Real >::PartitionedConvolver::pending_
private

◆ plan_

template<std::floating_point Real = double>
Plan Aleph::FFT< Real >::PartitionedConvolver::plan_
private

◆ total_input_size_

template<std::floating_point Real = double>
size_t Aleph::FFT< Real >::PartitionedConvolver::total_input_size_ = 0
private

The documentation for this class was generated from the following file: