Re: Simplest way to generate audio tones?
Re: Simplest way to generate audio tones?
- Subject: Re: Simplest way to generate audio tones?
- From: Jens Alfke <email@hidden>
- Date: Sun, 29 May 2016 10:10:22 -0700
> On May 28, 2016, at 8:24 PM, Graham Cox <email@hidden> wrote:
>
> I’m looking for general pointers to the simplest/quickest way to generate an audio tone (sine wave) of a given frequency and duration. Most of the audio APIs seem concerned with playing samples rather than generating tones, so it’s not immediately obvious where to look.
It’s easy to generate a sample buffer of a sine wave. Allocate an array of uint16_t, and fill in each sample by scaling such that -1 ⟶ 0 and 1 ⟶ 255. Then tell whatever API you’re using that it’s a 1-channel 16-bit PCM buffer. Choose whatever sample rate you want to make it come out the right frequency; it’ll do the interpolation for you.
—Jens
_______________________________________________
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