|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Multichannel overlap-add convolver with one shared kernel FFT. More...
#include <fft.H>
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_ |
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.
|
inlineexplicit |
Definition at line 14852 of file fft.H.
References ah_invalid_argument_if, Aleph::Array< T >::append(), Aleph::FFT< Real >::OverlapAddBank::block_size(), Aleph::FFT< Real >::OverlapAddBank::block_size_, Aleph::FFT< Real >::OverlapAddBank::clear_overlaps(), Aleph::Array< T >::create(), Aleph::FFT< Real >::OverlapAddBank::default_block_size(), Aleph::FFT< Real >::OverlapAddBank::fft_size_, Aleph::FFT< Real >::OverlapAddBank::has_pending_tail_, Aleph::Array< T >::is_empty(), Aleph::FFT< Real >::OverlapAddBank::kernel_, Aleph::FFT< Real >::OverlapAddBank::kernel_spectrum_, Aleph::FFT< Real >::next_power_of_two(), Aleph::FFT< Real >::OverlapAddBank::num_channels(), Aleph::FFT< Real >::OverlapAddBank::overlaps_, Aleph::FFT< Real >::OverlapAddBank::plan_, Aleph::Array< T >::reserve(), Aleph::Array< T >::size(), and Aleph::FFT< Real >::Plan::transform().
|
default |
Copy the kernel, the plan and the pending tails of another bank.
| [in] | other | bank to copy. |
| std::bad_alloc | if the buffers cannot be allocated. |
|
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.
| [in,out] | other | bank to move from. |
|
inlinenoexcept |
Definition at line 14959 of file fft.H.
References Aleph::FFT< Real >::OverlapAddBank::block_size_.
Referenced by Aleph::FFT< Real >::OverlapAddBank::OverlapAddBank().
|
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().
|
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().
|
inlineprivate |
implementation helper for preparing a signal block for FFT.
Definition at line 14629 of file fft.H.
References ah_invalid_argument_if, Aleph::FFT< Real >::OverlapAddBank::block_size_, Aleph::Array< T >::create(), Aleph::FFT< Real >::OverlapAddBank::fft_size_, offset, and Aleph::Array< T >::size().
Referenced by Aleph::FFT< Real >::OverlapAddBank::build_signal_batch(), and Aleph::FFT< Real >::OverlapAddBank::build_signal_batch().
|
inlineprivate |
Rationale: Resets the overlap buffer for a single channel.
Definition at line 14698 of file fft.H.
References Aleph::FFT< Real >::OverlapAddBank::has_pending_tail_, and Aleph::FFT< Real >::OverlapAddBank::overlaps_.
Referenced by Aleph::FFT< Real >::OverlapAddBank::clear_overlaps(), Aleph::FFT< Real >::OverlapAddBank::flush(), and Aleph::FFT< Real >::OverlapAddBank::pflush().
|
inlineprivate |
Definition at line 14706 of file fft.H.
References Aleph::FFT< Real >::OverlapAddBank::clear_channel_overlap(), and Aleph::FFT< Real >::OverlapAddBank::overlaps_.
Referenced by Aleph::FFT< Real >::OverlapAddBank::OverlapAddBank(), and Aleph::FFT< Real >::OverlapAddBank::reset().
|
inline |
Convolve a whole signal per channel with the kernel.
| [in] | signals | one signal per channel. |
| std::runtime_error | if the bank is empty (it was moved from). |
| std::invalid_argument | if 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().
|
inlineprivate |
Definition at line 14781 of file fft.H.
References Aleph::Array< T >::append(), Aleph::FFT< Real >::OverlapAddBank::block_size_, Aleph::FFT< Real >::OverlapAddBank::build_signal_batch(), Aleph::Array< T >::create(), Aleph::FFT< Real >::OverlapAddBank::fft_size_, Aleph::FFT< Real >::Plan::inverse_transform_real_batch(), Aleph::Array< T >::is_empty(), Aleph::FFT< Real >::OverlapAddBank::kernel_, Aleph::FFT< Real >::OverlapAddBank::max_batch_length(), offset, output, Aleph::FFT< Real >::Plan::pinverse_transform_real_batch(), Aleph::FFT< Real >::OverlapAddBank::plan_, Aleph::FFT< Real >::OverlapAddBank::pointwise_multiply_batch(), Aleph::FFT< Real >::Plan::ptransform_batch(), Aleph::Array< T >::reserve(), Aleph::FFT< Real >::should_parallelize_batch_work(), Aleph::Array< T >::size(), Aleph::size(), and Aleph::FFT< Real >::Plan::transform_batch().
Referenced by Aleph::FFT< Real >::OverlapAddBank::convolve(), and Aleph::FFT< Real >::OverlapAddBank::pconvolve().
|
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().
|
inlinenoexcept |
Definition at line 14960 of file fft.H.
References Aleph::FFT< Real >::OverlapAddBank::fft_size_.
|
inline |
Definition at line 15110 of file fft.H.
References Aleph::and, Aleph::FFT< Real >::OverlapAddBank::clear_channel_overlap(), Aleph::FFT< Real >::OverlapAddBank::has_pending_tail_, and Aleph::FFT< Real >::OverlapAddBank::overlaps_.
|
inlinenoexcept |
Definition at line 14971 of file fft.H.
References Aleph::FFT< Real >::OverlapAddBank::kernel_.
|
inlinestaticprivatenoexcept |
Returns the maximum signal length in a batch.
Definition at line 14606 of file fft.H.
References Aleph::size().
Referenced by Aleph::FFT< Real >::OverlapAddBank::convolve_impl(), Aleph::FFT< Real >::OverlapAddBank::pprocess_block(), and Aleph::FFT< Real >::OverlapAddBank::process_block().
|
inlinenoexcept |
Definition at line 14954 of file fft.H.
References Aleph::FFT< Real >::OverlapAddBank::overlaps_.
Referenced by Aleph::FFT< Real >::OverlapAddBank::OverlapAddBank().
|
default |
Copy the kernel, the plan and the pending tails of another bank.
| [in] | other | bank to copy. |
| std::bad_alloc | if the buffers cannot be allocated. |
|
inlinenoexcept |
Exchange this bank with another, which is left with the previous state of this one.
| [in,out] | other | bank to move from. |
Definition at line 14934 of file fft.H.
References Aleph::FFT< Real >::OverlapAddBank::swap().
|
inlinenoexcept |
Returns the size of the tail of each channel.
Definition at line 14966 of file fft.H.
References Aleph::Array< T >::is_empty(), Aleph::FFT< Real >::OverlapAddBank::kernel_, and Aleph::Array< T >::size().
|
inline |
convolve() with parallel transforms.
| [in] | pool | thread pool for the transforms. |
| [in] | signals | one signal per channel. |
| [in] | chunk_size | minimum iterations per parallel chunk (0 = auto). |
| std::runtime_error | if the bank is empty (it was moved from). |
| std::invalid_argument | if 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().
|
inline |
|
inlineprivate |
Rationale: Parallel pointwise multiplication of multiple signal spectra with the shared kernel spectrum.
Definition at line 14679 of file fft.H.
References Aleph::and, Aleph::FFT< Real >::OverlapAddBank::fft_size_, Aleph::FFT< Real >::OverlapAddBank::kernel_spectrum_, Aleph::ThreadPool::num_threads(), and Aleph::parallel_for_index().
Referenced by Aleph::FFT< Real >::OverlapAddBank::convolve_impl(), and Aleph::FFT< Real >::OverlapAddBank::process_chunk_batch_impl().
|
inline |
process_block() with parallel transforms.
| [in] | pool | thread pool for the transforms. |
| [in] | block | next samples of each channel, of any number. |
| [in] | chunk_size | minimum iterations per parallel chunk (0 = auto). |
block, per channel. | std::runtime_error | if the bank is empty (it was moved from). |
| std::invalid_argument | if 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().
|
inline |
Convolve the next samples of a stream per channel.
| [in] | block | next samples of each channel, of any number. |
block, per channel. | std::runtime_error | if the bank is empty (it was moved from). |
| std::invalid_argument | if 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().
|
inlineprivate |
Definition at line 14713 of file fft.H.
References Aleph::Array< T >::append(), Aleph::FFT< Real >::OverlapAddBank::build_signal_batch(), Aleph::FFT< Real >::count_non_empty_real_batch(), Aleph::Array< T >::create(), Aleph::FFT< Real >::OverlapAddBank::fft_size_, Aleph::FFT< Real >::OverlapAddBank::has_pending_tail_, Aleph::FFT< Real >::Plan::inverse_transform_real_batch(), Aleph::Array< T >::is_empty(), Aleph::FFT< Real >::OverlapAddBank::overlaps_, Aleph::FFT< Real >::Plan::pinverse_transform_real_batch(), Aleph::FFT< Real >::OverlapAddBank::plan_, Aleph::FFT< Real >::OverlapAddBank::pointwise_multiply_batch(), Aleph::FFT< Real >::Plan::ptransform_batch(), Aleph::Array< T >::reserve(), Aleph::FFT< Real >::should_parallelize_batch_work(), Aleph::Array< T >::size(), Aleph::size(), Aleph::FFT< Real >::Plan::transform_batch(), and Aleph::FFT< Real >::OverlapAddBank::validate_channel_count().
Referenced by Aleph::FFT< Real >::OverlapAddBank::pprocess_block(), and Aleph::FFT< Real >::OverlapAddBank::process_block().
|
inline |
Definition at line 14973 of file fft.H.
References Aleph::FFT< Real >::OverlapAddBank::clear_overlaps().
|
inlinestaticprivate |
Returns a contiguous slice of input.
Definition at line 14616 of file fft.H.
References Aleph::Array< T >::append(), offset, and Aleph::Array< T >::reserve().
Referenced by Aleph::FFT< Real >::OverlapAddBank::pprocess_block(), and Aleph::FFT< Real >::OverlapAddBank::process_block().
|
inlinenoexcept |
Exchange in O(1) the state of this bank and another.
| [in,out] | other | bank to exchange with. |
Definition at line 14943 of file fft.H.
References Aleph::FFT< Real >::OverlapAddBank::block_size_, Aleph::FFT< Real >::OverlapAddBank::fft_size_, Aleph::FFT< Real >::OverlapAddBank::has_pending_tail_, Aleph::FFT< Real >::OverlapAddBank::kernel_, Aleph::FFT< Real >::OverlapAddBank::kernel_spectrum_, Aleph::FFT< Real >::OverlapAddBank::overlaps_, Aleph::FFT< Real >::OverlapAddBank::plan_, Aleph::Array< T >::swap(), and Aleph::FFT< Real >::Plan::swap().
Referenced by Aleph::FFT< Real >::OverlapAddBank::operator=().
|
inlineprivate |
Rationale: Internal safety guard.
Definition at line 14596 of file fft.H.
References ah_invalid_argument_if, Aleph::count(), and Aleph::FFT< Real >::OverlapAddBank::overlaps_.
Referenced by Aleph::FFT< Real >::OverlapAddBank::convolve(), Aleph::FFT< Real >::OverlapAddBank::pconvolve(), Aleph::FFT< Real >::OverlapAddBank::pprocess_block(), Aleph::FFT< Real >::OverlapAddBank::process_block(), and Aleph::FFT< Real >::OverlapAddBank::process_chunk_batch_impl().
|
private |
Definition at line 14576 of file fft.H.
Referenced by Aleph::FFT< Real >::OverlapAddBank::OverlapAddBank(), Aleph::FFT< Real >::OverlapAddBank::block_size(), Aleph::FFT< Real >::OverlapAddBank::build_signal_block(), Aleph::FFT< Real >::OverlapAddBank::convolve_impl(), Aleph::FFT< Real >::OverlapAddBank::pprocess_block(), Aleph::FFT< Real >::OverlapAddBank::process_block(), and Aleph::FFT< Real >::OverlapAddBank::swap().
|
private |
Definition at line 14577 of file fft.H.
Referenced by Aleph::FFT< Real >::OverlapAddBank::OverlapAddBank(), Aleph::FFT< Real >::OverlapAddBank::build_signal_block(), Aleph::FFT< Real >::OverlapAddBank::convolve_impl(), Aleph::FFT< Real >::OverlapAddBank::fft_size(), Aleph::FFT< Real >::OverlapAddBank::pointwise_multiply_batch(), Aleph::FFT< Real >::OverlapAddBank::process_chunk_batch_impl(), and Aleph::FFT< Real >::OverlapAddBank::swap().
|
private |
Definition at line 14581 of file fft.H.
Referenced by Aleph::FFT< Real >::OverlapAddBank::OverlapAddBank(), Aleph::FFT< Real >::OverlapAddBank::clear_channel_overlap(), Aleph::FFT< Real >::OverlapAddBank::flush(), Aleph::FFT< Real >::OverlapAddBank::pflush(), Aleph::FFT< Real >::OverlapAddBank::process_chunk_batch_impl(), and Aleph::FFT< Real >::OverlapAddBank::swap().
|
private |
Definition at line 14575 of file fft.H.
Referenced by Aleph::FFT< Real >::OverlapAddBank::OverlapAddBank(), Aleph::FFT< Real >::OverlapAddBank::convolve(), Aleph::FFT< Real >::OverlapAddBank::convolve_impl(), Aleph::FFT< Real >::OverlapAddBank::kernel(), Aleph::FFT< Real >::OverlapAddBank::overlap_size(), Aleph::FFT< Real >::OverlapAddBank::pconvolve(), Aleph::FFT< Real >::OverlapAddBank::pprocess_block(), Aleph::FFT< Real >::OverlapAddBank::process_block(), and Aleph::FFT< Real >::OverlapAddBank::swap().
|
private |
Definition at line 14579 of file fft.H.
Referenced by Aleph::FFT< Real >::OverlapAddBank::OverlapAddBank(), Aleph::FFT< Real >::OverlapAddBank::pointwise_multiply_batch(), and Aleph::FFT< Real >::OverlapAddBank::swap().
|
private |
Definition at line 14580 of file fft.H.
Referenced by Aleph::FFT< Real >::OverlapAddBank::OverlapAddBank(), Aleph::FFT< Real >::OverlapAddBank::clear_channel_overlap(), Aleph::FFT< Real >::OverlapAddBank::clear_overlaps(), Aleph::FFT< Real >::OverlapAddBank::flush(), Aleph::FFT< Real >::OverlapAddBank::num_channels(), Aleph::FFT< Real >::OverlapAddBank::pflush(), Aleph::FFT< Real >::OverlapAddBank::process_chunk_batch_impl(), Aleph::FFT< Real >::OverlapAddBank::swap(), and Aleph::FFT< Real >::OverlapAddBank::validate_channel_count().
|
private |
Definition at line 14578 of file fft.H.
Referenced by Aleph::FFT< Real >::OverlapAddBank::OverlapAddBank(), Aleph::FFT< Real >::OverlapAddBank::convolve_impl(), Aleph::FFT< Real >::OverlapAddBank::process_chunk_batch_impl(), and Aleph::FFT< Real >::OverlapAddBank::swap().