diff --git a/src/blank/blank.cxx b/src/blank/blank.cxx index 1c779a7b..a9067a54 100644 --- a/src/blank/blank.cxx +++ b/src/blank/blank.cxx @@ -114,9 +114,8 @@ complex BLANK::mixer(complex in, double f) z = in * complex( cos(phaseacc), sin(phaseacc) ); phaseacc -= TWOPI * f / corrRxSampleRate(); - if (phaseacc > TWOPI) phaseacc -= TWOPI; - if (phaseacc < -TWOPI) phaseacc += TWOPI; - + if (phaseacc < 0) phaseacc += TWOPI; + return z; } diff --git a/src/contestia/contestia.cxx b/src/contestia/contestia.cxx index 1e81d4e8..f29baf3a 100644 --- a/src/contestia/contestia.cxx +++ b/src/contestia/contestia.cxx @@ -46,8 +46,8 @@ double contestia::nco(double freq) { preamblephase += 2.0 * M_PI * freq / samplerate; - if (preamblephase > M_PI) - preamblephase -= 2.0 * M_PI; + if (preamblephase > TWOPI) + preamblephase -= TWOPI; return cos(preamblephase); } diff --git a/src/cw_rtty/cw.cxx b/src/cw_rtty/cw.cxx index 7266f3b4..314a6c84 100644 --- a/src/cw_rtty/cw.cxx +++ b/src/cw_rtty/cw.cxx @@ -536,10 +536,7 @@ cmplx cw::mixer(cmplx in) z = z * in; phaseacc += TWOPI * frequency / samplerate; - if (phaseacc > M_PI) - phaseacc -= TWOPI; - else if (phaseacc < M_PI) - phaseacc += TWOPI; + if (phaseacc > TWOPI) phaseacc -= TWOPI; return z; } @@ -618,10 +615,7 @@ void cw::rx_FFTprocess(const double *buf, int len) z = cmplx ( *buf * cos(FFTphase), *buf * sin(FFTphase) ); FFTphase += TWOPI * frequency / samplerate; - if (FFTphase > M_PI) - FFTphase -= TWOPI; - else if (FFTphase < M_PI) - FFTphase += TWOPI; + if (FFTphase > TWOPI) FFTphase -= TWOPI; buf++; @@ -655,10 +649,7 @@ void cw::rx_FIRprocess(const double *buf, int len) buf++; FIRphase += TWOPI * frequency / samplerate; - if (FIRphase > M_PI) - FIRphase -= TWOPI; - else if (FIRphase < M_PI) - FIRphase += TWOPI; + if (FIRphase > TWOPI) FIRphase -= TWOPI; if (cw_FIR_filter->run ( z, z )) { @@ -910,8 +901,7 @@ inline double cw::nco(double freq) { phaseacc += 2.0 * M_PI * freq / samplerate; - if (phaseacc > M_PI) - phaseacc -= 2.0 * M_PI; + if (phaseacc > TWOPI) phaseacc -= TWOPI; return sin(phaseacc); } @@ -920,8 +910,7 @@ inline double cw::qsknco() { qskphase += 2.0 * M_PI * 1000 / samplerate; - if (qskphase > M_PI) - qskphase -= 2.0 * M_PI; + if (qskphase > TWOPI) qskphase -= TWOPI; return sin(qskphase); } diff --git a/src/cw_rtty/rtty.cxx b/src/cw_rtty/rtty.cxx index 920159f4..2ba19ced 100644 --- a/src/cw_rtty/rtty.cxx +++ b/src/cw_rtty/rtty.cxx @@ -843,8 +843,7 @@ double rtty::nco(double freq) { phaseacc += TWOPI * freq / samplerate; - if (phaseacc > M_PI) - phaseacc -= TWOPI; + if (phaseacc > TWOPI) phaseacc -= TWOPI; return cos(phaseacc); } @@ -853,9 +852,7 @@ double rtty::FSKnco() { FSKphaseacc += TWOPI * 1000 / samplerate; - if (FSKphaseacc > M_PI) - - FSKphaseacc -= TWOPI; + if (FSKphaseacc > TWOPI) FSKphaseacc -= TWOPI; return sin(FSKphaseacc); @@ -1246,7 +1243,8 @@ Oscillator::Oscillator( double samplerate ) double Oscillator::Update( double frequency ) { m_phase += frequency/m_samplerate * TWOPI; - if ( m_phase > M_PI ) m_phase -= TWOPI; + if ( m_phase > TWOPI ) m_phase -= TWOPI; + return ( sin( m_phase ) ); } diff --git a/src/dominoex/dominoex.cxx b/src/dominoex/dominoex.cxx index 2c736b1a..0262629b 100644 --- a/src/dominoex/dominoex.cxx +++ b/src/dominoex/dominoex.cxx @@ -335,10 +335,8 @@ cmplx dominoex::mixer(int n, cmplx in) z = cmplx( cos(phase[n]), sin(phase[n])); z = z * in; phase[n] -= TWOPI * f / samplerate; - if (phase[n] > M_PI) - phase[n] -= TWOPI; - else if (phase[n] < M_PI) - phase[n] += TWOPI; + if (phase[n] < 0) phase[n] += TWOPI; + return z; } @@ -632,10 +630,7 @@ void dominoex::sendtone(int tone, int duration) for (int i = 0; i < symlen; i++) { outbuf[i] = cos(txphase); txphase -= phaseincr; - if (txphase > M_PI) - txphase -= TWOPI; - else if (txphase < M_PI) - txphase += TWOPI; + if (txphase < 0) txphase += TWOPI; } ModulateXmtr(outbuf, symlen); } diff --git a/src/feld/feld.cxx b/src/feld/feld.cxx index 78d2ae04..2047c75e 100644 --- a/src/feld/feld.cxx +++ b/src/feld/feld.cxx @@ -222,10 +222,7 @@ cmplx feld::mixer(cmplx in) rxphacc -= 2.0 * M_PI * frequency / samplerate; - if (rxphacc > M_PI) - rxphacc -= 2.0 * M_PI; - else if (rxphacc < M_PI) - rxphacc += 2.0 * M_PI; + if (rxphacc < 0) rxphacc += TWOPI; return z; } @@ -451,8 +448,7 @@ double feld::nco(double freq) txphacc += 2.0 * M_PI * freq / samplerate; - if (txphacc > M_PI) - txphacc -= 2.0 * M_PI; + if (txphacc > TWOPI) txphacc -= TWOPI; return x; } diff --git a/src/mfsk/mfsk.cxx b/src/mfsk/mfsk.cxx index f0e8b7a6..241310bb 100644 --- a/src/mfsk/mfsk.cxx +++ b/src/mfsk/mfsk.cxx @@ -677,8 +677,7 @@ cmplx mfsk::mixer(cmplx in, double f) z = in * cmplx( cos(phaseacc), sin(phaseacc) ); phaseacc -= TWOPI * f / samplerate; - if (phaseacc > TWOPI) phaseacc -= TWOPI; - if (phaseacc < -TWOPI) phaseacc += TWOPI; + if (phaseacc < 0) phaseacc += TWOPI; return z; } @@ -918,10 +917,7 @@ void mfsk::sendsymbol(int sym) for (int i = 0; i < symlen; i++) { outbuf[i] = cos(phaseacc); phaseacc -= phaseincr; - if (phaseacc > M_PI) - phaseacc -= TWOPI; - else if (phaseacc < M_PI) - phaseacc += TWOPI; + if (phaseacc < 0) phaseacc += TWOPI; } transmit (outbuf, symlen); } @@ -994,8 +990,7 @@ void mfsk::sendpic(unsigned char *data, int len) for (j = 0; j < TXspp; j++) { *ptr++ = cos(phaseacc); phaseacc += TWOPI * f / samplerate; - if (phaseacc > M_PI) - phaseacc -= 2.0 * M_PI; + if (phaseacc > TWOPI) phaseacc -= TWOPI; } } @@ -1011,8 +1006,7 @@ void mfsk::flush_xmt_filter(int n) for (int i = 0; i < n; i++) { outbuf[i] = cos(phaseacc); phaseacc += TWOPI * (reverse ? f2 : f1) / samplerate; - if (phaseacc > M_PI) - phaseacc -= 2.0 * M_PI; + if (phaseacc > TWOPI) phaseacc -= TWOPI; } transmit (outbuf, tracepair.delay); } diff --git a/src/psk/psk.cxx b/src/psk/psk.cxx index 46bff1d6..ddf26053 100644 --- a/src/psk/psk.cxx +++ b/src/psk/psk.cxx @@ -1023,8 +1023,7 @@ static double averageamp; phase = arg ( conj(prevsymbol[car]) * symbol ); prevsymbol[car] = symbol; - if (phase < 0) - phase += TWOPI; + if (phase < 0) phase += TWOPI; if (_qpsk) { bits = ((int) (phase / M_PI_2 + 0.5)) & 3; @@ -1207,8 +1206,7 @@ int psk::rx_process(const double *buf, int len) z = cmplx ( *buf * cos(phaseacc[car]), *buf * sin(phaseacc[car]) ); phaseacc[car] += delta[car]; - if (phaseacc[car] > M_PI) - phaseacc[car] -= TWOPI; + if (phaseacc[car] > TWOPI) phaseacc[car] -= TWOPI; // Filter and downsample // by 16 (psk31, qpsk31) @@ -1433,8 +1431,7 @@ void psk::tx_carriers() } phaseacc[car] += delta[car]; - if (phaseacc[car] > M_PI) - phaseacc[car] -= 2.0 * M_PI; + if (phaseacc[car] > TWOPI) phaseacc[car] -= TWOPI; } prevsymbol[car] = symbol; diff --git a/src/thor/thor.cxx b/src/thor/thor.cxx index a45f47f3..bef6c8c5 100644 --- a/src/thor/thor.cxx +++ b/src/thor/thor.cxx @@ -335,15 +335,11 @@ cmplx thor::mixer(int n, const cmplx& in) else f = THORFIRSTIF - THORBASEFREQ - bandwidth*0.5 + (samplerate / symlen) * ( (double)n / paths); - double phase_n = phase[n]; - cmplx z( cos(phase_n), sin(phase_n) ); + cmplx z( cos(phase[n]), sin(phase[n]) ); z *= in; - phase_n -= TWOPI * f / samplerate; - if (phase_n > M_PI) - phase_n -= TWOPI; - else if (phase_n < M_PI) - phase_n += TWOPI; - phase[n] = phase_n; + phase[n] -= TWOPI * f / samplerate; + if (phase[n] < 0) phase[n] += TWOPI; + return z; } @@ -957,10 +953,7 @@ void thor::sendtone(int tone, int duration) for (int i = 0; i < symlen; i++) { outbuf[i] = cos(txphase); txphase -= phaseincr; - if (txphase > M_PI) - txphase -= TWOPI; - else if (txphase < M_PI) - txphase += TWOPI; + if (txphase < 0) txphase += TWOPI; } ModulateXmtr(outbuf, symlen); } diff --git a/src/throb/throb.cxx b/src/throb/throb.cxx index eaf23c86..47bc3785 100644 --- a/src/throb/throb.cxx +++ b/src/throb/throb.cxx @@ -280,10 +280,7 @@ cmplx throb::mixer(cmplx in) phaseacc -= 2.0 * M_PI * f / THROB_SAMPLE_RATE; - if (phaseacc < -M_PI) - phaseacc += 2.0 * M_PI; - if (phaseacc > M_PI) - phaseacc -= 2.0 * M_PI; + if (phaseacc < 0) phaseacc += TWOPI; return z; } diff --git a/src/trx/modem.cxx b/src/trx/modem.cxx index 00b72358..5feee64d 100644 --- a/src/trx/modem.cxx +++ b/src/trx/modem.cxx @@ -336,8 +336,7 @@ void modem::set_samplerate(int smprate) double modem::PTTnco() { PTTphaseacc += TWOPI * 1000 / samplerate; - if (PTTphaseacc > M_PI) - PTTphaseacc -= TWOPI; + if (PTTphaseacc > TWOPI) PTTphaseacc -= TWOPI; return sin(PTTphaseacc); } @@ -579,8 +578,7 @@ double modem::cwid_nco(double freq) { cwid_phaseacc += 2.0 * M_PI * freq / samplerate; - if (cwid_phaseacc > M_PI) - cwid_phaseacc -= 2.0 * M_PI; + if (cwid_phaseacc > TWOPI) cwid_phaseacc -= TWOPI; return sin(cwid_phaseacc); } @@ -806,7 +804,7 @@ void modem::pretone() for (int j = 0; j < symlen; j++) { outbuf[j] = (0.5 * (1.0 - cos (M_PI * j / symlen)))*sin(phase); phase += phaseincr; - if (phase > 2.0 * M_PI) phase -= 2.0 * M_PI; + if (phase > TWOPI) phase -= TWOPI; } ModulateXmtr(outbuf, symlen); @@ -814,7 +812,7 @@ void modem::pretone() for (int j = 0; j < symlen; j++) { outbuf[j] = sin(phase); phase += phaseincr; - if (phase > 2.0 * M_PI) phase -= 2.0 * M_PI; + if (phase > TWOPI) phase -= TWOPI; } ModulateXmtr(outbuf, symlen); } @@ -822,7 +820,7 @@ void modem::pretone() for (int j = 0; j < symlen; j++) { outbuf[j] = (0.5 * (1.0 - cos (M_PI * (symlen - j) / symlen)))*sin(phase); phase += phaseincr; - if (phase > 2.0 * M_PI) phase -= 2.0 * M_PI; + if (phase > TWOPI) phase -= TWOPI; } ModulateXmtr(outbuf, symlen); diff --git a/src/trx/tune.cxx b/src/trx/tune.cxx index b3c2d81e..783f4562 100644 --- a/src/trx/tune.cxx +++ b/src/trx/tune.cxx @@ -79,8 +79,7 @@ double outbuf[BUFLEN]; inline double nco() { phaseacc += phaseincr; - if (phaseacc > M_PI) - phaseacc -= 2.0 * M_PI; + if (phaseacc > TWOPI) phaseacc -= TWOPI; return cos(phaseacc); } diff --git a/src/wwv/analysis.cxx b/src/wwv/analysis.cxx index 00fad04f..777df8ec 100644 --- a/src/wwv/analysis.cxx +++ b/src/wwv/analysis.cxx @@ -147,10 +147,7 @@ cmplx anal::mixer(cmplx in) cmplx z = cmplx( cos(phaseacc), sin(phaseacc)) * in; phaseacc -= TWOPI * frequency / samplerate; - if (phaseacc > M_PI) - phaseacc -= TWOPI; - else if (phaseacc < M_PI) - phaseacc += TWOPI; + if (phaseacc < 0) phaseacc += TWOPI; return z; } @@ -197,7 +194,7 @@ int anal::rx_process(const double *buf, int len) // create analytic signal from sound card input samples z = cmplx( *buf, *buf ); buf++; - hilbert->run(z, z); +// hilbert->run(z, z); // mix it with the audio carrier frequency to create a baseband signal z = mixer(z); // low pass filter using Windowed Sinc - Overlap-Add convolution filter diff --git a/src/wwv/wwv.cxx b/src/wwv/wwv.cxx index 537e822e..0019d4af 100644 --- a/src/wwv/wwv.cxx +++ b/src/wwv/wwv.cxx @@ -135,8 +135,7 @@ int wwv::rx_process(const double *buf, int len) z = znco * z; phaseacc += phaseincr; - if (phaseacc > M_PI) - phaseacc -= 2.0 * M_PI; + if (phaseacc > TWOPI) phaseacc -= TWOPI; if (lpfilter->run ( z, z )) { buffer[smpl_ctr % 1000] = vidfilter->run( abs(z) );