A sine wave is derived from this function:
y(t) = Amplitude * Sin( 2* PI * Frequency * SAMPLE_TIME)
This line of code:
samples[i] = (short) (amp * Math.sin(ph));
is essentially the function above. On the first execution of the for-loop, ph
is zero
, hence, the computation works. ph
essentially is the angle part given to the function above. Next, ph
takes the value:
ph += twopi * fr/sr;
Here, fr / sr
is Frequency / Sample_Rate. Also, note that:
SAMPLE_TIME = 1 / SAMPLE_RATE