iphonegeneratordtmf

Generate DTMF Tones


I am wondering if anyone has come across a way to generate tones in the iPhone SDK. I am trying to generate DTMF tones, and can't seem to find anything substantial out there. I want to be able to specify how long to play the tone for as well (i.e. to simulate holding the button down as opposed to just pressing it briefly..

I found an open source app called iPhreak. It supposedly generates DTMF tones to fool payphones (I Assure you this is not my intention - my company deals with telephone based Intercom systems). The only problem with that application is that there are files missing from the open source project. Perhaps someone else has gotten this project to work in the past?

If anyone has any idea on where I would look for something like this, I would be very appreciative with my votes :)


Solution

  • should be easy enough to generate yourself. given that the hardware can playback a pcm buffer (16bit samples) at 44.1 khz (which it surely can with some library function or the other), you're only left with calculating the waveform:

     const int PLAYBACKFREQ = 44100;
     const float PI2 = 3.14159265359f * 2;
    
     void generateDTMF(short *buffer, int length, float freq1, float freq2)
     {
          int i;
          short *dest = buffer;
          for(i=0; i<length; i++)
          {
               *(dest++) = (sin(i*(PI2*(PLAYBACKFREQ/freq1))) + sin(i (PI2*(PLAYBACKFREQ/freq2)))) * 16383;
          }
     }
    

    the 16383 is done since I'm using additive synthesis (just adding the sinewaves together). Therefore the max result is -2.0 - 2.0 So after multiplying by 16383 I get more or less the max 16 bit result: -32768 - +32767

    EDIT: the 2 frequenties are the frequenties from the wikipedia article the other person who answered linked to. Two unique frequencies make a DTMF sound