The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

673 lines
24KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. //===============================================================================
  20. /** Abstract class for the provided oversampling engines used internally in
  21. the Oversampling class.
  22. */
  23. template <typename SampleType>
  24. class OversamplingEngine
  25. {
  26. public:
  27. //===============================================================================
  28. OversamplingEngine (size_t newFactor) { factor = newFactor; }
  29. virtual ~OversamplingEngine() {}
  30. //===============================================================================
  31. virtual SampleType getLatencyInSamples() = 0;
  32. size_t getFactor() { return factor; }
  33. virtual void initProcessing (size_t maximumNumberOfSamplesBeforeOversampling)
  34. {
  35. buffer.setSize (1, static_cast<int> (maximumNumberOfSamplesBeforeOversampling * factor));
  36. }
  37. virtual void reset()
  38. {
  39. buffer.clear();
  40. }
  41. SampleType* getProcessedSamples() { return buffer.getWritePointer (0); }
  42. size_t getNumProcessedSamples() { return static_cast<size_t> (buffer.getNumSamples()); }
  43. virtual void processSamplesUp (SampleType *samples, size_t numSamples) = 0;
  44. virtual void processSamplesDown (SampleType *samples, size_t numSamples) = 0;
  45. protected:
  46. //===============================================================================
  47. AudioBuffer<SampleType> buffer;
  48. size_t factor;
  49. };
  50. //===============================================================================
  51. /** Dummy oversampling engine class which simply copies and pastes the input
  52. signal, which could be equivalent to a "one time" oversampling processing.
  53. */
  54. template <typename SampleType>
  55. class OversamplingDummy : public OversamplingEngine<SampleType>
  56. {
  57. public:
  58. //===============================================================================
  59. OversamplingDummy() : OversamplingEngine<SampleType>(1) {}
  60. ~OversamplingDummy() {}
  61. //===============================================================================
  62. SampleType getLatencyInSamples() override
  63. {
  64. return 0.f;
  65. }
  66. void processSamplesUp (SampleType *samples, size_t numSamples) override
  67. {
  68. auto bufferSamples = this->buffer.getWritePointer (0);
  69. for (size_t i = 0; i < numSamples; i++)
  70. bufferSamples[i] = samples[i];
  71. }
  72. void processSamplesDown (SampleType *samples, size_t numSamples) override
  73. {
  74. auto bufferSamples = OversamplingEngine<SampleType>::buffer.getWritePointer (0);
  75. for (size_t i = 0; i < numSamples; i++)
  76. samples[i] = bufferSamples[i];
  77. }
  78. private:
  79. //===============================================================================
  80. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OversamplingDummy)
  81. };
  82. //===============================================================================
  83. /**
  84. Oversampling engine class performing 2 times oversampling using the Filter
  85. Design FIR Equiripple method. The resulting filter is linear phase,
  86. symmetric, and has every two samples but the middle one equal to zero,
  87. leading to specific processing optimizations.
  88. */
  89. template <typename SampleType>
  90. class Oversampling2TimesEquirippleFIR : public OversamplingEngine<SampleType>
  91. {
  92. public:
  93. //===============================================================================
  94. Oversampling2TimesEquirippleFIR (SampleType normalizedTransitionWidthUp,
  95. SampleType stopbandAttenuationdBUp,
  96. SampleType normalizedTransitionWidthDown,
  97. SampleType stopbandAttenuationdBDown) : OversamplingEngine<SampleType> (2)
  98. {
  99. coefficientsUp = *dsp::FilterDesign<SampleType>::designFIRLowpassHalfBandEquirippleMethod (normalizedTransitionWidthUp, stopbandAttenuationdBUp);
  100. coefficientsDown = *dsp::FilterDesign<SampleType>::designFIRLowpassHalfBandEquirippleMethod (normalizedTransitionWidthDown, stopbandAttenuationdBDown);
  101. auto N = coefficientsDown.getFilterOrder() + 1;
  102. auto Ndiv2 = N / 2;
  103. auto Ndiv4 = Ndiv2 / 2;
  104. stateUp.setSize (1, static_cast<int> (coefficientsUp.getFilterOrder() + 1));
  105. stateDown.setSize (1, static_cast<int> (N));
  106. stateDown2.setSize (1, static_cast<int> (Ndiv4));
  107. }
  108. ~Oversampling2TimesEquirippleFIR() {}
  109. //===============================================================================
  110. SampleType getLatencyInSamples() override
  111. {
  112. return static_cast<SampleType> (coefficientsUp.getFilterOrder() + coefficientsDown.getFilterOrder());
  113. }
  114. void reset() override
  115. {
  116. OversamplingEngine<SampleType>::reset();
  117. stateUp.clear();
  118. stateDown.clear();
  119. stateDown2.clear();
  120. position = 0;
  121. }
  122. void processSamplesUp (SampleType *samples, size_t numSamples) override
  123. {
  124. // Initialization
  125. auto bufferSamples = OversamplingEngine<SampleType>::buffer.getWritePointer (0);
  126. auto fir = coefficientsUp.getRawCoefficients();
  127. auto buf = stateUp.getWritePointer (0);
  128. auto N = coefficientsUp.getFilterOrder() + 1;
  129. auto Ndiv2 = N / 2;
  130. // Processing
  131. for (size_t i = 0; i < numSamples; i++)
  132. {
  133. // Input
  134. buf[N - 1] = 2 * samples[i];
  135. // Convolution
  136. auto out = static_cast<SampleType> (0.0);
  137. for (size_t k = 0; k < Ndiv2; k += 2)
  138. out += (buf[k] + buf[N - k - 1]) * fir[k];
  139. // Outputs
  140. bufferSamples[i << 1] = out;
  141. bufferSamples[(i << 1) + 1] = buf[Ndiv2 + 1] * fir[Ndiv2];
  142. // Shift data
  143. for (size_t k = 0; k < N - 2; k+=2)
  144. buf[k] = buf[k + 2];
  145. }
  146. }
  147. void processSamplesDown (SampleType *samples, size_t numSamples) override
  148. {
  149. // Initialization
  150. auto bufferSamples = OversamplingEngine<SampleType>::buffer.getWritePointer (0);
  151. auto fir = coefficientsDown.getRawCoefficients();
  152. auto buf = stateDown.getWritePointer (0);
  153. auto buf2 = stateDown2.getWritePointer (0);
  154. auto N = coefficientsDown.getFilterOrder() + 1;
  155. auto Ndiv2 = N / 2;
  156. auto Ndiv4 = Ndiv2 / 2;
  157. // Processing
  158. for (size_t i = 0; i < numSamples; i++)
  159. {
  160. // Input
  161. buf[N - 1] = bufferSamples[2 * i];
  162. // Convolution
  163. auto out = static_cast<SampleType> (0.0);
  164. for (size_t k = 0; k < Ndiv2; k += 2)
  165. out += (buf[k] + buf[N - k - 1]) * fir[k];
  166. // Output
  167. out += buf2[position] * fir[Ndiv2];
  168. buf2[position] = bufferSamples[2 * i + 1];
  169. samples[i] = out;
  170. // Shift data
  171. for (size_t k = 0; k < N - 2; k++)
  172. buf[k] = buf[k + 2];
  173. // Circular buffer
  174. position = (position == 0 ? Ndiv4 - 1 : position - 1);
  175. }
  176. }
  177. private:
  178. //===============================================================================
  179. dsp::FIR::Coefficients<SampleType> coefficientsUp, coefficientsDown;
  180. AudioBuffer<SampleType> stateUp, stateDown, stateDown2;
  181. size_t position;
  182. //===============================================================================
  183. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Oversampling2TimesEquirippleFIR)
  184. };
  185. //===============================================================================
  186. /** Oversampling engine class performing 2 times oversampling using the Filter
  187. Design IIR Polyphase Allpass Cascaded method. The resulting filter is minimum
  188. phase, and provided with a method to get the exact resulting latency.
  189. */
  190. template <typename SampleType>
  191. class Oversampling2TimesPolyphaseIIR : public OversamplingEngine<SampleType>
  192. {
  193. public:
  194. //===============================================================================
  195. Oversampling2TimesPolyphaseIIR (SampleType normalizedTransitionWidthUp,
  196. SampleType stopbandAttenuationdBUp,
  197. SampleType normalizedTransitionWidthDown,
  198. SampleType stopbandAttenuationdBDown) : OversamplingEngine<SampleType> (2)
  199. {
  200. auto structureUp = dsp::FilterDesign<SampleType>::designIIRLowpassHalfBandPolyphaseAllpassMethod (normalizedTransitionWidthUp, stopbandAttenuationdBUp);
  201. dsp::IIR::Coefficients<SampleType> coeffsUp = getCoefficients (structureUp);
  202. latency = static_cast<SampleType> (-(coeffsUp.getPhaseForFrequency (0.0001, 1.0)) / (0.0001 * 2 * double_Pi));
  203. auto structureDown = dsp::FilterDesign<SampleType>::designIIRLowpassHalfBandPolyphaseAllpassMethod (normalizedTransitionWidthDown, stopbandAttenuationdBDown);
  204. dsp::IIR::Coefficients<SampleType> coeffsDown = getCoefficients (structureDown);
  205. latency += static_cast<SampleType> (-(coeffsDown.getPhaseForFrequency (0.0001, 1.0)) / (0.0001 * 2 * double_Pi));
  206. for (auto i = 0; i < structureUp.directPath.size(); i++)
  207. coefficientsUp.add (structureUp.directPath[i].coefficients[0]);
  208. for (auto i = 1; i < structureUp.delayedPath.size(); i++)
  209. coefficientsUp.add (structureUp.delayedPath[i].coefficients[0]);
  210. for (auto i = 0; i < structureDown.directPath.size(); i++)
  211. coefficientsDown.add (structureDown.directPath[i].coefficients[0]);
  212. for (auto i = 1; i < structureDown.delayedPath.size(); i++)
  213. coefficientsDown.add (structureDown.delayedPath[i].coefficients[0]);
  214. v1Up.resize (coefficientsUp.size());
  215. v1Down.resize (coefficientsDown.size());
  216. }
  217. ~Oversampling2TimesPolyphaseIIR() {}
  218. //===============================================================================
  219. SampleType getLatencyInSamples() override
  220. {
  221. return latency;
  222. }
  223. void reset() override
  224. {
  225. OversamplingEngine<SampleType>::reset();
  226. v1Up.fill (0);
  227. v1Down.fill (0);
  228. delayDown = 0;
  229. }
  230. void processSamplesUp (SampleType *samples, size_t numSamples) override
  231. {
  232. // Initialization
  233. auto bufferSamples = OversamplingEngine<SampleType>::buffer.getWritePointer (0);
  234. auto coeffs = coefficientsUp.getRawDataPointer();
  235. auto lv1 = v1Up.getRawDataPointer();
  236. auto numStages = coefficientsUp.size();
  237. auto delayedStages = numStages / 2;
  238. auto directStages = numStages - delayedStages;
  239. // Processing
  240. for (size_t i = 0; i < numSamples; i++)
  241. {
  242. // Direct path cascaded allpass filters
  243. auto input = samples[i];
  244. for (auto n = 0; n < directStages; n++)
  245. {
  246. auto alpha = coeffs[n];
  247. auto output = alpha * input + lv1[n];
  248. lv1[n] = input - alpha * output;
  249. input = output;
  250. }
  251. // Output
  252. bufferSamples[i << 1] = input;
  253. // Delayed path cascaded allpass filters
  254. input = samples[i];
  255. for (auto n = directStages; n < numStages; n++)
  256. {
  257. auto alpha = coeffs[n];
  258. auto output = alpha * input + lv1[n];
  259. lv1[n] = input - alpha * output;
  260. input = output;
  261. }
  262. // Output
  263. bufferSamples[(i << 1) + 1] = input;
  264. }
  265. // Snap To Zero
  266. snapToZero (true);
  267. }
  268. void processSamplesDown (SampleType *samples, size_t numSamples) override
  269. {
  270. // Initialization
  271. auto bufferSamples = OversamplingEngine<SampleType>::buffer.getWritePointer (0);
  272. auto coeffs = coefficientsDown.getRawDataPointer();
  273. auto lv1 = v1Down.getRawDataPointer();
  274. auto numStages = coefficientsDown.size();
  275. auto delayedStages = numStages / 2;
  276. auto directStages = numStages - delayedStages;
  277. // Processing
  278. for (size_t i = 0; i < numSamples; i++)
  279. {
  280. // Direct path cascaded allpass filters
  281. auto input = bufferSamples[i << 1];
  282. for (auto n = 0; n < directStages; n++)
  283. {
  284. auto alpha = coeffs[n];
  285. auto output = alpha * input + lv1[n];
  286. lv1[n] = input - alpha * output;
  287. input = output;
  288. }
  289. auto directOut = input;
  290. // Delayed path cascaded allpass filters
  291. input = bufferSamples[(i << 1) + 1];
  292. for (auto n = directStages; n < numStages; n++)
  293. {
  294. auto alpha = coeffs[n];
  295. auto output = alpha * input + lv1[n];
  296. lv1[n] = input - alpha * output;
  297. input = output;
  298. }
  299. // Output
  300. samples[i] = (delayDown + directOut) * static_cast<SampleType> (0.5);
  301. delayDown = input;
  302. }
  303. // Snap To Zero
  304. snapToZero (false);
  305. }
  306. void snapToZero (bool snapUpProcessing)
  307. {
  308. if (snapUpProcessing)
  309. {
  310. auto lv1 = v1Up.getRawDataPointer();
  311. auto numStages = coefficientsUp.size();
  312. for (auto n = 0; n < numStages; n++)
  313. JUCE_SNAP_TO_ZERO (lv1[n]);
  314. }
  315. else
  316. {
  317. auto lv1 = v1Down.getRawDataPointer();
  318. auto numStages = coefficientsDown.size();
  319. for (auto n = 0; n < numStages; n++)
  320. JUCE_SNAP_TO_ZERO (lv1[n]);
  321. }
  322. }
  323. private:
  324. //===============================================================================
  325. /** This function calculates the equivalent high order IIR filter of a given
  326. polyphase cascaded allpass filters structure.
  327. */
  328. const dsp::IIR::Coefficients<SampleType> getCoefficients (typename dsp::FilterDesign<SampleType>::IIRPolyphaseAllpassStructure &structure) const
  329. {
  330. dsp::Polynomial<SampleType> numerator1 ({ static_cast<SampleType> (1.0) });
  331. dsp::Polynomial<SampleType> denominator1 ({ static_cast<SampleType> (1.0) });
  332. dsp::Polynomial<SampleType> numerator2 ({ static_cast<SampleType> (1.0) });
  333. dsp::Polynomial<SampleType> denominator2 ({ static_cast<SampleType> (1.0) });
  334. dsp::Polynomial<SampleType> temp;
  335. for (auto n = 0; n < structure.directPath.size(); n++)
  336. {
  337. auto *coeffs = structure.directPath.getReference (n).getRawCoefficients();
  338. if (structure.directPath[n].getFilterOrder() == 1)
  339. {
  340. temp = dsp::Polynomial<SampleType> ({ coeffs[0], coeffs[1] });
  341. numerator1 = numerator1.getProductWith (temp);
  342. temp = dsp::Polynomial<SampleType> ({ static_cast<SampleType> (1.0), coeffs[2] });
  343. denominator1 = denominator1.getProductWith (temp);
  344. }
  345. else
  346. {
  347. temp = dsp::Polynomial<SampleType> ({ coeffs[0], coeffs[1], coeffs[2] });
  348. numerator1 = numerator1.getProductWith (temp);
  349. temp = dsp::Polynomial<SampleType> ({ static_cast<SampleType> (1.0), coeffs[3], coeffs[4] });
  350. denominator1 = denominator1.getProductWith (temp);
  351. }
  352. }
  353. for (auto n = 0; n < structure.delayedPath.size(); n++)
  354. {
  355. auto *coeffs = structure.delayedPath.getReference (n).getRawCoefficients();
  356. if (structure.delayedPath[n].getFilterOrder() == 1)
  357. {
  358. temp = dsp::Polynomial<SampleType> ({ coeffs[0], coeffs[1] });
  359. numerator2 = numerator2.getProductWith (temp);
  360. temp = dsp::Polynomial<SampleType> ({ static_cast<SampleType> (1.0), coeffs[2] });
  361. denominator2 = denominator2.getProductWith (temp);
  362. }
  363. else
  364. {
  365. temp = dsp::Polynomial<SampleType> ({ coeffs[0], coeffs[1], coeffs[2] });
  366. numerator2 = numerator2.getProductWith (temp);
  367. temp = dsp::Polynomial<SampleType> ({ static_cast<SampleType> (1.0), coeffs[3], coeffs[4] });
  368. denominator2 = denominator2.getProductWith (temp);
  369. }
  370. }
  371. dsp::Polynomial<SampleType> numeratorf1 = numerator1.getProductWith (denominator2);
  372. dsp::Polynomial<SampleType> numeratorf2 = numerator2.getProductWith (denominator1);
  373. dsp::Polynomial<SampleType> numerator = numeratorf1.getSumWith (numeratorf2);
  374. dsp::Polynomial<SampleType> denominator = denominator1.getProductWith (denominator2);
  375. dsp::IIR::Coefficients<SampleType> coeffs;
  376. coeffs.coefficients.clear();
  377. auto inversion = static_cast<SampleType> (1.0) / denominator[0];
  378. for (auto i = 0; i <= numerator.getOrder(); i++)
  379. coeffs.coefficients.add (numerator[i] * inversion);
  380. for (auto i = 1; i <= denominator.getOrder(); i++)
  381. coeffs.coefficients.add (denominator[i] * inversion);
  382. return coeffs;
  383. }
  384. //===============================================================================
  385. Array<SampleType> coefficientsUp, coefficientsDown;
  386. SampleType latency;
  387. Array<SampleType> v1Up, v1Down;
  388. SampleType delayDown;
  389. //===============================================================================
  390. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Oversampling2TimesPolyphaseIIR)
  391. };
  392. //===============================================================================
  393. template <typename SampleType>
  394. Oversampling<SampleType>::Oversampling (size_t newNumChannels, size_t newFactor, FilterType newType, bool newMaxQuality)
  395. {
  396. jassert (newFactor >= 0 && newFactor <= 4 && newNumChannels > 0);
  397. factorOversampling = (size_t) 1 << newFactor;
  398. isMaximumQuality = newMaxQuality;
  399. type = newType;
  400. numChannels = newNumChannels;
  401. if (newFactor == 0)
  402. {
  403. for (size_t channel = 0; channel < numChannels; channel++)
  404. engines.add (new OversamplingDummy<SampleType>());
  405. numStages = 1;
  406. }
  407. else if (type == FilterType::filterHalfBandPolyphaseIIR)
  408. {
  409. numStages = newFactor;
  410. for (size_t channel = 0; channel < numChannels; channel++)
  411. for (size_t n = 0; n < numStages; n++)
  412. {
  413. auto tw1 = (isMaximumQuality ? 0.10f : 0.12f);
  414. auto tw2 = (isMaximumQuality ? 0.12f : 0.15f);
  415. engines.add (new Oversampling2TimesPolyphaseIIR<SampleType> (tw1, -75.f + 10.f * n, tw2, -70.f + 10.f * n));
  416. }
  417. }
  418. else if (type == FilterType::filterHalfBandFIREquiripple)
  419. {
  420. numStages = newFactor;
  421. for (size_t channel = 0; channel < numChannels; channel++)
  422. for (size_t n = 0; n < numStages; n++)
  423. {
  424. auto tw1 = (isMaximumQuality ? 0.10f : 0.12f);
  425. auto tw2 = (isMaximumQuality ? 0.12f : 0.15f);
  426. engines.add (new Oversampling2TimesEquirippleFIR<SampleType> (tw1, -90.f + 10.f * n, tw2, -70.f + 10.f * n));
  427. }
  428. }
  429. }
  430. template <typename SampleType>
  431. Oversampling<SampleType>::~Oversampling()
  432. {
  433. engines.clear();
  434. }
  435. //===============================================================================
  436. template <typename SampleType>
  437. SampleType Oversampling<SampleType>::getLatencyInSamples() noexcept
  438. {
  439. auto latency = static_cast<SampleType> (0);
  440. size_t order = 1;
  441. for (size_t n = 0; n < numStages; n++)
  442. {
  443. auto& engine = *engines[static_cast<int> (n)];
  444. order *= engine.getFactor();
  445. latency += engine.getLatencyInSamples() / std::pow (static_cast<SampleType> (2), static_cast<SampleType> (order));
  446. }
  447. return latency;
  448. }
  449. template <typename SampleType>
  450. size_t Oversampling<SampleType>::getOversamplingFactor() noexcept
  451. {
  452. return factorOversampling;
  453. }
  454. //===============================================================================
  455. template <typename SampleType>
  456. void Oversampling<SampleType>::initProcessing (size_t maximumNumberOfSamplesBeforeOversampling)
  457. {
  458. jassert (engines.size() > 0);
  459. for (size_t channel = 0; channel < numChannels; channel++)
  460. {
  461. auto currentNumSamples = maximumNumberOfSamplesBeforeOversampling;
  462. auto offset = numStages * channel;
  463. for (size_t n = 0; n < numStages; n++)
  464. {
  465. auto& engine = *engines[static_cast<int> (n + offset)];
  466. engine.initProcessing (currentNumSamples);
  467. currentNumSamples *= engine.getFactor();
  468. }
  469. }
  470. isReady = true;
  471. reset();
  472. }
  473. template <typename SampleType>
  474. void Oversampling<SampleType>::reset() noexcept
  475. {
  476. jassert (engines.size() > 0);
  477. if (isReady)
  478. for (auto n = 0; n < engines.size(); n++)
  479. engines[n]->reset();
  480. }
  481. template <typename SampleType>
  482. typename dsp::AudioBlock<SampleType> Oversampling<SampleType>::getProcessedSamples()
  483. {
  484. jassert (engines.size() > 0);
  485. Array<SampleType*> arrayChannels;
  486. for (size_t channel = 0; channel < numChannels; channel++)
  487. arrayChannels.add (engines[static_cast<int> (((channel + 1) * numStages) - 1)]->getProcessedSamples());
  488. auto numSamples = engines[static_cast<int> (numStages - 1)]->getNumProcessedSamples();
  489. auto block = dsp::AudioBlock<SampleType> (arrayChannels.getRawDataPointer(), numChannels, numSamples);
  490. return block;
  491. }
  492. template <typename SampleType>
  493. void Oversampling<SampleType>::processSamplesUp (dsp::AudioBlock<SampleType> &block) noexcept
  494. {
  495. jassert (engines.size() > 0 && block.getNumChannels() <= numChannels);
  496. if (! isReady)
  497. return;
  498. for (size_t channel = 0; channel < jmin (numChannels, block.getNumChannels()); channel++)
  499. {
  500. SampleType* dataSamples = block.getChannelPointer (channel);
  501. auto currentNumSamples = block.getNumSamples();
  502. auto offset = numStages * channel;
  503. for (size_t n = 0; n < numStages; n++)
  504. {
  505. auto& engine = *engines[static_cast<int> (n + offset)];
  506. engine.processSamplesUp (dataSamples, currentNumSamples);
  507. currentNumSamples *= engine.getFactor();
  508. dataSamples = engine.getProcessedSamples();
  509. }
  510. }
  511. }
  512. template <typename SampleType>
  513. void Oversampling<SampleType>::processSamplesDown (dsp::AudioBlock<SampleType> &block) noexcept
  514. {
  515. jassert (engines.size() > 0 && block.getNumChannels() <= numChannels);
  516. if (! isReady)
  517. return;
  518. for (size_t channel = 0; channel < jmin (numChannels, block.getNumChannels()); channel++)
  519. {
  520. auto currentNumSamples = block.getNumSamples();
  521. auto offset = numStages * channel;
  522. for (size_t n = 0; n < numStages - 1; n++)
  523. currentNumSamples *= engines[static_cast<int> (n + offset)]->getFactor();
  524. for (size_t n = numStages - 1; n > 0; n--)
  525. {
  526. auto& engine = *engines[static_cast<int> (n + offset)];
  527. auto dataSamples = engines[static_cast<int> (n + offset - 1)]->getProcessedSamples();
  528. engine.processSamplesDown (dataSamples, currentNumSamples);
  529. currentNumSamples /= engine.getFactor();
  530. }
  531. engines[static_cast<int> (offset)]->processSamplesDown (block.getChannelPointer (channel), currentNumSamples);
  532. }
  533. }
  534. template class Oversampling<float>;
  535. template class Oversampling<double>;