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

Multichannel overlap-add convolver with one shared kernel FFT. More...

#include <fft.H>

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

Public Member Functions

 OverlapAddBank (const size_t num_channels, const Array< Real > &kernel, const size_t block_size=0)
 
 OverlapAddBank (const OverlapAddBank &other)=default
 Copy the kernel, the plan and the pending tails of another bank.
 
 OverlapAddBank (OverlapAddBank &&other) noexcept
 Take the state of another bank, which is left empty.
 
OverlapAddBank & operator= (const OverlapAddBank &other)=default
 Copy the kernel, the plan and the pending tails of another bank.
 
OverlapAddBank & operator= (OverlapAddBank &&other) noexcept
 Exchange this bank with another, which is left with the previous state of this one.
 
void swap (OverlapAddBank &other) noexcept
 Exchange in O(1) the state of this bank and another.
 
size_t num_channels () const noexcept
 
size_t block_size () const noexcept
 
size_t fft_size () const noexcept
 
size_t overlap_size () const noexcept
 Returns the size of the tail of each channel.
 
const Array< Real > & kernel () const noexcept
 
void reset ()
 
Array< Array< Real > > convolve (const Array< Array< Real > > &signals) const
 Convolve a whole signal per channel with the kernel.
 
Array< Array< Real > > pconvolve (ThreadPool &pool, const Array< Array< Real > > &signals, const size_t chunk_size=0) const
 convolve() with parallel transforms.
 
Array< Array< Real > > process_block (const Array< Array< Real > > &block)
 Convolve the next samples of a stream per channel.
 
Array< Array< Real > > pprocess_block (ThreadPool &pool, const Array< Array< Real > > &block, const size_t chunk_size=0)
 process_block() with parallel transforms.
 
Array< Array< Real > > flush ()
 
Array< Array< Real > > pflush (ThreadPool &pool, const size_t chunk_size=0)
 

Private Member Functions

void validate_channel_count (const size_t count, const char *ctx) const
 Rationale: Internal safety guard.
 
Array< Complex > build_signal_block (const Array< Real > &signal, const size_t offset=0, const size_t length=std::numeric_limits< size_t >::max()) const
 implementation helper for preparing a signal block for FFT.
 
Array< Array< Complex > > build_signal_batch (const Array< Array< Real > > &block) const
 implementation helper for preparing a batch of signal blocks.
 
Array< Array< Complex > > build_signal_batch (const Array< Array< Real > > &source, const Array< size_t > &channels, const Array< size_t > &lengths, const size_t offset=0) const
 implementation helper for preparing a subset of signal blocks.
 
void pointwise_multiply_batch (Array< Array< Complex > > &spectra, ThreadPool *pool, const size_t chunk_size) const
 Rationale: Parallel pointwise multiplication of multiple signal spectra with the shared kernel spectrum.
 
void clear_channel_overlap (const size_t channel)
 Rationale: Resets the overlap buffer for a single channel.
 
void clear_overlaps ()
 
Array< Array< Real > > process_chunk_batch_impl (const Array< Array< Real > > &block, ThreadPool *pool, const size_t chunk_size)
 
Array< Array< Real > > convolve_impl (const Array< Array< Real > > &signals, ThreadPool *pool, const size_t chunk_size) const
 

Static Private Member Functions

static size_t default_block_size (const size_t kernel_size)
 Rationale: Selects a block size that is at least as large as the kernel to ensure efficient FFT processing (defaults to power of two).
 
static size_t max_batch_length (const Array< Array< Real > > &signals) noexcept
 Returns the maximum signal length in a batch.
 
static Array< Real > slice_chunk (const Array< Real > &input, const size_t offset, const size_t length)
 Returns a contiguous slice of input.
 

Private Attributes

Array< Real > kernel_
 
size_t block_size_ = 0
 
size_t fft_size_ = 0
 
Plan plan_
 
Array< Complex > kernel_spectrum_
 
Array< Array< Real > > overlaps_
 
Array< bool > has_pending_tail_
 

Detailed Description

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

Multichannel overlap-add convolver with one shared kernel FFT.

All channels reuse the same transform plan and kernel spectrum. This avoids recomputing the kernel FFT per channel and enables batched FFT execution when many channels share the same FIR kernel.

Definition at line 14573 of file fft.H.

Constructor & Destructor Documentation

◆ OverlapAddBank() [1/3]

◆ OverlapAddBank() [2/3]

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

Copy the kernel, the plan and the pending tails of another bank.

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

◆ OverlapAddBank() [3/3]

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

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

The implicit move took the kernel, the plan and the buffers but copied the sizes: after a move assignment, the source kept its sizes with the plan tables and the buffers of the other bank. Now it has no channels, no kernel and sizes of 0: it rejects every batch, while reset(), flush() and an assignment to it still work.

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

Definition at line 14910 of file fft.H.

Member Function Documentation

◆ block_size()

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

◆ build_signal_batch() [1/2]

template<std::floating_point Real = double>
Array< Array< Complex > > Aleph::FFT< Real >::OverlapAddBank::build_signal_batch ( const Array< Array< Real > > &  block) const
inlineprivate

implementation helper for preparing a batch of signal blocks.

Definition at line 14652 of file fft.H.

References Aleph::FFT< Real >::OverlapAddBank::build_signal_block().

Referenced by Aleph::FFT< Real >::OverlapAddBank::convolve_impl(), and Aleph::FFT< Real >::OverlapAddBank::process_chunk_batch_impl().

◆ build_signal_batch() [2/2]

template<std::floating_point Real = double>
Array< Array< Complex > > Aleph::FFT< Real >::OverlapAddBank::build_signal_batch ( const Array< Array< Real > > &  source,
const Array< size_t > &  channels,
const Array< size_t > &  lengths,
const size_t  offset = 0 
) const
inlineprivate

implementation helper for preparing a subset of signal blocks.

Definition at line 14662 of file fft.H.

References Aleph::FFT< Real >::OverlapAddBank::build_signal_block(), offset, and Aleph::Array< T >::size().

◆ build_signal_block()

template<std::floating_point Real = double>
Array< Complex > Aleph::FFT< Real >::OverlapAddBank::build_signal_block ( const Array< Real > &  signal,
const size_t  offset = 0,
const size_t  length = std::numeric_limits<size_t>::max() 
) const
inlineprivate

◆ clear_channel_overlap()

template<std::floating_point Real = double>
void Aleph::FFT< Real >::OverlapAddBank::clear_channel_overlap ( const size_t  channel)
inlineprivate

◆ clear_overlaps()

template<std::floating_point Real = double>
void Aleph::FFT< Real >::OverlapAddBank::clear_overlaps ( )
inlineprivate

◆ convolve()

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

Convolve a whole signal per channel with the kernel.

Parameters
[in]signalsone signal per channel.
Returns
the linear convolution of each signal.
Exceptions
std::runtime_errorif the bank is empty (it was moved from).
std::invalid_argumentif signals does not have num_channels() signals.

Definition at line 14986 of file fft.H.

References ah_runtime_error_if, Aleph::FFT< Real >::OverlapAddBank::convolve_impl(), Aleph::Array< T >::is_empty(), Aleph::FFT< Real >::OverlapAddBank::kernel_, and Aleph::FFT< Real >::OverlapAddBank::validate_channel_count().

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

◆ convolve_impl()

◆ default_block_size()

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

Rationale: Selects a block size that is at least as large as the kernel to ensure efficient FFT processing (defaults to power of two).

Definition at line 14587 of file fft.H.

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

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

◆ fft_size()

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

Definition at line 14960 of file fft.H.

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

◆ flush()

template<std::floating_point Real = double>
Array< Array< Real > > Aleph::FFT< Real >::OverlapAddBank::flush ( )
inline

◆ kernel()

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

Definition at line 14971 of file fft.H.

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

◆ max_batch_length()

template<std::floating_point Real = double>
static size_t Aleph::FFT< Real >::OverlapAddBank::max_batch_length ( const Array< Array< Real > > &  signals)
inlinestaticprivatenoexcept

◆ num_channels()

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

◆ operator=() [1/2]

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

Copy the kernel, the plan and the pending tails of another bank.

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

◆ operator=() [2/2]

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

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

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

Definition at line 14934 of file fft.H.

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

◆ overlap_size()

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

Returns the size of the tail of each channel.

Returns
kernel().size() - 1, or 0 for an empty bank (moved from), which has no kernel.

Definition at line 14966 of file fft.H.

References Aleph::Array< T >::is_empty(), Aleph::FFT< Real >::OverlapAddBank::kernel_, and Aleph::Array< T >::size().

◆ pconvolve()

template<std::floating_point Real = double>
Array< Array< Real > > Aleph::FFT< Real >::OverlapAddBank::pconvolve ( ThreadPool &  pool,
const Array< Array< Real > > &  signals,
const size_t  chunk_size = 0 
) const
inline

convolve() with parallel transforms.

Parameters
[in]poolthread pool for the transforms.
[in]signalsone signal per channel.
[in]chunk_sizeminimum iterations per parallel chunk (0 = auto).
Returns
the linear convolution of each signal.
Exceptions
std::runtime_errorif the bank is empty (it was moved from).
std::invalid_argumentif signals does not have num_channels() signals.

Definition at line 15005 of file fft.H.

References ah_runtime_error_if, Aleph::FFT< Real >::OverlapAddBank::convolve_impl(), Aleph::Array< T >::is_empty(), Aleph::FFT< Real >::OverlapAddBank::kernel_, and Aleph::FFT< Real >::OverlapAddBank::validate_channel_count().

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

◆ pflush()

template<std::floating_point Real = double>
Array< Array< Real > > Aleph::FFT< Real >::OverlapAddBank::pflush ( ThreadPool &  pool,
const size_t  chunk_size = 0 
)
inline

◆ pointwise_multiply_batch()

template<std::floating_point Real = double>
void Aleph::FFT< Real >::OverlapAddBank::pointwise_multiply_batch ( Array< Array< Complex > > &  spectra,
ThreadPool *  pool,
const size_t  chunk_size 
) const
inlineprivate

◆ pprocess_block()

template<std::floating_point Real = double>
Array< Array< Real > > Aleph::FFT< Real >::OverlapAddBank::pprocess_block ( ThreadPool &  pool,
const Array< Array< Real > > &  block,
const size_t  chunk_size = 0 
)
inline

process_block() with parallel transforms.

Parameters
[in]poolthread pool for the transforms.
[in]blocknext samples of each channel, of any number.
[in]chunk_sizeminimum iterations per parallel chunk (0 = auto).
Returns
one output sample for each sample of block, per channel.
Exceptions
std::runtime_errorif the bank is empty (it was moved from).
std::invalid_argumentif block does not have num_channels() channels.

Definition at line 15071 of file fft.H.

References ah_runtime_error_if, Aleph::Array< T >::append(), Aleph::FFT< Real >::OverlapAddBank::block_size_, Aleph::Array< T >::is_empty(), Aleph::FFT< Real >::OverlapAddBank::kernel_, Aleph::FFT< Real >::OverlapAddBank::max_batch_length(), offset, Aleph::FFT< Real >::OverlapAddBank::process_chunk_batch_impl(), Aleph::Array< T >::reserve(), Aleph::Array< T >::size(), Aleph::size(), Aleph::FFT< Real >::OverlapAddBank::slice_chunk(), and Aleph::FFT< Real >::OverlapAddBank::validate_channel_count().

◆ process_block()

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

Convolve the next samples of a stream per channel.

Parameters
[in]blocknext samples of each channel, of any number.
Returns
one output sample for each sample of block, per channel.
Exceptions
std::runtime_errorif the bank is empty (it was moved from).
std::invalid_argumentif block does not have num_channels() channels.

Definition at line 15023 of file fft.H.

References ah_runtime_error_if, Aleph::Array< T >::append(), Aleph::FFT< Real >::OverlapAddBank::block_size_, Aleph::Array< T >::is_empty(), Aleph::FFT< Real >::OverlapAddBank::kernel_, Aleph::FFT< Real >::OverlapAddBank::max_batch_length(), offset, Aleph::FFT< Real >::OverlapAddBank::process_chunk_batch_impl(), Aleph::Array< T >::reserve(), Aleph::Array< T >::size(), Aleph::size(), Aleph::FFT< Real >::OverlapAddBank::slice_chunk(), and Aleph::FFT< Real >::OverlapAddBank::validate_channel_count().

◆ process_chunk_batch_impl()

◆ reset()

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

Definition at line 14973 of file fft.H.

References Aleph::FFT< Real >::OverlapAddBank::clear_overlaps().

◆ slice_chunk()

template<std::floating_point Real = double>
static Array< Real > Aleph::FFT< Real >::OverlapAddBank::slice_chunk ( const Array< Real > &  input,
const size_t  offset,
const size_t  length 
)
inlinestaticprivate

◆ swap()

◆ validate_channel_count()

template<std::floating_point Real = double>
void Aleph::FFT< Real >::OverlapAddBank::validate_channel_count ( const size_t  count,
const char *  ctx 
) const
inlineprivate

Member Data Documentation

◆ block_size_

◆ fft_size_

◆ has_pending_tail_

◆ kernel_

◆ kernel_spectrum_

template<std::floating_point Real = double>
Array<Complex> Aleph::FFT< Real >::OverlapAddBank::kernel_spectrum_
private

◆ overlaps_

◆ plan_


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