Allpass filter feedforward/feedback design and code
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?