Neil Baldwin over at Duty Cycle Generator has added the ability in his sound engine “Nijuu” to add an “echo effect” to a single square wave channel.
How it works is to have a circular buffer (one each for voices Square 1, Square 2 & Noise) that the echo writes to by figuring out what is going to get written to the PAPU (Pseudo Audio Processing Unit) registers each frame. It then captures the register settings and continues to do so until the buffer is filled, then starts again at the beginning. When you enable echo, Nijuu retrieves the values from the buffer and writes them to the PAPU registers in the “gaps” in between notes when it decides that there’s no activity on the voice (I do this by detecting if the ADSR envelope on the voice has reached the release phase or if there is no note playing). The echo feedback continues to loop around, attenuating the captured amplitude until it reaches zero. All the while, any new notes are captured to the echo buffer in the same way and it continues to capture/attenuate/feedback notes forever until you turn it off.
(The above quote was taken from Neil’s article and slightly modified for accuracy.)