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

            Line data    Source code
       1              : #pragma once
       2              : 
       3              : // Pitch shifting effect for semitone-based transposition.
       4              : // The shift ratio is r = 2^(semitones/12); the processor reads from a delay
       5              : // line/resampling window at rate r and crossfades windows to reduce clicks,
       6              : // producing y[n] from time-scaled input samples.
       7              : 
       8              : #include "audio/effects/effect.h"
       9              : #include <vector>
      10              : 
      11              : namespace Amplitron {
      12              : 
      13              : /**
      14              :  * Pitch Shifter — shifts pitch by +/- 12 semitones using a dual-tap
      15              :  * granular overlap-add algorithm.
      16              :  *
      17              :  * Two read pointers scan through a circular buffer at a rate determined by
      18              :  * the pitch ratio. A raised-cosine (Hann) crossfade between the two taps
      19              :  * hides the grain boundary discontinuities.
      20              :  *
      21              :  * Controls: Shift (semitones), Fine (cents), Mix.
      22              :  */
      23              : class PitchShifter : public Effect {
      24              : public:
      25              :     PitchShifter();
      26              :     void process(float* buffer, int num_samples) override;
      27              :     void set_sample_rate(int sample_rate) override;
      28              :     void reset() override;
      29            0 :     const char* name() const override { return "Pitch Shifter"; }
      30            3 :     const char* type_id() const override { return "Pitch Shifter"; }
      31           18 :     std::vector<EffectParam>& params() override { return params_; }
      32              : 
      33              : private:
      34              :     std::vector<EffectParam> params_;
      35              : 
      36              :     // Grain buffer
      37              :     std::vector<float> grain_buf_;
      38              :     int buf_size_ = 0;
      39              :     int write_pos_ = 0;
      40              : 
      41              :     // Two crossfading read taps (phase in [0, buf_size_))
      42              :     float read_phase_a_ = 0.0f;
      43              :     float read_phase_b_ = 0.0f;
      44              : 
      45              :     // Parameter smoothing
      46              :     float shift_smooth_ = 0.0f;
      47              :     float fine_smooth_ = 0.0f;
      48              :     float mix_smooth_ = 0.0f;
      49              : 
      50              :     float read_linear(float phase) const;
      51              : };
      52              : 
      53              : } // namespace Amplitron
        

Generated by: LCOV version 2.0-1