MediaSuite.NET Sample code

Generating DTMF Tones

This sample demonstrates the creation and use of the DTMF Tone Generator.

using System;
using System.Collections.Generic;
using System.Text;
using StreamCoders.Wave;
using StreamCoders.Signals;
 
namespace DtmfTones
{
    class Program
    {
        static void Main(string[] args)
        {
            WaveOutput wout = new WaveOutput();
            wout.BitsPerSample = 16;
            wout.Channels = 1;
            wout.SampleRate = 8000;
            wout.Init();
            wout.OpenDevice();
 
            DTMFGenerator tg = new DTMFGenerator();
            tg.SampleFrequency = 8000;
 
            bool res = tg.Init();
 
            uint duration = 200;
 
            Console.WriteLine("Enter 0-9, #, * ");
 
            while (true)
            {
                if (Console.KeyAvailable == false)
                {
                    System.Threading.Thread.Sleep(10);
                    continue;
                }
 
                var ki = Console.ReadKey(false);
                if (ki.Key == ConsoleKey.X || ki.Key == ConsoleKey.Escape)
                    break;
                byte[] buf = tg.Generate((sbyte)char.ToUpper(ki.KeyChar), duration, 11);
 
                if (buf != null)
                {
                    Console.WriteLine("Generated {0} for {1} ({2} bytes)", ki.Key.ToString(), duration, buf.Length);
                    wout.Enqueue(buf);
                }
                else
                    Console.WriteLine("not a dtmf tone");
 
            }
 
        }
    }
}