4 ms·
As others noted, merely switching back and forth between -1 and 1 will result in heavy aliasing. Also, since you can only switch from -1 to 1 at integer sample
by meindnoch 2y ago
As others noted, merely switching back and forth between -1 and 1 will result in heavy aliasing. Also, since you can only switch from -1 to 1 at integer sample points, you won't be able to accurately generate frequencies that don't divide the sample rate evenly. E.g. if your sample rate is 48 kHz, you won't be able to generate a 50% duty cycle 11 kHz square wave. Either the duty cycle, or the frequency will be different. Like, audibly different.
The proper way is either via the Fourier series; or look into BLIT [1] synthesis.
[1] https://ccrma.stanford.edu/~stilti/papers/blit.pdf https://ccrma.stanford.edu/~stilti/papers/blit.pdf
- nkozyra 2y agoAliasing seems like a potentially desirable feature for a chiptune / retro sound, though.
- iamdan 2y agoThis is the nice thing about constraining myself to a rather old and crude sound style, the rough edges can remain a little rough
- montag 2y agoBlargg's Blip Buffer library is a widely-used implementation (especially in chip music synthesis), explained in detail here: https://www.slack.net/~ant/bl-synth/ https://www.slack.net/~ant/bl-synth/