mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-19 03:08:45 +00:00
- Code formatting
- remove coef_in.h and coef_out.h that was only included as data definitions in fskmodem.c If you understand spanish, please help us translate the comments in fskmodem.c. Thanks! git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@48205 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -81,7 +81,7 @@ static inline void gen_tones(unsigned char *buf, int len, int codec, float ddr1,
|
|||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
float t;
|
float t;
|
||||||
for (x=0;x<len;x++) {
|
for (x = 0; x < len; x++) {
|
||||||
t = *cr1 * ddr1 - *ci1 * ddi1;
|
t = *cr1 * ddr1 - *ci1 * ddi1;
|
||||||
*ci1 = *cr1 * ddi1 + *ci1 * ddr1;
|
*ci1 = *cr1 * ddi1 + *ci1 * ddr1;
|
||||||
*cr1 = t;
|
*cr1 = t;
|
||||||
@@ -103,7 +103,7 @@ static inline void gen_tone(unsigned char *buf, int len, int codec, float ddr1,
|
|||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
float t;
|
float t;
|
||||||
for (x=0;x<len;x++) {
|
for (x = 0; x < len; x++) {
|
||||||
t = *cr1 * ddr1 - *ci1 * ddi1;
|
t = *cr1 * ddr1 - *ci1 * ddi1;
|
||||||
*ci1 = *cr1 * ddi1 + *ci1 * ddr1;
|
*ci1 = *cr1 * ddi1 + *ci1 * ddr1;
|
||||||
*cr1 = t;
|
*cr1 = t;
|
||||||
@@ -226,8 +226,8 @@ void callerid_get_dtmf(char *cidstring, char *number, int *flags)
|
|||||||
}
|
}
|
||||||
number[i] = 0;
|
number[i] = 0;
|
||||||
} else {
|
} else {
|
||||||
ast_log(LOG_DEBUG, "Unknown CID protocol, start digit '%c'\n",
|
if (option_debug)
|
||||||
cidstring[0]);
|
ast_log(LOG_DEBUG, "Unknown CID protocol, start digit '%c'\n", cidstring[0]);
|
||||||
*flags = CID_UNKNOWN_NUMBER;
|
*flags = CID_UNKNOWN_NUMBER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -235,11 +235,12 @@ void callerid_get_dtmf(char *cidstring, char *number, int *flags)
|
|||||||
int ast_gen_cas(unsigned char *outbuf, int sendsas, int len, int codec)
|
int ast_gen_cas(unsigned char *outbuf, int sendsas, int len, int codec)
|
||||||
{
|
{
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
int saslen=2400;
|
int saslen = 2400;
|
||||||
float cr1 = 1.0;
|
float cr1 = 1.0;
|
||||||
float ci1 = 0.0;
|
float ci1 = 0.0;
|
||||||
float cr2 = 1.0;
|
float cr2 = 1.0;
|
||||||
float ci2 = 0.0;
|
float ci2 = 0.0;
|
||||||
|
|
||||||
if (sendsas) {
|
if (sendsas) {
|
||||||
if (len < saslen)
|
if (len < saslen)
|
||||||
return -1;
|
return -1;
|
||||||
@@ -262,12 +263,11 @@ static unsigned short calc_crc(unsigned short crc, unsigned char data)
|
|||||||
for (i = 0; i < CHAR_BIT; i++) {
|
for (i = 0; i < CHAR_BIT; i++) {
|
||||||
org <<= 1;
|
org <<= 1;
|
||||||
dst >>= 1;
|
dst >>= 1;
|
||||||
if (org & 0x100) {
|
if (org & 0x100)
|
||||||
dst |= 0x80;
|
dst |= 0x80;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
data = (unsigned char)dst;
|
data = (unsigned char) dst;
|
||||||
crc ^= (unsigned int)data << (16 - CHAR_BIT);
|
crc ^= (unsigned int) data << (16 - CHAR_BIT);
|
||||||
for (j = 0; j < CHAR_BIT; j++) {
|
for (j = 0; j < CHAR_BIT; j++) {
|
||||||
if (crc & 0x8000U)
|
if (crc & 0x8000U)
|
||||||
crc = (crc << 1) ^ 0x1021U ;
|
crc = (crc << 1) ^ 0x1021U ;
|
||||||
@@ -290,7 +290,7 @@ int callerid_feed_jp(struct callerid_state *cid, unsigned char *ubuf, int len, i
|
|||||||
buf = alloca(2 * len + cid->oldlen);
|
buf = alloca(2 * len + cid->oldlen);
|
||||||
|
|
||||||
memcpy(buf, cid->oldstuff, cid->oldlen);
|
memcpy(buf, cid->oldstuff, cid->oldlen);
|
||||||
mylen += cid->oldlen/2;
|
mylen += cid->oldlen / 2;
|
||||||
|
|
||||||
for (x = 0; x < len; x++)
|
for (x = 0; x < len; x++)
|
||||||
buf[x+cid->oldlen/2] = AST_XLAW(ubuf[x]);
|
buf[x+cid->oldlen/2] = AST_XLAW(ubuf[x]);
|
||||||
@@ -344,24 +344,20 @@ int callerid_feed_jp(struct callerid_state *cid, unsigned char *ubuf, int len, i
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1: /* SOH */
|
case 1: /* SOH */
|
||||||
if (b == 0x01) {
|
if (b == 0x01)
|
||||||
cid->sawflag = 2;
|
cid->sawflag = 2;
|
||||||
}
|
|
||||||
break ;
|
break ;
|
||||||
case 2: /* HEADER */
|
case 2: /* HEADER */
|
||||||
if (b == 0x07) {
|
if (b == 0x07)
|
||||||
cid->sawflag = 3;
|
cid->sawflag = 3;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 3: /* STX */
|
case 3: /* STX */
|
||||||
if (b == 0x02) {
|
if (b == 0x02)
|
||||||
cid->sawflag = 4;
|
cid->sawflag = 4;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 4: /* SERVICE TYPE */
|
case 4: /* SERVICE TYPE */
|
||||||
if (b == 0x40) {
|
if (b == 0x40)
|
||||||
cid->sawflag = 5;
|
cid->sawflag = 5;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 5: /* Frame Length */
|
case 5: /* Frame Length */
|
||||||
cid->sawflag = 6;
|
cid->sawflag = 6;
|
||||||
@@ -401,7 +397,7 @@ int callerid_feed_jp(struct callerid_state *cid, unsigned char *ubuf, int len, i
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
/* extract caller id data */
|
/* extract caller id data */
|
||||||
for (x=0; x<cid->pos;) {
|
for (x = 0; x < cid->pos;) {
|
||||||
switch (cid->rawdata[x++]) {
|
switch (cid->rawdata[x++]) {
|
||||||
case 0x02: /* caller id number */
|
case 0x02: /* caller id number */
|
||||||
cid->number[0] = '\0';
|
cid->number[0] = '\0';
|
||||||
@@ -690,7 +686,8 @@ static int callerid_genmsg(char *msg, int size, const char *number, const char *
|
|||||||
struct tm tm;
|
struct tm tm;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
int res;
|
int res;
|
||||||
int i,x;
|
int i, x;
|
||||||
|
|
||||||
/* Get the time */
|
/* Get the time */
|
||||||
time(&t);
|
time(&t);
|
||||||
localtime_r(&t,&tm);
|
localtime_r(&t,&tm);
|
||||||
@@ -715,7 +712,8 @@ static int callerid_genmsg(char *msg, int size, const char *number, const char *
|
|||||||
} else {
|
} else {
|
||||||
/* Send up to 16 digits of number MAX */
|
/* Send up to 16 digits of number MAX */
|
||||||
i = strlen(number);
|
i = strlen(number);
|
||||||
if (i > 16) i = 16;
|
if (i > 16)
|
||||||
|
i = 16;
|
||||||
res = snprintf(ptr, size, "\002%c", i);
|
res = snprintf(ptr, size, "\002%c", i);
|
||||||
size -= res;
|
size -= res;
|
||||||
ptr += res;
|
ptr += res;
|
||||||
@@ -739,11 +737,12 @@ static int callerid_genmsg(char *msg, int size, const char *number, const char *
|
|||||||
} else {
|
} else {
|
||||||
/* Send up to 16 digits of name MAX */
|
/* Send up to 16 digits of name MAX */
|
||||||
i = strlen(name);
|
i = strlen(name);
|
||||||
if (i > 16) i = 16;
|
if (i > 16)
|
||||||
|
i = 16;
|
||||||
res = snprintf(ptr, size, "\007%c", i);
|
res = snprintf(ptr, size, "\007%c", i);
|
||||||
size -= res;
|
size -= res;
|
||||||
ptr += res;
|
ptr += res;
|
||||||
for (x=0;x<i;x++)
|
for (x = 0; x < i; x++)
|
||||||
ptr[x] = name[x];
|
ptr[x] = name[x];
|
||||||
ptr[i] = '\0';
|
ptr[i] = '\0';
|
||||||
ptr += i;
|
ptr += i;
|
||||||
@@ -763,6 +762,7 @@ int vmwi_generate(unsigned char *buf, int active, int mdmf, int codec)
|
|||||||
float cr = 1.0;
|
float cr = 1.0;
|
||||||
float ci = 0.0;
|
float ci = 0.0;
|
||||||
float scont = 0.0;
|
float scont = 0.0;
|
||||||
|
|
||||||
if (mdmf) {
|
if (mdmf) {
|
||||||
/* MDMF Message waiting */
|
/* MDMF Message waiting */
|
||||||
msg[len++] = 0x82;
|
msg[len++] = 0x82;
|
||||||
|
@@ -1,13 +0,0 @@
|
|||||||
{ { 1.8229206611e-04,-7.8997325866e-01,2.2401819940e+00,-4.6751353581e+00,5.5080745712e+00,-5.0571565772e+00,2.6215820004e+00,0.0000000000e+00,
|
|
||||||
}, { 9.8532175289e-02,-5.6297236492e-02,3.3146713415e-01,-9.2239200436e-01,1.4844365184e+00,-2.0183258642e+00,2.0074154497e+00,0.0000000000e+00,
|
|
||||||
}, }, { { 1.8229206610e-04,-7.8997325866e-01,7.7191410839e-01,-2.8075643964e+00,1.6948618347e+00,-3.0367273700e+00,9.0333559408e-01,0.0000000000e+00,
|
|
||||||
}, { 9.8531161839e-02,-5.6297236492e-02,1.1421579050e-01,-4.8122536483e-01,4.0121072432e-01,-7.4834487567e-01,6.9170822332e-01,0.0000000000e+00,
|
|
||||||
}, }, { { 1.8229206611e-04,-7.8997325866e-01,2.9003821430e+00,-6.1082779024e+00,7.7169345751e+00,-6.6075999680e+00,3.3941838836e+00,0.0000000000e+00,
|
|
||||||
}, { 9.8539686961e-02,-5.6297236492e-02,4.2915323820e-01,-1.2609358633e+00,2.2399213250e+00,-2.9928879142e+00,2.5990173742e+00,0.0000000000e+00,
|
|
||||||
}, }, { { 1.8229206610e-04,-7.8997325866e-01,-7.7191410839e-01,-2.8075643964e+00,-1.6948618347e+00,-3.0367273700e+00,-9.0333559408e-01,0.0000000000e+00,
|
|
||||||
}, { 9.8531161839e-02,-5.6297236492e-02,-1.1421579050e-01,-4.8122536483e-01,-4.0121072432e-01,-7.4834487567e-01,-6.9170822332e-01,0.0000000000e+00,
|
|
||||||
}, }, { { 1.8229206611e-04,-7.8997325866e-01,2.5782298908e+00,-5.3629717478e+00,6.5890882172e+00,-5.8012914776e+00,3.0171839130e+00,0.0000000000e+00,
|
|
||||||
}, { 9.8534230718e-02,-5.6297236492e-02,3.8148618075e-01,-1.0848760410e+00,1.8441165168e+00,-2.4860666655e+00,2.3103384142e+00,0.0000000000e+00,
|
|
||||||
}, }, { { 1.8229206610e-04,-7.8997325866e-01,-3.8715051001e-01,-2.6192408538e+00,-8.3977994034e-01,-2.8329897913e+00,-4.5306444352e-01,0.0000000000e+00,
|
|
||||||
}, { 9.8531160936e-02,-5.6297236492e-02,-5.7284484199e-02,-4.3673866734e-01,-1.9564766257e-01,-6.2028156584e-01,-3.4692356122e-01,0.0000000000e+00,
|
|
||||||
}, },
|
|
@@ -1,4 +0,0 @@
|
|||||||
{ 1.3868644653e-08,-6.3283665042e-01,4.0895057217e+00,-1.1020074592e+01,1.5850766191e+01,-1.2835109292e+01,5.5477477340e+00,0.0000000000e+00,
|
|
||||||
}, { 3.1262119724e-03,-7.8390522307e-03,8.5209627801e-02,-4.0804129163e-01,1.1157139955e+00,-1.8767603680e+00,1.8916395224e+00,0.0000000000e+00
|
|
||||||
},
|
|
||||||
|
|
243
main/fskmodem.c
243
main/fskmodem.c
@@ -25,6 +25,9 @@
|
|||||||
* \author Mark Spencer <markster@digium.com>
|
* \author Mark Spencer <markster@digium.com>
|
||||||
*
|
*
|
||||||
* \arg Includes code and algorithms from the Zapata library.
|
* \arg Includes code and algorithms from the Zapata library.
|
||||||
|
*
|
||||||
|
* \todo - REMOVE ALL SPANISH COMMENTS AND TRANSLATE THEM TO ENGLISH. Thank you.
|
||||||
|
* Swedish will work too :-)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "asterisk.h"
|
#include "asterisk.h"
|
||||||
@@ -52,83 +55,113 @@ static inline float get_sample(short **buffer, int *len)
|
|||||||
(*buffer)++;
|
(*buffer)++;
|
||||||
(*len)--;
|
(*len)--;
|
||||||
return retval;
|
return retval;
|
||||||
}
|
};
|
||||||
|
|
||||||
#define GET_SAMPLE get_sample(&buffer, len)
|
#define GET_SAMPLE get_sample(&buffer, len)
|
||||||
|
|
||||||
/* Coeficientes para filtros de entrada */
|
/* Coeficientes para filtros de entrada */
|
||||||
/* Tabla de coeficientes, generada a partir del programa "mkfilter" */
|
/* Tabla de coeficientes, generada a partir del programa "mkfilter" */
|
||||||
/* Formato: coef[IDX_FREC][IDX_BW][IDX_COEF] */
|
/* Formato: coef[IDX_FREC][IDX_BW][IDX_COEF] */
|
||||||
/* IDX_COEF=0 => 1/GAIN */
|
/* IDX_COEF = 0 => 1/GAIN */
|
||||||
/* IDX_COEF=1-6 => Coeficientes y[n] */
|
/* IDX_COEF = 1-6 => Coeficientes y[n] */
|
||||||
|
|
||||||
static double coef_in[NF][NBW][8]={
|
static double coef_in[NF][NBW][8] = {
|
||||||
#include "coef_in.h"
|
{
|
||||||
|
{ 1.8229206611e-04,-7.8997325866e-01,2.2401819940e+00,-4.6751353581e+00,5.5080745712e+00,-5.0571565772e+00,2.6215820004e+00,0.0000000000e+00, },
|
||||||
|
{ 9.8532175289e-02,-5.6297236492e-02,3.3146713415e-01,-9.2239200436e-01,1.4844365184e+00,-2.0183258642e+00,2.0074154497e+00,0.0000000000e+00, },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{ 1.8229206610e-04,-7.8997325866e-01,7.7191410839e-01,-2.8075643964e+00,1.6948618347e+00,-3.0367273700e+00,9.0333559408e-01,0.0000000000e+00, } ,
|
||||||
|
{ 9.8531161839e-02,-5.6297236492e-02,1.1421579050e-01,-4.8122536483e-01,4.0121072432e-01,-7.4834487567e-01,6.9170822332e-01,0.0000000000e+00, },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{ 1.8229206611e-04,-7.8997325866e-01,2.9003821430e+00,-6.1082779024e+00,7.7169345751e+00,-6.6075999680e+00,3.3941838836e+00,0.0000000000e+00, },
|
||||||
|
{ 9.8539686961e-02,-5.6297236492e-02,4.2915323820e-01,-1.2609358633e+00,2.2399213250e+00,-2.9928879142e+00,2.5990173742e+00,0.0000000000e+00, },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{ 1.8229206610e-04,-7.8997325866e-01,-7.7191410839e-01,-2.8075643964e+00,-1.6948618347e+00,-3.0367273700e+00,-9.0333559408e-01,0.0000000000e+00, },
|
||||||
|
{ 9.8531161839e-02,-5.6297236492e-02,-1.1421579050e-01,-4.8122536483e-01,-4.0121072432e-01,-7.4834487567e-01,-6.9170822332e-01,0.0000000000e+00, },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{ 1.8229206611e-04,-7.8997325866e-01,2.5782298908e+00,-5.3629717478e+00,6.5890882172e+00,-5.8012914776e+00,3.0171839130e+00,0.0000000000e+00, },
|
||||||
|
{ 9.8534230718e-02,-5.6297236492e-02,3.8148618075e-01,-1.0848760410e+00,1.8441165168e+00,-2.4860666655e+00,2.3103384142e+00,0.0000000000e+00, },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{ 1.8229206610e-04,-7.8997325866e-01,-3.8715051001e-01,-2.6192408538e+00,-8.3977994034e-01,-2.8329897913e+00,-4.5306444352e-01,0.0000000000e+00, },
|
||||||
|
{ 9.8531160936e-02,-5.6297236492e-02,-5.7284484199e-02,-4.3673866734e-01,-1.9564766257e-01,-6.2028156584e-01,-3.4692356122e-01,0.0000000000e+00, },
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Coeficientes para filtro de salida */
|
/* Coeficientes para filtro de salida */
|
||||||
/* Tabla de coeficientes, generada a partir del programa "mkfilter" */
|
/* Tabla de coeficientes, generada a partir del programa "mkfilter" */
|
||||||
/* Formato: coef[IDX_BW][IDX_COEF] */
|
/* Formato: coef[IDX_BW][IDX_COEF] */
|
||||||
/* IDX_COEF=0 => 1/GAIN */
|
/* IDX_COEF = 0 => 1/GAIN */
|
||||||
/* IDX_COEF=1-6 => Coeficientes y[n] */
|
/* IDX_COEF = 1-6 => Coeficientes y[n] */
|
||||||
|
|
||||||
static double coef_out[NBW][8]={
|
static double coef_out[NBW][8] = {
|
||||||
#include "coef_out.h"
|
{ 1.3868644653e-08,-6.3283665042e-01,4.0895057217e+00,-1.1020074592e+01,1.5850766191e+01,-1.2835109292e+01,5.5477477340e+00,0.0000000000e+00, },
|
||||||
|
{ 3.1262119724e-03,-7.8390522307e-03,8.5209627801e-02,-4.0804129163e-01,1.1157139955e+00,-1.8767603680e+00,1.8916395224e+00,0.0000000000e+00, },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*! Filtro pasa-banda para frecuencia de MARCA */
|
/*! Filtro pasa-banda para frecuencia de MARCA */
|
||||||
static inline float filtroM(fsk_data *fskd,float in)
|
static inline float filtroM(fsk_data *fskd,float in)
|
||||||
{
|
{
|
||||||
int i,j;
|
int i, j;
|
||||||
double s;
|
double s;
|
||||||
double *pc;
|
double *pc;
|
||||||
|
|
||||||
pc=&coef_in[fskd->f_mark_idx][fskd->bw][0];
|
pc = &coef_in[fskd->f_mark_idx][fskd->bw][0];
|
||||||
fskd->fmxv[(fskd->fmp+6)&7]=in*(*pc++);
|
fskd->fmxv[(fskd->fmp+6)&7] = in*(*pc++);
|
||||||
|
|
||||||
s=(fskd->fmxv[(fskd->fmp+6)&7] - fskd->fmxv[fskd->fmp]) + 3 * (fskd->fmxv[(fskd->fmp+2)&7] - fskd->fmxv[(fskd->fmp+4)&7]);
|
s = (fskd->fmxv[(fskd->fmp + 6) & 7] - fskd->fmxv[fskd->fmp]) + 3 * (fskd->fmxv[(fskd->fmp + 2) & 7] - fskd->fmxv[(fskd->fmp + 4) & 7]);
|
||||||
for (i=0,j=fskd->fmp;i<6;i++,j++) s+=fskd->fmyv[j&7]*(*pc++);
|
for (i = 0, j = fskd->fmp; i < 6; i++, j++)
|
||||||
fskd->fmyv[j&7]=s;
|
s += fskd->fmyv[j&7]*(*pc++);
|
||||||
fskd->fmp++; fskd->fmp&=7;
|
fskd->fmyv[j&7] = s;
|
||||||
|
fskd->fmp++;
|
||||||
|
fskd->fmp &= 7;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Filtro pasa-banda para frecuencia de ESPACIO */
|
/*! Filtro pasa-banda para frecuencia de ESPACIO */
|
||||||
static inline float filtroS(fsk_data *fskd,float in)
|
static inline float filtroS(fsk_data *fskd,float in)
|
||||||
{
|
{
|
||||||
int i,j;
|
int i, j;
|
||||||
double s;
|
double s;
|
||||||
double *pc;
|
double *pc;
|
||||||
|
|
||||||
pc=&coef_in[fskd->f_space_idx][fskd->bw][0];
|
pc = &coef_in[fskd->f_space_idx][fskd->bw][0];
|
||||||
fskd->fsxv[(fskd->fsp+6)&7]=in*(*pc++);
|
fskd->fsxv[(fskd->fsp+6)&7] = in*(*pc++);
|
||||||
|
|
||||||
s=(fskd->fsxv[(fskd->fsp+6)&7] - fskd->fsxv[fskd->fsp]) + 3 * (fskd->fsxv[(fskd->fsp+2)&7] - fskd->fsxv[(fskd->fsp+4)&7]);
|
s = (fskd->fsxv[(fskd->fsp + 6) & 7] - fskd->fsxv[fskd->fsp]) + 3 * (fskd->fsxv[(fskd->fsp + 2) & 7] - fskd->fsxv[(fskd->fsp + 4) & 7]);
|
||||||
for (i=0,j=fskd->fsp;i<6;i++,j++) s+=fskd->fsyv[j&7]*(*pc++);
|
for (i = 0, j = fskd->fsp; i < 6; i++, j++)
|
||||||
fskd->fsyv[j&7]=s;
|
s += fskd->fsyv[j&7]*(*pc++);
|
||||||
fskd->fsp++; fskd->fsp&=7;
|
fskd->fsyv[j&7] = s;
|
||||||
|
fskd->fsp++;
|
||||||
|
fskd->fsp &= 7;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Filtro pasa-bajos para datos demodulados */
|
/*! Filtro pasa-bajos para datos demodulados */
|
||||||
static inline float filtroL(fsk_data *fskd,float in)
|
static inline float filtroL(fsk_data *fskd,float in)
|
||||||
{
|
{
|
||||||
int i,j;
|
int i, j;
|
||||||
double s;
|
double s;
|
||||||
double *pc;
|
double *pc;
|
||||||
|
|
||||||
pc=&coef_out[fskd->bw][0];
|
pc = &coef_out[fskd->bw][0];
|
||||||
fskd->flxv[(fskd->flp + 6) & 7]=in * (*pc++);
|
fskd->flxv[(fskd->flp + 6) & 7] = in * (*pc++);
|
||||||
|
|
||||||
s= (fskd->flxv[fskd->flp] + fskd->flxv[(fskd->flp+6)&7]) +
|
s = (fskd->flxv[fskd->flp] + fskd->flxv[(fskd->flp+6)&7]) +
|
||||||
6 * (fskd->flxv[(fskd->flp+1)&7] + fskd->flxv[(fskd->flp+5)&7]) +
|
6 * (fskd->flxv[(fskd->flp+1)&7] + fskd->flxv[(fskd->flp+5)&7]) +
|
||||||
15 * (fskd->flxv[(fskd->flp+2)&7] + fskd->flxv[(fskd->flp+4)&7]) +
|
15 * (fskd->flxv[(fskd->flp+2)&7] + fskd->flxv[(fskd->flp+4)&7]) +
|
||||||
20 * fskd->flxv[(fskd->flp+3)&7];
|
20 * fskd->flxv[(fskd->flp+3)&7];
|
||||||
|
|
||||||
for (i=0,j=fskd->flp;i<6;i++,j++) s+=fskd->flyv[j&7]*(*pc++);
|
for (i = 0,j = fskd->flp;i<6;i++,j++)
|
||||||
fskd->flyv[j&7]=s;
|
s += fskd->flyv[j&7]*(*pc++);
|
||||||
fskd->flp++; fskd->flp&=7;
|
fskd->flyv[j&7] = s;
|
||||||
|
fskd->flp++;
|
||||||
|
fskd->flp &= 7;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,20 +169,20 @@ static inline int demodulador(fsk_data *fskd, float *retval, float x)
|
|||||||
{
|
{
|
||||||
float xS,xM;
|
float xS,xM;
|
||||||
|
|
||||||
fskd->cola_in[fskd->pcola]=x;
|
fskd->cola_in[fskd->pcola] = x;
|
||||||
|
|
||||||
xS=filtroS(fskd,x);
|
xS = filtroS(fskd,x);
|
||||||
xM=filtroM(fskd,x);
|
xM = filtroM(fskd,x);
|
||||||
|
|
||||||
fskd->cola_filtro[fskd->pcola]=xM-xS;
|
fskd->cola_filtro[fskd->pcola] = xM-xS;
|
||||||
|
|
||||||
x=filtroL(fskd,xM*xM - xS*xS);
|
x = filtroL(fskd,xM*xM - xS*xS);
|
||||||
|
|
||||||
fskd->cola_demod[fskd->pcola++]=x;
|
fskd->cola_demod[fskd->pcola++] = x;
|
||||||
fskd->pcola &= (NCOLA-1);
|
fskd->pcola &= (NCOLA-1);
|
||||||
|
|
||||||
*retval = x;
|
*retval = x;
|
||||||
return(0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_bit_raw(fsk_data *fskd, short *buffer, int *len)
|
static int get_bit_raw(fsk_data *fskd, short *buffer, int *len)
|
||||||
@@ -158,36 +191,42 @@ static int get_bit_raw(fsk_data *fskd, short *buffer, int *len)
|
|||||||
float x,spb,spb2,ds;
|
float x,spb,spb2,ds;
|
||||||
int f;
|
int f;
|
||||||
|
|
||||||
spb=fskd->spb;
|
spb = fskd->spb;
|
||||||
if (fskd->spb == 7) spb = 8000.0 / 1200.0;
|
if (fskd->spb == 7)
|
||||||
ds=spb/32.;
|
spb = 8000.0 / 1200.0;
|
||||||
spb2=spb/2.;
|
ds = spb/32.;
|
||||||
|
spb2 = spb/2.;
|
||||||
|
|
||||||
for (f=0;;){
|
for (f = 0;;) {
|
||||||
if (demodulador(fskd,&x, GET_SAMPLE)) return(-1);
|
if (demodulador(fskd, &x, GET_SAMPLE))
|
||||||
if ((x*fskd->x0)<0) { /* Transicion */
|
return -1;
|
||||||
|
if ((x * fskd->x0) < 0) { /* Transicion */
|
||||||
if (!f) {
|
if (!f) {
|
||||||
if (fskd->cont<(spb2)) fskd->cont+=ds; else fskd->cont-=ds;
|
if (fskd->cont<(spb2))
|
||||||
f=1;
|
fskd->cont += ds;
|
||||||
|
else
|
||||||
|
fskd->cont -= ds;
|
||||||
|
f = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fskd->x0=x;
|
fskd->x0 = x;
|
||||||
fskd->cont+=1.;
|
fskd->cont += 1.;
|
||||||
if (fskd->cont>spb) {
|
if (fskd->cont > spb) {
|
||||||
fskd->cont-=spb;
|
fskd->cont -= spb;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
f=(x>0)?0x80:0;
|
f = (x > 0) ? 0x80 : 0;
|
||||||
return(f);
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fsk_serie(fsk_data *fskd, short *buffer, int *len, int *outbyte)
|
int fsk_serie(fsk_data *fskd, short *buffer, int *len, int *outbyte)
|
||||||
{
|
{
|
||||||
int a;
|
int a;
|
||||||
int i,j,n1,r;
|
int i,j,n1,r;
|
||||||
int samples=0;
|
int samples = 0;
|
||||||
int olen;
|
int olen;
|
||||||
|
|
||||||
switch(fskd->state) {
|
switch(fskd->state) {
|
||||||
/* Pick up where we left off */
|
/* Pick up where we left off */
|
||||||
case STATE_SEARCH_STARTBIT2:
|
case STATE_SEARCH_STARTBIT2:
|
||||||
@@ -199,54 +238,59 @@ int fsk_serie(fsk_data *fskd, short *buffer, int *len, int *outbyte)
|
|||||||
}
|
}
|
||||||
/* Esperamos bit de start */
|
/* Esperamos bit de start */
|
||||||
do {
|
do {
|
||||||
/* this was jesus's nice, reasonable, working (at least with RTTY) code
|
/* this was jesus's nice, reasonable, working (at least with RTTY) code
|
||||||
to look for the beginning of the start bit. Unfortunately, since TTY/TDD's
|
to look for the beginning of the start bit. Unfortunately, since TTY/TDD's
|
||||||
just start sending a start bit with nothing preceding it at the beginning
|
just start sending a start bit with nothing preceding it at the beginning
|
||||||
of a transmission (what a LOSING design), we cant do it this elegantly */
|
of a transmission (what a LOSING design), we cant do it this elegantly */
|
||||||
/*
|
/*
|
||||||
if (demodulador(zap,&x1)) return(-1);
|
if (demodulador(zap,&x1)) return(-1);
|
||||||
for(;;) {
|
for(;;) {
|
||||||
if (demodulador(zap,&x2)) return(-1);
|
if (demodulador(zap,&x2)) return(-1);
|
||||||
if (x1>0 && x2<0) break;
|
if (x1>0 && x2<0) break;
|
||||||
x1=x2;
|
x1 = x2;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
/* this is now the imprecise, losing, but functional code to detect the
|
/* this is now the imprecise, losing, but functional code to detect the
|
||||||
beginning of a start bit in the TDD sceanario. It just looks for sufficient
|
beginning of a start bit in the TDD sceanario. It just looks for sufficient
|
||||||
level to maybe, perhaps, guess, maybe that its maybe the beginning of
|
level to maybe, perhaps, guess, maybe that its maybe the beginning of
|
||||||
a start bit, perhaps. This whole thing stinks! */
|
a start bit, perhaps. This whole thing stinks! */
|
||||||
if (demodulador(fskd,&fskd->x1,GET_SAMPLE)) return(-1);
|
if (demodulador(fskd,&fskd->x1,GET_SAMPLE))
|
||||||
|
return -1;
|
||||||
samples++;
|
samples++;
|
||||||
for(;;)
|
for(;;) {
|
||||||
{
|
|
||||||
search_startbit2:
|
search_startbit2:
|
||||||
if (!*len) {
|
if (!*len) {
|
||||||
fskd->state = STATE_SEARCH_STARTBIT2;
|
fskd->state = STATE_SEARCH_STARTBIT2;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
samples++;
|
samples++;
|
||||||
if (demodulador(fskd,&fskd->x2,GET_SAMPLE)) return(-1);
|
if (demodulador(fskd,&fskd->x2,GET_SAMPLE))
|
||||||
|
return(-1);
|
||||||
#if 0
|
#if 0
|
||||||
printf("x2 = %5.5f ", fskd->x2);
|
printf("x2 = %5.5f ", fskd->x2);
|
||||||
#endif
|
#endif
|
||||||
if (fskd->x2 < -0.5) break;
|
if (fskd->x2 < -0.5)
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
search_startbit3:
|
search_startbit3:
|
||||||
/* Esperamos 0.5 bits antes de usar DPLL */
|
/* Esperamos 0.5 bits antes de usar DPLL */
|
||||||
i=fskd->spb/2;
|
i = fskd->spb/2;
|
||||||
if (*len < i) {
|
if (*len < i) {
|
||||||
fskd->state = STATE_SEARCH_STARTBIT3;
|
fskd->state = STATE_SEARCH_STARTBIT3;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
for(;i;i--) { if (demodulador(fskd,&fskd->x1,GET_SAMPLE)) return(-1);
|
for(;i;i--) {
|
||||||
|
if (demodulador(fskd,&fskd->x1,GET_SAMPLE))
|
||||||
|
return(-1);
|
||||||
#if 0
|
#if 0
|
||||||
printf("x1 = %5.5f ", fskd->x1);
|
printf("x1 = %5.5f ", fskd->x1);
|
||||||
#endif
|
#endif
|
||||||
samples++; }
|
samples++;
|
||||||
|
}
|
||||||
|
|
||||||
/* x1 debe ser negativo (confirmaci<63>n del bit de start) */
|
/* x1 debe ser negativo (confirmaci<63>n del bit de start) */
|
||||||
|
|
||||||
} while (fskd->x1>0);
|
} while (fskd->x1 > 0);
|
||||||
fskd->state = STATE_GET_BYTE;
|
fskd->state = STATE_GET_BYTE;
|
||||||
|
|
||||||
getbyte:
|
getbyte:
|
||||||
@@ -261,38 +305,47 @@ getbyte:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* Leemos ahora los bits de datos */
|
/* Leemos ahora los bits de datos */
|
||||||
j=fskd->nbit;
|
j = fskd->nbit;
|
||||||
for (a=n1=0;j;j--) {
|
for (a = n1 = 0; j; j--) {
|
||||||
olen = *len;
|
olen = *len;
|
||||||
i=get_bit_raw(fskd, buffer, len);
|
i = get_bit_raw(fskd, buffer, len);
|
||||||
buffer += (olen - *len);
|
buffer += (olen - *len);
|
||||||
if (i == -1) return(-1);
|
if (i == -1)
|
||||||
if (i) n1++;
|
return(-1);
|
||||||
a>>=1; a|=i;
|
if (i)
|
||||||
|
n1++;
|
||||||
|
a >>= 1;
|
||||||
|
a |= i;
|
||||||
}
|
}
|
||||||
j=8-fskd->nbit;
|
j = 8-fskd->nbit;
|
||||||
a>>=j;
|
a >>= j;
|
||||||
|
|
||||||
/* Leemos bit de paridad (si existe) y la comprobamos */
|
/* Leemos bit de paridad (si existe) y la comprobamos */
|
||||||
if (fskd->paridad) {
|
if (fskd->paridad) {
|
||||||
olen = *len;
|
olen = *len;
|
||||||
i=get_bit_raw(fskd, buffer, len);
|
i = get_bit_raw(fskd, buffer, len);
|
||||||
buffer += (olen - *len);
|
buffer += (olen - *len);
|
||||||
if (i == -1) return(-1);
|
if (i == -1)
|
||||||
if (i) n1++;
|
return(-1);
|
||||||
if (fskd->paridad==1) { /* paridad=1 (par) */
|
if (i)
|
||||||
if (n1&1) a|=0x100; /* error */
|
n1++;
|
||||||
} else { /* paridad=2 (impar) */
|
if (fskd->paridad == 1) { /* paridad = 1 (par) */
|
||||||
if (!(n1&1)) a|=0x100; /* error */
|
if (n1&1)
|
||||||
|
a |= 0x100; /* error */
|
||||||
|
} else { /* paridad = 2 (impar) */
|
||||||
|
if (!(n1&1))
|
||||||
|
a |= 0x100; /* error */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Leemos bits de STOP. Todos deben ser 1 */
|
/* Leemos bits de STOP. Todos deben ser 1 */
|
||||||
|
|
||||||
for (j=fskd->nstop;j;j--) {
|
for (j = fskd->nstop;j;j--) {
|
||||||
r = get_bit_raw(fskd, buffer, len);
|
r = get_bit_raw(fskd, buffer, len);
|
||||||
if (r == -1) return(-1);
|
if (r == -1)
|
||||||
if (!r) a|=0x200;
|
return(-1);
|
||||||
|
if (!r)
|
||||||
|
a |= 0x200;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Por fin retornamos */
|
/* Por fin retornamos */
|
||||||
|
@@ -174,7 +174,8 @@ int tdd_feed(struct tdd_state *tdd, unsigned char *ubuf, int len)
|
|||||||
if (b > 0x7f)
|
if (b > 0x7f)
|
||||||
continue;
|
continue;
|
||||||
c = tdd_decode_baudot(tdd,b);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user