I'm having a really weird issue with generating waveforms from frequencies C1 to C8.
When I generate sine waves, everything sounds good; no problems whatsoever. However, when I generate a square wave... BAM weird aliasing issues on the higher frequencies (around C6 to C8). I have no idea what I'm doing wrong at this point.
I'm going to take a wild guess here but I'm thinking it might be because square waves have a lot of harmonics so it's not producing the higher harmonics correctly when I reach a higher frequency... thus the really high harmonics are getting aliased. Would like someone to confirm with me/guide me to a solution to this. Is it possible to try to implement a filter or is there a better solution ?
Thanks!
I'm setting my sample rate to 44.1 kHz and here are my functions for waveform generation:
float generateSin {
sample = sinf(_phs);
_phs += _phs_incr;
_phs = wrapPhase(_phs);
}
float generateSqr {
sample = sinf(_phs);
if (sample > 0) sample = 1;
else if (sample < 0) sample = -1;
_phs += _phs_incr;
_phs = wrapPhase(_phs);
}