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

            Line data    Source code
       1              : #pragma once
       2              : 
       3              : // Hard-clipping distortion effect with tone shaping.
       4              : // The driven sample u=drive*x[n] is clipped with y=clamp(u, -clip, clip), then
       5              : // filtered by the tone stage and level-scaled; this creates odd harmonics as
       6              : // the transfer function flattens near the clipping threshold.
       7              : 
       8              : #include "audio/effects/effect.h"
       9              : #include "audio/dsp/biquad.h"
      10              : 
      11              : namespace Amplitron {
      12              : 
      13            2 : class Distortion : public Effect {
      14              : public:
      15              :     // Create a distortion effect with drive, tone, and output gain controls.
      16              :     Distortion();
      17              :     // Apply the distortion curve and filtering to a mono audio buffer.
      18              :     void process(float* buffer, int num_samples) override;
      19              :     // Clear any filter state held by the effect.
      20              :     void reset() override;
      21              :     // Return the display name for this effect.
      22          116 :     const char* name() const override { return "Distortion"; }
      23            3 :     const char* type_id() const override { return "Distortion"; }
      24              :     // Return editable parameters exposed by this effect.
      25          117 :     std::vector<EffectParam>& params() override { return params_; }
      26              : 
      27              : private:
      28              :     std::vector<EffectParam> params_;
      29              :     OnePole tone_lp_;
      30              : 
      31              :     // One-pole smoothing states (avoids zipper noise on parameter changes)
      32              :     float drive_smoothed_ = 2.0f;
      33              :     float tone_smoothed_  = 0.6f;
      34              :     float level_smoothed_ = 0.5f;
      35              : };
      36              : 
      37              : } // namespace Amplitron
        

Generated by: LCOV version 2.0-1