PLUG'N SCRIPT
rapid plugin development
Tutorial
DSP
KUIML
How-to
Scripts
GUI
  • Drawing
  • Simple knobs
Library
  • Params
Rave Generation
  • Preamp
ScriptsBy authorRave GenerationPreamp
November 04, 2025

Preamp

A minimal stereo preamp introducing musical soft saturation, gentle harmonics, and automatic gain normalization. Designed as a clean example script.

Download

preamp.cpp

Contents

preamp.cpp

  1. // -----------------------------------------------------------------------------
  2. // PreAmp - Simple warm saturation
  3. // Author: ravegeneration.io
  4. //
  5. // A minimal stereo preamp introducing musical soft saturation, gentle harmonics,
  6. // and automatic gain normalization. Designed as a clean example script.
  7. //
  8. // - Single control: "PreAmp" adjusts drive amount (0–100%)
  9. // - Stereo processing
  10. // - Lightweight CPU usage
  11. // -----------------------------------------------------------------------------
  12.  
  13. #include <cmath>
  14. #include <string>
  15. #include <vector>
  16. #include "../dspapi.h"
  17. #include "../cpphelpers.h"
  18. #include "../params.h"
  19.  
  20. DSP_EXPORT string name = "PreAmp";
  21.  
  22. int PREAMP;
  23.  
  24. inline double processPreamp(double x, double p)
  25. {
  26. if (p < 0.001) return x;
  27.  
  28. double drive = 1.0 + p * 3.0;
  29. double warmth = p * 0.25;
  30.  
  31. double sat = tanh(x * drive * 0.9);
  32. double harm = x * x * warmth;
  33.  
  34. return (sat + harm) * (1.0 / (1.0 + p * 0.8));
  35. }
  36.  
  37. DSP_EXPORT bool initialize()
  38. {
  39. audioInputsCount = 2;
  40. audioOutputsCount = 2;
  41.  
  42. PREAMP = ip("PreAmp", "%", 0, 100, 0, ".1");
  43. return true;
  44. }
  45.  
  46. DSP_EXPORT void processBlock(BlockData& data)
  47. {
  48. double p = IP[PREAMP] / 100.0;
  49.  
  50. for (uint i = 0; i < data.samplesToProcess; i++)
  51. {
  52. data.samples[0][i] = processPreamp(data.samples[0][i], p);
  53. data.samples[1][i] = processPreamp(data.samples[1][i], p);
  54. }
  55. }

Comments

Please, authorize to view and post comments.

2020 - 2026 © Site by LetiMix · Donate  |  Plug'n Script and KUIML by Blue Cat Audio