Re: sine wave
Re: sine wave
- Subject: Re: sine wave
- From: David Rowland <email@hidden>
- Date: Sun, 31 Jan 2010 21:57:18 -0800
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@hidden)
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:
This email sent to email@hidden
References: | |
| >sine wave (From: Chunk 1978 <email@hidden>) |