LMMS
Loading...
Searching...
No Matches
juce_Oversampling.cpp
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28namespace dsp
29{
30
34template <typename SampleType>
36{
37 OversamplingStage (size_t numChans, size_t newFactor) : numChannels (numChans), factor (newFactor) {}
38 virtual ~OversamplingStage() {}
39
40 //==============================================================================
41 virtual SampleType getLatencyInSamples() const = 0;
42
43 virtual void initProcessing (size_t maximumNumberOfSamplesBeforeOversampling)
44 {
45 buffer.setSize (static_cast<int> (numChannels),
46 static_cast<int> (maximumNumberOfSamplesBeforeOversampling * factor),
47 false, false, true);
48 }
49
50 virtual void reset()
51 {
52 buffer.clear();
53 }
54
56 {
57 return AudioBlock<SampleType> (buffer).getSubBlock (0, numSamples);
58 }
59
62
65};
66
67
68//==============================================================================
72template <typename SampleType>
74{
76
77 OversamplingDummy (size_t numChans) : ParentType (numChans, 1) {}
78
79 //==============================================================================
80 SampleType getLatencyInSamples() const override
81 {
82 return 0;
83 }
84
85 void processSamplesUp (const AudioBlock<const SampleType>& inputBlock) override
86 {
87 jassert (inputBlock.getNumChannels() <= static_cast<size_t> (ParentType::buffer.getNumChannels()));
88 jassert (inputBlock.getNumSamples() * ParentType::factor <= static_cast<size_t> (ParentType::buffer.getNumSamples()));
89
90 for (size_t channel = 0; channel < inputBlock.getNumChannels(); ++channel)
91 ParentType::buffer.copyFrom (static_cast<int> (channel), 0,
92 inputBlock.getChannelPointer (channel), static_cast<int> (inputBlock.getNumSamples()));
93 }
94
95 void processSamplesDown (AudioBlock<SampleType>& outputBlock) override
96 {
97 jassert (outputBlock.getNumChannels() <= static_cast<size_t> (ParentType::buffer.getNumChannels()));
98 jassert (outputBlock.getNumSamples() * ParentType::factor <= static_cast<size_t> (ParentType::buffer.getNumSamples()));
99
100 outputBlock.copyFrom (ParentType::getProcessedSamples (outputBlock.getNumSamples()));
101 }
102
104};
105
106//==============================================================================
112template <typename SampleType>
114{
116
118 SampleType normalisedTransitionWidthUp,
119 SampleType stopbandAmplitudedBUp,
120 SampleType normalisedTransitionWidthDown,
121 SampleType stopbandAmplitudedBDown)
122 : ParentType (numChans, 2)
123 {
124 coefficientsUp = *FilterDesign<SampleType>::designFIRLowpassHalfBandEquirippleMethod (normalisedTransitionWidthUp, stopbandAmplitudedBUp);
125 coefficientsDown = *FilterDesign<SampleType>::designFIRLowpassHalfBandEquirippleMethod (normalisedTransitionWidthDown, stopbandAmplitudedBDown);
126
127 auto N = coefficientsUp.getFilterOrder() + 1;
128 stateUp.setSize (static_cast<int> (this->numChannels), static_cast<int> (N));
129
130 N = coefficientsDown.getFilterOrder() + 1;
131 auto Ndiv2 = N / 2;
132 auto Ndiv4 = Ndiv2 / 2;
133
134 stateDown.setSize (static_cast<int> (this->numChannels), static_cast<int> (N));
135 stateDown2.setSize (static_cast<int> (this->numChannels), static_cast<int> (Ndiv4 + 1));
136
137 position.resize (static_cast<int> (this->numChannels));
138 }
139
140 //==============================================================================
141 SampleType getLatencyInSamples() const override
142 {
143 return static_cast<SampleType> (coefficientsUp.getFilterOrder() + coefficientsDown.getFilterOrder()) * 0.5f;
144 }
145
146 void reset() override
147 {
148 ParentType::reset();
149
150 stateUp.clear();
151 stateDown.clear();
152 stateDown2.clear();
153
154 position.fill (0);
155 }
156
157 void processSamplesUp (const AudioBlock<const SampleType>& inputBlock) override
158 {
159 jassert (inputBlock.getNumChannels() <= static_cast<size_t> (ParentType::buffer.getNumChannels()));
160 jassert (inputBlock.getNumSamples() * ParentType::factor <= static_cast<size_t> (ParentType::buffer.getNumSamples()));
161
162 // Initialization
163 auto fir = coefficientsUp.getRawCoefficients();
164 auto N = coefficientsUp.getFilterOrder() + 1;
165 auto Ndiv2 = N / 2;
166 auto numSamples = inputBlock.getNumSamples();
167
168 // Processing
169 for (size_t channel = 0; channel < inputBlock.getNumChannels(); ++channel)
170 {
171 auto bufferSamples = ParentType::buffer.getWritePointer (static_cast<int> (channel));
172 auto buf = stateUp.getWritePointer (static_cast<int> (channel));
173 auto samples = inputBlock.getChannelPointer (channel);
174
175 for (size_t i = 0; i < numSamples; ++i)
176 {
177 // Input
178 buf[N - 1] = 2 * samples[i];
179
180 // Convolution
181 auto out = static_cast<SampleType> (0.0);
182
183 for (size_t k = 0; k < Ndiv2; k += 2)
184 out += (buf[k] + buf[N - k - 1]) * fir[k];
185
186 // Outputs
187 bufferSamples[i << 1] = out;
188 bufferSamples[(i << 1) + 1] = buf[Ndiv2 + 1] * fir[Ndiv2];
189
190 // Shift data
191 for (size_t k = 0; k < N - 2; k += 2)
192 buf[k] = buf[k + 2];
193 }
194 }
195 }
196
197 void processSamplesDown (AudioBlock<SampleType>& outputBlock) override
198 {
199 jassert (outputBlock.getNumChannels() <= static_cast<size_t> (ParentType::buffer.getNumChannels()));
200 jassert (outputBlock.getNumSamples() * ParentType::factor <= static_cast<size_t> (ParentType::buffer.getNumSamples()));
201
202 // Initialization
203 auto fir = coefficientsDown.getRawCoefficients();
204 auto N = coefficientsDown.getFilterOrder() + 1;
205 auto Ndiv2 = N / 2;
206 auto Ndiv4 = Ndiv2 / 2;
207 auto numSamples = outputBlock.getNumSamples();
208
209 // Processing
210 for (size_t channel = 0; channel < outputBlock.getNumChannels(); ++channel)
211 {
212 auto bufferSamples = ParentType::buffer.getWritePointer (static_cast<int> (channel));
213 auto buf = stateDown.getWritePointer (static_cast<int> (channel));
214 auto buf2 = stateDown2.getWritePointer (static_cast<int> (channel));
215 auto samples = outputBlock.getChannelPointer (channel);
216 auto pos = position.getUnchecked (static_cast<int> (channel));
217
218 for (size_t i = 0; i < numSamples; ++i)
219 {
220 // Input
221 buf[N - 1] = bufferSamples[i << 1];
222
223 // Convolution
224 auto out = static_cast<SampleType> (0.0);
225
226 for (size_t k = 0; k < Ndiv2; k += 2)
227 out += (buf[k] + buf[N - k - 1]) * fir[k];
228
229 // Output
230 out += buf2[pos] * fir[Ndiv2];
231 buf2[pos] = bufferSamples[(i << 1) + 1];
232
233 samples[i] = out;
234
235 // Shift data
236 for (size_t k = 0; k < N - 2; ++k)
237 buf[k] = buf[k + 2];
238
239 // Circular buffer
240 pos = (pos == 0 ? Ndiv4 : pos - 1);
241 }
242
243 position.setUnchecked (static_cast<int> (channel), pos);
244 }
245
246 }
247
248private:
249 //==============================================================================
253
254 //==============================================================================
256};
257
258
259//==============================================================================
264template <typename SampleType>
266{
268
270 SampleType normalisedTransitionWidthUp,
271 SampleType stopbandAmplitudedBUp,
272 SampleType normalisedTransitionWidthDown,
273 SampleType stopbandAmplitudedBDown)
274 : ParentType (numChans, 2)
275 {
276 auto structureUp = FilterDesign<SampleType>::designIIRLowpassHalfBandPolyphaseAllpassMethod (normalisedTransitionWidthUp, stopbandAmplitudedBUp);
277 auto coeffsUp = getCoefficients (structureUp);
278 latency = static_cast<SampleType> (-(coeffsUp.getPhaseForFrequency (0.0001, 1.0)) / (0.0001 * MathConstants<double>::twoPi));
279
280 auto structureDown = FilterDesign<SampleType>::designIIRLowpassHalfBandPolyphaseAllpassMethod (normalisedTransitionWidthDown, stopbandAmplitudedBDown);
281 auto coeffsDown = getCoefficients (structureDown);
282 latency += static_cast<SampleType> (-(coeffsDown.getPhaseForFrequency (0.0001, 1.0)) / (0.0001 * MathConstants<double>::twoPi));
283
284 for (auto i = 0; i < structureUp.directPath.size(); ++i)
285 coefficientsUp.add (structureUp.directPath.getObjectPointer (i)->coefficients[0]);
286
287 for (auto i = 1; i < structureUp.delayedPath.size(); ++i)
288 coefficientsUp.add (structureUp.delayedPath.getObjectPointer (i)->coefficients[0]);
289
290 for (auto i = 0; i < structureDown.directPath.size(); ++i)
291 coefficientsDown.add (structureDown.directPath.getObjectPointer (i)->coefficients[0]);
292
293 for (auto i = 1; i < structureDown.delayedPath.size(); ++i)
294 coefficientsDown.add (structureDown.delayedPath.getObjectPointer (i)->coefficients[0]);
295
296 v1Up.setSize (static_cast<int> (this->numChannels), coefficientsUp.size());
297 v1Down.setSize (static_cast<int> (this->numChannels), coefficientsDown.size());
298 delayDown.resize (static_cast<int> (this->numChannels));
299 }
300
301 //==============================================================================
302 SampleType getLatencyInSamples() const override
303 {
304 return latency;
305 }
306
307 void reset() override
308 {
309 ParentType::reset();
310 v1Up.clear();
311 v1Down.clear();
312 delayDown.fill (0);
313 }
314
315 void processSamplesUp (const AudioBlock<const SampleType>& inputBlock) override
316 {
317 jassert (inputBlock.getNumChannels() <= static_cast<size_t> (ParentType::buffer.getNumChannels()));
318 jassert (inputBlock.getNumSamples() * ParentType::factor <= static_cast<size_t> (ParentType::buffer.getNumSamples()));
319
320 // Initialization
321 auto coeffs = coefficientsUp.getRawDataPointer();
322 auto numStages = coefficientsUp.size();
323 auto delayedStages = numStages / 2;
324 auto directStages = numStages - delayedStages;
325 auto numSamples = inputBlock.getNumSamples();
326
327 // Processing
328 for (size_t channel = 0; channel < inputBlock.getNumChannels(); ++channel)
329 {
330 auto bufferSamples = ParentType::buffer.getWritePointer (static_cast<int> (channel));
331 auto lv1 = v1Up.getWritePointer (static_cast<int> (channel));
332 auto samples = inputBlock.getChannelPointer (channel);
333
334 for (size_t i = 0; i < numSamples; ++i)
335 {
336 // Direct path cascaded allpass filters
337 auto input = samples[i];
338
339 for (auto n = 0; n < directStages; ++n)
340 {
341 auto alpha = coeffs[n];
342 auto output = alpha * input + lv1[n];
343 lv1[n] = input - alpha * output;
344 input = output;
345 }
346
347 // Output
348 bufferSamples[i << 1] = input;
349
350 // Delayed path cascaded allpass filters
351 input = samples[i];
352
353 for (auto n = directStages; n < numStages; ++n)
354 {
355 auto alpha = coeffs[n];
356 auto output = alpha * input + lv1[n];
357 lv1[n] = input - alpha * output;
358 input = output;
359 }
360
361 // Output
362 bufferSamples[(i << 1) + 1] = input;
363 }
364 }
365
366 #if JUCE_DSP_ENABLE_SNAP_TO_ZERO
367 snapToZero (true);
368 #endif
369 }
370
371 void processSamplesDown (AudioBlock<SampleType>& outputBlock) override
372 {
373 jassert (outputBlock.getNumChannels() <= static_cast<size_t> (ParentType::buffer.getNumChannels()));
374 jassert (outputBlock.getNumSamples() * ParentType::factor <= static_cast<size_t> (ParentType::buffer.getNumSamples()));
375
376 // Initialization
377 auto coeffs = coefficientsDown.getRawDataPointer();
378 auto numStages = coefficientsDown.size();
379 auto delayedStages = numStages / 2;
380 auto directStages = numStages - delayedStages;
381 auto numSamples = outputBlock.getNumSamples();
382
383 // Processing
384 for (size_t channel = 0; channel < outputBlock.getNumChannels(); ++channel)
385 {
386 auto bufferSamples = ParentType::buffer.getWritePointer (static_cast<int> (channel));
387 auto lv1 = v1Down.getWritePointer (static_cast<int> (channel));
388 auto samples = outputBlock.getChannelPointer (channel);
389 auto delay = delayDown.getUnchecked (static_cast<int> (channel));
390
391 for (size_t i = 0; i < numSamples; ++i)
392 {
393 // Direct path cascaded allpass filters
394 auto input = bufferSamples[i << 1];
395
396 for (auto n = 0; n < directStages; ++n)
397 {
398 auto alpha = coeffs[n];
399 auto output = alpha * input + lv1[n];
400 lv1[n] = input - alpha * output;
401 input = output;
402 }
403
404 auto directOut = input;
405
406 // Delayed path cascaded allpass filters
407 input = bufferSamples[(i << 1) + 1];
408
409 for (auto n = directStages; n < numStages; ++n)
410 {
411 auto alpha = coeffs[n];
412 auto output = alpha * input + lv1[n];
413 lv1[n] = input - alpha * output;
414 input = output;
415 }
416
417 // Output
418 samples[i] = (delay + directOut) * static_cast<SampleType> (0.5);
419 delay = input;
420 }
421
422 delayDown.setUnchecked (static_cast<int> (channel), delay);
423 }
424
425 #if JUCE_DSP_ENABLE_SNAP_TO_ZERO
426 snapToZero (false);
427 #endif
428 }
429
430 void snapToZero (bool snapUpProcessing)
431 {
432 if (snapUpProcessing)
433 {
434 for (auto channel = 0; channel < ParentType::buffer.getNumChannels(); ++channel)
435 {
436 auto lv1 = v1Up.getWritePointer (channel);
437 auto numStages = coefficientsUp.size();
438
439 for (auto n = 0; n < numStages; ++n)
440 util::snapToZero (lv1[n]);
441 }
442 }
443 else
444 {
445 for (auto channel = 0; channel < ParentType::buffer.getNumChannels(); ++channel)
446 {
447 auto lv1 = v1Down.getWritePointer (channel);
448 auto numStages = coefficientsDown.size();
449
450 for (auto n = 0; n < numStages; ++n)
451 util::snapToZero (lv1[n]);
452 }
453 }
454 }
455
456private:
457 //==============================================================================
462 {
463 constexpr auto one = static_cast<SampleType> (1.0);
464
465 Polynomial<SampleType> numerator1 ({ one }), denominator1 ({ one }),
466 numerator2 ({ one }), denominator2 ({ one });
467
468 for (auto* i : structure.directPath)
469 {
470 auto coeffs = i->getRawCoefficients();
471
472 if (i->getFilterOrder() == 1)
473 {
474 numerator1 = numerator1 .getProductWith (Polynomial<SampleType> ({ coeffs[0], coeffs[1] }));
475 denominator1 = denominator1.getProductWith (Polynomial<SampleType> ({ one, coeffs[2] }));
476 }
477 else
478 {
479 numerator1 = numerator1 .getProductWith (Polynomial<SampleType> ({ coeffs[0], coeffs[1], coeffs[2] }));
480 denominator1 = denominator1.getProductWith (Polynomial<SampleType> ({ one, coeffs[3], coeffs[4] }));
481 }
482 }
483
484 for (auto* i : structure.delayedPath)
485 {
486 auto coeffs = i->getRawCoefficients();
487
488 if (i->getFilterOrder() == 1)
489 {
490 numerator2 = numerator2 .getProductWith (Polynomial<SampleType> ({ coeffs[0], coeffs[1] }));
491 denominator2 = denominator2.getProductWith (Polynomial<SampleType> ({ one, coeffs[2] }));
492 }
493 else
494 {
495 numerator2 = numerator2 .getProductWith (Polynomial<SampleType> ({ coeffs[0], coeffs[1], coeffs[2] }));
496 denominator2 = denominator2.getProductWith (Polynomial<SampleType> ({ one, coeffs[3], coeffs[4] }));
497 }
498 }
499
500 auto numeratorf1 = numerator1.getProductWith (denominator2);
501 auto numeratorf2 = numerator2.getProductWith (denominator1);
502 auto numerator = numeratorf1.getSumWith (numeratorf2);
503 auto denominator = denominator1.getProductWith (denominator2);
504
506
507 coeffs.coefficients.clear();
508 auto inversion = one / denominator[0];
509
510 for (int i = 0; i <= numerator.getOrder(); ++i)
511 coeffs.coefficients.add (numerator[i] * inversion);
512
513 for (int i = 1; i <= denominator.getOrder(); ++i)
514 coeffs.coefficients.add (denominator[i] * inversion);
515
516 return coeffs;
517 }
518
519 //==============================================================================
521 SampleType latency;
522
525
526 //==============================================================================
528};
529
530
531//==============================================================================
532template <typename SampleType>
534 : numChannels (newNumChannels)
535{
536 jassert (numChannels > 0);
537
539}
540
541template <typename SampleType>
542Oversampling<SampleType>::Oversampling (size_t newNumChannels, size_t newFactor,
543 FilterType newType, bool isMaximumQuality,
544 bool useIntegerLatency)
545 : numChannels (newNumChannels), shouldUseIntegerLatency (useIntegerLatency)
546{
547 jassert (isPositiveAndBelow (newFactor, 5) && numChannels > 0);
548
549 if (newFactor == 0)
550 {
552 }
553 else if (newType == FilterType::filterHalfBandPolyphaseIIR)
554 {
555 for (size_t n = 0; n < newFactor; ++n)
556 {
557 auto twUp = (isMaximumQuality ? 0.10f : 0.12f) * (n == 0 ? 0.5f : 1.0f);
558 auto twDown = (isMaximumQuality ? 0.12f : 0.15f) * (n == 0 ? 0.5f : 1.0f);
559
560 auto gaindBStartUp = (isMaximumQuality ? -90.0f : -70.0f);
561 auto gaindBStartDown = (isMaximumQuality ? -75.0f : -60.0f);
562 auto gaindBFactorUp = (isMaximumQuality ? 10.0f : 8.0f);
563 auto gaindBFactorDown = (isMaximumQuality ? 10.0f : 8.0f);
564
566 twUp, gaindBStartUp + gaindBFactorUp * (float) n,
567 twDown, gaindBStartDown + gaindBFactorDown * (float) n);
568 }
569 }
570 else if (newType == FilterType::filterHalfBandFIREquiripple)
571 {
572 for (size_t n = 0; n < newFactor; ++n)
573 {
574 auto twUp = (isMaximumQuality ? 0.10f : 0.12f) * (n == 0 ? 0.5f : 1.0f);
575 auto twDown = (isMaximumQuality ? 0.12f : 0.15f) * (n == 0 ? 0.5f : 1.0f);
576
577 auto gaindBStartUp = (isMaximumQuality ? -90.0f : -70.0f);
578 auto gaindBStartDown = (isMaximumQuality ? -75.0f : -60.0f);
579 auto gaindBFactorUp = (isMaximumQuality ? 10.0f : 8.0f);
580 auto gaindBFactorDown = (isMaximumQuality ? 10.0f : 8.0f);
581
583 twUp, gaindBStartUp + gaindBFactorUp * (float) n,
584 twDown, gaindBStartDown + gaindBFactorDown * (float) n);
585 }
586 }
587}
588
589template <typename SampleType>
594
595//==============================================================================
596template <typename SampleType>
601
602template <typename SampleType>
604 float normalisedTransitionWidthUp,
605 float stopbandAmplitudedBUp,
606 float normalisedTransitionWidthDown,
607 float stopbandAmplitudedBDown)
608{
610 {
612 normalisedTransitionWidthUp, stopbandAmplitudedBUp,
613 normalisedTransitionWidthDown, stopbandAmplitudedBDown));
614 }
615 else
616 {
618 normalisedTransitionWidthUp, stopbandAmplitudedBUp,
619 normalisedTransitionWidthDown, stopbandAmplitudedBDown));
620 }
621
623}
624
625template <typename SampleType>
631
632//==============================================================================
633template <typename SampleType>
634void Oversampling<SampleType>::setUsingIntegerLatency (bool useIntegerLatency) noexcept
635{
636 shouldUseIntegerLatency = useIntegerLatency;
637}
638
639template <typename SampleType>
641{
642 auto latency = getUncompensatedLatency();
643 return shouldUseIntegerLatency ? latency + fractionalDelay : latency;
644}
645
646template <typename SampleType>
648{
649 auto latency = static_cast<SampleType> (0);
650 size_t order = 1;
651
652 for (auto* stage : stages)
653 {
654 order *= stage->factor;
655 latency += stage->getLatencyInSamples() / static_cast<SampleType> (order);
656 }
657
658 return latency;
659}
660
661template <typename SampleType>
666
667//==============================================================================
668template <typename SampleType>
669void Oversampling<SampleType>::initProcessing (size_t maximumNumberOfSamplesBeforeOversampling)
670{
671 jassert (! stages.isEmpty());
672 auto currentNumSamples = maximumNumberOfSamplesBeforeOversampling;
673
674 for (auto* stage : stages)
675 {
676 stage->initProcessing (currentNumSamples);
677 currentNumSamples *= stage->factor;
678 }
679
680 ProcessSpec spec = { 0.0, (uint32) maximumNumberOfSamplesBeforeOversampling, (uint32) numChannels };
681 delay.prepare (spec);
683
684 isReady = true;
685 reset();
686}
687
688template <typename SampleType>
690{
691 jassert (! stages.isEmpty());
692
693 if (isReady)
694 for (auto* stage : stages)
695 stage->reset();
696
697 delay.reset();
698}
699
700template <typename SampleType>
702{
703 jassert (! stages.isEmpty());
704
705 if (! isReady)
706 return {};
707
708 auto* firstStage = stages.getUnchecked (0);
709 firstStage->processSamplesUp (inputBlock);
710 auto block = firstStage->getProcessedSamples (inputBlock.getNumSamples() * firstStage->factor);
711
712 for (int i = 1; i < stages.size(); ++i)
713 {
714 stages[i]->processSamplesUp (block);
715 block = stages[i]->getProcessedSamples (block.getNumSamples() * stages[i]->factor);
716 }
717
718 return block;
719}
720
721template <typename SampleType>
723{
724 jassert (! stages.isEmpty());
725
726 if (! isReady)
727 return;
728
729 auto currentNumSamples = outputBlock.getNumSamples();
730
731 for (int n = 0; n < stages.size() - 1; ++n)
732 currentNumSamples *= stages.getUnchecked(n)->factor;
733
734 for (int n = stages.size() - 1; n > 0; --n)
735 {
736 auto& stage = *stages.getUnchecked(n);
737 auto audioBlock = stages.getUnchecked (n - 1)->getProcessedSamples (currentNumSamples);
738 stage.processSamplesDown (audioBlock);
739
740 currentNumSamples /= stage.factor;
741 }
742
743 stages.getFirst()->processSamplesDown (outputBlock);
744
745 if (shouldUseIntegerLatency && fractionalDelay > static_cast<SampleType> (0.0))
746 {
747 auto context = ProcessContextReplacing<SampleType> (outputBlock);
748 delay.process (context);
749 }
750}
751
752template <typename SampleType>
754{
755 auto latency = getUncompensatedLatency();
756 fractionalDelay = static_cast<SampleType> (1.0) - (latency - std::floor (latency));
757
758 if (fractionalDelay == static_cast<SampleType> (1.0))
759 fractionalDelay = static_cast<SampleType> (0.0);
760 else if (fractionalDelay < static_cast<SampleType> (0.618))
761 fractionalDelay += static_cast<SampleType> (1.0);
762
763 delay.setDelay (fractionalDelay);
764}
765
766template class Oversampling<float>;
767template class Oversampling<double>;
768
769} // namespace dsp
770} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
CAdPlugDatabase::CRecord::RecordType type
Definition adplugdb.cpp:93
Definition juce_Array.h:56
void add(const ElementType &newElement)
Definition juce_Array.h:418
void clear()
Definition juce_Array.h:188
Definition juce_AudioSampleBuffer.h:34
Definition juce_AudioBlock.h:70
AudioBlock getSubBlock(size_t newOffset, size_t newLength) const noexcept
Definition juce_AudioBlock.h:371
constexpr size_t getNumChannels() const noexcept
Definition juce_AudioBlock.h:235
SampleType * getChannelPointer(size_t channel) const noexcept
Definition juce_AudioBlock.h:241
AudioBlock & copyFrom(const AudioBlock< OtherSampleType > &src) noexcept
Definition juce_AudioBlock.h:314
constexpr size_t getNumSamples() const noexcept
Definition juce_AudioBlock.h:238
Definition juce_Oversampling.h:56
void setUsingIntegerLatency(bool shouldUseIntegerLatency) noexcept
Definition juce_Oversampling.cpp:634
void processSamplesDown(AudioBlock< SampleType > &outputBlock) noexcept
Definition juce_Oversampling.cpp:722
SampleType getUncompensatedLatency() const noexcept
Definition juce_Oversampling.cpp:647
FilterType
Definition juce_Oversampling.h:60
@ filterHalfBandFIREquiripple
Definition juce_Oversampling.h:61
@ filterHalfBandPolyphaseIIR
Definition juce_Oversampling.h:62
bool isReady
Definition juce_Oversampling.h:205
void clearOversamplingStages()
Definition juce_Oversampling.cpp:626
bool shouldUseIntegerLatency
Definition juce_Oversampling.h:205
void initProcessing(size_t maximumNumberOfSamplesBeforeOversampling)
Definition juce_Oversampling.cpp:669
void updateDelayLine()
Definition juce_Oversampling.cpp:753
SampleType getLatencyInSamples() const noexcept
Definition juce_Oversampling.cpp:640
DelayLine< SampleType, DelayLineInterpolationTypes::Thiran > delay
Definition juce_Oversampling.h:206
size_t factorOversampling
Definition juce_Oversampling.h:191
AudioBlock< SampleType > processSamplesUp(const AudioBlock< const SampleType > &inputBlock) noexcept
Definition juce_Oversampling.cpp:701
Oversampling(size_t numChannels=1)
Definition juce_Oversampling.cpp:533
void reset() noexcept
Definition juce_Oversampling.cpp:689
SampleType fractionalDelay
Definition juce_Oversampling.h:207
void addDummyOversamplingStage()
Definition juce_Oversampling.cpp:597
size_t numChannels
Definition juce_Oversampling.h:192
~Oversampling()
Definition juce_Oversampling.cpp:590
void addOversamplingStage(FilterType, float normalisedTransitionWidthUp, float stopbandAmplitudedBUp, float normalisedTransitionWidthDown, float stopbandAmplitudedBDown)
Definition juce_Oversampling.cpp:603
size_t getOversamplingFactor() const noexcept
Definition juce_Oversampling.cpp:662
OwnedArray< OversamplingStage > stages
Definition juce_Oversampling.h:204
Definition juce_Polynomial.h:38
Polynomial< FloatingType > getProductWith(const Polynomial< FloatingType > &other) const
Definition juce_Polynomial.h:135
register unsigned k
Definition inflate.c:946
register unsigned i
Definition inflate.c:1575
#define jassert(expression)
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
float out
Definition lilv_test.c:1461
void snapToZero(SIMDRegister< Type > &) noexcept
Definition juce_SIMDRegister_Impl.h:167
Definition juce_AudioBlock.h:29
Definition carla_juce.cpp:31
unsigned int uint32
Definition juce_MathsFunctions.h:45
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
Definition juce_MathsFunctions.h:279
#define N
Definition nseel-cfunc.c:36
static constexpr FloatType twoPi
Definition juce_MathsFunctions.h:385
Definition juce_FIRFilter.h:219
ReferenceCountedArray< IIRCoefficients > directPath
Definition juce_FilterDesign.h:260
ReferenceCountedArray< IIRCoefficients > delayedPath
Definition juce_FilterDesign.h:260
static IIRPolyphaseAllpassStructure designIIRLowpassHalfBandPolyphaseAllpassMethod(FloatType normalisedTransitionWidth, FloatType stopbandAmplitudedB)
Definition juce_FilterDesign.cpp:615
static FIRCoefficientsPtr designFIRLowpassHalfBandEquirippleMethod(FloatType normalisedTransitionWidth, FloatType amplitudedB)
Definition juce_FilterDesign.cpp:238
Definition juce_IIRFilter.h:129
Array< NumericType > coefficients
Definition juce_IIRFilter.h:274
Definition juce_Oversampling.cpp:114
void processSamplesUp(const AudioBlock< const SampleType > &inputBlock) override
Definition juce_Oversampling.cpp:157
AudioBuffer< SampleType > stateDown2
Definition juce_Oversampling.cpp:251
typename Oversampling< SampleType >::OversamplingStage ParentType
Definition juce_Oversampling.cpp:115
Array< size_t > position
Definition juce_Oversampling.cpp:252
FIR::Coefficients< SampleType > coefficientsUp
Definition juce_Oversampling.cpp:250
SampleType getLatencyInSamples() const override
Definition juce_Oversampling.cpp:141
AudioBuffer< SampleType > stateUp
Definition juce_Oversampling.cpp:251
void reset() override
Definition juce_Oversampling.cpp:146
Oversampling2TimesEquirippleFIR(size_t numChans, SampleType normalisedTransitionWidthUp, SampleType stopbandAmplitudedBUp, SampleType normalisedTransitionWidthDown, SampleType stopbandAmplitudedBDown)
Definition juce_Oversampling.cpp:117
void processSamplesDown(AudioBlock< SampleType > &outputBlock) override
Definition juce_Oversampling.cpp:197
FIR::Coefficients< SampleType > coefficientsDown
Definition juce_Oversampling.cpp:250
AudioBuffer< SampleType > stateDown
Definition juce_Oversampling.cpp:251
Definition juce_Oversampling.cpp:266
void snapToZero(bool snapUpProcessing)
Definition juce_Oversampling.cpp:430
SampleType latency
Definition juce_Oversampling.cpp:521
void processSamplesUp(const AudioBlock< const SampleType > &inputBlock) override
Definition juce_Oversampling.cpp:315
typename Oversampling< SampleType >::OversamplingStage ParentType
Definition juce_Oversampling.cpp:267
void processSamplesDown(AudioBlock< SampleType > &outputBlock) override
Definition juce_Oversampling.cpp:371
SampleType getLatencyInSamples() const override
Definition juce_Oversampling.cpp:302
void reset() override
Definition juce_Oversampling.cpp:307
Oversampling2TimesPolyphaseIIR(size_t numChans, SampleType normalisedTransitionWidthUp, SampleType stopbandAmplitudedBUp, SampleType normalisedTransitionWidthDown, SampleType stopbandAmplitudedBDown)
Definition juce_Oversampling.cpp:269
AudioBuffer< SampleType > v1Down
Definition juce_Oversampling.cpp:523
IIR::Coefficients< SampleType > getCoefficients(typename FilterDesign< SampleType >::IIRPolyphaseAllpassStructure &structure) const
Definition juce_Oversampling.cpp:461
AudioBuffer< SampleType > v1Up
Definition juce_Oversampling.cpp:523
Array< SampleType > delayDown
Definition juce_Oversampling.cpp:524
Array< SampleType > coefficientsUp
Definition juce_Oversampling.cpp:520
Array< SampleType > coefficientsDown
Definition juce_Oversampling.cpp:520
Definition juce_Oversampling.cpp:36
size_t factor
Definition juce_Oversampling.cpp:64
size_t numChannels
Definition juce_Oversampling.cpp:64
virtual void initProcessing(size_t maximumNumberOfSamplesBeforeOversampling)
Definition juce_Oversampling.cpp:43
AudioBlock< SampleType > getProcessedSamples(size_t numSamples)
Definition juce_Oversampling.cpp:55
virtual void processSamplesUp(const AudioBlock< const SampleType > &)=0
virtual void reset()
Definition juce_Oversampling.cpp:50
AudioBuffer< SampleType > buffer
Definition juce_Oversampling.cpp:63
virtual void processSamplesDown(AudioBlock< SampleType > &)=0
virtual SampleType getLatencyInSamples() const =0
virtual ~OversamplingStage()
Definition juce_Oversampling.cpp:38
OversamplingStage(size_t numChans, size_t newFactor)
Definition juce_Oversampling.cpp:37
Definition juce_Oversampling.cpp:74
typename Oversampling< SampleType >::OversamplingStage ParentType
Definition juce_Oversampling.cpp:75
void processSamplesUp(const AudioBlock< const SampleType > &inputBlock) override
Definition juce_Oversampling.cpp:85
OversamplingDummy(size_t numChans)
Definition juce_Oversampling.cpp:77
SampleType getLatencyInSamples() const override
Definition juce_Oversampling.cpp:80
void processSamplesDown(AudioBlock< SampleType > &outputBlock) override
Definition juce_Oversampling.cpp:95
Definition juce_ProcessContext.h:88
Definition juce_ProcessContext.h:38
int n
Definition crypt.c:458
#define const
Definition zconf.h:137