12#include "../AudioBuffer.h"
13#include "../Convolver.h"
14#include "../FIRFilter.h"
27 int factor_, latency_ = 0;
40 return factor >= 1 && factor <= 16 && (factor & (factor - 1)) == 0 &&
41 settings.filterSpan >= 2 && settings.filterSpan <= 65536 &&
42 (settings.filterSpan & 1) == 0 && settings.partitionFrames >= 16 &&
43 settings.partitionFrames <= 4096 &&
44 (settings.partitionFrames & (settings.partitionFrames - 1)) == 0 &&
45 std::isfinite(settings.beta) && settings.beta >= 0 && settings.beta <= 30 &&
46 std::isfinite(settings.cutoff) && settings.cutoff > 0 && settings.cutoff <= 0.5;
52 bool withReference)
noexcept
54 assert(
valid(factor, settings));
55 const auto buffers =
static_cast<std::size_t
>(withReference ? 2 : 1);
56 const auto storage = buffers * 256 *
static_cast<std::size_t
>(factor) *
sizeof(
double);
59 const auto block =
static_cast<std::size_t
>(settings.partitionFrames * factor);
60 const auto length =
static_cast<std::size_t
>(settings.filterSpan * factor + 1);
61 return storage + 6 * (length *
sizeof(double) + 64) +
70 std::size_t length)
noexcept
72 const auto partitions = (length + block - 1) / block;
73 return ((4 * partitions + 9) * block + 4 * partitions + 2) *
sizeof(
double) +
75 2 * partitions *
sizeof(std::vector<double>) +
sizeof(
FFTReal<double>) + 2048 +
76 (2 * partitions + 12) * 64;
82 assert(
valid(factor, settings));
83 buffer_.
resize(1, 256 * factor);
85 reference_.
resize(1, 256 * factor);
89 const int length = settings.
filterSpan * factor + 1;
92 for (
auto &value : up)
94 up_.prepare(block, up.data(), length);
96 referenceUp_.prepare(block, up.data(), length);
97 down_.prepare(block, down.data(), length);
98 latency_ = (length - 1 + 2 * block) / factor;
109 referenceUp_.reset();
115 assert(reference_.
getNumChannels() == 1 && count >= 0 && count <= 256);
117 std::fill_n(out, count * factor_, 0.);
118 for (
int i = 0; i < count; ++i)
119 out[i * factor_] = input[i];
121 referenceUp_.processInPlace(out, count * factor_);
127 const int count = input.getNumSamples();
128 assert(input.getNumChannels() == 1 && count <= 256);
130 std::fill_n(out, count * factor_, 0.);
131 for (
int i = 0; i < count; ++i)
132 out[i * factor_] = input.getChannel(0)[i];
134 up_.processInPlace(out, count * factor_);
135 return buffer_.
toView().getSubView(0, count * factor_);
140 const int count = output.getNumSamples();
141 assert(output.getNumChannels() == 1 && count <= 256);
144 down_.processInPlace(data, count * factor_);
145 for (
int i = 0; i < count; ++i)
146 output.getChannel(0)[i] = data[i * factor_];
Non-owning view over audio channel data.
Owning audio buffer with contiguous, 32-byte aligned storage.
AudioBufferView< T, MaxChannels > toView() noexcept
Returns a non-owning mutable view of this buffer. The view's channel capacity is propagated from MaxC...
int getNumChannels() const noexcept
Returns the number of active channels.
T * getChannel(int ch) noexcept
Returns a pointer to the sample data.
void resize(int numChannels, int numSamples)
Allocates the buffer for the given dimensions.
Real-time partitioned convolution using overlap-save with FFT.
FFT optimised for real-valued input signals (the common audio case).
static size_t allocationBytes(size_t size) noexcept
Upper bound of the heap bytes a constructor of this size requests, excluding the object itself,...
static std::vector< T > lowPass(double sampleRate, double cutoffHz, int numTaps, T beta=T(5))
Designs a low-pass FIR filter.
int latency() const noexcept
static std::size_t allocationBound(int factor, Settings settings, bool withReference) noexcept
AudioBufferView< double > upsample(AudioBufferView< double > input) noexcept
double * upsampleReference(const double *input, int count) noexcept
static bool valid(int factor, Settings settings) noexcept
static std::size_t convolutionAllocationBound(std::size_t block, std::size_t length) noexcept
ConvolutionRate(int factor, Settings settings, bool withReference)
void downsample(AudioBufferView< double > output) noexcept