CMLSDelay.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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->delayRange
  25. this->delayLine.prepare(spec);
  26. this->delayLine.setMaximumDelayInSamples(this->maximumDelaySamples);
  27. this->mixer.prepare(spec);
  28. this->mixer.setMixingRule(juce::dsp::DryWetMixingRule::linear);
  29. }
  30. void CMLSDelay::process(const juce::dsp::ProcessContextReplacing<float>& context) {
  31. auto audioBlock = context.getOutputBlock();
  32. auto numChannels = audioBlock.getNumChannels();
  33. const auto numSamples = audioBlock.getNumSamples();
  34. this->mixer.pushDrySamples(context.getInputBlock());
  35. for (int channel = 0; channel < numChannels; ++channel)
  36. {
  37. for (int i = 0; i < numSamples; i++)
  38. {
  39. this->delayLine.pushSample(channel, context.getInputBlock().getSample(channel, i));
  40. audioBlock.setSample(
  41. channel,
  42. i,
  43. this->delayLine.popSample(channel, this->delayLength)
  44. );
  45. }
  46. }
  47. // Adding wet (elaborated) signal
  48. this->mixer.mixWetSamples(audioBlock);
  49. }
  50. void CMLSDelay::setDryWet(float value) {
  51. this->dryWetProp = value;
  52. this->mixer.setWetMixProportion(this->dryWetProp);
  53. }
  54. void CMLSDelay::setAmount(float value) {
  55. this->delayLength = this->delayRange->convertFrom0to1(value);
  56. }
  57. const float CMLSDelay::getDryWet() {
  58. return this->dryWetProp;
  59. }
  60. const float CMLSDelay::getAmount() {
  61. return this->amount;
  62. }