views:

36

answers:

2

I have the following code to send as audio RTP packet some DTMF digits:

 int count=0
 for(int j = 0; j < samples; j++) 
  {
      waves = 0;
      // dtmf tone 1

      waves += sin( ((PI * 2.0f / 8000) * 697.0f) * count );
      waves += sin( ((PI * 2.0f / 8000) * 1209.0f) * count);
      waves *= 8191.0f;   //amplitude   
      ++count;
      values[j] = (SInt16)waves;  
  }

I'm generating the digits programatically. This code basically adds up 2 sinewaves and applies scaling. This will produce 16bit PCM data which can then be encoded. The sample rate is 8K to transmit as RTP packet.

Have I done this correctly?

A: 

There are more efficient ways to program it, and it really shouldn't be hard-coded (volume, frequencies, length, etc), but that's roughly correct. I'd use M_PI instead of PI.

Note: count == j, waves = 0 is useless (change first += to =), etc.

jesup
A: 

Hi

Slightly off-topic, but if you are sending the data out as RTP, then have you checked whether the remote peer supports RFC2833? If so, you can pass the DTMF digits using RFC2833-compliant RTP packets and avoid lots of work a both ends of the link.

Mike

MikeBrom