Generating a rising sine tone with sinf()
Generating a rising sine tone with sinf()
- Subject: Generating a rising sine tone with sinf()
- From: Jim McGowan <email@hidden>
- Date: Fri, 20 Jun 2014 00:42:01 +0800
I’m writing some code to generate a sine tone that begins at a given frequency and the frequency rises linearly to a maximum over a specified time. Seemingly straightforward, my approach was to fill a sample buffer in a loop (I’m using the AudioSampleType on OS X, i.e. Float32):
frequency = minFreq + (frequencyRangeLength * (sampleIndex / lengthInSamples));
sineSweepSamples[sampleIndex] = sinf((2.0 * M_PI * sampleIndex * frequency) / sampleRate)
However, this generates a tone where the frequency increases at a faster rate than it should. When I remove the “2.0 *”, i.e. use pi instead of 2pi, I get the results I want, but I don’t understand why. Checking the formula (with the 2pi) in the Grapher app shows it is correct, and by dumping all the values in each iteration of the loop I see that the frequency is being calculated properly.
Can anyone explain this for me?
Thanks,
Jim
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden