12kHz sine or square. I can hear the difference - why? I can hear 12kHz sinewave but not 22kHz. 

A 12kHz squarewave has the fundamental and harmonics I think.  But the first harmonic is outside my hearing range, so how come I can hear the difference between 12kHz sine and 12kHz square?  It's a long time since I did any audio electronics so I've probably forgotten some basic rules - cut me some slack!
Try synthesizing your “square wave” using only sinusoidal components below half the sample rate.  Otherwise, most of the infinite train of odd harmonics can alias to some other (lower) frequency in the sampled data.