I am trying to generate sine tone with sweep. I am using the code below which i got from here. The problem is, i can hear sound that is above 200Hz but i cannot hear tone that is below 200Hz (like 20hz or 50Hz). Please help me to generate accurate sine tone.
private final int sampleRate = 44100;
public void generateTone(double startFreq, double endFreq, float duration)
{
double dnumSamples = duration * sampleRate;
dnumSamples = Math.ceil(dnumSamples);
numSamples = (int) dnumSamples;
double sample[] = new double[numSamples];
double currentFreq = 0,numerator;
for (int i = 0; i < numSamples; ++i) {
numerator = (double) i / (double) numSamples;
currentFreq = startFreq + (numerator * (endFreq - startFreq))/2;
if ((i % 1000) == 0) {
Log.e("Current Freq:", String.format("Freq is: %f at loop %d of %d", currentFreq, i, numSamples));
}
sample[i] = Math.sin(2 * Math.PI * i / (sampleRate / currentFreq));
}
generatedSnd = new byte[2 * numSamples];
int idx = 0;
for (final double dVal : sample) {
// scale to maximum amplitude
final short val = (short) ((dVal * 32767));
// in 16 bit wav PCM, first byte is the low order byte
generatedSnd[idx++] = (byte) (val & 0x00ff);
generatedSnd[idx++] = (byte) ((val & 0xff00) >>> 8);
}
}