[Asterisk-Dev] Patch: So tone generator can do modulated tones

Stephen Davies steve at daviesfam.org
Tue Jun 17 13:33:36 MST 2003


Hi Mark, others,

In some countries (.au and .za I know about), dialtone and ringback
are made with one tone modulated with another.  Like 400Hz modulated
with 33Hz.

Here's a patch to allow these tones to be made.  I used the obvious
tone1*tone2 to specify it in Playtones or indications.conf.

I also adjusted indications.conf.sample for .au and added .za.

Hope its helpful,

Steve
-------------- next part --------------
Index: indications.c
===================================================================
RCS file: /usr/cvsroot/asterisk/indications.c,v
retrieving revision 1.3
diff -u -r1.3 indications.c
--- indications.c	17 Jun 2003 18:59:58 -0000	1.3
+++ indications.c	17 Jun 2003 20:46:31 -0000
@@ -14,6 +14,8 @@
  * Each element has two frequencies, which are mixed together and a
  * duration. For silence both frequencies can be set to 0.
  * The playtones can be given as a comma seperated string.
+ *
+ * Mixing can be by summing, or modulation (multiplication)
  */
 
 #include <stdio.h>
@@ -34,6 +36,7 @@
 	int freq1;
 	int freq2;
 	int duration;
+	int modulate;
 };
 
 struct playtones_def {
@@ -106,7 +109,15 @@
 
 	pi = &ps->items[ps->npos];
 	for (x=0;x<len/2;x++) {
-		ps->data[x] = ps->vol * (
+		if (pi->modulate)
+			/* Modulate 1st tone with 2nd, to 90% modulation depth */
+			ps->data[x] = ps->vol * 2 * (
+				sin((pi->freq1 * 2.0 * M_PI / 8000.0) * (ps->pos + x)) *
+				(0.9 * fabs(sin((pi->freq2 * 2.0 * M_PI / 8000.0) * (ps->pos + x))) + 0.1)
+			);
+		else
+			/* Add 2 tones together */
+			ps->data[x] = ps->vol * (
 				sin((pi->freq1 * 2.0 * M_PI / 8000.0) * (ps->pos + x)) +
 				sin((pi->freq2 * 2.0 * M_PI / 8000.0) * (ps->pos + x))
 			);
@@ -160,7 +171,7 @@
 		separator = ",";
 	s = strsep(&stringp,separator);
         while(s && *s) {
-		int freq1, freq2, time;
+		int freq1, freq2, time, modulate=0;
 
 		if (s[0]=='!')
 			s++;
@@ -171,6 +182,13 @@
 		} else if (sscanf(s, "%d+%d", &freq1, &freq2) == 2) {
 			/* f1+f2 format */
 			time = 0;
+		} else if (sscanf(s, "%d*%d/%d", &freq1, &freq2, &time) == 3) {
+			/* f1*f2/time format */
+			modulate = 1;
+		} else if (sscanf(s, "%d*%d", &freq1, &freq2) == 2) {
+			/* f1*f2 format */
+			time = 0;
+			modulate = 1;
 		} else if (sscanf(s, "%d/%d", &freq1, &time) == 2) {
 			/* f1/time format */
 			freq2 = 0;
@@ -189,6 +207,7 @@
 		d.items[d.nitems].freq1    = freq1;
 		d.items[d.nitems].freq2    = freq2;
 		d.items[d.nitems].duration = time;
+		d.items[d.nitems].modulate = modulate;
 		d.nitems++;
 
 		s = strsep(&stringp,separator);
Index: configs/indications.conf.sample
===================================================================
RCS file: /usr/cvsroot/asterisk/configs/indications.conf.sample,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 indications.conf.sample
--- configs/indications.conf.sample	12 Feb 2003 13:59:15 -0000	1.1.1.1
+++ configs/indications.conf.sample	17 Jun 2003 20:46:31 -0000
@@ -61,14 +61,13 @@
 [au]
 description = Australia
 ringcadance = 400,200,400,2000
-; XXX Dialtone: Should be modulated, not added XXX
-dial = 425+25
+dial = 425*25
 busy = 400/375,0/375
-ring = 400+17/400,0/200,400+17/400,0/2000
+ring = 400*17/400,0/200,400*17/400,0/2000
 ; XXX Congestion: Should reduce by 10 db every other cadence XXX
 congestion = 400/375,0/375
 callwaiting = 425/100,0/100,525/100,0/4700
-dialrecall = !425+25/100!0/100,!425+25/100,!0/100,!425+25/100,!0/100,425+25
+dialrecall = !425*25/100!0/100,!425*25/100,!0/100,!425*25/100,!0/100,425*25
 record = 1400/425,0/14525
 info = 400/2500,0/500
 
@@ -118,3 +117,30 @@
 ; XXX Not sure about the RECORDTONE
 record = 1400/500,0/10000
 info = 950/330,1400/330,1800/330
+
+; Tone definition source for za was
+; http://www.cisco.com/univercd/cc/td/doc/product/tel_pswt/vco_prod/safr_sup/saf02.htm
+; (definitions for other countries can also be found there)
+; Note, though, that South Africa uses two switch types in their network - Alcatel
+; switches - mainly in the Western Cape, and Siemens elsewhere.
+; The former use 383+417 in dial, ringback etc.  The latter use 400*33
+; I've provided both, uncomment the ones you prefer
+
+[za]
+description = South Africa
+ringcadance = 400,200,400,2000
+; dial/ring/callwaiting for the Siemens switches:
+dial = 400*33
+ring = 400*33/400,0/200,400*33/400,0/2000
+callwaiting = 400*33/250,0/250,400*33/250,0/250,400*33/250,0/250,400*33/250,0/250 
+; dial/ring/callwaiting for the Alcatel switches:
+; dial = 383+417
+; ring = 383+417/400,0/200,383+417/400,0/2000
+; callwaiting = 383+417/250,0/250,383+417/250,0/250,383+417/250,0/250,383+417/250,0/250 
+congestion = 400/250,0/250
+busy = 400/500,0/500
+dialrecall = 350+440
+; XXX Not sure about the RECORDTONE
+record = 1400/500,0/10000
+info = 950/330,1400/330,1800/330,0/330
+


More information about the asterisk-dev mailing list