LCOV - code coverage report
Current view: top level - src/audio/effects - overdrive.cpp (source / functions) Coverage Total Hit
Test: merged.info Lines: 100.0 % 36 36
Test Date: 2026-06-01 11:15:25 Functions: 100.0 % 3 3

            Line data    Source code
       1              : #include "audio/effects/overdrive.h"
       2              : #include "audio/effects/effect_factory.h"
       3              : 
       4              : namespace Amplitron {
       5              : 
       6            2 : static EffectRegistrar<Overdrive> reg("Overdrive");
       7              : 
       8          496 : Overdrive::Overdrive() {
       9         1116 :     params_ = {
      10          372 :         {"Drive",  1.5f,  1.0f, 10.0f, 1.5f, "x", "Amount of input gain pushing into soft-clipping. Increases harmonic saturation and sustain."},
      11          124 :         {"Tone",   0.7f,  0.0f,  1.0f, 0.7f, "", "Adjusts high-frequency content. Lower values are darker and smoother, higher values are brighter and more biting."},
      12          124 :         {"Level",  0.7f,  0.0f,  1.0f, 0.7f, "", "Master output volume of the pedal to compensate for the gain added by the Drive control."},
      13         1116 :     };
      14          744 : }
      15              : 
      16           27 : void Overdrive::process(float* buffer, int num_samples) {
      17           27 :     if (!enabled_) return;
      18              : 
      19           27 :     const float alpha = 1.0f - std::exp(-1.0f / (sample_rate_ * 0.010f)); // 10 ms
      20           27 :     smoothed_drive_ += alpha * (params_[0].value - smoothed_drive_);
      21           27 :     smoothed_tone_  += alpha * (params_[1].value - smoothed_tone_);
      22           27 :     smoothed_level_ += alpha * (params_[2].value - smoothed_level_);
      23              : 
      24           27 :     float drive = smoothed_drive_;
      25           27 :     float tone = smoothed_tone_;
      26           27 :     float level = smoothed_level_;
      27              : 
      28           27 :     float lp_coeff = 0.05f + tone * 0.9f;
      29              : 
      30         6195 :     for (int i = 0; i < num_samples; ++i) {
      31         6168 :         float dry = buffer[i];
      32              : 
      33              :         // Asymmetric soft clipping (tube-like)
      34         6168 :         float x = buffer[i] * drive;
      35         6168 :         if (x > 0.0f) {
      36         2979 :             x = 1.0f - std::exp(-x);
      37          993 :         } else {
      38         3189 :             x = -1.0f + std::exp(x);
      39         3189 :             x *= 0.8f; // asymmetry
      40              :         }
      41              : 
      42              :         // Tone: LP filter
      43         6168 :         x = tone_lp_.lp(x, lp_coeff);
      44              : 
      45              :         // DC blocking HP filter
      46         6168 :         x = dc_block_.hp(x, 0.001f);
      47              : 
      48         6168 :         x *= level;
      49         6168 :         buffer[i] = dry * (1.0f - mix_) + x * mix_;
      50         2056 :     }
      51            9 : }
      52              : 
      53          336 : void Overdrive::reset() {
      54          336 :     tone_lp_.reset();
      55          336 :     dc_block_.reset();
      56          336 : }
      57              : 
      58              : } // namespace Amplitron
        

Generated by: LCOV version 2.0-1