I'm following along with The Audio Programming Book by Richard Boulanger. In Chapter two we create several basic audio rate oscillators using C and the standard libraries to generate simple WAV files.
Both my implementation and the book's code exhibit a strange issue:
I am able to generate a simple sine wave using sin() (from math.h), but noticed the playback has a bit of static. Upon investigation I noticed that occasionally, some of the audio frames at peak amplitude are getting "flipped" to a negative value.
To debug this situation, I'm outputting the values of the audio frames generated to stdout and this flipping behavior lines up with the peak value of 0.999999.
When I scale the output by 0.99 this problem disappears. What's going on?