Reputation: 5177
I need my iPhone generate constant sound of specified frequency and amplitude for a short while. Then I can hear the sound by a headphone. What should I do?
Upvotes: 2
Views: 1637
Reputation: 70673
Use the Audio Queue or RemoteIO Audio Unit API. Fill the callback buffers with samples of the appropriate frequency sine wave:
buffer[i] = myVolume * sinf( twoPiFrequencyOverSampleRate * i );
Save the phase between callbacks to avoid clicks.
Upvotes: 1
Reputation: 4254
The easiest approach is to just play back a sample that is already at the required frequency. If you use OpenAL then you can adjust the pitch from half to double. So, say you have a beep sample that you know is at 440Hz then OpenAL allows you to reproduce beeps from 220Hz - 880Hz. For the continuous tone I would use another sample, again at a known frequency but suitable for looping and play it back looped (again using OpenAL).
Any synthesiser should be capable of reproducing basic tones at known frequencies. If you have access to Sound Forge you can use Tools/Synthesis/Simple to generate simple tones.
here is a link that will help you
http://atastypixel.com/blog/using-remoteio-audio-unit/
Upvotes: 1