home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <dos.h>
- #include <stdlib.h>
-
- /* timing constants determined by linear regression */
- #define K1 758
- #define K2 45
-
- void nap(long delay)
- {
- while(--delay > 0) ;
- }
-
- void twotone(long pt1, long pt2, long duration)
- {
- char bits;
- register int delay = 0;
- long t1=pt1, t2=pt2;
-
- bits = inportb(0x61);
- bits &= 0xfc;
- disable();
- while(duration > 0) {
- outportb(0x61, bits);
- bits ^= 2;
- if(t1 < t2) {
- delay += t1;
- t2 -= delay;
- t1 = pt1;
- } else {
- delay += t2;
- t1 -= delay;
- t2 = pt2;
- }
- duration -= delay;
- delay -= K1;
- while(delay > 0) delay -= K2;
- }
-
- enable();
- }
-
- struct dtmf {
- int lo;
- int hi;
- } tones[] = {
- 941, 1336,
- 697, 1209,
- 697, 1336,
- 697, 1477,
- 770, 1209,
- 770, 1336,
- 770, 1477,
- 852, 1209,
- 852, 1336,
- 852, 1477
- };
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- long pt1 = 4294;
- long pt2 = 16000;
- long duration = 2500000;
- char *number = argv[1];
- long one = 10000000;
-
- if(argc==4) { /* for testing, period1 period2 duration */
- pt1 = atol(argv[1]);
- pt2 = atol(argv[2]);
- duration = atol(argv[3]);
- twotone(pt1, pt2, duration);
- exit(0);
- }
-
- if(argc!=2) {
- fprintf(stderr, "usage: tt number\n");
- exit(1);
- }
- while(*number) {
- int digit = *number - '0';
- if(digit >= 0 && digit <= 9) {
- int lo = tones[digit].lo;
- int hi = tones[digit].hi;
- int f1 = hi + lo;
- int f2 = hi - lo;
- pt1 = (one + f1/2) / f1;
- pt2 = (one + f2/2) / f2;
- printf("%ld %ld %ld\n", pt1, pt2, duration);
- twotone(pt1, pt2, duration);
- }
- nap(2000);
- number++;
- }
- }