Fix unused-but-set-variable warnings
[asterisk/asterisk.git] / channels / xpmr / xpmr.c
index 5e1b0f5..4bfc2c5 100755 (executable)
@@ -56,7 +56,9 @@
 #include <string.h>
 #include <unistd.h>
 #include <sys/ioctl.h>
+#ifdef HAVE_SYS_IO_H
 #include <sys/io.h>
+#endif
 #include <fcntl.h>
 #include <sys/time.h>
 #include <stdlib.h>
@@ -76,13 +78,13 @@ static int ppdrvdev=0;
 /*
        Trace Routines
 */
-void strace(i16 point, t_sdbg *sdbg, i16 index, i16 value)
+void strace(i16 point, t_sdbg *sdbg, i16 idx, i16 value)
 {
        // make dbg_trace buffer in structure
        if(!sdbg->mode || sdbg->point[point]<0){
                return;
     } else {
-               sdbg->buffer[(index*XPMR_DEBUG_CHANS) + sdbg->point[point]] = value;
+               sdbg->buffer[(idx*XPMR_DEBUG_CHANS) + sdbg->point[point]] = value;
        }
 }
 /*
@@ -155,7 +157,7 @@ i16 string_parse(char *src, char **dest, char ***ptrs)
        TRACEJ(2,(" source len = %i\n",slen));
 
        pd=*dest;
-       if(pd) free(pd);
+       free(pd);
     pd=calloc(slen+1,1);
        memcpy(pd,src,slen);
        *dest=pd;
@@ -268,8 +270,8 @@ i16 code_string_parse(t_pmr_chan *pChan)
        // Do Receive Codes String
        for(i=0;i<pChan->numrxcodes;i++)
        {
-               i16 ii,ri,ti;
-               float f;
+               i16 ri,_ti;
+               float _f;
 
                p=pChan->pStr=pChan->pRxCode[i];
 
@@ -277,32 +279,33 @@ i16 code_string_parse(t_pmr_chan *pChan)
                if(!xpmrx(pChan,XXO_LSDCODEPARSE_1))
                #endif
                {
-                       sscanf(p,"%f",&f);
-                       ri=CtcssFreqIndex(f);
+                       sscanf(p, "%30f", &_f);
+                       ri=CtcssFreqIndex(_f);
                        if(ri>maxctcssindex)maxctcssindex=ri;
 
-                       sscanf(pChan->pTxCode[i],"%f",&f);
-                   ti=CtcssFreqIndex(f);
-                       if(f>maxctcsstxfreq)maxctcsstxfreq=f;
+                       sscanf(pChan->pTxCode[i], "%30f", &_f);
+                   _ti=CtcssFreqIndex(_f);
+                       if(_f>maxctcsstxfreq)maxctcsstxfreq=_f;
 
-                       if(ri>CTCSS_NULL && ti>CTCSS_NULL)
+                       if(ri>CTCSS_NULL && _ti>CTCSS_NULL)
                        {
                                pChan->b.ctcssRxEnable=pChan->b.ctcssTxEnable=1;
-                               pChan->rxCtcssMap[ri]=ti;
+                               pChan->rxCtcssMap[ri]=_ti;
                                pChan->numrxctcssfreqs++;
-                               TRACEF(1,("pChan->rxctcss[%i]=%s  pChan->rxCtcssMap[%i]=%i\n",i,pChan->rxctcss[i],ri,ti));
+                               TRACEF(1,("pChan->rxctcss[%i]=%s  pChan->rxCtcssMap[%i]=%i\n",i,pChan->rxctcss[i],ri,_ti));
                        }
-                       else if(ri>CTCSS_NULL && f==0)
+                       else if(ri>CTCSS_NULL && _f==0)
                        {
                                pChan->b.ctcssRxEnable=1;
                                pChan->rxCtcssMap[ri]=CTCSS_RXONLY;
                                pChan->numrxctcssfreqs++;
-                               TRACEF(1,("pChan->rxctcss[%i]=%s  pChan->rxCtcssMap[%i]=%i RXONLY\n",i,pChan->rxctcss[i],ri,ti));
+                               TRACEF(1,("pChan->rxctcss[%i]=%s  pChan->rxCtcssMap[%i]=%i RXONLY\n",i,pChan->rxctcss[i],ri,_ti));
                        }
                        else
                        {
+                               i16 _ii;
                                pChan->numrxctcssfreqs=0;
-                               for(ii=0;ii<CTCSS_NUM_CODES;ii++) pChan->rxCtcssMap[ii]=CTCSS_NULL;
+                               for(_ii=0;_ii<CTCSS_NUM_CODES;_ii++) pChan->rxCtcssMap[_ii]=CTCSS_NULL;
                                TRACEF(1,("WARNING: Invalid Channel code detected and ignored. %i %s %s \n",i,pChan->pRxCode[i],pChan->pTxCode[i]));
                        }
                }
@@ -347,7 +350,7 @@ i16 code_string_parse(t_pmr_chan *pChan)
        if(!lsd_code_parse(pChan,3))
        #endif
        {
-               sscanf(p,"%f",&f);
+               sscanf(p, "%30f", &f);
            ti=CtcssFreqIndex(f);
                if(f>maxctcsstxfreq)maxctcsstxfreq=f;
 
@@ -477,7 +480,7 @@ i16 pmr_rx_frontend(t_pmr_sps *mySps)
        #define DCgainBpfNoise  65536
 
        i16 samples,iOutput, *input, *output, *noutput;
-       i16 *x, *coef, *coef2;
+       i16 *x, *coef;
     i32 i, naccum, outputGain, calcAdjust;
        i64 y;
        i16 nx, hyst, setpt, compOut;
@@ -497,7 +500,6 @@ i16 pmr_rx_frontend(t_pmr_sps *mySps)
 
        nx        = mySps->nx;
        coef      = mySps->coef;
-       coef2     = mySps->coef2;
 
        calcAdjust = mySps->calcAdjust;
        outputGain = mySps->outputGain;
@@ -776,7 +778,7 @@ i16 gp_inte_00(t_pmr_sps *mySps)
        i16 npoints;
        i16 *input, *output;
 
-       i32 inputGain, outputGain,calcAdjust;
+       i32 outputGain;
        i32     i;
        i32 accum;
 
@@ -791,9 +793,7 @@ i16 gp_inte_00(t_pmr_sps *mySps)
 
        npoints=mySps->nSamples;
 
-       inputGain=mySps->inputGain;
        outputGain=mySps->outputGain;
-       calcAdjust=mySps->calcAdjust;
 
        coeff00=((i16*)mySps->coef)[0];
        coeff01=((i16*)mySps->coef)[1];
@@ -821,13 +821,12 @@ i16 gp_diff(t_pmr_sps *mySps)
 {
        i16 *input, *output;
        i16 npoints;
-       i32 inputGain, outputGain, calcAdjust;
+       i32 outputGain, calcAdjust;
        i32     i;
        i32 temp0,temp1;
        i16 x0;
-       i32 y0;
+       i32 _y0;
        i16 a0,a1;
-       i16 b0;
        i16 *coef;
        i16 *x;
 
@@ -836,7 +835,6 @@ i16 gp_diff(t_pmr_sps *mySps)
 
        npoints=mySps->nSamples;
 
-       inputGain=mySps->inputGain;
        outputGain=mySps->outputGain;
        calcAdjust=mySps->calcAdjust;
 
@@ -844,7 +842,6 @@ i16 gp_diff(t_pmr_sps *mySps)
        x=(i16*)(mySps->x);
        a0=coef[0];
        a1=coef[1];
-       b0=coef[2];
 
        x0=x[0];
 
@@ -855,12 +852,12 @@ i16 gp_diff(t_pmr_sps *mySps)
                temp0 = x0 * a1;
                   x0 = input[i];
                temp1 = input[i] * a0;
-                  y0 = (temp0 + temp1)/calcAdjust;
-                  y0 =(y0*outputGain)/M_Q8;
+                 _y0 = (temp0 + temp1)/calcAdjust;
+                 _y0 = (_y0*outputGain)/M_Q8;
                
-               if(y0>32766)y0=32766;
-               else if(y0<-32766)y0=-32766;
-        output[i]=y0;
+               if(_y0>32766)_y0=32766;
+               else if(_y0<-32766)_y0=-32766;
+        output[i]=_y0;
     }
 
        x[0]=x0;
@@ -872,10 +869,10 @@ i16 gp_diff(t_pmr_sps *mySps)
 */
 i16 CenterSlicer(t_pmr_sps *mySps)
 {
-       i16 npoints,lhit,uhit;
+       i16 npoints/*, lhit, uhit*/;
        i16 *input, *output, *buff;
 
-       i32 inputGain, outputGain, inputGainB;
+       i32 inputGainB;
        i32     i;
        i32 accum;
 
@@ -898,8 +895,6 @@ i16 CenterSlicer(t_pmr_sps *mySps)
 
        npoints=mySps->nSamples;
 
-       inputGain=mySps->inputGain;
-       outputGain=mySps->outputGain;
        inputGainB=mySps->inputGainB;
 
        amax=mySps->amax;
@@ -914,28 +909,31 @@ i16 CenterSlicer(t_pmr_sps *mySps)
 
        for(i=0;i<npoints;i++)
        {
+               #if XPMR_DEBUG0 == 1
+               static i32 tfx=0;
+               #endif
                accum=input[i];
 
-               lhit=uhit=0;
+               /* lhit=uhit=0; */
 
                if(accum>amax)
                {
                        amax=accum;
-                       uhit=1;
+                       /* uhit=1; */
                        if(amin<(amax-setpt))
                        {
                                amin=(amax-setpt);
-                               lhit=1;
+                               /* lhit=1; */
                        }
                }
                else if(accum<amin)
                {
                        amin=accum;
-                       lhit=1;
+                       /* lhit=1; */
                        if(amax>(amin+setpt))
                        {
                                amax=(amin+setpt);
-                               uhit=1;
+                               /* uhit=1; */
                        }
                }
                #if 0
@@ -975,7 +973,6 @@ i16 CenterSlicer(t_pmr_sps *mySps)
                #if 0
                mySps->parentChan->pRxLsdCen[i]=center;         // trace center ref
                #else
-               static i32 tfx=0;
                if((tfx++/8)&1)                                                         // trace min/max levels
                        mySps->parentChan->pRxLsdCen[i]=amax;
                else
@@ -1005,7 +1002,6 @@ i16 MeasureBlock(t_pmr_sps *mySps)
        i16 npoints;
        i16 *input, *output;
 
-       i32 inputGain, outputGain;
        i32     i;
        i32 accum;
 
@@ -1035,9 +1031,6 @@ i16 MeasureBlock(t_pmr_sps *mySps)
 
        npoints=mySps->nSamples;
 
-       inputGain=mySps->inputGain;
-       outputGain=mySps->outputGain;
-
        amax=mySps->amax;
        amin=mySps->amin;
        setpt=mySps->setpt;
@@ -1097,7 +1090,7 @@ i16 SoftLimiter(t_pmr_sps *mySps)
        //i16 samples, lhit,uhit;
        i16 *input, *output;
 
-       i32 inputGain, outputGain;
+       i32 /*inputGain, */outputGain;
        i32     i;
        i32 accum;
        i32  tmp;
@@ -1106,12 +1099,11 @@ i16 SoftLimiter(t_pmr_sps *mySps)
        i32  amin;                      // buffer amplitude minimum
        //i32  apeak;           // buffer amplitude peak
        i32  setpt;                     // amplitude set point for amplitude comparator
-       i16  compOut;           // amplitude comparator output
 
        input   = mySps->source;
        output  = mySps->sink;
 
-       inputGain=mySps->inputGain;
+       /* inputGain=mySps->inputGain; */
        outputGain=mySps->outputGain;
 
        npoints=mySps->nSamples;
@@ -1132,7 +1124,6 @@ i16 SoftLimiter(t_pmr_sps *mySps)
                    tmp=((accum-setpt)*4)/128;
                    accum=setpt+tmp;
                        if(accum>amax)accum=amax;
-                       compOut=1;
                        accum=setpt;
                }
                else if(accum<-setpt)
@@ -1140,7 +1131,6 @@ i16 SoftLimiter(t_pmr_sps *mySps)
                    tmp=((accum+setpt)*4)/128;
                    accum=(-setpt)-tmp;
                        if(accum<amin)accum=amin;
-                       compOut=1;
                        accum=-setpt;
                }
 
@@ -1387,8 +1377,8 @@ i16 DelayLine(t_pmr_sps *mySps)
 i16 ctcss_detect(t_pmr_chan *pChan)
 {
        i16 i,points2do,*pInput,hit,thit,relax;
-       i16 tnum, tmp,indexNow,gain,diffpeak;
-       i16 difftrig;
+       i16 tnum, tmp,indexNow,diffpeak;
+       /* i16 difftrig; */
        i16 tv0,tv1,tv2,tv3,indexDebug;
        i16 points=0;
        i16 indexWas=0;
@@ -1403,10 +1393,11 @@ i16 ctcss_detect(t_pmr_chan *pChan)
 
        relax  = pChan->rxCtcss->relax;
        pInput = pChan->rxCtcss->input;
-       gain   = pChan->rxCtcss->gain;
 
+       /*
        if(relax) difftrig=(-0.1*M_Q15);
        else difftrig=(-0.05*M_Q15);
+       */
 
        thit=hit=-1;
 
@@ -1550,7 +1541,7 @@ i16 ctcss_detect(t_pmr_chan *pChan)
                        }
                        #endif
                        indexWas=indexNow;
-                       ptdet->zIndex=(++ptdet->zIndex)%4;
+                       ptdet->zIndex=(ptdet->zIndex + 1) % 4;
                }
                ptdet->counter-=(points2do*CTCSS_SCOUNT_MUL);
 
@@ -2014,7 +2005,7 @@ t_pmr_chan        *createPmrChannel(t_pmr_chan *tChan, i16 numSamples)
        pSps->sigProc=pmr_rx_frontend;
        pSps->enabled=1;
        pSps->decimator=pSps->decimate=6;
-       pSps->interpolate=pSps->interpolate=1;
+       pSps->interpolate=1;
        pSps->nSamples=pChan->nSamplesRx;
        pSps->ncoef=taps_fir_bpf_noise_1;
        pSps->size_coef=2;
@@ -2400,6 +2391,9 @@ t_pmr_chan        *createPmrChannel(t_pmr_chan *tChan, i16 numSamples)
 */
 i16 destroyPmrChannel(t_pmr_chan *pChan)
 {
+       #if XPMR_DEBUG0 == 1
+       i16 i;
+       #endif
        t_pmr_sps       *pmr_sps, *tmp_sps;
 
        TRACEF(1,("destroyPmrChannel()\n"));
@@ -2442,7 +2436,6 @@ i16 destroyPmrChannel(t_pmr_chan *pChan)
        free(pChan->rxCtcss->pDebug0);
        free(pChan->rxCtcss->pDebug1);
 
-       i16 i;
        for(i=0;i<CTCSS_NUM_CODES;i++)
        {
                free(pChan->rxCtcss->tdet[i].pDebug0);
@@ -3220,6 +3213,11 @@ void dedrift(t_pmr_chan *pChan)
        }
        else if(pChan->dd.initcnt==0)
        {
+               const i32 a0 =  26231;
+               const i32 a1 =  26231;
+               const i32 b0 =  32768;
+               const i32 b1 = -32358;
+               const i32 dg =  128;
                void *vptr;
                i16 inputindex;
                i16 indextweak;
@@ -3258,11 +3256,6 @@ void dedrift(t_pmr_chan *pChan)
                pChan->dd.err = pChan->dd.lead - (pChan->dd.buffersize/2);
 
                // WinFilter, IIR Fs=50, Fc=0.1
-               const i32 a0 =  26231;
-               const i32 a1 =  26231;
-               const i32 b0 =  32768;
-               const i32 b1 = -32358;
-               const i32 dg =  128;
                pChan->dd.x1 = pChan->dd.x0;
            pChan->dd.y1 = pChan->dd.y0;
                pChan->dd.x0 = pChan->dd.err;