Mon May 14 04:48:03 2007

Asterisk developer's documentation


fskmodem.c File Reference

FSK Modulator/Demodulator. More...

#include "asterisk.h"
#include <stdio.h>
#include "asterisk/fskmodem.h"
#include "coef_in.h"
#include "coef_out.h"

Include dependency graph for fskmodem.c:

Go to the source code of this file.

Defines

#define BWLIST   {75,800}
#define FLIST   {1400,1800,1200,2200,1300,2100}
#define GET_SAMPLE   get_sample(&buffer, len)
#define NBW   2
#define NF   6
#define STATE_GET_BYTE   3
#define STATE_SEARCH_STARTBIT   0
#define STATE_SEARCH_STARTBIT2   1
#define STATE_SEARCH_STARTBIT3   2

Functions

static int demodulador (fsk_data *fskd, float *retval, float x)
static float filtroL (fsk_data *fskd, float in)
static float filtroM (fsk_data *fskd, float in)
static float filtroS (fsk_data *fskd, float in)
int fsk_serie (fsk_data *fskd, short *buffer, int *len, int *outbyte)
static int get_bit_raw (fsk_data *fskd, short *buffer, int *len)
static float get_sample (short **buffer, int *len)

Variables

static double coef_in [NF][NBW][8]
static double coef_out [NBW][8]


Detailed Description

FSK Modulator/Demodulator.

Author:
Mark Spencer <markster@digium.com>

Definition in file fskmodem.c.


Define Documentation

#define BWLIST   {75,800}

Definition at line 39 of file fskmodem.c.

#define FLIST   {1400,1800,1200,2200,1300,2100}

Definition at line 41 of file fskmodem.c.

#define GET_SAMPLE   get_sample(&buffer, len)

Definition at line 57 of file fskmodem.c.

Referenced by demodulador(), and fsk_serie().

#define NBW   2

Definition at line 38 of file fskmodem.c.

#define NF   6

Definition at line 40 of file fskmodem.c.

#define STATE_GET_BYTE   3

Definition at line 46 of file fskmodem.c.

#define STATE_SEARCH_STARTBIT   0

Definition at line 43 of file fskmodem.c.

#define STATE_SEARCH_STARTBIT2   1

Definition at line 44 of file fskmodem.c.

Referenced by fsk_serie().

#define STATE_SEARCH_STARTBIT3   2

Definition at line 45 of file fskmodem.c.


Function Documentation

static int demodulador ( fsk_data fskd,
float *  retval,
float  x 
) [inline, static]

Definition at line 154 of file fskmodem.c.

References f, GET_SAMPLE, and fsk_data::spb.

Referenced by fsk_serie().

00156 {
00157    /* Esta funcion implementa un DPLL para sincronizarse con los bits */
00158    float x,spb,spb2,ds;
00159    int f;
00160 
00161    spb=fskd->spb; 
00162    if (fskd->spb == 7) spb = 8000.0 / 1200.0;
00163    ds=spb/32.;
00164    spb2=spb/2.;
00165 
00166    for (f=0;;){
00167       if (demodulador(fskd,&x, GET_SAMPLE)) return(-1);
00168       if ((x*fskd->x0)<0) {   /* Transicion */
00169          if (!f) {
00170             if (fskd->cont<(spb2)) fskd->cont+=ds; else fskd->cont-=ds;
00171             f=1;
00172          }

static float filtroL ( fsk_data fskd,
float  in 
) [inline, static]

Filtro pasa-bajos para datos demodulados

Definition at line 134 of file fskmodem.c.

References fsk_data::cola_demod, fsk_data::cola_filtro, fsk_data::cola_in, filtroM(), filtroS(), NCOLA, and fsk_data::pcola.

00136 {
00137    float xS,xM;
00138 
00139    fskd->cola_in[fskd->pcola]=x;
00140    
00141    xS=filtroS(fskd,x);
00142    xM=filtroM(fskd,x);
00143 
00144    fskd->cola_filtro[fskd->pcola]=xM-xS;
00145 
00146    x=filtroL(fskd,xM*xM - xS*xS);
00147    
00148    fskd->cola_demod[fskd->pcola++]=x;
00149    fskd->pcola &= (NCOLA-1);
00150 
00151    *retval = x;
00152    return(0);

static float filtroM ( fsk_data fskd,
float  in 
) [inline, static]

Filtro pasa-banda para frecuencia de MARCA

Definition at line 100 of file fskmodem.c.

Referenced by filtroL().

00116 {

static float filtroS ( fsk_data fskd,
float  in 
) [inline, static]

Filtro pasa-banda para frecuencia de ESPACIO

Definition at line 117 of file fskmodem.c.

Referenced by filtroL().

00136 {

int fsk_serie ( fsk_data fskd,
short *  buffer,
int *  len,
int *  outbyte 
)

Definition at line 204 of file fskmodem.c.

References demodulador(), GET_SAMPLE, and STATE_SEARCH_STARTBIT2.

Referenced by callerid_feed(), callerid_feed_jp(), and tdd_feed().

00208               {
00209          if (demodulador(zap,&x2)) return(-1);
00210          if (x1>0 && x2<0) break;
00211          x1=x2;
00212       }
00213 */
00214 /* this is now the imprecise, losing, but functional code to detect the
00215 beginning of a start bit in the TDD sceanario. It just looks for sufficient
00216 level to maybe, perhaps, guess, maybe that its maybe the beginning of
00217 a start bit, perhaps. This whole thing stinks! */
00218       if (demodulador(fskd,&fskd->x1,GET_SAMPLE)) return(-1);
00219       samples++;
00220       for(;;)
00221          {
00222 search_startbit2:       
00223          if (!*len) {
00224             fskd->state = STATE_SEARCH_STARTBIT2;
00225             return 0;
00226          }
00227          samples++;
00228          if (demodulador(fskd,&fskd->x2,GET_SAMPLE)) return(-1);
00229 #if 0
00230          printf("x2 = %5.5f ", fskd->x2);
00231 #endif         
00232          if (fskd->x2 < -0.5) break; 
00233          }
00234 search_startbit3:       
00235       /* Esperamos 0.5 bits antes de usar DPLL */
00236       i=fskd->spb/2;
00237       if (*len < i) {
00238          fskd->state = STATE_SEARCH_STARTBIT3;
00239          return 0;
00240       }
00241       for(;i;i--) { if (demodulador(fskd,&fskd->x1,GET_SAMPLE)) return(-1); 
00242 #if 0
00243          printf("x1 = %5.5f ", fskd->x1);
00244 #endif         
00245    samples++; }
00246 
00247       /* x1 debe ser negativo (confirmación del bit de start) */
00248 
00249    } while (fskd->x1>0);
00250    fskd->state = STATE_GET_BYTE;
00251 
00252 getbyte:
00253 
00254    /* Need at least 80 samples (for 1200) or
00255       1320 (for 45.5) to be sure we'll have a byte */
00256    if (fskd->nbit < 8) {
00257       if (*len < 1320)
00258          return 0;
00259    } else {
00260       if (*len < 80)
00261          return 0;
00262    }
00263    /* Leemos ahora los bits de datos */
00264    j=fskd->nbit;
00265    for (a=n1=0;j;j--) {
00266       olen = *len;
00267       i=get_bit_raw(fskd, buffer, len);
00268       buffer += (olen - *len);
00269       if (i == -1) return(-1);
00270       if (i) n1++;
00271       a>>=1; a|=i;
00272    }
00273    j=8-fskd->nbit;
00274    a>>=j;
00275 
00276    /* Leemos bit de paridad (si existe) y la comprobamos */
00277    if (fskd->paridad) {
00278       olen = *len;
00279       i=get_bit_raw(fskd, buffer, len); 
00280       buffer += (olen - *len);
00281       if (i == -1) return(-1);
00282       if (i) n1++;
00283       if (fskd->paridad==1) { /* paridad=1 (par) */
00284          if (n1&1) a|=0x100;     /* error */
00285       } else {       /* paridad=2 (impar) */
00286          if (!(n1&1)) a|=0x100;  /* error */
00287       }
00288    }
00289    
00290    /* Leemos bits de STOP. Todos deben ser 1 */
00291    
00292    for (j=fskd->nstop;j;j--) {
00293       r = get_bit_raw(fskd, buffer, len);
00294       if (r == -1) return(-1);
00295       if (!r) a|=0x200;
00296    }
00297 
00298    /* Por fin retornamos  */
00299    /* Bit 8 : Error de paridad */
00300    /* Bit 9 : Error de Framming */
00301 
00302    *outbyte = a;
00303    fskd->state = STATE_SEARCH_STARTBIT;
00304    return 1;
00305 }
00306 }

static int get_bit_raw ( fsk_data fskd,
short *  buffer,
int *  len 
) [static]

Definition at line 174 of file fskmodem.c.

00176                           {
00177          fskd->cont-=spb;
00178          break;
00179       }
00180    }
00181    f=(x>0)?0x80:0;
00182    return(f);
00183 }
00184 
00185 int fsk_serie(fsk_data *fskd, short *buffer, int *len, int *outbyte)
00186 {
00187    int a;
00188    int i,j,n1,r;
00189    int samples=0;
00190    int olen;
00191    switch(fskd->state) {
00192       /* Pick up where we left off */
00193    case STATE_SEARCH_STARTBIT2:
00194       goto search_startbit2;
00195    case STATE_SEARCH_STARTBIT3:
00196       goto search_startbit3;
00197    case STATE_GET_BYTE:
00198       goto getbyte;
00199    }
00200    /* Esperamos bit de start  */
00201    do {
00202 /* this was jesus's nice, reasonable, working (at least with RTTY) code

static float get_sample ( short **  buffer,
int *  len 
) [inline, static]

Definition at line 48 of file fskmodem.c.

00049 {
00050    float retval;
00051    retval = (float) **buffer / 256;
00052    (*buffer)++;
00053    (*len)--;
00054    return retval;
00055 }


Variable Documentation

double coef_in[NF][NBW][8] [static]

Definition at line 65 of file fskmodem.c.

double coef_out[NBW][8] [static]

Definition at line 89 of file fskmodem.c.


Generated on Mon May 14 04:48:04 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.1