Unit Delay (Z¯¹)

A literal mono unit delay (that is, a delay of 1 sample without a way to have any other delay lenght) could be something like :


class unit_delay
{
public:
    unit_delay() : m_previous(0.0f) {}
    float process(float input)
    {
        float temp = m_previous;
        m_previous = input;
        return temp;
    }
private:
    float m_previous;
};

You need an instance of this class in a scope where it will retain its state as long as your audio processing is going on. You need a separate instance for every audio channel you process. (That is, if you have a stereo signal, you need 2 independent object instances etc...)

The implementation shown above may not be optimal. It is common to make audio processing classes process buffers of audio, not single samples, to reduce possible overhead from function calls. (I'd suspect though that the class above is so simple the compiler can figure out a way to not make any function calls.) But you shouldn't be worrying about efficiency at this point. Just get things working in the cleanest and easiest way possible.