I'm making audio app on Android and I have simple generation of three types of sound waves - Sine, Sawtooth and Square.
Generating of waves is fine. I printed out the result and it's looking good. But the sound is weird. Here is what I recorded. https://soundcloud.com/syntey/synth-sine-wave-test-nothing-to-do-here
It's same for sawtooth and square, but when I play with sawtooth any A, then sound is normal.
Does someone know what is wrong? If I increase size of buffer, then period is longer, but still the same problem
Code for generating sine wave:
play(JNIEnv* env, jclass clazz, jint which, jint count, jdouble freqOfTone)
{
unsigned i;
int j = 0;
double sampleRate = SAMPLERATE/freqOfTone;
switch (which) {
case SINE:
for (i = 0; i < TONE_FRAMES; ++i) {
toneBuffer[i] = sin(2.0*M_PI * i/sampleRate) * 32768;
}
nextBuffer = createResampledBuf(SINE, SL_SAMPLINGRATE_8, &nextSize);
if(!nextBuffer) {
nextBuffer = (short*) toneBuffer;
nextSize = sizeof(toneBuffer);
}
break;
}
nextCount = count;
if (nextSize > 0) {
SLresult result;
result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, nextBuffer, nextSize);
if (SL_RESULT_SUCCESS != result) {
bqPlayerRecorderBusy = 1;
return JNI_FALSE;
}
}
return JNI_TRUE;
}