From f928dbbced084622838fa6c8772833a96c66d960 Mon Sep 17 00:00:00 2001 From: jim Date: Sun, 15 Feb 2004 02:23:25 +0000 Subject: Added support for modulation (not just two tone addition) in tonezones git-svn-id: http://svn.digium.com/svn/zaptel/trunk@313 5390a7c7-147a-4af0-8ec9-7488f05a26cb --- tonezone.c | 15 +++++++++++++++ zaptel.c | 2 ++ zaptel.conf.sample | 1 + zaptel.h | 15 +++++++++++++-- zonedata.c | 15 +++++++++++++-- 5 files changed, 44 insertions(+), 4 deletions(-) diff --git a/tonezone.c b/tonezone.c index f70f9f4..c0aa66d 100755 --- a/tonezone.c +++ b/tonezone.c @@ -70,6 +70,7 @@ static int build_tone(char *data, int size, struct tone_zone_sound *t, int *coun int firstnobang = -1; int freq1, freq2, time; int used = 0; + int modulate = 0; float gain; dup = strdup(t->data); s = strtok(dup, ","); @@ -87,10 +88,22 @@ static int build_tone(char *data, int size, struct tone_zone_sound *t, int *coun /* f1+f2/time format */ #if 0 printf("f1+f2/time format: %d, %d, %d\n", freq1, freq2, time); +#endif + } else if (sscanf(s, "%d*%d/%d", &freq1, &freq2, &time) == 3) { + /* f1*f2/time format */ + modulate = 1; +#if 0 + printf("f1+f2/time format: %d, %d, %d\n", freq1, freq2, time); #endif } else if (sscanf(s, "%d+%d", &freq1, &freq2) == 2) { #if 0 printf("f1+f2 format: %d, %d\n", freq1, freq2); +#endif + time = 0; + } else if (sscanf(s, "%d*%d", &freq1, &freq2) == 2) { + modulate = 1; +#if 0 + printf("f1+f2 format: %d, %d\n", freq1, freq2); #endif time = 0; } else if (sscanf(s, "%d/%d", &freq1, &time) == 2) { @@ -129,6 +142,8 @@ static int build_tone(char *data, int size, struct tone_zone_sound *t, int *coun td->init_v2_2 = sin(-4.0 * M_PI * (freq2 / 8000.0)) * gain; td->init_v3_2 = sin(-2.0 * M_PI * (freq2 / 8000.0)) * gain; + td->modulate = modulate; + data += (sizeof(struct zt_tone_def)); used += (sizeof(struct zt_tone_def)); size -= (sizeof(struct zt_tone_def)); diff --git a/zaptel.c b/zaptel.c index 937cb69..1f2bf9a 100755 --- a/zaptel.c +++ b/zaptel.c @@ -2335,6 +2335,7 @@ ioctl_load_zone(unsigned long data) t->fac2 = td.fac2; t->init_v2_2 = td.init_v2_2; t->init_v3_2 = td.init_v3_2; + t->modulate = td.modulate; t->next = NULL; /* XXX Unnecessary XXX */ if (!z->tones[td.tone]) z->tones[td.tone] = t; @@ -2358,6 +2359,7 @@ void zt_init_tone_state(struct zt_tone_state *ts, struct zt_tone *zt) ts->v1_2 = 0; ts->v2_2 = zt->init_v2_2; ts->v3_2 = zt->init_v3_2; + ts->modulate = zt->modulate; } struct zt_tone *zt_dtmf_tone(char digit, int mf) diff --git a/zaptel.conf.sample b/zaptel.conf.sample index 9b5140b..69af46e 100755 --- a/zaptel.conf.sample +++ b/zaptel.conf.sample @@ -123,6 +123,7 @@ # is a two letter country code. # loadzone = us +#loadzone = us-old #loadzone=it #loadzone=fr #loadzone=de diff --git a/zaptel.h b/zaptel.h index a45b561..aa42374 100755 --- a/zaptel.h +++ b/zaptel.h @@ -641,7 +641,7 @@ struct zt_tone_def { /* Structure for zone programming */ int fac2; int init_v2_2; int init_v3_2; - + int modulate; }; @@ -842,6 +842,7 @@ struct zt_tone_state { int v1_2; int v2_2; int v3_2; + int modulate; }; #ifdef CONFIG_ZAPATA_NET @@ -1322,12 +1323,16 @@ struct zt_tone { int tonesamples; /* How long to play this tone before going to the next (in samples) */ struct zt_tone *next; /* Next tone in this sequence */ + + int modulate; }; static inline short zt_tone_nextsample(struct zt_tone_state *ts, struct zt_tone *zt) { /* follow the curves, return the sum */ + int p; + ts->v1_1 = ts->v2_1; ts->v2_1 = ts->v3_1; ts->v3_1 = (zt->fac1 * ts->v2_1 >> 15) - ts->v1_1; @@ -1337,7 +1342,13 @@ static inline short zt_tone_nextsample(struct zt_tone_state *ts, struct zt_tone ts->v3_2 = (zt->fac2 * ts->v2_2 >> 15) - ts->v1_2; /* Return top 16 bits */ - return ts->v3_1 + ts->v3_2; + if (!ts->modulate) return ts->v3_1 + ts->v3_2; + /* we are modulating */ + p = ts->v3_2 - 32768; + if (p < 0) p = -p; + p = ((p * 9) / 10) + 1; + return (ts->v3_1 * p) >> 15; + } static inline short zt_txtone_nextsample(struct zt_chan *ss) diff --git a/zonedata.c b/zonedata.c index 274dc60..e7404e2 100755 --- a/zonedata.c +++ b/zonedata.c @@ -40,8 +40,7 @@ struct tone_zone builtin_zones[] = }, { 1, "au", "Australia", { 400, 200, 400, 2000 }, { - /* XXX Dialtone: Should be modulated, not added XXX */ - { ZT_TONE_DIALTONE, "425+25" }, + { ZT_TONE_DIALTONE, "425*25" }, { ZT_TONE_BUSY, "400/375,0/375" }, { ZT_TONE_RINGTONE, "400+17/400,0/200,400+17/400,0/2000" }, /* XXX Congestion: Should reduce by 10 db every other cadence XXX */ @@ -183,6 +182,18 @@ struct tone_zone builtin_zones[] = { ZT_TONE_INFO, "!950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,0" }, { ZT_TONE_STUTTER, "470/400,425/400" } }, }, + { 12, "us-old", "United States Circa 1950/ North America", { 2000, 4000 }, + { + { ZT_TONE_DIALTONE, "600*120" }, + { ZT_TONE_BUSY, "500*100/500,0/500" }, + { ZT_TONE_RINGTONE, "420*40/2000,0/4000" }, + { ZT_TONE_CONGESTION, "500*100/250,0/250" }, + { ZT_TONE_CALLWAIT, "440/300,0/10000" }, + { ZT_TONE_DIALRECALL, "!600*120/100,!0/100,!600*120/100,!0/100,!600*120/100,!0/100,600*120" }, + { ZT_TONE_RECORDTONE, "1400/500,0/15000" }, + { ZT_TONE_INFO, "!950/330,!1400/330,!1800/330,0" }, + { ZT_TONE_STUTTER, "!600*120/100,!0/100,!600*120/100,!0/100,!600*120/100,!0/100,!600*120/100,!0/100,!600*120/100,!0/100,!600*120/100,!0/100,600*120" } }, + }, { -1 } }; -- cgit v1.2.3