⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xpmr.c

📁 asterisk 是一个很有知名度开源软件
💻 C
📖 第 1 页 / 共 4 页
字号:
	if(pmrChan->rxCtcss->BlankingTimer>0)pmrChan->rxCtcss->BlankingTimer-=points;	if(pmrChan->rxCtcss->BlankingTimer<0)pmrChan->rxCtcss->BlankingTimer=0;    if(thit>=0 && pmrChan->rxCtcss->decode<0 && !pmrChan->rxCtcss->BlankingTimer)    {		pmrChan->rxCtcss->decode=thit;			}	else if(thit<0 && pmrChan->rxCtcss->decode>=0)	{		pmrChan->rxCtcss->BlankingTimer=SAMPLE_RATE_NETWORK/5;		pmrChan->rxCtcss->decode=-1;			for(tnum=0;tnum<CTCSS_NUM_CODES;tnum++)		{		    t_tdet	*ptdet=NULL;			ptdet=&(pmrChan->rxCtcss->tdet[tnum]);		    ptdet->decode=0;			ptdet->z[0]=ptdet->z[1]=ptdet->z[2]=ptdet->z[3]=0;		}	}	//TRACEX((" ctcss_detect() thit %i %i\n",thit,pmrChan->rxCtcss->decode));	return(0);}/*	TxTestTone*/static i16	TxTestTone(t_pmr_chan *pChan, i16 function){	if(function==1)	{		pChan->spsSigGen1->enabled=1;		pChan->spsSigGen1->option=1;		pChan->spsTx->source=pChan->spsSigGen1->sink;	}	else	{		pChan->spsSigGen1->option=3;	}	return 0;}/*		assumes:	sampling rate is 48KS/s	samples are all 16 bits    samples are filtered and decimated by 1/6th*/t_pmr_chan	*createPmrChannel(t_pmr_chan *tChan, i16 numSamples){	i16 i, *inputTmp;	t_pmr_chan 	*pChan;	t_pmr_sps  	*pSps;	t_dec_ctcss	*pDecCtcss;	t_tdet     	*ptdet;	TRACEX(("createPmrChannel(%p,%i)\n",tChan,numSamples));	pChan = (t_pmr_chan *)calloc(sizeof(t_pmr_chan),1);	if(pChan==NULL)	{		printf("createPmrChannel() failed\n");		return(NULL);	}		pChan->nSamplesRx=numSamples;	pChan->nSamplesTx=numSamples;	pChan->index=pmrChanIndex++;	for(i=0;i<CTCSS_NUM_CODES;i++)	{		pChan->rxCtcssMap[i]=-1;		}	pChan->rxCtcssIndex=-1;	if(tChan==NULL)	{		pChan->rxNoiseSquelchEnable=0;		pChan->rxHpfEnable=0;		pChan->rxDeEmpEnable=0;		pChan->rxCenterSlicerEnable=0;		pChan->rxCtcssDecodeEnable=0;		pChan->rxDcsDecodeEnable=0;		pChan->rxCarrierPoint = 17000;		pChan->rxCarrierHyst = 2500;		pChan->rxCtcssFreq=103.5;		pChan->txHpfEnable=0;		pChan->txLimiterEnable=0;		pChan->txPreEmpEnable=0;		pChan->txLpfEnable=1;		pChan->txCtcssFreq=103.5;		pChan->txMixA=TX_OUT_VOICE;		pChan->txMixB=TX_OUT_LSD;	}	else	{		pChan->rxDemod=tChan->rxDemod;		pChan->rxCdType=tChan->rxCdType;		pChan->rxSquelchPoint = tChan->rxSquelchPoint;		pChan->rxCarrierHyst = 3000;		pChan->rxCtcssFreq=tChan->rxCtcssFreq;		for(i=0;i<CTCSS_NUM_CODES;i++)			pChan->rxCtcssMap[i]=tChan->rxCtcssMap[i];				pChan->txMod=tChan->txMod;		pChan->txHpfEnable=1; 		pChan->txLpfEnable=1;		pChan->txCtcssFreq=tChan->txCtcssFreq;		pChan->txMixA=tChan->txMixA;		pChan->txMixB=tChan->txMixB;		pChan->radioDuplex=tChan->radioDuplex;	}	TRACEX(("misc settings \n"));	if(pChan->rxCdType==CD_XPMR_NOISE){		pChan->rxNoiseSquelchEnable=1;	}	if(pChan->rxDemod==RX_AUDIO_FLAT){		pChan->rxHpfEnable=1;		pChan->rxDeEmpEnable=1;	}	pChan->rxCarrierPoint=(pChan->rxSquelchPoint*32767)/100;	pChan->rxCarrierHyst = 3000; //pChan->rxCarrierPoint/15;		pChan->rxDcsDecodeEnable=0;	if(pChan->rxCtcssFreq!=0){		pChan->rxHpfEnable=1;		pChan->rxCenterSlicerEnable=1;		pChan->rxCtcssDecodeEnable=1;		pChan->rxCtcssIndex=CtcssFreqIndex(pChan->rxCtcssFreq);	}	if(pChan->txMod){		pChan->txPreEmpEnable=1;		pChan->txLimiterEnable=1;	}		TRACEX(("calloc buffers \n"));	pChan->pRxDemod 	= calloc(numSamples,2);	pChan->pRxNoise 	= calloc(numSamples,2);	pChan->pRxBase 		= calloc(numSamples,2);	pChan->pRxHpf 		= calloc(numSamples,2);	pChan->pRxLsd 		= calloc(numSamples,2);	pChan->pRxSpeaker 	= calloc(numSamples,2);	pChan->pRxCtcss 	= calloc(numSamples,2);	pChan->pRxDcTrack 	= calloc(numSamples,2);	pChan->pRxLsdLimit 	= calloc(numSamples,2);			pChan->pTxBase  	= calloc(numSamples,2);	pChan->pTxHpf	 	= calloc(numSamples,2);	pChan->pTxPreEmp 	= calloc(numSamples,2);	pChan->pTxLimiter 	= calloc(numSamples,2);	pChan->pTxLsd	 	= calloc(numSamples,2);	pChan->pTxLsdLpf    = calloc(numSamples,2);	pChan->pTxComposite	= calloc(numSamples,2);	pChan->pSigGen0		= calloc(numSamples,2);    pChan->pSigGen1		= calloc(numSamples,2);	pChan->pTxCode      = calloc(numSamples,2);	pChan->pTxOut		= calloc(numSamples,2*2*6);		// output buffer		#if XPMR_DEBUG0 == 1	pChan->pTxPttIn     = calloc(numSamples,2);	pChan->pTxPttOut    = calloc(numSamples,2);	pChan->prxDebug0	= calloc(numSamples,2);	pChan->prxDebug1	= calloc(numSamples,2);	pChan->prxDebug2	= calloc(numSamples,2);	pChan->prxDebug3	= calloc(numSamples,2);	pChan->ptxDebug0	= calloc(numSamples,2);	pChan->ptxDebug1	= calloc(numSamples,2);	pChan->ptxDebug2	= calloc(numSamples,2);	pChan->ptxDebug3	= calloc(numSamples,2);	pChan->pNull		= calloc(numSamples,2);	for(i=0;i<numSamples;i++)pChan->pNull[i]=((i%(numSamples/2))*8000)-4000; 	#endif	TRACEX(("create ctcss\n"));	pDecCtcss = (t_dec_ctcss *)calloc(sizeof(t_dec_ctcss),1);	 	pChan->rxCtcss=pDecCtcss; 	pDecCtcss->enabled=1;	pDecCtcss->gain=1*M_Q8;	pDecCtcss->limit=8192;	pDecCtcss->input=pChan->pRxLsdLimit;	pDecCtcss->testIndex=pChan->rxCtcssIndex;	if(!pDecCtcss->testIndex)pDecCtcss->testIndex=1;	pChan->rxCtcssMap[pChan->rxCtcssIndex]=pChan->rxCtcssIndex;	pDecCtcss->decode=-1;	for(i=0;i<CTCSS_NUM_CODES;i++)	{		ptdet=&(pChan->rxCtcss->tdet[i]);		ptdet->state=1;		ptdet->setpt=(M_Q15*0.067);		   			// 0.069		ptdet->hyst =(M_Q15*0.020);		ptdet->counterFactor=coef_ctcss_div[i];		ptdet->binFactor=(M_Q15*0.135);			  	// was 0.140		ptdet->fudgeFactor=8; 		}	// General Purpose Function Generator	pSps=pChan->spsSigGen1=createPmrSps();	pSps->parentChan=pChan;	pSps->sink=pChan->pSigGen1; 	pSps->numChanOut=1;	pSps->selChanOut=0;	pSps->sigProc=SigGen; 	pSps->nSamples=pChan->nSamplesTx;	pSps->sampleRate=SAMPLE_RATE_NETWORK;	pSps->freq=10000; 						// in increments of 0.1 Hz	pSps->outputGain=(.25*M_Q8);	pSps->option=0;	pSps->interpolate=1;	pSps->decimate=1;	pSps->enabled=0;	// CTCSS ENCODER	pSps = pChan->spsSigGen0 = createPmrSps();	pSps->parentChan=pChan;	pSps->sink=pChan->pTxLsd;  	pSps->sigProc=SigGen; 	pSps->numChanOut=1;	pSps->selChanOut=0;	pSps->nSamples=pChan->nSamplesTx;	pSps->sampleRate=SAMPLE_RATE_NETWORK;	pSps->freq=pChan->txCtcssFreq*10;		// in increments of 0.1 Hz	pSps->outputGain=(0.5*M_Q8);	pSps->option=0;	pSps->interpolate=1;	pSps->decimate=1;	pSps->enabled=0;	// Tx LSD Low Pass Filter	pSps=pChan->spsTxLsdLpf=pSps->nextSps=createPmrSps();	pSps->source=pChan->pTxLsd;	pSps->sink=pChan->pTxLsdLpf;  	pSps->sigProc=pmr_gp_fir;	pSps->enabled=0;	pSps->numChanOut=1;	pSps->selChanOut=0;	pSps->nSamples=pChan->nSamplesTx;	pSps->decimator=pSps->decimate=1;	pSps->interpolate=1;	pSps->inputGain=(1*M_Q8);	pSps->outputGain=(1*M_Q8);	if(pChan->txCtcssFreq>203.0)	{		pSps->ncoef=taps_fir_lpf_250_9_66;		pSps->size_coef=2;		pSps->coef=(void*)coef_fir_lpf_250_9_66;		pSps->nx=taps_fir_lpf_250_9_66;		pSps->size_x=2;		pSps->x=(void*)(calloc(pSps->nx,pSps->size_x));		pSps->calcAdjust=gain_fir_lpf_250_9_66;	}	else	{		pSps->ncoef=taps_fir_lpf_215_9_88;		pSps->size_coef=2;		pSps->coef=(void*)coef_fir_lpf_215_9_88;		pSps->nx=taps_fir_lpf_215_9_88;		pSps->size_x=2;		pSps->x=(void*)(calloc(pSps->nx,pSps->size_x));		pSps->calcAdjust=gain_fir_lpf_215_9_88;	}	pSps->inputGain=(1*M_Q8);	pSps->outputGain=(1*M_Q8);		if(pSps==NULL)printf("Error: calloc(), createPmrChannel()\n");  			// RX Process	TRACEX(("create rx\n"));	pSps = NULL;	// allocate space for first sps and set pointers	pSps=pChan->spsRx=createPmrSps();	pSps->parentChan=pChan;	pSps->source=NULL;					//set when called	pSps->sink=pChan->pRxBase;	pSps->sigProc=pmr_rx_frontend;	pSps->enabled=1;	pSps->decimator=pSps->decimate=6;	pSps->interpolate=pSps->interpolate=1;	pSps->nSamples=pChan->nSamplesRx;	pSps->ncoef=taps_fir_bpf_noise_1;	pSps->size_coef=2;	pSps->coef=(void*)coef_fir_lpf_3K_1;	pSps->coef2=(void*)coef_fir_bpf_noise_1;	pSps->nx=taps_fir_bpf_noise_1;	pSps->size_x=2;	pSps->x=(void*)(calloc(pSps->nx,pSps->size_coef));	pSps->calcAdjust=(gain_fir_lpf_3K_1*256)/0x0100;	pSps->outputGain=(1.0*M_Q8);	pSps->discfactor=2;	  	pSps->hyst=pChan->rxCarrierHyst;	pSps->setpt=pChan->rxCarrierPoint;	pChan->prxSquelchAdjust=&pSps->setpt;	#if XPMR_DEBUG0 == 1	pSps->debugBuff0=pChan->pRxDemod;	pSps->debugBuff1=pChan->pRxNoise;	pSps->debugBuff2=pChan->prxDebug0;	#endif 	// allocate space for next sps and set pointers	// Rx SubAudible Decoder Low Pass Filter	pSps=pSps->nextSps=createPmrSps();	pSps->parentChan=pChan;	pSps->source=pChan->pRxBase;	pSps->sink=pChan->pRxLsd;	pSps->sigProc=pmr_gp_fir;	pSps->enabled=1;	pSps->numChanOut=1;	pSps->selChanOut=0;	pSps->nSamples=pChan->nSamplesRx;	pSps->decimator=pSps->decimate=1;	pSps->interpolate=1;	if(pChan->rxCtcssFreq>203.5)	{		pSps->ncoef=taps_fir_lpf_250_9_66;		pSps->size_coef=2;		pSps->coef=(void*)coef_fir_lpf_250_9_66;		pSps->nx=taps_fir_lpf_250_9_66;		pSps->size_x=2;		pSps->x=(void*)(calloc(pSps->nx,pSps->size_x));		pSps->calcAdjust=gain_fir_lpf_250_9_66;	}	else	{		pSps->ncoef=taps_fir_lpf_215_9_88;		pSps->size_coef=2;		pSps->coef=(void*)coef_fir_lpf_215_9_88;		pSps->nx=taps_fir_lpf_215_9_88;		pSps->size_x=2;		pSps->x=(void*)(calloc(pSps->nx,pSps->size_x));		pSps->calcAdjust=gain_fir_lpf_215_9_88;	}	pSps->inputGain=(1*M_Q8);	pSps->outputGain=(1*M_Q8);	pChan->prxCtcssMeasure=pSps->sink;	pChan->prxCtcssAdjust=&(pSps->outputGain);	 	// allocate space for next sps and set pointers	// CenterSlicer	if(pChan->rxCenterSlicerEnable)	{		pSps=pSps->nextSps=createPmrSps();		pSps->parentChan=pChan;		pSps->source=pChan->pRxLsd;		pSps->sink=pChan->pRxDcTrack;		pSps->buff=pChan->pRxLsdLimit;		pSps->sigProc=CenterSlicer;		pSps->enabled=1;		pSps->nSamples=pChan->nSamplesRx;		pSps->discfactor=800;		pSps->inputGain=(1*M_Q8);		pSps->outputGain=(1*M_Q8);		pSps->setpt=3000;		pSps->inputGainB=1000; 			// limiter set point	}	// allocate space for next sps and set pointers	// Rx HPF	pSps=pSps->nextSps=createPmrSps();	pSps->parentChan=pChan;	pChan->spsRxHpf=pSps;	pSps->source=pChan->pRxBase;	pSps->sink=pChan->pRxHpf;  	pSps->sigProc=pmr_gp_fir;	pSps->enabled=1;	pSps->numChanOut=1;	pSps->selChanOut=0;	pSps->nSamples=pChan->nSamplesRx;	pSps->decimator=pSps->decimate=1;	pSps->interpolate=1;	pSps->ncoef=taps_fir_hpf_300_9_66;	pSps->size_coef=2;	pSps->coef=(void*)coef_fir_hpf_300_9_66;	pSps->nx=taps_fir_hpf_300_9_66;	pSps->size_x=2;	pSps->x=(void*)(calloc(pSps->nx,pSps->size_x));	if(pSps==NULL)printf("Error: calloc(), createPmrChannel()\n"); 	pSps->calcAdjust=gain_fir_hpf_300_9_66;	pSps->inputGain=(1*M_Q8);	pSps->outputGain=(1*M_Q8);	pChan->spsRxOut=pSps;	// allocate space for next sps and set pointers	// Rx DeEmp	if(pChan->rxDeEmpEnable){		pSps=pSps->nextSps=createPmrSps();		pSps->parentChan=pChan;		pChan->spsRxDeEmp=pSps;		pSps->source=pChan->pRxHpf;		pSps->sink=pChan->pRxSpeaker;  		pChan->spsRxOut=pSps;					 // OUTPUT STRUCTURE! maw		pSps->sigProc=gp_inte_00;		pSps->enabled=1;		pSps->nSamples=pChan->nSamplesRx;			pSps->ncoef=taps_int_lpf_300_1_2;		pSps->size_coef=2;		pSps->coef=(void*)coef_int_lpf_300_1_2;			pSps->nx=taps_int_lpf_300_1_2;		pSps->size_x=4;		pSps->x=(void*)(calloc(pSps->nx,pSps->size_x));		if(pSps==NULL)printf("Error: calloc(), createPmrChannel()\n"); 		pSps->calcAdjust=gain_int_lpf_300_1_2/2;		pSps->inputGain=(1.0*M_Q8);		pSps->outputGain=(1.0*M_Q8);		pChan->prxVoiceMeasure=pSps->sink;		pChan->prxVoiceAdjust=&(pSps->outputGain);		}	if(pChan->rxDelayLineEnable)	{		TRACEX(("create delayline\n"));		pSps=pChan->spsDelayLine=pSps->nextSps=createPmrSps();		pSps->sigProc=DelayLine;		pSps->source=pChan->pRxSpeaker;	 		pSps->sink=pChan->pRxSpeaker;		pSps->enabled=0;		pSps->inputGain=1*M_Q8;			pSps->outputGain=1*M_Q8;		pSps->nSamples=pChan->nSamplesRx;		pSps->buffSize=4096;		pSps->buff=calloc(4096,2);	 		// one second maximum		pSps->buffLead = (SAMPLE_RATE_NETWORK*0.100);		pSps->buffOutIndex=0;	}	if(pChan->rxCdType==CD_XPMR_VOX)	{		TRACEX(("create vox measureblock\n"));		pSps=pChan->spsRxVox=pSps->nextSps=createPmrSps();		pSps->sigProc=MeasureBlock;		pSps->parentChan=pChan;		pSps->source=pChan->pRxBase;		pSps->sink=pChan->prxDebug1;		pSps->inputGain=1*M_Q8;			pSps->outputGain=1*M_Q8;		pSps->nSamples=pChan->nSamplesRx;		pSps->discfactor=3;		pSps->setpt=(0.01*M_Q15);		pSps->hyst=(pSps->setpt/10);		pSps->enabled=1;	}	// tuning measure block	pSps=pChan->spsMeasure=pSps->nextSps=createPmrSps();	pSps->parentChan=pChan;	pSps->source=pChan->spsRx->sink;					 	pSps->sink=pChan->prxDebug2;	pSps->sigProc=MeasureBlock;	pSps->enabled=0;	pSps->nSamples=pChan->nSamplesRx;	pSps->discfactor=10;	    	pSps->nextSps=NULL;		// last sps in chain RX	// CREATE TRANSMIT CHAIN	TRACEX((" create tx\n"));	inputTmp=NULL;	pSps = NULL;	// allocate space for first sps and set pointers	// Tx HPF SubAudible	if(pChan->txHpfEnable)	{		pSps=createPmrSps();		pChan->spsTx=pSps;		pSps->source=pChan->pTxBase;		pSps->sink=pChan->pTxHpf;  		pSps->sigProc=pmr_gp_fir;		pSps->enabled=1;		pSps->numChanOut=1;		pSps->selChanOut=0;		pSps->nSamples=pChan->nSamplesTx;		pSps->decimator=pSps->decimate=1;		pSps->interpolate=1;		pSps->ncoef=taps_fir_hpf_300_9_66;		pSps->size_coef=2;		pSps->coef=(void*)coef_fir_hpf_300_9_66;		pSps->nx=taps_fir_hpf_300_9_66;		pSps->size_x=2;		pSps->x=(void*)(calloc(pSps->nx,pSps->size_x));		if(pSps==NULL)printf("Error: calloc(), createPmrChannel()\n"); 		pSps->calcAdjust=gain_fir_hpf_300_9_66;		pSps->inputGain=(1*M_Q8);		pSps->outputGain=(1*M_Q8);		inputTmp=pChan->pTxHpf;	}	// Tx PreEmphasis	if(pChan->txPreEmpEnable)	{		if(pSps==NULL) pSps=pChan->spsTx=createPmrSps();		else pSps=pSps->nextSps=createPmrSps();				pSps->parentChan=pChan;		pSps->source=inputTmp;		pSps->sink=pChan->pTxPreEmp;  				pSps->sigProc=gp_diff;		pSps->enabled=1;		pSps->nSamples=pChan->nSamplesTx;			pSps->ncoef=taps_int_hpf_4000_1_2;		pSps->size_coef=2;		pSps->coef=(void*)coef_int_hpf_4000_1_2;			pSps->nx=taps_int_hpf_4000_1_2;		pSps->size_x=2;		pSps->x=(void*)(calloc(pSps->nx,pSps->size_x));		if(pSps==NULL)printf("Error: calloc(), createPmrChannel()\n");		pSps->outputGain=(1*M_Q8);		pSps->calcAdjust=gain_int_hpf_4000_1_2;		pSps->inputGain=(1*M_Q8);		pSps->outputGain=(1*M_Q8);		inputTmp=pSps->sink;	}	// Tx Limiter	if(pChan->txLimiterEnable)	{		if(pSps==NULL) pSps=pChan->spsTx=createPmrSps();		else pSps=pSps->nextSps=createPmrSps();		pSps->source=inputTmp;		pSps->sink=pChan->pTxLimiter;		pSps->sigProc=SoftLimiter;		pSps->enabled=1;		pSps->nSamples=pChan->nSamplesTx;		pSps->inputGain=(1*M_Q8);		pSps->outputGain=(1*M_Q8);		pSps->setpt=12000;		inputTmp=pSps->sink;	}	// Composite Mix of Voice and LSD	if((pChan->txMixA==TX_OUT_COMPOSITE)||(pChan->txMixB==TX_OUT_COMPOSITE))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -