mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* i4l dtmf errors
@ 2002-12-12 10:45 Roy Sigurd Karlsbakk
  2002-12-12 12:10 ` Matti Aarnio
  2002-12-14 20:51 ` Wolfgang Fritz
  0 siblings, 2 replies; 8+ messages in thread
From: Roy Sigurd Karlsbakk @ 2002-12-12 10:45 UTC (permalink / raw)
  To: Kernel mailing list

hi

it seems isdn4linux detects DTMF tones from normal speach. This is rather 
annoying when using i4l for voice with Asterisk.org. This is tested on all 
recent kernels

see thread "[MGCP] Asterisk/D-Link phones generates ugly DTMF tones!!!" at 
http://www.marko.net/asterisk/archives/ for more info.

roy
-- 
Roy Sigurd Karlsbakk, Datavaktmester
ProntoTV AS - http://www.pronto.tv/
Tel: +47 9801 3356

Computers are like air conditioners.
They stop working when you open Windows.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: i4l dtmf errors
  2002-12-12 10:45 i4l dtmf errors Roy Sigurd Karlsbakk
@ 2002-12-12 12:10 ` Matti Aarnio
  2002-12-14 14:54   ` Roy Sigurd Karlsbakk
  2002-12-14 20:51 ` Wolfgang Fritz
  1 sibling, 1 reply; 8+ messages in thread
From: Matti Aarnio @ 2002-12-12 12:10 UTC (permalink / raw)
  To: Roy Sigurd Karlsbakk, Kernel mailing list

  This is possibly more of   linux-isdn@vger.kernel.org  list thing,
  than linux-kernel per se.

On Thu, Dec 12, 2002 at 11:45:26AM +0100, Roy Sigurd Karlsbakk wrote:
> hi
> 
> it seems isdn4linux detects DTMF tones from normal speach. This is rather 
> annoying when using i4l for voice with Asterisk.org. This is tested on all 
> recent kernels
> 
> see thread "[MGCP] Asterisk/D-Link phones generates ugly DTMF tones!!!" at 
> http://www.marko.net/asterisk/archives/ for more info.

  Quick reading of  drivers/isdn/isdn_audio.c(*)  shows that it does use
  fixed-point Görtzel (Goertzel in english) algorithm for detecting
  tones, but it does _not_ do comparison of received overall signal
  power vs. detected DTMF tone powers.

  When there is signal power outside the DTMF channels, signal should
  not be detected.  Also, DTMF tone powers should be roughly equal,
  and exactly two tones should be present for valid detection.

      http://www.numerix-dsp.com/goertzel.html

  Adding those power tests should be fairly trivial, but I leave it
  to Somebody Else...

(*) kernel version I looked upon was 2.4.16-0.11custom -- some RH kernel

> roy
> -- 
> Roy Sigurd Karlsbakk, Datavaktmester
> ProntoTV AS - http://www.pronto.tv/
> Tel: +47 9801 3356

/Matti Aarnio

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: i4l dtmf errors
  2002-12-12 12:10 ` Matti Aarnio
@ 2002-12-14 14:54   ` Roy Sigurd Karlsbakk
  0 siblings, 0 replies; 8+ messages in thread
From: Roy Sigurd Karlsbakk @ 2002-12-14 14:54 UTC (permalink / raw)
  To: Matti Aarnio, Kernel mailing list

>   Quick reading of  drivers/isdn/isdn_audio.c(*)  shows that it does use
>   fixed-point Görtzel (Goertzel in english) algorithm for detecting
>   tones, but it does _not_ do comparison of received overall signal
>   power vs. detected DTMF tone powers.
>
>   When there is signal power outside the DTMF channels, signal should
>   not be detected.  Also, DTMF tone powers should be roughly equal,
>   and exactly two tones should be present for valid detection.
>
>       http://www.numerix-dsp.com/goertzel.html
>
>   Adding those power tests should be fairly trivial, but I leave it
>   to Somebody Else...

Is there a 'somebody else' (perhaps the isdn maintainer?) that have time to 
look at this?

thanks

roy
-- 
Roy Sigurd Karlsbakk, Datavaktmester
ProntoTV AS - http://www.pronto.tv/
Tel: +47 9801 3356

Computers are like air conditioners.
They stop working when you open Windows.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: i4l dtmf errors
  2002-12-12 10:45 i4l dtmf errors Roy Sigurd Karlsbakk
  2002-12-12 12:10 ` Matti Aarnio
@ 2002-12-14 20:51 ` Wolfgang Fritz
  2002-12-14 23:14   ` Kai Germaschewski
  2002-12-16 11:07   ` i4l dtmf errors Roy Sigurd Karlsbakk
  1 sibling, 2 replies; 8+ messages in thread
From: Wolfgang Fritz @ 2002-12-14 20:51 UTC (permalink / raw)
  To: linux-kernel

Roy Sigurd Karlsbakk wrote:

> hi
> 
> it seems isdn4linux detects DTMF tones from normal speach. This is
> rather annoying when using i4l for voice with Asterisk.org. This is
> tested on all recent kernels

The DTMF detection is broken since kernel 2.0.x. I have a patch for a 
2.2 kernel which may manually be applied 2.4 kernels with some manual 
work. It fixes an overflow problem in the goertzel algorithm (which 
does the basic tone detection) and changes the algorithm to detect the 
DTMF pairs. If interested, I can try to recover that patch.

Wolfgang
  
> 
> see thread "[MGCP] Asterisk/D-Link phones generates ugly DTMF
> tones!!!" at http://www.marko.net/asterisk/archives/ for more info.
> 
> roy



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: i4l dtmf errors
  2002-12-14 20:51 ` Wolfgang Fritz
@ 2002-12-14 23:14   ` Kai Germaschewski
  2002-12-16 17:44     ` [PATCH] (Was: i4l dtmf errors) Wolfgang Fritz
  2002-12-16 11:07   ` i4l dtmf errors Roy Sigurd Karlsbakk
  1 sibling, 1 reply; 8+ messages in thread
From: Kai Germaschewski @ 2002-12-14 23:14 UTC (permalink / raw)
  To: Wolfgang Fritz; +Cc: linux-kernel

On Sat, 14 Dec 2002, Wolfgang Fritz wrote:

> > it seems isdn4linux detects DTMF tones from normal speach. This is
> > rather annoying when using i4l for voice with Asterisk.org. This is
> > tested on all recent kernels
> 
> The DTMF detection is broken since kernel 2.0.x. I have a patch for a 
> 2.2 kernel which may manually be applied 2.4 kernels with some manual 
> work. It fixes an overflow problem in the goertzel algorithm (which 
> does the basic tone detection) and changes the algorithm to detect the 
> DTMF pairs. If interested, I can try to recover that patch.

If you dig out that patch and submit it (to me), I'm pretty sure there's 
a good chance of it going into the official kernel. ISTR there was talk 
about that earlier, but nothing ever happened.

--Kai



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: i4l dtmf errors
  2002-12-14 20:51 ` Wolfgang Fritz
  2002-12-14 23:14   ` Kai Germaschewski
@ 2002-12-16 11:07   ` Roy Sigurd Karlsbakk
  1 sibling, 0 replies; 8+ messages in thread
From: Roy Sigurd Karlsbakk @ 2002-12-16 11:07 UTC (permalink / raw)
  To: Wolfgang Fritz, linux-kernel

> The DTMF detection is broken since kernel 2.0.x. I have a patch for a
> 2.2 kernel which may manually be applied 2.4 kernels with some manual
> work. It fixes an overflow problem in the goertzel algorithm (which
> does the basic tone detection) and changes the algorithm to detect the
> DTMF pairs. If interested, I can try to recover that patch.

I'm very interested, as the alternative is to rewrite Asterisk (dot org) to 
use it's own. Today, I get beeps whenever I speak on the phone - espessialy 
with my girlfriend ;-P

roy
-- 
Roy Sigurd Karlsbakk, Datavaktmester
ProntoTV AS - http://www.pronto.tv/
Tel: +47 9801 3356

Computers are like air conditioners.
They stop working when you open Windows.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] (Was: i4l dtmf errors)
  2002-12-14 23:14   ` Kai Germaschewski
@ 2002-12-16 17:44     ` Wolfgang Fritz
  2003-01-06  9:57       ` Roy Sigurd Karlsbakk
  0 siblings, 1 reply; 8+ messages in thread
From: Wolfgang Fritz @ 2002-12-16 17:44 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1167 bytes --]

<veröffentlicht & per Mail versendet>

Kai Germaschewski wrote:

> On Sat, 14 Dec 2002, Wolfgang Fritz wrote:
> 
>> > it seems isdn4linux detects DTMF tones from normal speach. This is
>> > rather annoying when using i4l for voice with Asterisk.org. This is
>> > tested on all recent kernels
>> 
>> The DTMF detection is broken since kernel 2.0.x. I have a patch for a
>> 2.2 kernel which may manually be applied 2.4 kernels with some manual
>> work. It fixes an overflow problem in the goertzel algorithm (which
>> does the basic tone detection) and changes the algorithm to detect
>> the DTMF pairs. If interested, I can try to recover that patch.
> 
> If you dig out that patch and submit it (to me), I'm pretty sure
> there's a good chance of it going into the official kernel. ISTR there
> was talk about that earlier, but nothing ever happened.
> 
> --Kai
> 

Here is the patch against 2.4.20.

Wolfgang
> 
> -
> To unsubscribe from this list: send the line "unsubscribe
> linux-kernel" in the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: dtmf.patch --]
[-- Type: text/x-diff; name="dtmf.patch", Size: 4835 bytes --]

diff -urN -X dontdiff linux-2.4.20/drivers/isdn/isdn_audio.c linux-2.4.20.mod/drivers/isdn/isdn_audio.c
--- linux-2.4.20/drivers/isdn/isdn_audio.c	Mon Feb 25 20:37:58 2002
+++ linux-2.4.20.mod/drivers/isdn/isdn_audio.c	Mon Dec 16 17:45:39 2002
@@ -169,39 +169,19 @@
 	0x8a, 0x8a, 0x6a, 0x6a, 0xea, 0xea, 0x2a, 0x2a
 };
 
-#define NCOEFF           16     /* number of frequencies to be analyzed       */
-#define DTMF_TRESH    25000     /* above this is dtmf                         */
+#define NCOEFF            8     /* number of frequencies to be analyzed       */
+#define DTMF_TRESH     4000     /* above this is dtmf                         */
 #define SILENCE_TRESH   200     /* below this is silence                      */
-#define H2_TRESH      20000     /* 2nd harmonic                               */
 #define AMP_BITS          9     /* bits per sample, reduced to avoid overflow */
 #define LOGRP             0
 #define HIGRP             1
 
-typedef struct {
-	int grp;                /* low/high group     */
-	int k;                  /* k                  */
-	int k2;                 /* k fuer 2. harmonic */
-} dtmf_t;
-
 /* For DTMF recognition:
  * 2 * cos(2 * PI * k / N) precalculated for all k
  */
 static int cos2pik[NCOEFF] =
 {
-	55812, 29528, 53603, 24032, 51193, 14443, 48590, 6517,
-	38113, -21204, 33057, -32186, 25889, -45081, 18332, -55279
-};
-
-static dtmf_t dtmf_tones[8] =
-{
-	{LOGRP, 0, 1},          /*  697 Hz */
-	{LOGRP, 2, 3},          /*  770 Hz */
-	{LOGRP, 4, 5},          /*  852 Hz */
-	{LOGRP, 6, 7},          /*  941 Hz */
-	{HIGRP, 8, 9},          /* 1209 Hz */
-	{HIGRP, 10, 11},        /* 1336 Hz */
-	{HIGRP, 12, 13},        /* 1477 Hz */
-	{HIGRP, 14, 15}         /* 1633 Hz */
+	55813, 53604, 51193, 48591, 38114, 33057, 25889, 18332
 };
 
 static char dtmf_matrix[4][4] =
@@ -499,6 +479,18 @@
 			sk2 = sk1;
 			sk1 = sk;
 		}
+		/* Avoid overflows */
+		sk >>= 1;
+		sk2 >>= 1;
+		/* compute |X(k)|**2 */
+		/* report overflows. This should not happen. */
+		/* Comment this out if desired */
+		if (sk < -32768 || sk > 32767)
+			printk(KERN_DEBUG
+			       "isdn_audio: dtmf goertzel overflow, sk=%d\n", sk);
+		if (sk2 < -32768 || sk2 > 32767)
+			printk(KERN_DEBUG
+			       "isdn_audio: dtmf goertzel overflow, sk2=%d\n", sk2);
 		result[k] =
 		    ((sk * sk) >> AMP_BITS) -
 		    ((((cos2pik[k] * sk) >> 15) * sk2) >> AMP_BITS) +
@@ -522,28 +514,58 @@
 	int grp[2];
 	char what;
 	char *p;
+	int thresh;
 
 	while ((skb = skb_dequeue(&info->dtmf_queue))) {
 		result = (int *) skb->data;
 		s = info->dtmf_state;
-		grp[LOGRP] = grp[HIGRP] = -2;
+		grp[LOGRP] = grp[HIGRP] = -1;
 		silence = 0;
-		for (i = 0; i < 8; i++) {
-			if ((result[dtmf_tones[i].k] > DTMF_TRESH) &&
-			    (result[dtmf_tones[i].k2] < H2_TRESH))
-				grp[dtmf_tones[i].grp] = (grp[dtmf_tones[i].grp] == -2) ? i : -1;
-			else if ((result[dtmf_tones[i].k] < SILENCE_TRESH) &&
-			      (result[dtmf_tones[i].k2] < SILENCE_TRESH))
+		thresh = 0;
+		for (i = 0; i < NCOEFF; i++) {
+			if (result[i] > DTMF_TRESH) {
+				if (result[i] > thresh)
+					thresh = result[i];
+			}
+			else if (result[i] < SILENCE_TRESH)
 				silence++;
 		}
-		if (silence == 8)
+		if (silence == NCOEFF)
 			what = ' ';
 		else {
-			if ((grp[LOGRP] >= 0) && (grp[HIGRP] >= 0)) {
-				what = dtmf_matrix[grp[LOGRP]][grp[HIGRP] - 4];
-				if (s->last != ' ' && s->last != '.')
-					s->last = what;	/* min. 1 non-DTMF between DTMF */
-			} else
+			if (thresh > 0)	{
+				thresh = thresh >> 4;  /* touchtones must match within 12 dB */
+				for (i = 0; i < NCOEFF; i++) {
+					if (result[i] < thresh)
+						continue;  /* ignore */
+					/* good level found. This is allowed only one time per group */
+					if (i < NCOEFF / 2) {
+						/* lowgroup*/
+						if (grp[LOGRP] >= 0) {
+							// Bad. Another tone found. */
+							grp[LOGRP] = -1;
+							break;
+						}
+						else
+							grp[LOGRP] = i;
+					}
+					else { /* higroup */
+						if (grp[HIGRP] >= 0) { // Bad. Another tone found. */
+							grp[HIGRP] = -1;
+							break;
+						}
+						else
+							grp[HIGRP] = i - NCOEFF/2;
+					}
+				}
+				if ((grp[LOGRP] >= 0) && (grp[HIGRP] >= 0)) {
+					what = dtmf_matrix[grp[LOGRP]][grp[HIGRP]];
+					if (s->last != ' ' && s->last != '.')
+						s->last = what;	/* min. 1 non-DTMF between DTMF */
+				} else
+					what = '.';
+			}
+			else
 				what = '.';
 		}
 		if ((what != s->last) && (what != ' ') && (what != '.')) {
diff -urN -X dontdiff linux-2.4.20/drivers/isdn/isdn_audio.h linux-2.4.20.mod/drivers/isdn/isdn_audio.h
--- linux-2.4.20/drivers/isdn/isdn_audio.h	Fri Dec 21 18:41:54 2001
+++ linux-2.4.20.mod/drivers/isdn/isdn_audio.h	Mon Dec 16 17:42:32 2002
@@ -20,6 +20,7 @@
 
 typedef struct dtmf_state {
 	char last;
+	char llast;
 	int idx;
 	int buf[DTMF_NPOINTS];
 } dtmf_state;

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] (Was: i4l dtmf errors)
  2002-12-16 17:44     ` [PATCH] (Was: i4l dtmf errors) Wolfgang Fritz
@ 2003-01-06  9:57       ` Roy Sigurd Karlsbakk
  0 siblings, 0 replies; 8+ messages in thread
From: Roy Sigurd Karlsbakk @ 2003-01-06  9:57 UTC (permalink / raw)
  To: Wolfgang Fritz, linux-kernel

hi

thanks for the patch, but sorry - it really didn't help anything. still 
meep-meep's all over ...

roy

On Monday 16 December 2002 18:44, Wolfgang Fritz wrote:
> <veröffentlicht & per Mail versendet>
>
> Kai Germaschewski wrote:
> > On Sat, 14 Dec 2002, Wolfgang Fritz wrote:
> >> > it seems isdn4linux detects DTMF tones from normal speach. This is
> >> > rather annoying when using i4l for voice with Asterisk.org. This is
> >> > tested on all recent kernels
> >>
> >> The DTMF detection is broken since kernel 2.0.x. I have a patch for a
> >> 2.2 kernel which may manually be applied 2.4 kernels with some manual
> >> work. It fixes an overflow problem in the goertzel algorithm (which
> >> does the basic tone detection) and changes the algorithm to detect
> >> the DTMF pairs. If interested, I can try to recover that patch.
> >
> > If you dig out that patch and submit it (to me), I'm pretty sure
> > there's a good chance of it going into the official kernel. ISTR there
> > was talk about that earlier, but nothing ever happened.
> >
> > --Kai
>
> Here is the patch against 2.4.20.
>
> Wolfgang
>
> > -
> > To unsubscribe from this list: send the line "unsubscribe
> > linux-kernel" in the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > Please read the FAQ at  http://www.tux.org/lkml/

-- 
Roy Sigurd Karlsbakk, Datavaktmester
ProntoTV AS - http://www.pronto.tv/
Tel: +47 9801 3356

Computers are like air conditioners.
They stop working when you open Windows.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2003-01-06  9:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-12 10:45 i4l dtmf errors Roy Sigurd Karlsbakk
2002-12-12 12:10 ` Matti Aarnio
2002-12-14 14:54   ` Roy Sigurd Karlsbakk
2002-12-14 20:51 ` Wolfgang Fritz
2002-12-14 23:14   ` Kai Germaschewski
2002-12-16 17:44     ` [PATCH] (Was: i4l dtmf errors) Wolfgang Fritz
2003-01-06  9:57       ` Roy Sigurd Karlsbakk
2002-12-16 11:07   ` i4l dtmf errors Roy Sigurd Karlsbakk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®