Go to the source code of this file.
Defines | |
#define | TDD_BYTES_PER_CHAR 2700 |
Typedefs | |
typedef tdd_state | TDDSTATE |
Functions | |
int | ast_tdd_gen_ecdisa (unsigned char *outbuf, int len) |
int | tdd_feed (struct tdd_state *tdd, unsigned char *ubuf, int samples) |
void | tdd_free (struct tdd_state *tdd) |
int | tdd_gen_holdtone (unsigned char *outbuf) |
int | tdd_generate (struct tdd_state *tdd, unsigned char *buf, const char *string) |
void | tdd_init (void) |
tdd_state * | tdd_new (void) |
Definition in file tdd.h.
#define TDD_BYTES_PER_CHAR 2700 |
int ast_tdd_gen_ecdisa | ( | unsigned char * | outbuf, | |
int | len | |||
) |
Generate Echo Canceller disable tone (2100HZ)
outbuf | This is the buffer to receive the tone data | |
len | This is the length (in samples) of the tone data to generate Returns 0 if no error, and -1 if error. |
Definition at line 143 of file tdd.c.
References ecdisa, and tdd_state::pos.
Referenced by dahdi_setoption().
00144 { 00145 int pos = 0; 00146 int cnt; 00147 while (len) { 00148 cnt = len > sizeof(ecdisa) ? sizeof(ecdisa) : len; 00149 memcpy(outbuf + pos, ecdisa, cnt); 00150 pos += cnt; 00151 len -= cnt; 00152 } 00153 return 0; 00154 }
int tdd_feed | ( | struct tdd_state * | tdd, | |
unsigned char * | ubuf, | |||
int | samples | |||
) |
Read samples into the state machine, and return character (if any).
tdd | Which state machine to act upon | |
ubuf | containing your samples | |
samples | number of samples contained within the buffer. |
Definition at line 156 of file tdd.c.
References ast_log(), AST_MULAW, calloc, free, fsk_serial(), tdd_state::fskd, LOG_ERROR, LOG_NOTICE, LOG_WARNING, tdd_state::mode, tdd_state::oldlen, tdd_state::oldstuff, and tdd_decode_baudot().
Referenced by dahdi_read().
00157 { 00158 int mylen = len; 00159 int olen; 00160 int b = 'X'; 00161 int res; 00162 int c,x; 00163 short *buf = calloc(1, 2 * len + tdd->oldlen); 00164 short *obuf = buf; 00165 if (!buf) { 00166 ast_log(LOG_WARNING, "Out of memory\n"); 00167 return -1; 00168 } 00169 memcpy(buf, tdd->oldstuff, tdd->oldlen); 00170 mylen += tdd->oldlen / 2; 00171 for (x = 0; x < len; x++) 00172 buf[x + tdd->oldlen / 2] = AST_MULAW(ubuf[x]); 00173 c = res = 0; 00174 while (mylen >= 1320) { /* has to have enough to work on */ 00175 olen = mylen; 00176 res = fsk_serial(&tdd->fskd, buf, &mylen, &b); 00177 if (mylen < 0) { 00178 ast_log(LOG_ERROR, "fsk_serial made mylen < 0 (%d) (olen was %d)\n", mylen, olen); 00179 free(obuf); 00180 return -1; 00181 } 00182 buf += (olen - mylen); 00183 if (res < 0) { 00184 ast_log(LOG_NOTICE, "fsk_serial failed\n"); 00185 free(obuf); 00186 return -1; 00187 } 00188 if (res == 1) { 00189 /* Ignore invalid bytes */ 00190 if (b > 0x7f) 00191 continue; 00192 c = tdd_decode_baudot(tdd, b); 00193 if ((c < 1) || (c > 126)) 00194 continue; /* if not valid */ 00195 break; 00196 } 00197 } 00198 if (mylen) { 00199 memcpy(tdd->oldstuff, buf, mylen * 2); 00200 tdd->oldlen = mylen * 2; 00201 } else 00202 tdd->oldlen = 0; 00203 free(obuf); 00204 if (res) { 00205 tdd->mode = 2; 00206 /* put it in mode where it 00207 reliably puts teleprinter in correct shift mode */ 00208 return(c); 00209 } 00210 return 0; 00211 }
void tdd_free | ( | struct tdd_state * | tdd | ) |
int tdd_gen_holdtone | ( | unsigned char * | buf | ) |
Generate TDD hold tone
buf | Result buffer |
Definition at line 280 of file tdd.c.
References PUT_AUDIO_SAMPLE, and tdd_getcarrier().
00281 { 00282 int bytes = 0; 00283 float scont = 0.0, cr = 1.0, ci=0.0; 00284 while (scont < tddsb * 10.0) { 00285 PUT_AUDIO_SAMPLE(tdd_getcarrier(&cr, &ci, 1)); 00286 scont += 1.0; 00287 } 00288 return bytes; 00289 }
int tdd_generate | ( | struct tdd_state * | tdd, | |
unsigned char * | buf, | |||
const char * | string | |||
) |
Generates a CallerID FSK stream in ulaw format suitable for transmission.
tdd | tdd structure | |
buf | Buffer to use. This needs to be large enough to accomodate all the generated samples. | |
string | This is the string to send. This function creates a stream of TDD data in ulaw format. It returns the size (in bytes) of the data (if it returns a size of 0, there is probably an error) |
Baudot letters
Baudot figures
Definition at line 291 of file tdd.c.
References tdd_state::charnum, tdd_state::mode, and PUT_TDD.
Referenced by dahdi_sendtext().
00292 { 00293 int bytes = 0; 00294 int i,x; 00295 char c; 00296 /*! Baudot letters */ 00297 static unsigned char lstr[31] = "\000E\nA SIU\rDRJNFCKTZLWHYPQOBG\000MXV"; 00298 /*! Baudot figures */ 00299 static unsigned char fstr[31] = "\0003\n- \00787\r$4',!:(5\")2\0006019?+\000./;"; 00300 /* Initial carriers (real/imaginary) */ 00301 float cr = 1.0; 00302 float ci = 0.0; 00303 float scont = 0.0; 00304 00305 for(x = 0; str[x]; x++) { 00306 /* Do synch for each 72th character */ 00307 if ( (tdd->charnum++) % 72 == 0) 00308 PUT_TDD(tdd->mode ? 27 /* FIGS */ : 31 /* LTRS */); 00309 00310 c = toupper(str[x]); 00311 #if 0 00312 printf("%c",c); fflush(stdout); 00313 #endif 00314 if (c == 0) { /* send null */ 00315 PUT_TDD(0); 00316 continue; 00317 } 00318 if (c == '\r') { /* send c/r */ 00319 PUT_TDD(8); 00320 continue; 00321 } 00322 if (c == '\n') { /* send c/r and l/f */ 00323 PUT_TDD(8); 00324 PUT_TDD(2); 00325 continue; 00326 } 00327 if (c == ' ') { /* send space */ 00328 PUT_TDD(4); 00329 continue; 00330 } 00331 for (i = 0; i < 31; i++) { 00332 if (lstr[i] == c) 00333 break; 00334 } 00335 if (i < 31) { /* if we found it */ 00336 if (tdd->mode) { /* if in figs mode, change it */ 00337 PUT_TDD(31); /* Send LTRS */ 00338 tdd->mode = 0; 00339 } 00340 PUT_TDD(i); 00341 continue; 00342 } 00343 for (i = 0; i < 31; i++) { 00344 if (fstr[i] == c) 00345 break; 00346 } 00347 if (i < 31) { /* if we found it */ 00348 if (tdd->mode != 1) { /* if in ltrs mode, change it */ 00349 PUT_TDD(27); /* send FIGS */ 00350 tdd->mode = 1; 00351 } 00352 PUT_TDD(i); /* send byte */ 00353 continue; 00354 } 00355 } 00356 return bytes; 00357 }
void tdd_init | ( | void | ) |
CallerID Initialization Initializes the TDD system. Mostly stuff for inverse FFT
Definition at line 89 of file tdd.c.
References cos, M_PI, TDD_MARK, and TDD_SPACE.
Referenced by main().
00090 { 00091 /* Initialize stuff for inverse FFT */ 00092 dr[0] = cos(TDD_SPACE * 2.0 * M_PI / 8000.0); 00093 di[0] = sin(TDD_SPACE * 2.0 * M_PI / 8000.0); 00094 dr[1] = cos(TDD_MARK * 2.0 * M_PI / 8000.0); 00095 di[1] = sin(TDD_MARK * 2.0 * M_PI / 8000.0); 00096 }
struct tdd_state* tdd_new | ( | void | ) |
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.
Definition at line 98 of file tdd.c.
References ast_log(), calloc, fskmodem_init(), and LOG_WARNING.
Referenced by dahdi_setoption().
00099 { 00100 struct tdd_state *tdd; 00101 tdd = calloc(1, sizeof(*tdd)); 00102 if (tdd) { 00103 #ifdef INTEGER_CALLERID 00104 tdd->fskd.ispb = 176; /* 45.5 baud */ 00105 /* Set up for 45.5 / 8000 freq *32 to allow ints */ 00106 tdd->fskd.pllispb = (int)((8000 * 32 * 2) / 90); 00107 tdd->fskd.pllids = tdd->fskd.pllispb / 32; 00108 tdd->fskd.pllispb2 = tdd->fskd.pllispb / 2; 00109 tdd->fskd.hdlc = 0; /* Async */ 00110 tdd->fskd.nbit = 5; /* 5 bits */ 00111 tdd->fskd.instop = 1; /* integer rep of 1.5 stop bits */ 00112 tdd->fskd.parity = 0; /* No parity */ 00113 tdd->fskd.bw=0; /* Filter 75 Hz */ 00114 tdd->fskd.f_mark_idx = 0; /* 1400 Hz */ 00115 tdd->fskd.f_space_idx = 1; /* 1800 Hz */ 00116 tdd->fskd.xi0 = 0; 00117 tdd->fskd.state = 0; 00118 tdd->pos = 0; 00119 tdd->mode = 0; 00120 fskmodem_init(&tdd->fskd); 00121 #else 00122 tdd->fskd.spb = 176; /* 45.5 baud */ 00123 tdd->fskd.hdlc = 0; /* Async */ 00124 tdd->fskd.nbit = 5; /* 5 bits */ 00125 tdd->fskd.nstop = 1.5; /* 1.5 stop bits */ 00126 tdd->fskd.parity = 0; /* No parity */ 00127 tdd->fskd.bw=0; /* Filter 75 Hz */ 00128 tdd->fskd.f_mark_idx = 0; /* 1400 Hz */ 00129 tdd->fskd.f_space_idx = 1; /* 1800 Hz */ 00130 tdd->fskd.pcola = 0; /* No clue */ 00131 tdd->fskd.cont = 0; /* Digital PLL reset */ 00132 tdd->fskd.x0 = 0.0; 00133 tdd->fskd.state = 0; 00134 tdd->pos = 0; 00135 tdd->mode = 2; 00136 #endif 00137 tdd->charnum = 0; 00138 } else 00139 ast_log(LOG_WARNING, "Out of memory\n"); 00140 return tdd; 00141 }