Period= 1/frequency, if that helps you figure it out.
You can substitute this for your sample generation expression:
sample[i]= 2*(i%(sampleRate/freqOfTone))/(sampleRate/freqOfTone)-1;
Here is an example of how it works. Code is adapted from here