On Jan 31, 2010, at 6:22 PM, Chunk 1978 wrote:
> i'm searching for a general algorithm to produce a cartesian sine wave
> that outputs numbers, which i suppose would be based on maximum
> distance (range) from Y while using a timer.
//Make the transition from buffer to buffer seamless, and avoid
//transient jumps when the loop ends.
//Number of samples in one cycle = sample rate/frequency.
//Keep a count of the samples and store it in a static var so that the next
buffer can pick
//up where the previous one left off.
void fillToneBuffer(short * theBuffer, int sizeInBytes, float frequency, float
sampleRate )
{
const float maxVolume = 32767;
const int samplesPerCycle = sampleRate/frequency;
static int samplecounter = 0;
int jj = 0;
while (jj < (sizeInBytes/sizeof(short)))
{
theBuffer[jj] = maxVolume * (sin((2*M_PI*samplecounter)/samplesPerCycle));
++jj;
++samplecounter;
if (samplecounter >= samplesPerCycle)
samplecounter = 0;
}
}
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]