From: dttsp Date: Fri, 29 Apr 2005 21:39:06 +0000 (+0000) Subject: changes to speechproc, correct IQ -- restore squelch in sdr.c -- other minor stuff X-Git-Url: https://git.rkrishnan.org/pf/content/en//%22%22?a=commitdiff_plain;h=e6378ca554f94a8bf2da81d49929ae244d004b73;p=dttsp.git changes to speechproc, correct IQ -- restore squelch in sdr.c -- other minor stuff --- diff --git a/jDttSP/correctIQ.c b/jDttSP/correctIQ.c index 3fc3e52..ef261f7 100644 --- a/jDttSP/correctIQ.c +++ b/jDttSP/correctIQ.c @@ -37,10 +37,10 @@ Bridgewater, NJ 08807 #include IQ -newCorrectIQ(REAL phaseadjustment, REAL gainadjustment) { +newCorrectIQ(REAL phase, REAL gain) { IQ iq = (IQ) safealloc(1, sizeof(iqstate), "IQ state"); - iq->phase = phaseadjustment; - iq->gain = gainadjustment; + iq->phase = phase; + iq->gain = gain; return iq; } diff --git a/jDttSP/correctIQ.h b/jDttSP/correctIQ.h index 0077a0a..fcbf749 100644 --- a/jDttSP/correctIQ.h +++ b/jDttSP/correctIQ.h @@ -7,7 +7,7 @@ typedef struct _iqstate { REAL phase, gain; } *IQ, iqstate; -extern IQ newCorrectIQ(REAL phaseadjusment, REAL gainadjustment); +extern IQ newCorrectIQ(REAL phase, REAL gain); extern void delCorrectIQ(IQ iq); extern void correctIQ(CXB sigbuf, IQ iq); diff --git a/jDttSP/sdr.c b/jDttSP/sdr.c index a198d21..5028ac3 100644 --- a/jDttSP/sdr.c +++ b/jDttSP/sdr.c @@ -444,12 +444,13 @@ do_rx_pre(void) { OSCCdata(rx.osc.gen, i)); } - /* filtering, metering, & AGC */ + /* filtering, metering, squelch, & AGC */ if (rx.mode != SPEC) { if (rx.tick == 0) reset_OvSv(rx.filt.ovsv); filter_OvSv(rx.filt.ovsv); CXBhave(rx.buf.o) = CXBhave(rx.buf.i); - if (uni.meter.flag) do_meter(CXBbase(rx.buf.o), uni.buflen); + if (uni.meter.flag) do_meter(CXBbase(rx.buf.o), uni.buflen); + if (should_do_rx_squelch()) do_squelch(); if (rx.agc.flag) DigitalAgc(rx.agc.gen, rx.tick); } else if (uni.meter.flag) do_meter(CXBbase(rx.buf.o), uni.buflen); @@ -671,7 +672,7 @@ process_samples(float *bufl, float *bufr, int n) { do_rx(), rx.tick++; for (i = 0; i < n; i++) - bufl[i] = (float)CXBimag(rx.buf.o, i), bufr[i] = (float)CXBreal(rx.buf.o, i); + bufl[i] = (float) CXBimag(rx.buf.o, i), bufr[i] = (float) CXBreal(rx.buf.o, i); CXBhave(rx.buf.o) = n; break; @@ -683,7 +684,7 @@ process_samples(float *bufl, float *bufr, int n) { do_tx(), tx.tick++; for (i = 0; i < n; i++) - bufl[i] = (float)CXBimag(tx.buf.o, i), bufr[i] = (float)CXBreal(tx.buf.o, i); + bufl[i] = (float) CXBimag(tx.buf.o, i), bufr[i] = (float) CXBreal(tx.buf.o, i); CXBhave(tx.buf.o) = n; break; } diff --git a/jDttSP/speechproc.c b/jDttSP/speechproc.c index 505304d..2d31126 100644 --- a/jDttSP/speechproc.c +++ b/jDttSP/speechproc.c @@ -1,8 +1,9 @@ -/* speechproc.c +/* speechproc.h This file is part of a program that implements a Software-Defined Radio. -Copyright (C) 2004 by Frank Brickle, AB2KT and Bob McGwier, N4HY +Copyright (C) 2004 by Frank Brickle, AB2KT and Bob McGwier, N4HY, Phil Harman, VK6APH +Based on Visual Basic code for SDR by Phil Harman This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -48,6 +49,7 @@ newSpeechProc(REAL K, REAL MaxCompression, COMPLEX *spdat, int size) { void delSpeechProc(SpeechProc sp) { if (sp) { + delRLB(sp->CG); delCXB(sp->SpeechProcessorBuffer); safefree((char *) sp); } @@ -57,27 +59,24 @@ void SpeechProcessor(SpeechProc sp) { int i; REAL r = 0.0, Mag; + + // K was 0.4 in VB version, this value is better, perhaps due to filters that follow? for (i = 0; i < sp->size; i++) - r = max(r, Cmag(CXBdata(sp->SpeechProcessorBuffer, i))); - Mag = Cmag(CXBdata(sp->SpeechProcessorBuffer, 0)); - if (Mag > 0.0) { - RLBdata(sp->CG, 0) = sp->LastCG * (1.0 - sp->K) + (sp->K * r / Mag); - if (RLBdata(sp->CG, 0) > sp->MaxGain) - RLBdata(sp->CG, 0) = sp->MaxGain; - } else - RLBdata(sp->CG, 0) = 1.0; - for (i = 1; i < sp->size; i++) { - Mag = Cmag(CXBdata(sp->SpeechProcessorBuffer, i)); - if (Mag > 0.0) { - RLBdata(sp->CG, i) = - RLBdata(sp->CG, i - 1) * (1 - sp->K) + (sp->K * r / Mag); + r = max(r, Cmag(CXBdata(sp->SpeechProcessorBuffer, i))); // find the peak magnitude value in the sample buffer + RLBdata(sp->CG, 0) = sp->LastCG; // restore from last time + for (i = 1; i <= sp->size ; i++) { + Mag = Cmag(CXBdata(sp->SpeechProcessorBuffer, i - 1)); + if (Mag != 0.0) { + RLBdata(sp->CG, i) = RLBdata(sp->CG, i - 1) * (1 - sp->K) + (sp->K * r / Mag); // Frerking's formula if (RLBdata(sp->CG, i) > sp->MaxGain) RLBdata(sp->CG, i) = sp->MaxGain; } else - RLBdata(sp->CG, i) = 1.0; + RLBdata(sp->CG, i) = sp->MaxGain; } - sp->LastCG = RLBdata(sp->CG, sp->size - 1); - for (i = 0; i < sp->size; i++) - CXBdata(sp->SpeechProcessorBuffer, i) = - Cscl(CXBdata(sp->SpeechProcessorBuffer, i), RLBdata(sp->CG, i)); + sp->LastCG = RLBdata(sp->CG, sp->size); // save for next time + + for (i = 0; i < sp->size; i++) // multiply each sample by its gain constant + CXBdata(sp->SpeechProcessorBuffer, i) = Cscl(CXBdata(sp->SpeechProcessorBuffer, i), + RLBdata(sp->CG, i)); } + diff --git a/jDttSP/speechproc.h b/jDttSP/speechproc.h index cd69331..3112078 100644 --- a/jDttSP/speechproc.h +++ b/jDttSP/speechproc.h @@ -44,7 +44,7 @@ typedef struct _speechprocessor { int size; RLB CG; CXB SpeechProcessorBuffer; - REAL LastCG, K, MaxGain; + REAL LastCG, K, MaxGain, Threshold; } speech_proc, *SpeechProc; extern SpeechProc newSpeechProc(REAL, REAL, COMPLEX *, int);