116 SampleType normalisedTransitionWidthUp,
117 SampleType stopbandAmplitudedBUp,
118 SampleType normalisedTransitionWidthDown,
119 SampleType stopbandAmplitudedBDown)
120 : ParentType (numChans, 2)
126 stateUp.
setSize (
static_cast<int> (this->numChannels),
static_cast<int> (N));
130 auto Ndiv4 = Ndiv2 / 2;
132 stateDown.
setSize (
static_cast<int> (this->numChannels),
static_cast<int> (N));
133 stateDown2.
setSize (
static_cast<int> (this->numChannels),
static_cast<int> (Ndiv4 + 1));
135 position.
resize (
static_cast<int> (this->numChannels));
139 SampleType getLatencyInSamples()
const override
144 void reset()
override
157 jassert (inputBlock.
getNumChannels() <=
static_cast<size_t> (ParentType::buffer.getNumChannels()));
158 jassert (inputBlock.
getNumSamples() * ParentType::factor <=
static_cast<size_t> (ParentType::buffer.getNumSamples()));
167 for (
size_t channel = 0; channel < inputBlock.
getNumChannels(); ++channel)
169 auto bufferSamples = ParentType::buffer.getWritePointer (
static_cast<int> (channel));
173 for (
size_t i = 0; i < numSamples; ++i)
176 buf[N - 1] = 2 * samples[i];
179 auto out =
static_cast<SampleType
> (0.0);
181 for (
size_t k = 0; k < Ndiv2; k += 2)
182 out += (buf[k] + buf[N - k - 1]) * fir[k];
185 bufferSamples[i << 1] = out;
186 bufferSamples[(i << 1) + 1] = buf[Ndiv2 + 1] * fir[Ndiv2];
189 for (
size_t k = 0; k < N - 2; k += 2)
197 jassert (outputBlock.
getNumChannels() <=
static_cast<size_t> (ParentType::buffer.getNumChannels()));
198 jassert (outputBlock.
getNumSamples() * ParentType::factor <=
static_cast<size_t> (ParentType::buffer.getNumSamples()));
204 auto Ndiv4 = Ndiv2 / 2;
208 for (
size_t channel = 0; channel < outputBlock.
getNumChannels(); ++channel)
210 auto bufferSamples = ParentType::buffer.getWritePointer (
static_cast<int> (channel));
214 auto pos = position.
getUnchecked (
static_cast<int> (channel));
216 for (
size_t i = 0; i < numSamples; ++i)
219 buf[N - 1] = bufferSamples[i << 1];
222 auto out =
static_cast<SampleType
> (0.0);
224 for (
size_t k = 0; k < Ndiv2; k += 2)
225 out += (buf[k] + buf[N - k - 1]) * fir[k];
228 out += buf2[pos] * fir[Ndiv2];
229 buf2[pos] = bufferSamples[(i << 1) + 1];
234 for (
size_t k = 0; k < N - 2; ++k)
238 pos = (pos == 0 ? Ndiv4 : pos - 1);
241 position.
setUnchecked (
static_cast<int> (channel), pos);
268 SampleType normalisedTransitionWidthUp,
269 SampleType stopbandAmplitudedBUp,
270 SampleType normalisedTransitionWidthDown,
271 SampleType stopbandAmplitudedBDown)
272 : ParentType (numChans, 2)
275 auto coeffsUp = getCoefficients (structureUp);
279 auto coeffsDown = getCoefficients (structureDown);
282 for (
auto i = 0; i < structureUp.directPath.size(); ++i)
283 coefficientsUp.
add (structureUp.directPath.getObjectPointer (i)->coefficients[0]);
285 for (
auto i = 1; i < structureUp.delayedPath.size(); ++i)
286 coefficientsUp.
add (structureUp.delayedPath.getObjectPointer (i)->coefficients[0]);
288 for (
auto i = 0; i < structureDown.directPath.size(); ++i)
289 coefficientsDown.
add (structureDown.directPath.getObjectPointer (i)->coefficients[0]);
291 for (
auto i = 1; i < structureDown.delayedPath.size(); ++i)
292 coefficientsDown.
add (structureDown.delayedPath.getObjectPointer (i)->coefficients[0]);
294 v1Up.
setSize (
static_cast<int> (this->numChannels), coefficientsUp.
size());
295 v1Down.
setSize (
static_cast<int> (this->numChannels), coefficientsDown.
size());
296 delayDown.
resize (
static_cast<int> (this->numChannels));
300 SampleType getLatencyInSamples()
const override
305 void reset()
override
315 jassert (inputBlock.
getNumChannels() <=
static_cast<size_t> (ParentType::buffer.getNumChannels()));
316 jassert (inputBlock.
getNumSamples() * ParentType::factor <=
static_cast<size_t> (ParentType::buffer.getNumSamples()));
320 auto numStages = coefficientsUp.
size();
321 auto delayedStages = numStages / 2;
322 auto directStages = numStages - delayedStages;
326 for (
size_t channel = 0; channel < inputBlock.
getNumChannels(); ++channel)
328 auto bufferSamples = ParentType::buffer.getWritePointer (
static_cast<int> (channel));
332 for (
size_t i = 0; i < numSamples; ++i)
335 auto input = samples[i];
337 for (
auto n = 0; n < directStages; ++n)
339 auto alpha = coeffs[n];
340 auto output = alpha * input + lv1[n];
341 lv1[n] = input - alpha * output;
346 bufferSamples[i << 1] = input;
351 for (
auto n = directStages; n < numStages; ++n)
353 auto alpha = coeffs[n];
354 auto output = alpha * input + lv1[n];
355 lv1[n] = input - alpha * output;
360 bufferSamples[(i << 1) + 1] = input;
364 #if JUCE_DSP_ENABLE_SNAP_TO_ZERO
371 jassert (outputBlock.
getNumChannels() <=
static_cast<size_t> (ParentType::buffer.getNumChannels()));
372 jassert (outputBlock.
getNumSamples() * ParentType::factor <=
static_cast<size_t> (ParentType::buffer.getNumSamples()));
376 auto numStages = coefficientsDown.
size();
377 auto delayedStages = numStages / 2;
378 auto directStages = numStages - delayedStages;
382 for (
size_t channel = 0; channel < outputBlock.
getNumChannels(); ++channel)
384 auto bufferSamples = ParentType::buffer.getWritePointer (
static_cast<int> (channel));
387 auto delay = delayDown.
getUnchecked (
static_cast<int> (channel));
389 for (
size_t i = 0; i < numSamples; ++i)
392 auto input = bufferSamples[i << 1];
394 for (
auto n = 0; n < directStages; ++n)
396 auto alpha = coeffs[n];
397 auto output = alpha * input + lv1[n];
398 lv1[n] = input - alpha * output;
402 auto directOut = input;
405 input = bufferSamples[(i << 1) + 1];
407 for (
auto n = directStages; n < numStages; ++n)
409 auto alpha = coeffs[n];
410 auto output = alpha * input + lv1[n];
411 lv1[n] = input - alpha * output;
416 samples[i] = (delay + directOut) *
static_cast<SampleType
> (0.5);
420 delayDown.
setUnchecked (
static_cast<int> (channel), delay);
423 #if JUCE_DSP_ENABLE_SNAP_TO_ZERO
428 void snapToZero (
bool snapUpProcessing)
430 if (snapUpProcessing)
432 for (
auto channel = 0; channel < ParentType::buffer.getNumChannels(); ++channel)
435 auto numStages = coefficientsUp.
size();
437 for (
auto n = 0; n < numStages; ++n)
438 util::snapToZero (lv1[n]);
443 for (
auto channel = 0; channel < ParentType::buffer.getNumChannels(); ++channel)
446 auto numStages = coefficientsDown.
size();
448 for (
auto n = 0; n < numStages; ++n)
449 util::snapToZero (lv1[n]);
461 constexpr auto one =
static_cast<SampleType
> (1.0);
464 numerator2 ({ one }), denominator2 ({ one });
466 for (
auto* i : structure.directPath)
468 auto coeffs = i->getRawCoefficients();
470 if (i->getFilterOrder() == 1)
482 for (
auto* i : structure.delayedPath)
484 auto coeffs = i->getRawCoefficients();
486 if (i->getFilterOrder() == 1)
499 auto numeratorf2 = numerator2.getProductWith (denominator1);
500 auto numerator = numeratorf1.getSumWith (numeratorf2);
501 auto denominator = denominator1.getProductWith (denominator2);
506 auto inversion = one / denominator[0];
508 for (
int i = 0; i <= numerator.getOrder(); ++i)
511 for (
int i = 1; i <= denominator.getOrder(); ++i)
542 bool useIntegerLatency)
543 : numChannels (newNumChannels), shouldUseIntegerLatency (useIntegerLatency)
545 jassert (isPositiveAndBelow (newFactor, 5) && numChannels > 0);
551 else if (newType == FilterType::filterHalfBandPolyphaseIIR)
553 for (
size_t n = 0; n < newFactor; ++n)
555 auto twUp = (isMaximumQuality ? 0.10f : 0.12f) * (n == 0 ? 0.5f : 1.0f);
556 auto twDown = (isMaximumQuality ? 0.12f : 0.15f) * (n == 0 ? 0.5f : 1.0f);
558 auto gaindBStartUp = (isMaximumQuality ? -90.0f : -70.0f);
559 auto gaindBStartDown = (isMaximumQuality ? -75.0f : -60.0f);
560 auto gaindBFactorUp = (isMaximumQuality ? 10.0f : 8.0f);
561 auto gaindBFactorDown = (isMaximumQuality ? 10.0f : 8.0f);
564 twUp, gaindBStartUp + gaindBFactorUp * (
float) n,
565 twDown, gaindBStartDown + gaindBFactorDown * (
float) n);
568 else if (newType == FilterType::filterHalfBandFIREquiripple)
570 for (
size_t n = 0; n < newFactor; ++n)
572 auto twUp = (isMaximumQuality ? 0.10f : 0.12f) * (n == 0 ? 0.5f : 1.0f);
573 auto twDown = (isMaximumQuality ? 0.12f : 0.15f) * (n == 0 ? 0.5f : 1.0f);
575 auto gaindBStartUp = (isMaximumQuality ? -90.0f : -70.0f);
576 auto gaindBStartDown = (isMaximumQuality ? -75.0f : -60.0f);
577 auto gaindBFactorUp = (isMaximumQuality ? 10.0f : 8.0f);
578 auto gaindBFactorDown = (isMaximumQuality ? 10.0f : 8.0f);
581 twUp, gaindBStartUp + gaindBFactorUp * (
float) n,
582 twDown, gaindBStartDown + gaindBFactorDown * (
float) n);