I am very very new to signals, and I am trying to generate sounds based on some parameters from a database. So, the database stores the following:
- startFrequency
- endFrequency
- startAmplitude
- endAmplitude
- duration
I am generating a WAV file based on this information using the following code:
...
double currentFrequency;
double currentAmplitude;
int samplerate = 44100;
int samples = ceil(duration * samplerate);
int* mySampleBuffer = new int[samples];
for(int i=0; i<samples; i++)
{
currentFrequency = Interpolate(i, 0, samples, startFrequency, endFrequency);
currentAmplitude = Interpolate(i, 0, samples, startAmplitude, endAmplitude);
mySampleBuffer[i] = static_cast<int>(INT_MAX * (sin(((double)i * currentFrequency * PI * 2)/(double)samplerate) * (currentAmplitude/maxAmplitude)));
}
writeWAVData("mySound.wav", mySampleBuffer, mySampleBufferSize, samplerate, 1);
delete[] mySampleBuffer;
...
When the currentFrequency reaches 1/2 of the startFrequency, I notice that the sound wave flips (not sure what the correct term for this is). It doesn't seem like this is correct. Could someone help me understand what is going on.
Here is a screenshot of Audacity
For this image, startFrequency is 3380 Hz, endFrequency = 1380 Hz, duration is 0.512 s, and the amplitude is constant from start to finish. I have calculated that at 0.43264 s, the currentFrequency is exactly 1/2 of the startFrequency. In the picture you can see the "flip" happen at about 0.43 seconds.
delete[] mySampleBuffer;
after writing to the file! $\endgroup$