CMLSDelay.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. ==============================================================================
  3. CMLSDelay.cpp
  4. Created: 3 May 2025 5:39:35pm
  5. Author: Luigi
  6. ==============================================================================
  7. */
  8. #include "CMLSDelay.h"
  9. CMLSDelay::CMLSDelay() {
  10. //feedbackRange = new juce::NormalisableRange<float>(MIN_FEEDBACK, MAX_FEEDBACK);
  11. this->delayLength = 0.0f;
  12. this->feedback = 0.0f;
  13. this->amount = 0.0f;
  14. this->dryWetProp = 0.0f;
  15. }
  16. CMLSDelay::~CMLSDelay() {}
  17. void CMLSDelay::reset() {
  18. this->delayLine.reset();
  19. this->mixer.reset();
  20. }
  21. void CMLSDelay::prepare(const juce::dsp::ProcessSpec& spec) {
  22. this->maximumDelaySamples = spec.sampleRate * MAX_DELAY_LENGTH;
  23. this->delayRange = new juce::NormalisableRange<float>(0, this->maximumDelaySamples);
  24. this->delayLine.prepare(spec);
  25. this->delayLine.setMaximumDelayInSamples(this->maximumDelaySamples);
  26. this->mixer.prepare(spec);
  27. this->mixer.setMixingRule(juce::dsp::DryWetMixingRule::linear);
  28. }
  29. void CMLSDelay::process(const juce::dsp::ProcessContextReplacing<float>& context) {
  30. auto audioBlock = context.getOutputBlock();
  31. auto numChannels = audioBlock.getNumChannels();
  32. const auto numSamples = audioBlock.getNumSamples();
  33. this->mixer.pushDrySamples(context.getInputBlock());
  34. for (int channel = 0; channel < numChannels; ++channel)
  35. {
  36. for (int i = 0; i < numSamples; i++)
  37. {
  38. this->delayLine.pushSample(channel, context.getInputBlock().getSample(channel, i));
  39. audioBlock.setSample(
  40. channel,
  41. i,
  42. this->delayLine.popSample(channel, this->delayLength)
  43. );
  44. }
  45. }
  46. // Adding wet (elaborated) signal
  47. this->mixer.mixWetSamples(audioBlock);
  48. }
  49. void CMLSDelay::setDryWet(float value) {
  50. this->dryWetProp = value;
  51. this->mixer.setWetMixProportion(this->dryWetProp);
  52. }
  53. void CMLSDelay::setAmount(float value) {
  54. this->delayLength = this->delayRange->convertFrom0to1(value);
  55. }
  56. const float CMLSDelay::getDryWet() {
  57. return this->dryWetProp;
  58. }
  59. const float CMLSDelay::getAmount() {
  60. return this->amount;
  61. }