xmd79

Noise Gate

Dec 16th, 2022
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © peacefulLizard50262
  3.  
  4. //@version=5
  5. indicator("Noise Gate")
  6. // Define the input parameters for the script
  7. alt = input.bool(false, "Use Source as Input")
  8. source = input.source(close, "Source")
  9. ratio = input.float(10, "Ratio", 0.00000001)
  10. level = input.float(0, "Threshold", 0)
  11. knee_type = input.string("soft", "Knee Type", ["soft", "hard"])
  12.  
  13. noise_gate(signal, ratio, level, knee_type) =>
  14. // Calculate the absolute value of the signal
  15. abs_signal = math.abs(signal)
  16.  
  17. // Check the value of the knee_type parameter
  18. if knee_type == "hard"
  19. // If the knee_type is "hard", apply a hard knee
  20. if abs_signal > level
  21. out = signal
  22. else
  23. out = signal / ratio
  24. else
  25. // If the knee_type is not "hard", apply a soft knee
  26. if (abs_signal > level) or level == 0
  27. // If the absolute value is above the threshold, return the signal as is
  28. out = signal
  29. else
  30. // If the absolute value is below the threshold, calculate the soft knee ratio
  31. soft_knee_ratio = 1 - (level - abs_signal) / level
  32. // Reduce the amplitude of the signal by the soft knee ratio
  33. out = signal * soft_knee_ratio
  34.  
  35. // Return the filtered signal
  36.  
  37. plot(noise_gate(alt ? source : volume, ratio, level, knee_type))
  38.  
Advertisement
Add Comment
Please, Sign In to add comment