CMLSDelay.cpp 2.3 KB

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