I've got a really annoying problem that i cant figure out and i've been trying for a *long* time...
I'm making a modular synth, and i've got a sin generator module, and an add module which just adds two streams together.
i'm trying to get some FM going, and i've got at the moment:
sinegenerator 'modulator' with freq 1hz, and amplitude 1 - so values are -1 up to 1.
'modulator's output is added to a constant value of 800...
this total is then used for the frequency of the sine generator 'carrier', with amplitude 2000. this gives should give a sinewave with a frequency that goes between 799 and 801... this is then played through the speakers.
now, im sure in theory this is correct (?), and i think its starts off ok, but i'm getting results that sound like 'modulator's amplitude is getting larger over time. eg the difference in frequencies around 800mhz is getting larger over time. I've checked and checked and checked and the output from modulator is definately correct. I think it must be to do with my sine wave generator, but it generates tones perfectly... it's just when it comes to this FM example its all going wrong...
I'm looking at the index variable specifically but i cant figure it out. I think maybe its happening as the index gets high, but that doesnt make much sense to me. however, if i reset index to 0 at some point it just goes back to the beginning. So.. i guess what i'm asking is, is this code rubbish, and if so how should it be done?
Code: Select all
// pFreqBuffer holds the frequency value
// pAmpBuffer holds the amplitude
for(UINT i=0; i<numSamples; i++)
{
UINT value = CAudioStream::GetSampleRate();
double t = float(index++)/CAudioStream::GetSampleRate();
val = 6.2831385307179586f*pFreqBuffer[i]*t;
m_pBuffer[i] = pAmpBuffer[i]*sin(val);
}
I've uploaded a sound here:
http://rapidshare.de/files/7973881/sound.wav.html
if you listen you can see its definately not constant...
Thanks alot.