I\'m trying to use AudioTrack to generate sine, square, and sawtooth waves. However, the audio this is creating doesn\'t sound like a pure sine wave, but like it has some kind o
The only material difference that I can see in your two code samples is that the equation in your first example contains an integer (I
), and therefore you're probably doing integer (not floating-point) arithmetic. This would cause a staircasing effect, adding unwanted harmonics to your waveform.
I suspect that if you simply cast I
to a float in your equation, it will produce a pure sine wave.
samples[i]
= (float) Math.sin( (float)i * ((float)(2*Math.PI) * frequency / 44100));