summaryrefslogtreecommitdiff
path: root/gendigits.c
diff options
context:
space:
mode:
authormarkster <markster@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2001-12-08 20:42:54 +0000
committermarkster <markster@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2001-12-08 20:42:54 +0000
commitb03535c16b2443c521ad4474e5065d3d3496df8a (patch)
tree3011e3a74075c72609393498e63eb4f1fecb91cf /gendigits.c
parent763f2431276955b16dd64ee61ff77337389f4f99 (diff)
Version 0.1.4 from FTP
git-svn-id: http://svn.digium.com/svn/zaptel/trunk@39 5390a7c7-147a-4af0-8ec9-7488f05a26cb
Diffstat (limited to 'gendigits.c')
-rwxr-xr-xgendigits.c83
1 files changed, 33 insertions, 50 deletions
diff --git a/gendigits.c b/gendigits.c
index d1847cb..5613e4c 100755
--- a/gendigits.c
+++ b/gendigits.c
@@ -18,17 +18,17 @@ float f2; /* second freq */
} ZAP_DIAL;
ZAP_DIAL dtmf_dial[] = {
+{ '0',941.0,1336.0 },
{ '1',697.0,1209.0 },
-{ '4',770.0,1209.0 },
-{ '7',852.0,1209.0 },
-{ '*',941.0,1209.0 },
{ '2',697.0,1336.0 },
-{ '5',770.0,1336.0 },
-{ '8',852.0,1336.0 },
-{ '0',941.0,1336.0 },
{ '3',697.0,1477.0 },
+{ '4',770.0,1209.0 },
+{ '5',770.0,1336.0 },
{ '6',770.0,1477.0 },
+{ '7',852.0,1209.0 },
+{ '8',852.0,1336.0 },
{ '9',852.0,1477.0 },
+{ '*',941.0,1209.0 },
{ '#',941.0,1477.0 },
{ 'A',697.0,1633.0 },
{ 'B',770.0,1633.0 },
@@ -38,6 +38,7 @@ ZAP_DIAL dtmf_dial[] = {
} ;
ZAP_DIAL mf_dial[] = {
+{ '0',1300.0,1500.0 },
{ '1',700.0,900.0 },
{ '2',700.0,1100.0 },
{ '3',900.0,1100.0 },
@@ -47,7 +48,6 @@ ZAP_DIAL mf_dial[] = {
{ '7',700.0,1500.0 },
{ '8',900.0,1500.0 },
{ '9',1100.0,1500.0 },
-{ '0',1300.0,1500.0 },
{ '*',1100.0,1700.0 }, /* KP */
{ '#',1500.0,1700.0 }, /* ST */
{ 'A',900.0,1700.0 }, /* ST' */
@@ -56,8 +56,6 @@ ZAP_DIAL mf_dial[] = {
{ 0,0,0 }
} ;
-static float loudness=8192.0;
-
unsigned char
linear2ulaw(sample)
short sample; {
@@ -97,56 +95,37 @@ short sample; {
return(ulawbyte);
}
-static int calc_samples(int freq)
-{
- int x, samples;
- /* Calculate the number of samples at 8000hz sampling
- we need to have this wave form */
- samples = 8000;
- /* Take out common 2's up to six times */
- for (x=0;x<6;x++)
- if (!(freq % 2)) {
- freq /= 2;
- samples /= 2;
- }
- /* Take out common 5's (up to three times */
- for (x=0;x<3;x++)
- if (!(freq % 5)) {
- freq /= 5;
- samples /=5;
- }
- /* No more common factors. */
- return samples;
-}
+#define LEVEL -8
int process(FILE *f, char *label, ZAP_DIAL z[])
{
char c;
- int x, samples, samples1, samples2;
- float val;
+ float gain;
+ int fac1, init_v2_1, init_v3_1,
+ fac2, init_v2_2, init_v3_2;
+
while(z->chr) {
c = z->chr;
if (c == '*')
c = 's';
if (c == '#')
- c = 'p';
- samples1 = calc_samples((int)z->f1);
- samples2 = calc_samples((int)z->f2);
- samples = samples1;
- while(samples % samples2)
- samples += samples1;
- printf("Need %d samples for %s_%c\n", samples, label, c);
- fprintf(f, "static unsigned char %s_%c[%d] = {\n\t", label, c, samples);
- for (x=0;x<samples;x++) {
- val = loudness * sin((z->f1 * 2.0 * M_PI * x)/8000.0);
- val += loudness * sin((z->f2 * 2.0 * M_PI * x)/8000.0);
- fprintf(f, "%3d, ", linear2ulaw((int)val));
- if (!((x+1) % 15))
- fprintf(f, "\n\t");
- }
- if (x % 15)
- fprintf(f, "\n");
- fprintf(f, "};\n\n");
+ c ='p';
+ /* Bring it down 6 dbm */
+ gain = pow(10.0, (LEVEL - 3.14) / 20.0) * 65536.0 / 2.0;
+
+ fac1 = 2.0 * cos(2.0 * M_PI * (z->f1 / 8000.0)) * 32768.0;
+ init_v2_1 = sin(-4.0 * M_PI * (z->f1 / 8000.0)) * gain;
+ init_v3_1 = sin(-2.0 * M_PI * (z->f1 / 8000.0)) * gain;
+
+ fac2 = 2.0 * cos(2.0 * M_PI * (z->f2 / 8000.0)) * 32768.0;
+ init_v2_2 = sin(-4.0 * M_PI * (z->f2 / 8000.0)) * gain;
+ init_v3_2 = sin(-2.0 * M_PI * (z->f2 / 8000.0)) * gain;
+
+ fprintf(f, "\t /* %s_%c */ { %d, %d, %d, %d, %d, %d, DEFAULT_DTMF_LENGTH, &%s_silence }, \n", label, c,
+ fac1, init_v2_1, init_v3_1,
+ fac2, init_v2_2, init_v3_2,
+ label);
+
z++;
}
return 0;
@@ -159,8 +138,12 @@ int main(int argc, char *argv[])
if ((f = fopen("tones.h", "w"))) {
fprintf(f, "/* DTMF and MF tones used by the Tormenta Driver, in static tables.\n"
" Generated automatically from gendigits. Do not edit by hand. */\n");
+ fprintf(f, "static struct zt_tone dtmf_tones[16] = {\n");
process(f, "dtmf", dtmf_dial);
+ fprintf(f, "};\n\n");
+ fprintf(f, "static struct zt_tone mfv1_tones[15] = {\n");
process(f, "mfv1", mf_dial);
+ fprintf(f, "};\n\n");
fprintf(f, "/* END tones.h */\n");
fclose(f);
} else {