Medialooks Knowledge Base Support Center

Contact Us

DTMF tones support

Detecting DTMF signals and custom tones 

MPlatform SDK

To detect a tone you should add the MFSignalingDTMF class as a plugin into your source object, configure it and handle the events that will rise every time it detects a signal:

// Create DTMF class object  
MFSignalingDTMFClass m_objDTMF = new MFSignalingDTMFClass(); 

// Add it as plugin to another object where you plan to detect tones 
// For example MFile, MLive or any other 
m_objFile.PluginsAdd(m_objDTMF, 0); 

// Subscribe to it's events  
m_objDTMF.OnEventSafe += new IMEventsEvent_OnEventSafeEventHandler(m_objDTMF_OnEventSafe); 

// Set channel number you want monitor  
m_objDTMF.PropsSet("channel_detect", "0"); 

// Set High and Low ton frequences if you want to detect custom tones  
// You can specify just one of them to detect a custom single tone.  
// Skip this step if you want to detect DTMF tones only and don't want to check for custom frequency tones.  
m_objDTMF.PropsSet("low_hz", "25"); 
m_objDTMF.PropsSet("high_hz", "35"); 

//...  

// Handle the DTMF detection events  
private void m_objDTMF_OnEventSafe(string bsChannelID, string bsEventName, string bsEventParam, object pEventObject) 
{ 
    // Where:  
    // bsChannelID - audio channel number where the tone was detected;  
    // bsEventName - tone type: "DTMF" for standard DTFM signals or "custom" for custom tone.  
    // bsEventParam - DTMF char (for example '1', '2', 'A', '#' etc.) or detected custom tone frequency.  

    //... react for detected tone  
    richTextBoxDTMFLog.Text += " " + bsChannelID + ",\t" + bsEventName + ",\t" + bsEventParam + "\r"; 
} 

MFormats SDK

To detect a tone you should create the MFSignalingDTMF class object, configure it, subscribe to its events and process frames with it just like any other plugin.  The events will rise every time it detects a signal:

// Create MDTMF class object   
MFSignalingDTMFClass m_objDTMF = new MFSignalingDTMFClass(); 
 // Subscribe to it's events   
m_objDTMF.OnEventSafe += new MFORMATSLib.IMEventsEvent_OnEventSafeEventHandler(m_objDTMF_OnEventSafe); 
 // Set the channel number you want to monitor   

 // Set High and Low ton frequences if you want to detect custom tones   
// You can specify just one of them to detect a custom single tone.   
// Skip this step if you want to detect DTMF tones only and don't want to check for custom frequency tones.   
m_objDTMF.PropsSet("low_hz", "25"); 
m_objDTMF.PropsSet("high_hz", "35"); 
  // ...   
// Some threading stuff to start picking frames from the source.   
// ...   
 // Process frames by MDTMF class object  
m_objDTMF.ProcessFrame(pFrame, out pFrameOut, out nFramesRes, ""); 
 // Handle the DTMF detection events   
private void m_objDTMF_OnEventSafe(string bsChannelID, string bsEventName, string bsEventParam, object pEventObject) 
{ 
    // Where:   
    // bsChannelID - audio channel number where the tone was detected;   
    // bsEventName - tone type: "DTMF" for standard DTFM signals or "custom" for custom tone.   
    // bsEventParam - DTMF char (for example '1', '2', 'A', '#' etc.) or detected custom tone frequency.   
     //... react for detected tone   
    richTextBoxDTMFLog.Text += " " + bsChannelID + ",\t" + bsEventName + ",\t" + bsEventParam + "\r"; 
} 

Generating DTMF signals 

MPlatform SDK

To generate DTMF signals you should use the DTMFToneAdd method of MFSignalingDTMF class. 

Using the second parameter you can specify the DTMF creation way: replace original sound with your tone (1), or mix the tone with original sound (0).

// Create DTMF class object 
MFSignalingDTMFClass m_objDTMF = new MFSignalingDTMFClass(); 

// Add it as plugin to another object where you plan to detect tones 
// For example MFile, MLive or any other 
m_objFile.PluginsAdd(m_objDTMF, 0); 

// Set channel number you want to add DTMF signal to 
m_objDTMF.PropsSet("channel_generate", "0"); 

// Generate the "5" tone 
//The tone will replace the original sound of the channel 
m_objDTMF.DTMFToneAdd("5", 1); 

// Generate the "#12B" tones one by one with small silence spacers 
// The tones will be mixed with the original sound of the channel 
m_objDTMF.DTMFToneAdd("#12B", 0);  

MFormats SDK

To generate DTMF signals you should process each frame with MFSignalingDTMF class object and use the DTMFToneAdd method to add the tone to the channel. 

Using the second parameter you can specify the DTMF creation way: replace original sound with your tone (1), or mix the tone with original sound (0).

// Create DTMF class object  
MFSignalingDTMFClass m_objDTMF = new MFSignalingDTMFClass(); 

// Set channel number you want to add DTMF signal to  
m_objDTMF.PropsSet("channel_generate", "0"); 

// Generate the "5" tone  
//The tone will replace the original sound of the channel  
m_objDTMF.DTMFToneAdd("5", 1); 

// Generate the "#12B" tones one by one with small silence spacers  
// The tones will be mixed with the original sound of the channel  
m_objDTMF.DTMFToneAdd("#12B", 0); 

// ...    
// Some threading stuff to start picking frames from the source.    
// ...    

// Process source frames by MDTMF class object.   
m_objDTMF.ProcessFrame(pFrame, out pFrameOut, out nFramesRes, "");