• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: sine wave
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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>)

  • Prev by Date: Re: Crash in NSControl's sizeToFit
  • Next by Date: NSDocument "save as" bug
  • Previous by thread: [Moderator] Re: sine wave
  • Next by thread: NSDocument "save as" bug
  • Index(es):
    • Date
    • Thread