Reputation: 48406
I've seen countless infos on how to play a sound file, but how can I generate a specific audio tone (or several) at given Hertz in cocoa touch?
Upvotes: 1
Views: 1216
Reputation: 7337
Matt Gallagher's example will help you:
"An iOS tone generator (an introduction to AudioUnits)"
Upvotes: 0
Reputation: 34253
The low-level approach is using CoreAudio with the kAudioUnitSubType_RemoteIO
and kAudioUnitSubType_AU3DMixerEmbedded
audio units.
The SDK comes with some built-in CoreAudio units - you can't implement your own yet.
A good API to connect those units is AUGraph.
As you can't implement your own audio units that render a sinewave, you will have to use render-callbacks and attach them to the input bus of your mixer unit.
Fill out a AURenderCallbackStruct
and connect it to your Graph with AUGraphSetNodeInputCallback
To generate the actual sinewave you could use something like this as render callback (the code is actually for the Mac but the render callback should work on the phone)
Upvotes: 1
Reputation: 86196
One simple way: You've found sample code for playing audio files. Your audio file can be a sine wave. You can change the playback rate.
There are other ways if you go to the work of managing your own buffers.
Upvotes: 2