what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

jew.c

jew.c
Posted Sep 20, 2000
Authored by Morbid

jew.c v1.1 is a linux based bluebox program. Features DTMF dialing, CCITT 5 dialing, some c5 toys, ACTS tone generation, and more. Dosn't studder like ADM's linux tone generation program.

tags | telephony
systems | linux
SHA-256 | d885f5f4273ab67eb9826c4627253a1fe638e6aa037101077d2dfa0c2e663614

jew.c

Change Mirror Download
/*
Jewbox v1.1 by Morbie
(jevhova1@dobbs.com)

Note: This is still work in progress.

Current features:
DTMF Dialing
CCITT5 Dialing
Some C5 toys.
ACTS Tone Generation. (Gay, but oh well.)
Pause (Yay!)

!!Fixed Things!!

I made a stupid mistake and made 'hash'(pound) the actual sign, and the
same with star. Ewpz. They were replaced with H and P.

I don't know what I should do in the future with this, aside from giving it
a WAY better interface. If you play with the source any and make any
signifigant improvements, please send them to me.

Have fun, and stay out of trouble.

Compile by using the following commands with cc.

cc -O jew.c
cc -O jew.o -o jewbox -lm


--Morbie

---------------------
Shtuff:
1 through 0 - DTMF
q through p - CCITT5 (Note: Each letter represents the number above it on the
keyboard. So q = 1, w = 2, and so on.)
h == Whatever trunk you program. The default is 2400 x 2600 for 150 MS.
j == 2400 for 150 MS. This is standard.
(And now a gay addition, but someone was bound to do it anyways.)
m == A 'Nickel' in ACTS. 5 'Nickels' in a row makes a perfect Quarter. It's
what I use on my watch, and it works perfect. (Get them at Rat shack.)
n == A pause feature. Length editable via flag.
a == KP1
s == KP2
d == ST
f == Code 11
g == Code 12
---------------------

(gtk interface for creating dial scripts coming soon.)

*/


#include <math.h>
#include <stdio.h>
#include <fcntl.h>
#include <malloc.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/soundcard.h>

#define DEBUG(x)

void gen_costab(void);
void dial_digit(int c);
void silent(int msec);
void dial(int f1, int f2, int msec);

char *output = "/dev/dsp";
int bits = 16;
int speed = 8000;
int tone_time = 100;
int silent_time = 50;
int sleep_time = 500;
int volume = 100;
int format
= AFMT_U8;
int use_audio = 1;
int ton1 = 2400;
int ton2 = 2600;
int duh = 150;
int pauset = 50;

#define BSIZE 4096

unsigned char *buf;
int bufsize = BSIZE;
int bufidx;

#define MINTABSIZE 2
#define MAXTABSIZE 65536
signed short *costab;
int tabsize = 256;

int dialed = 0;

int right = 0;
int left = 0;

int fd;

void
Usage(void) {
printf("\n\nJewbox v1.1 by Morbie (jehova1@dobbs.com)\n\n");

fprintf(stderr, "usage: jewbox [Options] string ...\n\n"



" Valid options with their default values are:\n"



" Duration options:\n"



" --tone-time 100\n"



" --silent-time 50\n"



" --sleep-time 500\n"



" Audio output options:\n"



" --output-dev /dev/dsp\n"



" --use-audio 1\n"



" --bufsize 4096\n"



" --speed 8000\n"



" --bits 16\n"



" Audio generation options:\n"



" --table-size 256\n"



" --volume 100\n"



" --left 0\n"



" --right 0\n"



" Extra Bluebox commands:\n"
" --break-1 2400\n"
" --break-2 2600\n"
" --duration 150\n"
" --pause 50\n"

);





exit(1);
}

void
initialize_audiodev(void) {

int speed_local = speed;

int channels = 1;

int diff;


if(!use_audio)


return;


if(right || left)


channels = 2;


if(ioctl(fd, SNDCTL_DSP_CHANNELS, &channels)) {


perror("ioctl(SNDCTL_DSP_CHANNELS)");


exit(1);

}


if(ioctl(fd, SNDCTL_DSP_SETFMT, &format)) {


perror("ioctl(SNDCTL_DSP_SPEED)");


exit(1);

}


if(ioctl(fd, SNDCTL_DSP_SPEED, &speed_local)) {


perror("ioctl(SNDCTL_DSP_SPEED)");


exit(1);

}


diff = speed_local - speed;

if(diff < 0)


diff = -diff;

if(diff > 500) {


fprintf(stderr,


"Your sound card does not support the requested speed\n");


exit(1);

}

if(diff != 0) {


fprintf(stderr,


"Setting speed to %d\n", speed_local);

}

speed = speed_local;
}

void
getvalue(int *arg, int *index, int argc,

char **argv, int min, int max) {


if (*index >= argc-1)


Usage();


*arg = atoi(argv[1+*index]);


if(*arg < min || *arg > max) {


fprintf(stderr, "Value for %s should be in the range %d..%d\n",




argv[*index]+2, min, max);


exit(1);

}

++*index;
}

int
main(int argc, char **argv)
{

char *cp;

int i;


for(i = 1; i < argc; i++) {


if(argv[i][0] != '-' ||


argv[i][1] != '-')



break;



if(!strcmp(argv[i], "--table-size")) {



getvalue(&tabsize, &i, argc, argv,




MINTABSIZE, MAXTABSIZE);


}


else if(!strcmp(argv[i], "--tone-time")) {



getvalue(&tone_time, &i, argc, argv,




10, 10000);


}


else if(!strcmp(argv[i], "--sleep-time")) {



getvalue(&sleep_time, &i, argc, argv,




10, 10000);


}


else if(!strcmp(argv[i], "--silent-time")) {



getvalue(&silent_time, &i, argc, argv,



10, 10000);


}


else if(!strcmp(argv[i], "--sleep-time")) {



getvalue(&sleep_time, &i, argc, argv,




10, 100000);


}


else if(!strcmp(argv[i], "--volume")) {



getvalue(&volume, &i, argc, argv,




0, 100);


}


else if(!strcmp(argv[i], "--speed")) {



getvalue(&speed, &i, argc, argv,




5000, 48000);


}


else if(!strcmp(argv[i], "--bits")) {



getvalue(&bits, &i, argc, argv,




8, 16);


}


else if(!strcmp(argv[i], "--bufsize")) {



getvalue(&bufsize, &i, argc, argv,




4, 65536);


}


else if(!strcmp(argv[i], "--use-audio")) {



getvalue(&use_audio, &i, argc, argv,




0, 1);


}


else if(!strcmp(argv[i], "--right")) {



getvalue(&right, &i, argc, argv,




0, 1);


}


else if(!strcmp(argv[i], "--left")) {



getvalue(&left, &i, argc, argv,




0, 1);


}


else if(!strcmp(argv[i], "--output-dev")) {



i++;



if(i >= argc)




Usage();



output = argv[i];


}
else if(!strcmp(argv[i], "--break-1")) {
getvalue(&ton1, &i, argc, argv,
1, 7000);
}
else if(!strcmp(argv[i], "--break-2")) {
getvalue(&ton2, &i, argc, argv,
1, 7000);


}
else if(!strcmp(argv[i], "--duration")) {
getvalue(&duh, &i, argc, argv,
1, 400);
}
else if(!strcmp(argv[i], "--pause")) {
getvalue(&pauset, &i, argc, argv,
1, 500);
}


else



Usage();

}


if(i >= argc)


Usage();


if(!strcmp(output, "-"))


fd = 1;

/* stdout */

else {


fd = open(output, O_CREAT|O_TRUNC|O_WRONLY, 0644);


if(fd < 0) {



perror(output);



exit(1);


}

}


switch(bits) {


case 8:



format = AFMT_U8;



break;


case 16:



format = AFMT_S16_LE;



break;


default:



fprintf(stderr, "Value for bits should be 8 or 16\n");



exit(1);

}


initialize_audiodev();


gen_costab();

buf = malloc(bufsize);

if(buf == NULL) {


perror("malloc buf");


exit(1);

}


bufidx = 0;

for(; i < argc; i++) {


cp = argv[i];


if(dialed)



silent(sleep_time);


while(cp && *cp) {



if(*cp == ',' || *cp == ' ')




silent(sleep_time);



else {




if(dialed)





silent(silent_time);




dial_digit(*cp);



}



cp++;


}

}

if(bufidx > 0) {
#if 0


while(bufidx < bufsize) {



if(format == AFMT_U8) {




buf[bufidx++] = 128;



}



else {
/* AFMT_S16_LE */




buf[bufidx++] = 0;




buf[bufidx++] = 0;



}


}
#endif


write(fd, buf, bufidx);

}

exit(0);
}

void
dial_digit(int c) {

DEBUG(fprintf(stderr, "dial_digit %#c\n", c));

switch(c) {

case '0':


dial(941, 1336, tone_time);


break;

case '1':


dial(697, 1209, tone_time);


break;

case '2':


dial(697, 1336, tone_time);


break;

case '3':


dial(697, 1477, tone_time);


break;

case '4':


dial(770, 1209, tone_time);


break;

case '5':


dial(770, 1336, tone_time);


break;

case '6':


dial(770, 1477, tone_time);


break;

case '7':


dial(852, 1209, tone_time);


break;

case '8':


dial(852, 1336, tone_time);


break;

case '9':


dial(852, 1477, tone_time);


break;

case 'S':


dial(941, 1209, tone_time);


break;

case 'H':


dial(941, 1477, tone_time);


break;

case 'A':


dial(697, 1633, tone_time);


break;

case 'B':


dial(770, 1633, tone_time);


break;

case 'C':


dial(852, 1633, tone_time);


break;

case 'D':


dial(941, 1633, tone_time);


break;
case 'q':
dial(700, 900, tone_time);
break;
case 'w':
dial(700, 1100, tone_time);
break;
case 'e':
dial(900, 1100, tone_time);
break;
case 'r':
dial(700, 1300, tone_time);
break;
case 't':
dial(900, 1300, tone_time);
break;
case 'y':
dial(1100, 1300, tone_time);
break;
case 'u':
dial(700, 1500, tone_time);
break;
case 'i':
dial(900, 1500, tone_time);
break;
case 'o':
dial(1100, 1500, tone_time);
break;
case 'p':
dial(1300, 1500, tone_time);
break;
case 'a':
dial(1100, 1700, tone_time);
break;
case 's':
dial(1300, 1700, tone_time);
break;
case 'd':
dial(1500, 1700, tone_time);
break;
case 'f':
dial(1700, 1700, tone_time);
break;
case 'g':
dial(900, 1700, tone_time);
break;
case 'h':
dial(ton1, ton2, duh);
break;
case 'j':
dial(2400, 2400, 150);
break;
case 'm':
dial(2200, 1700, 33);
break;
case 'n':
silent(pauset);
return;
}

}

void
silent(int msec) {

int time;

if(msec <= 0)


return;


DEBUG(fprintf(stderr, "silent %d\n", msec));


time = (msec * speed) / 1000;

while(--time >= 0) {


if(format == AFMT_U8) {



buf[bufidx++] = 128;


}


else {
/* AFMT_S16_LE */



buf[bufidx++] = 0;



buf[bufidx++] = 0;


}


if(right || left) {



if(format == AFMT_U8) {




buf[bufidx++] = 128;



}



else {
/* AFMT_S16_LE */




buf[bufidx++] = 0;




buf[bufidx++] = 0;



}


}


if(bufidx >= bufsize) {



write(fd, buf, bufsize);



bufidx = 0;


}

}

dialed = 0;
}

void
dial(int f1, int f2, int msec) {

int i1, i2, d1, d2, e1, e2, g1, g2;

int time;

int val;


if(msec <= 0)


return;


DEBUG(fprintf(stderr, "dial %d %d %d\n", f1, f2, msec));


f1 *= tabsize;

f2 *= tabsize;

d1 = f1 / speed;

d2 = f2 / speed;

g1 = f1 - d1 * speed;

g2 = f2 - d2 * speed;

e1 = speed/2;

e2 = speed/2;


i1 = i2 = 0;


time = (msec * speed) / 1000;

while(--time >= 0) {


val = costab[i1] + costab[i2];



if(left || !right) {



if(format == AFMT_U8) {




buf[bufidx++] = 128 + (val >> 8);



}



else {
/* AFMT_S16_LE */




buf[bufidx++] = val & 0xff;




buf[bufidx++] = (val >> 8) & 0xff;



}


}


if (left != right) {



if(format == AFMT_U8) {




buf[bufidx++] = 128;



}



else {
/* AFMT_S16_LE */




buf[bufidx++] = 0;




buf[bufidx++] = 0;



}


}


if(right) {



if(format == AFMT_U8) {




buf[bufidx++] = 128 + (val >> 8);



}



else {
/* AFMT_S16_LE */




buf[bufidx++] = val & 0xff;




buf[bufidx++] = (val >> 8) & 0xff;



}


}



i1 += d1;


if (e1 < 0) {



e1 += speed;



i1 += 1;


}


if (i1 >= tabsize)



i1 -= tabsize;



i2 += d2;


if (e2 < 0) {



e2 += speed;



i2 += 1;


}


if (i2 >= tabsize)



i2 -= tabsize;



if(bufidx >= bufsize) {



write(fd, buf, bufsize);



bufidx = 0;


}


e1 -= g1;


e2 -= g2;

}

dialed = 1;
}

void
gen_costab(void) {

int i;

double d;


costab = (signed short *)malloc(tabsize * sizeof(signed short));

if(costab == NULL) {


perror("malloc costab");


exit(1);

}


for (i = 0; i < tabsize; i++) {


d = 2*M_PI*i;


costab[i] = (int)((volume/100.)*16383.*cos(d/tabsize));

}
}

Login or Register to add favorites

File Archive:

March 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Mar 1st
    16 Files
  • 2
    Mar 2nd
    0 Files
  • 3
    Mar 3rd
    0 Files
  • 4
    Mar 4th
    32 Files
  • 5
    Mar 5th
    28 Files
  • 6
    Mar 6th
    42 Files
  • 7
    Mar 7th
    17 Files
  • 8
    Mar 8th
    13 Files
  • 9
    Mar 9th
    0 Files
  • 10
    Mar 10th
    0 Files
  • 11
    Mar 11th
    15 Files
  • 12
    Mar 12th
    19 Files
  • 13
    Mar 13th
    21 Files
  • 14
    Mar 14th
    38 Files
  • 15
    Mar 15th
    15 Files
  • 16
    Mar 16th
    0 Files
  • 17
    Mar 17th
    0 Files
  • 18
    Mar 18th
    10 Files
  • 19
    Mar 19th
    32 Files
  • 20
    Mar 20th
    46 Files
  • 21
    Mar 21st
    16 Files
  • 22
    Mar 22nd
    13 Files
  • 23
    Mar 23rd
    0 Files
  • 24
    Mar 24th
    0 Files
  • 25
    Mar 25th
    12 Files
  • 26
    Mar 26th
    31 Files
  • 27
    Mar 27th
    19 Files
  • 28
    Mar 28th
    42 Files
  • 29
    Mar 29th
    0 Files
  • 30
    Mar 30th
    0 Files
  • 31
    Mar 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close