|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Reusable overlap-add convolver for long real sequences. More...
#include <fft.H>
Public Member Functions | |
| OverlapAdd (const Array< Real > &kernel, const size_t block_size=0) | |
| OverlapAdd (const OverlapAdd &other)=default | |
| Copy the kernel, the plan and the pending tail of another convolver. | |
| OverlapAdd (OverlapAdd &&other) noexcept | |
| Take the state of another convolver, which is left empty. | |
| OverlapAdd & | operator= (const OverlapAdd &other)=default |
| Copy the kernel, the plan and the pending tail of another convolver. | |
| OverlapAdd & | operator= (OverlapAdd &&other) noexcept |
| Exchange this convolver with another, which is left with the previous state of this one. | |
| void | swap (OverlapAdd &other) noexcept |
| Exchange in O(1) the state of this convolver and another. | |
| size_t | block_size () const noexcept |
| size_t | fft_size () const noexcept |
| const Array< Real > & | kernel () const noexcept |
| size_t | overlap_size () const noexcept |
| void | reset () |
| Array< Real > | convolve (const Array< Real > &signal) const |
| Convolve a whole signal with the kernel. | |
| Array< Real > | pconvolve (ThreadPool &pool, const Array< Real > &signal, const size_t chunk_size=0) const |
| Convolve a whole signal with the kernel, with parallel transforms. | |
| Array< Real > | process_block (const Array< Real > &block) |
| Convolve the next samples of a stream; the tail of each block is added to the next ones, and flush() returns the last one. | |
| Array< Real > | pprocess_block (ThreadPool &pool, const Array< Real > &block, const size_t chunk_size=0) |
| process_block() with parallel transforms. | |
| Array< Real > | flush () |
| template<typename Container > requires Is_Real_Container<Container> | |
| Array< Real > | convolve (const Container &signal) const |
| convolve() of the samples of a real container. | |
| template<typename Container > requires Is_Real_Container<Container> | |
| Array< Real > | pconvolve (ThreadPool &pool, const Container &signal, const size_t chunk_size=0) const |
| pconvolve() of the samples of a real container. | |
| 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 > | pprocess_block (ThreadPool &pool, const Container &block, const size_t chunk_size=0) |
| pprocess_block() of the samples of a real container. | |
Private Member Functions | |
| Array< Complex > | build_signal_block (const Array< Real > &signal, const size_t offset, const size_t length) const |
| Rationale: Prepares a chunk of signal for FFT by zero-padding it to the internal fft_size(). | |
| void | pointwise_multiply (Array< Complex > &spectrum, ThreadPool *pool, const size_t chunk_size) const |
| Rationale: Applies the precomputed FIR kernel in the frequency domain via element-wise multiplication. | |
| void | clear_overlap () |
| Rationale: Resets the overlap buffer between independent convolution runs. | |
| Array< Real > | process_chunk_impl (const Array< Real > &block, ThreadPool *pool, const size_t chunk_size) |
| Rationale: Implements the core Overlap-Add logic for a single block: | |
| Array< Real > | convolve_impl (const Array< Real > &signal, ThreadPool *pool, const size_t chunk_size) const |
| implementation of one-shot linear convolution. | |
Static Private Member Functions | |
| static size_t | default_block_size (const size_t kernel_size) |
Private Attributes | |
| Array< Real > | kernel_ |
| size_t | block_size_ = 0 |
| size_t | fft_size_ = 0 |
| Plan | plan_ |
| Array< Complex > | kernel_spectrum_ |
| Array< Real > | overlap_ |
| bool | has_pending_tail_ = false |
Reusable overlap-add convolver for long real sequences.
The kernel spectrum is precomputed once. Input signals are processed in blocks of size block_size(), each block transformed with an FFT of size fft_size() and accumulated in the output via overlap-add.
|
inlineexplicit |
Definition at line 14269 of file fft.H.
References ah_invalid_argument_if, Aleph::FFT< Real >::OverlapAdd::block_size(), Aleph::FFT< Real >::OverlapAdd::block_size_, Aleph::FFT< Real >::OverlapAdd::clear_overlap(), Aleph::Array< T >::create(), Aleph::FFT< Real >::OverlapAdd::default_block_size(), Aleph::FFT< Real >::OverlapAdd::fft_size_, Aleph::Array< T >::is_empty(), Aleph::FFT< Real >::OverlapAdd::kernel_, Aleph::FFT< Real >::OverlapAdd::kernel_spectrum_, Aleph::FFT< Real >::next_power_of_two(), Aleph::FFT< Real >::OverlapAdd::overlap_, Aleph::FFT< Real >::OverlapAdd::plan_, Aleph::Array< T >::size(), and Aleph::FFT< Real >::Plan::transform().
|
default |
Copy the kernel, the plan and the pending tail of another convolver.
| [in] | other | convolver to copy. |
| std::bad_alloc | if the buffers cannot be allocated. |
|
inlinenoexcept |
Take the state of another convolver, which is left empty.
The implicit move took the kernel, the plan and the buffers but copied the sizes: the moved-from convolver then transformed blocks with a plan that it no longer had. Now its sizes are 0 and it has no kernel: it rejects every block and signal, while reset(), flush() and an assignment to it still work.
| [in,out] | other | convolver to move from. |
|
inlinenoexcept |
Definition at line 14362 of file fft.H.
References Aleph::FFT< Real >::OverlapAdd::block_size_.
Referenced by Aleph::FFT< Real >::OverlapAdd::OverlapAdd().
|
inlineprivate |
Rationale: Prepares a chunk of signal for FFT by zero-padding it to the internal fft_size().
Definition at line 14127 of file fft.H.
References Aleph::Array< T >::create(), Aleph::FFT< Real >::OverlapAdd::fft_size_, and offset.
Referenced by Aleph::FFT< Real >::OverlapAdd::convolve_impl(), and Aleph::FFT< Real >::OverlapAdd::process_chunk_impl().
|
inlineprivate |
Rationale: Resets the overlap buffer between independent convolution runs.
Definition at line 14163 of file fft.H.
References Aleph::FFT< Real >::OverlapAdd::has_pending_tail_, Aleph::FFT< Real >::OverlapAdd::overlap_, and Aleph::Array< T >::size().
Referenced by Aleph::FFT< Real >::OverlapAdd::OverlapAdd(), Aleph::FFT< Real >::OverlapAdd::flush(), and Aleph::FFT< Real >::OverlapAdd::reset().
|
inline |
Convolve a whole signal with the kernel.
| [in] | signal | signal to convolve. |
| std::runtime_error | if the convolver is empty (it was moved from). |
| std::invalid_argument | if the size of the result overflows size_t. |
Definition at line 14383 of file fft.H.
References ah_runtime_error_if, Aleph::FFT< Real >::OverlapAdd::convolve_impl(), Aleph::Array< T >::is_empty(), and Aleph::FFT< Real >::OverlapAdd::kernel_.
Referenced by Aleph::FFT< Real >::OverlapAdd::convolve(), Aleph::FFT< Real >::filtfilt(), and Aleph::FFT< Real >::overlap_add_convolution().
|
inline |
convolve() of the samples of a real container.
| Container | type of the container. |
| [in] | signal | signal to convolve. |
| std::runtime_error | if the convolver is empty (it was moved from). |
Definition at line 14508 of file fft.H.
References Aleph::FFT< Real >::build_real_input(), and Aleph::FFT< Real >::OverlapAdd::convolve().
|
inlineprivate |
implementation of one-shot linear convolution.
Definition at line 14228 of file fft.H.
References ah_invalid_argument_if, Aleph::FFT< Real >::OverlapAdd::block_size_, Aleph::FFT< Real >::OverlapAdd::build_signal_block(), Aleph::Array< T >::create(), Aleph::FFT< Real >::Plan::inverse_transform_real(), Aleph::Array< T >::is_empty(), Aleph::FFT< Real >::OverlapAdd::kernel_, offset, output, Aleph::FFT< Real >::Plan::pinverse_transform_real(), Aleph::FFT< Real >::OverlapAdd::plan_, Aleph::FFT< Real >::OverlapAdd::pointwise_multiply(), Aleph::FFT< Real >::Plan::ptransform(), Aleph::Array< T >::size(), Aleph::FFT< Real >::spectrum(), and Aleph::FFT< Real >::Plan::transform().
Referenced by Aleph::FFT< Real >::OverlapAdd::convolve(), and Aleph::FFT< Real >::OverlapAdd::pconvolve().
|
inlinestaticprivate |
Definition at line 14115 of file fft.H.
References ah_invalid_argument_if, and Aleph::FFT< Real >::next_power_of_two().
Referenced by Aleph::FFT< Real >::OverlapAdd::OverlapAdd().
|
inlinenoexcept |
Definition at line 14363 of file fft.H.
References Aleph::FFT< Real >::OverlapAdd::fft_size_.
|
inline |
Definition at line 14485 of file fft.H.
References Aleph::FFT< Real >::OverlapAdd::clear_overlap(), Aleph::FFT< Real >::OverlapAdd::has_pending_tail_, Aleph::Array< T >::is_empty(), and Aleph::FFT< Real >::OverlapAdd::overlap_.
|
inlinenoexcept |
Definition at line 14364 of file fft.H.
References Aleph::FFT< Real >::OverlapAdd::kernel_.
|
default |
Copy the kernel, the plan and the pending tail of another convolver.
| [in] | other | convolver to copy. |
| std::bad_alloc | if the buffers cannot be allocated. |
|
inlinenoexcept |
Exchange this convolver with another, which is left with the previous state of this one.
| [in,out] | other | convolver to move from. |
Definition at line 14342 of file fft.H.
References Aleph::FFT< Real >::OverlapAdd::swap().
|
inlinenoexcept |
Definition at line 14365 of file fft.H.
References Aleph::FFT< Real >::OverlapAdd::overlap_, and Aleph::Array< T >::size().
|
inline |
Convolve a whole signal with the kernel, with parallel transforms.
| [in] | pool | thread pool for the transforms. |
| [in] | signal | signal to convolve. |
| [in] | chunk_size | minimum iterations per parallel chunk (0 = auto). |
| std::runtime_error | if the convolver is empty (it was moved from). |
| std::invalid_argument | if the size of the result overflows size_t. |
Definition at line 14404 of file fft.H.
References ah_runtime_error_if, Aleph::FFT< Real >::OverlapAdd::convolve_impl(), Aleph::Array< T >::is_empty(), and Aleph::FFT< Real >::OverlapAdd::kernel_.
Referenced by Aleph::FFT< Real >::OverlapAdd::pconvolve(), Aleph::FFT< Real >::pfiltfilt(), and Aleph::FFT< Real >::poverlap_add_convolution().
|
inline |
pconvolve() of the samples of a real container.
| Container | type of the container. |
| [in] | pool | thread pool for the transforms. |
| [in] | signal | signal to convolve. |
| [in] | chunk_size | minimum iterations per parallel chunk (0 = auto). |
| std::runtime_error | if the convolver is empty (it was moved from). |
Definition at line 14526 of file fft.H.
References Aleph::FFT< Real >::build_real_input(), and Aleph::FFT< Real >::OverlapAdd::pconvolve().
|
inlineprivate |
Rationale: Applies the precomputed FIR kernel in the frequency domain via element-wise multiplication.
Definition at line 14145 of file fft.H.
References Aleph::and, Aleph::FFT< Real >::OverlapAdd::fft_size_, Aleph::FFT< Real >::OverlapAdd::kernel_spectrum_, Aleph::ThreadPool::num_threads(), Aleph::parallel_for_index(), and Aleph::FFT< Real >::spectrum().
Referenced by Aleph::FFT< Real >::OverlapAdd::convolve_impl(), and Aleph::FFT< Real >::OverlapAdd::process_chunk_impl().
|
inline |
process_block() with parallel transforms.
| [in] | pool | thread pool for the transforms. |
| [in] | block | next samples, of any number. |
| [in] | chunk_size | minimum iterations per parallel chunk (0 = auto). |
block. | std::runtime_error | if the convolver is empty (it was moved from). |
Definition at line 14458 of file fft.H.
References ah_runtime_error_if, Aleph::Array< T >::append(), Aleph::FFT< Real >::OverlapAdd::block_size_, Aleph::Array< T >::is_empty(), Aleph::FFT< Real >::OverlapAdd::kernel_, offset, Aleph::FFT< Real >::OverlapAdd::process_chunk_impl(), Aleph::Array< T >::reserve(), and Aleph::Array< T >::size().
Referenced by Aleph::FFT< Real >::OverlapAdd::pprocess_block().
|
inline |
pprocess_block() of the samples of a real container.
| Container | type of the container. |
| [in] | pool | thread pool for the transforms. |
| [in] | block | next samples. |
| [in] | chunk_size | minimum iterations per parallel chunk (0 = auto). |
block. | std::runtime_error | if the convolver is empty (it was moved from). |
Definition at line 14560 of file fft.H.
References Aleph::FFT< Real >::build_real_input(), and Aleph::FFT< Real >::OverlapAdd::pprocess_block().
|
inline |
Convolve the next samples of a stream; the tail of each block is added to the next ones, and flush() returns the last one.
| [in] | block | next samples, of any number: they are taken block_size() at a time. |
block. | std::runtime_error | if the convolver is empty (it was moved from). |
Definition at line 14422 of file fft.H.
References ah_runtime_error_if, Aleph::Array< T >::append(), Aleph::FFT< Real >::OverlapAdd::block_size_, Aleph::Array< T >::is_empty(), Aleph::FFT< Real >::OverlapAdd::kernel_, offset, Aleph::FFT< Real >::OverlapAdd::process_chunk_impl(), Aleph::Array< T >::reserve(), and Aleph::Array< T >::size().
Referenced by Aleph::FFT< Real >::OverlapAdd::process_block().
|
inline |
process_block() of the samples of a real container.
| Container | type of the container. |
| [in] | block | next samples. |
block. | std::runtime_error | if the convolver is empty (it was moved from). |
Definition at line 14542 of file fft.H.
References Aleph::FFT< Real >::build_real_input(), and Aleph::FFT< Real >::OverlapAdd::process_block().
|
inlineprivate |
Rationale: Implements the core Overlap-Add logic for a single block:
Definition at line 14178 of file fft.H.
References ah_invalid_argument_if, Aleph::FFT< Real >::OverlapAdd::block_size_, Aleph::FFT< Real >::OverlapAdd::build_signal_block(), Aleph::Array< T >::create(), Aleph::FFT< Real >::OverlapAdd::has_pending_tail_, Aleph::FFT< Real >::Plan::inverse_transform_real(), Aleph::Array< T >::is_empty(), Aleph::FFT< Real >::OverlapAdd::overlap_, Aleph::FFT< Real >::Plan::pinverse_transform_real(), Aleph::FFT< Real >::OverlapAdd::plan_, Aleph::FFT< Real >::OverlapAdd::pointwise_multiply(), Aleph::FFT< Real >::Plan::ptransform(), Aleph::Array< T >::size(), Aleph::FFT< Real >::spectrum(), and Aleph::FFT< Real >::Plan::transform().
Referenced by Aleph::FFT< Real >::OverlapAdd::pprocess_block(), and Aleph::FFT< Real >::OverlapAdd::process_block().
|
inline |
Definition at line 14367 of file fft.H.
References Aleph::FFT< Real >::OverlapAdd::clear_overlap().
|
inlinenoexcept |
Exchange in O(1) the state of this convolver and another.
| [in,out] | other | convolver to exchange with. |
Definition at line 14351 of file fft.H.
References Aleph::FFT< Real >::OverlapAdd::block_size_, Aleph::FFT< Real >::OverlapAdd::fft_size_, Aleph::FFT< Real >::OverlapAdd::has_pending_tail_, Aleph::FFT< Real >::OverlapAdd::kernel_, Aleph::FFT< Real >::OverlapAdd::kernel_spectrum_, Aleph::FFT< Real >::OverlapAdd::overlap_, Aleph::FFT< Real >::OverlapAdd::plan_, Aleph::Array< T >::swap(), and Aleph::FFT< Real >::Plan::swap().
Referenced by Aleph::FFT< Real >::OverlapAdd::operator=().
|
private |
Definition at line 14107 of file fft.H.
Referenced by Aleph::FFT< Real >::OverlapAdd::OverlapAdd(), Aleph::FFT< Real >::OverlapAdd::block_size(), Aleph::FFT< Real >::OverlapAdd::convolve_impl(), Aleph::FFT< Real >::OverlapAdd::pprocess_block(), Aleph::FFT< Real >::OverlapAdd::process_block(), Aleph::FFT< Real >::OverlapAdd::process_chunk_impl(), and Aleph::FFT< Real >::OverlapAdd::swap().
|
private |
|
private |
Definition at line 14112 of file fft.H.
Referenced by Aleph::FFT< Real >::OverlapAdd::clear_overlap(), Aleph::FFT< Real >::OverlapAdd::flush(), Aleph::FFT< Real >::OverlapAdd::process_chunk_impl(), and Aleph::FFT< Real >::OverlapAdd::swap().
|
private |
Definition at line 14106 of file fft.H.
Referenced by Aleph::FFT< Real >::OverlapAdd::OverlapAdd(), Aleph::FFT< Real >::OverlapAdd::convolve(), Aleph::FFT< Real >::OverlapAdd::convolve_impl(), Aleph::FFT< Real >::OverlapAdd::kernel(), Aleph::FFT< Real >::OverlapAdd::pconvolve(), Aleph::FFT< Real >::OverlapAdd::pprocess_block(), Aleph::FFT< Real >::OverlapAdd::process_block(), and Aleph::FFT< Real >::OverlapAdd::swap().
|
private |
Definition at line 14110 of file fft.H.
Referenced by Aleph::FFT< Real >::OverlapAdd::OverlapAdd(), Aleph::FFT< Real >::OverlapAdd::pointwise_multiply(), and Aleph::FFT< Real >::OverlapAdd::swap().
|
private |
Definition at line 14111 of file fft.H.
Referenced by Aleph::FFT< Real >::OverlapAdd::OverlapAdd(), Aleph::FFT< Real >::OverlapAdd::clear_overlap(), Aleph::FFT< Real >::OverlapAdd::flush(), Aleph::FFT< Real >::OverlapAdd::overlap_size(), Aleph::FFT< Real >::OverlapAdd::process_chunk_impl(), and Aleph::FFT< Real >::OverlapAdd::swap().
|
private |
Definition at line 14109 of file fft.H.
Referenced by Aleph::FFT< Real >::OverlapAdd::OverlapAdd(), Aleph::FFT< Real >::OverlapAdd::convolve_impl(), Aleph::FFT< Real >::OverlapAdd::process_chunk_impl(), and Aleph::FFT< Real >::OverlapAdd::swap().