chenlh
2026-03-26 36e42207da4c088b5bfd96f2cfc8944f890440d7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#pragma once
 
#include <LinearInterpolationCircularBuffer.h>
 
#define FEEDBACK_LIMIT 0.99
 
/**
 * First Order All-Pass Filter that utilizes linear interpolation when poping samples.
 * 
 * Allows for smoother delay time changes and modulation.
 * 
 */
template <typename SampleType>
class InterpolatedAllPassFilter
{
public:
 
    /**
     * @brief Constructor
     */
    InterpolatedAllPassFilter();
 
    /**
     * @brief Destructor
     */
    ~InterpolatedAllPassFilter();
    
    /**
     * @brief Prepares object for playback
     * 
     * @param sampleRate Current sampling rate
     */
    void prepare(SampleType sampleRate);
 
    /**
     * @brief Sets the delay time in milliseconds 
     * 
     * @param delayInMs Delay time in milliseconds
     */
    void setDelayMs(SampleType delayInMs);
 
    /**
     * @brief Sets the delay time in samples 
     * 
     * @param delayInMs Delay time in samples
     */
    void setDelaySamples(SampleType delayInSamples);
 
    /**
     * @brief Sets the amount of feedback.
     * 
     * Values must range between 0 and 1
     * 
     * @param newFeedback Feedback amount
     */
    void setFeedback(SampleType newFeedback);
    /**
     * @brief Processes a single sample
     * 
     * @param input Input sample
     */
    SampleType processSample(SampleType input);
 
    /**
     * @brief Processes a memory block that holds audio samples
     * 
     * @param channelData Memory block start pointer 
     * @param startSample Sample index to start processing from
     * @param endSample Number of samples to process
     */
    void process(SampleType* channelData, int startSample, int endSample);
 
 
private:
 
    SampleType sampleRate;
    LinearInterpolationCircularBuffer<SampleType> circularBuffer;
    SampleType delayTime {0.0};
    SampleType feedback {0.0};
 
    SampleType lastOutput {0.0};
    SampleType lastInput {0.0};
    
};