4

I know how to play mp3 files and whatnot in Xcode iOS. But how do I play a certain frequency, like if I just wanted to emit a C# note for 25 seconds; how might I do that? (The synth isn't as important to me as just the pitch of the note.)

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Albert Renshaw
  • 17,282
  • 18
  • 107
  • 195
  • http://stackoverflow.com/questions/1399501/generate-dtmf-tones does this help? (in case i understood you correctly at first i was thinking about creating tones in C#.. ;) ) – thedanielhanke Nov 12 '11 at 18:23
  • 2
    In this context C# is a musical note, not a language. He clearly asked he wants this on iOS. – Miguel Grinberg Nov 12 '11 at 18:28

2 Answers2

1

You need to generate the PCM audio waveform that corresponds to the note you want to play and store that into a sample buffer in memory. Then you send that buffer to the audio hardware.

Here is a tutorial on generating waveforms of several types. The article goes into some details on the many aspects to a note you need to consider, including the frequency, volume, waveform shape, sampling rate, etc. The article comes with Flash source code, I think you should have no problem taking the concepts and adapting them to iOS.

If you also need a library that you can use to play the generated buffers on iOS, then I recommend the open source Finch.

I hope this helps!

Miguel Grinberg
  • 65,299
  • 14
  • 133
  • 152
  • Amazing! Flash is great! Actionscript 2 is what I learned to program on! Great language! Yes I should be able to quite easily, thanks again! That's great! :) – Albert Renshaw Nov 12 '11 at 18:42
0

You can synthesize waveforms of your desired frequency and feed them to the callbacks of either the Audio Queue or the RemoteIO Audio Unit API.

Here is a short tutorial on some of the code needed to create sine wave tones for iOS in C.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153