I'm trying to build an additive synth (sort of a learning project as well as, eventually, a useful instrument). By way of testing my design, I want to output a square wave by summing sines, but I can't seem to get it to work. I have the [cycle~] objects set up so that their frequency represents a harmonic, e.g., 1st is fundamental (first harmonic), say 100Hz, 2nd is second harmonic at 200Hz, etc., up to the 25th harmonic. The amplitude of each of these is set to alternate between zero and 1/h, where h = the number of the harmonic, e.g., the third harmonic is 1/3 the amplitude of the first/fundamental. It is my understanding that this is how one builds a square wave out of sines (see, for example, http://en.wikipedia.org/wiki/Square_wave#Examining_the_square_wave).
What I'm getting is not a square; it's weird, more like a triangle than a square wave, and clearly wrong. I haven't been able to figure out where I'm screwing up, so I built a simplified version for troubleshooting and it illustrates the problem well.
I've only used the first seven harmonics here, just to keep it simple, but, as I said, the math replicates what I'm doing in the more elaborate synth patch. You'll note I inserted a [rect~] object as a comparison, to make sure there wasn't something I was misunderstanding about how to use or read a [scope~].
Can anyone tell me what I'm doing wrong?