Allpass filter feedforward/feedback design and code I want to design/implement a simple feedforward/feedback all-pass filter, and I am having some troubles and questions with it.

From Shroeder design (based on J. Smith article here):
  

I came up with the following pseudocode (for first-order all-pass filter, meaning the delay was set to 1 sample, and b0 = aM):  

float allPassGain = aM, value from [0.0, 1.0);

float allPassFeedback = 0.0;
float allPassDelayedSample = 0.0;

float processAllPass(float x)
{
    float delayInput = x + allPassFeedback;
    float feedForward = delayInput * allPassGain;

    float delayOutput = allPassDelayedSample;
    allPassDelayedSample = delayInput;

    allPassFeedback = delayOutput * -allPassGain;

    return delayOutput + feedForward;
}


Here x is an input sample, to process some signal with this all-pass I am going through the signal feeding it sample-by-sample into processAllPass, and store the outputs in the parallel output signal.

But unfortunately it seems like this approach doesn't work. For example, if I create a simple Phaser with a set of successful all-pass filters designed like that, I don't get the desired effect, instead the signal becomes unstable and shoots through the roof.

Does the pseudo-code have issues? I am setting aM to an arbitrary value and the delay line length is strictly 1.



Matt L.'s answer helped me to fix the code, and here is the fixed pseudo-code if that would be interesting (please also note that for the Phaser effect I find it better to switch coefficients' signs, it is slightly different version of the all-pass filter, presented in e.g. "Reducing Artificial Reverberation Algorithm Requirements using FDN" by Jasmin Frenette):

float allPassGain = aM, value from [0.0, 1.0);

float allPassDelayedSample = 0.0;

float processAllPass(float x)
{
    float delayOutput = allPassDelayedSample;
    float feedBack = delayOutput * allPassGain;

    float delayInput = inSamp + feedBack;
    float feedForward = delayInput * -allPassGain;
    allPassDelayedSample = delayInput;

    return delayOutput + feedForward;
}
First of all make sure that the magnitude of $a_M$ is strictly less than $1$; this is necessary for the filter's stability. Second, you use several unnecessary variables. This is no serious problem, but it makes it harder to see what's going on. For $M=1$ a simple pseudo-code would be


v = x - aM * v_old;
y = v * b + v_old;
v_old = v;


The important thing is that the state variable v_old must be remembered between function calls. Are you sure that your variables allPassFeedback and allPassDelayedSample are not reset to $0$ every time you call the function?