rendered paste bodyIndex: include/asterisk/tdd.h
===================================================================
--- include/asterisk/tdd.h (revision 88972)
+++ include/asterisk/tdd.h (arbetskopia)
@@ -29,14 +29,12 @@
struct tdd_state;
typedef struct tdd_state TDDSTATE;
-/*! CallerID Initialization */
-/*!
+/*! CallerID Initialization
* Initializes the TDD system. Mostly stuff for inverse FFT
*/
void tdd_init(void);
-/*! Generates a CallerID FSK stream in ulaw format suitable for transmission. */
-/*!
+/*! Generates a CallerID FSK stream in ulaw format suitable for transmission.
* \param tdd tdd structure
* \param buf Buffer to use. This needs to be large enough to accomodate all the generated samples.
* \param string This is the string to send.
@@ -45,15 +43,13 @@
*/
int tdd_generate(struct tdd_state *tdd, unsigned char *buf, const char *string);
-/*! Create a TDD state machine */
-/*!
+/*! Create a TDD state machine
* This function returns a malloc'd instance of the tdd_state data structure.
* Returns a pointer to a malloc'd tdd_state structure, or NULL on error.
*/
struct tdd_state *tdd_new(void);
-/*! Read samples into the state machine, and return character (if any). */
-/*!
+/*! Read samples into the state machine, and return character (if any).
* \param tdd Which state machine to act upon
* \param ubuf containing your samples
* \param samples number of samples contained within the buffer.
@@ -64,19 +60,20 @@
*/
int tdd_feed(struct tdd_state *tdd, unsigned char *ubuf, int samples);
-/*! Free a TDD state machine */
-/*!
+/*! Free a TDD state machine
* \param tdd This is the tdd_state state machine to free
* This function frees tdd_state tdd.
*/
void tdd_free(struct tdd_state *tdd);
-/*! Generate Echo Canceller diable tone (2100HZ) */
-/*!
+/*! Generate Echo Canceller disable tone (2100HZ)
* \param outbuf This is the buffer to receive the tone data
* \param len This is the length (in samples) of the tone data to generate
* Returns 0 if no error, and -1 if error.
*/
int ast_tdd_gen_ecdisa(unsigned char *outbuf, int len);
+
+int tdd_gen_holdtone(unsigned char* outbuf);
+
#endif /* _ASTERISK_TDD_H */
Index: main/tdd.c
===================================================================
--- main/tdd.c (revision 88972)
+++ main/tdd.c (arbetskopia)
@@ -53,6 +53,7 @@
int pos;
int modo;
int mode;
+ int charnum;
};
static float dr[4], di[4];
@@ -67,10 +68,10 @@
'\n','D','R','J','N','F','C','K',
'T','Z','L','W','H','Y','P','Q',
'O','B','G','^','M','X','V','^' };
- static char figs[32] = { '<','3','\n','-',' ',',','8','7',
- '\n','$','4','\'',',','·',':','(',
- '5','+',')','2','·','6','0','1',
- '9','7','·','^','.','/','=','^' };
+ static char figs[32] = { '<','3','\n','-',' ','\'','8','7',
+ '\n','$','4','\'',',','!',':','(',
+ '5','\"',')','2','=','6','0','1',
+ '9','?','+','^','.','/',';','^' };
int d = 0; /* return 0 if not decodeable */
switch (data) {
case 0x1f:
@@ -101,9 +102,8 @@
struct tdd_state *tdd_new(void)
{
struct tdd_state *tdd;
- tdd = malloc(sizeof(struct tdd_state));
+ tdd = calloc(1, sizeof(*tdd));
if (tdd) {
- memset(tdd, 0, sizeof(struct tdd_state));
tdd->fskd.spb = 176; /* 45.5 baud */
tdd->fskd.hdlc = 0; /* Async */
tdd->fskd.nbit = 5; /* 5 bits */
@@ -117,7 +117,8 @@
tdd->fskd.x0 = 0.0;
tdd->fskd.state = 0;
tdd->pos = 0;
- tdd->mode = 2;
+ tdd->mode = 0;
+ tdd->charnum = 0;
} else
ast_log(LOG_WARNING, "Out of memory\n");
return tdd;
@@ -143,13 +144,12 @@
int b = 'X';
int res;
int c,x;
- short *buf = malloc(2 * len + tdd->oldlen);
+ short *buf = calloc(1, 2 * len + tdd->oldlen);
short *obuf = buf;
if (!buf) {
ast_log(LOG_WARNING, "Out of memory\n");
return -1;
}
- memset(buf, 0, 2 * len + tdd->oldlen);
memcpy(buf, tdd->oldstuff, tdd->oldlen);
mylen += tdd->oldlen/2;
for (x = 0; x < len; x++)
@@ -159,13 +159,13 @@
olen = mylen;
res = fsk_serie(&tdd->fskd, buf, &mylen, &b);
if (mylen < 0) {
- ast_log(LOG_ERROR, "fsk_serie made mylen < 0 (%d) (olen was %d)\n", mylen, olen);
+ ast_log(LOG_ERROR, "fsk_serial made mylen < 0 (%d) (olen was %d)\n", mylen, olen);
free(obuf);
return -1;
}
buf += (olen - mylen);
if (res < 0) {
- ast_log(LOG_NOTICE, "fsk_serie failed\n");
+ ast_log(LOG_NOTICE, "fsk_serial failed\n");
free(obuf);
return -1;
}
@@ -174,7 +174,8 @@
if (b > 0x7f)
continue;
c = tdd_decode_baudot(tdd,b);
- if ((c < 1) || (c > 126)) continue; /* if not valid */
+ if ((c < 1) || (c > 126))
+ continue; /* if not valid */
break;
}
}
@@ -185,7 +186,8 @@
tdd->oldlen = 0;
free(obuf);
if (res) {
- tdd->mode = 2; /* put it in mode where it
+ tdd->mode = 2;
+/* put it in mode where it
reliably puts teleprinter in correct shift mode */
return(c);
}
@@ -256,19 +258,41 @@
PUT_TDD_STOP; /* Stop bit */ \
} while(0);
+int tdd_gen_holdtone(unsigned char *buf)
+{
+ int bytes=0;
+ float scont=0.0,cr=1.0,ci=0.0;
+ while(scont < tddsb*10.0) {
+ PUT_AUDIO_SAMPLE(tdd_getcarrier(&cr, &ci, 1));
+ scont += 1.0;
+ }
+ return bytes;
+}
+
int tdd_generate(struct tdd_state *tdd, unsigned char *buf, const char *str)
{
int bytes=0;
int i,x;
char c;
+ /*! Baudot letters */
static unsigned char lstr[31] = "\000E\nA SIU\rDRJNFCKTZLWHYPQOBG\000MXV";
- static unsigned char fstr[31] = "\0003\n- \00787\r$4',!:(5\")2\0006019?&\000./;";
+ /*! Baudot figures */
+ static unsigned char fstr[31] = "\0003\n- \00787\r$4',!:(5\")2\0006019?+\000./;";
/* Initial carriers (real/imaginary) */
float cr = 1.0;
float ci = 0.0;
float scont = 0.0;
for(x = 0; str[x]; x++) {
+ /* Do synch for each 72th character */
+ if ( (tdd->charnum++) % 72 == 0) {
+ ast_log(LOG_DEBUG,"Sending synch!\n");
+ if(tdd->mode)
+ PUT_TDD(27); /* FIGS */
+ else
+ PUT_TDD(31); /* LTRS */
+ }
+
c = toupper(str[x]);
#if 0
printf("%c",c); fflush(stdout);