diff --git a/demod_afsk12.c b/demod_afsk12.c index fd4763e..4de75b0 100644 --- a/demod_afsk12.c +++ b/demod_afsk12.c @@ -3,6 +3,8 @@ * * Copyright (C) 1996 * Thomas Sailer (sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu) + * Copyright (C) 2024 + * Marat Fayzullin (luarvique@gmail.com) * * 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 @@ -79,16 +81,15 @@ static void afsk12_demod(struct demod_state *s, buffer_t buffer, int length) unsigned char curbit; if (s->l1.afsk12.subsamp) { - int numfill = SUBSAMP - s->l1.afsk12.subsamp; - if (length < numfill) { - s->l1.afsk12.subsamp += length; + if (length <= (int)s->l1.afsk12.subsamp) { + s->l1.afsk12.subsamp -= length; return; } - buffer.fbuffer += numfill; - length -= numfill; + buffer.fbuffer += s->l1.afsk12.subsamp; + length -= s->l1.afsk12.subsamp; s->l1.afsk12.subsamp = 0; } - for (; length >= SUBSAMP; length -= SUBSAMP, buffer.fbuffer += SUBSAMP) { + for (; length > 0; length -= SUBSAMP, buffer.fbuffer += SUBSAMP) { f = fsqr(mac(buffer.fbuffer, corr_mark_i, CORRLEN)) + fsqr(mac(buffer.fbuffer, corr_mark_q, CORRLEN)) - fsqr(mac(buffer.fbuffer, corr_space_i, CORRLEN)) - @@ -116,7 +117,7 @@ static void afsk12_demod(struct demod_state *s, buffer_t buffer, int length) hdlc_rxbit(s, curbit); } } - s->l1.afsk12.subsamp = length; + s->l1.afsk12.subsamp = -length; } /* ---------------------------------------------------------------------- */ diff --git a/demod_clipfsk.c b/demod_clipfsk.c index c82b554..b21f455 100644 --- a/demod_clipfsk.c +++ b/demod_clipfsk.c @@ -1,7 +1,7 @@ /* * demod_clipfsk.c -- 1200 baud FSK demodulator * - * Copyright (C) 2007 + * Copyright (C) 2007, 2024 * * 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 @@ -78,16 +78,15 @@ static void clipfsk_demod(struct demod_state *s, buffer_t buffer, int length) unsigned char curbit; if (s->l1.clipfsk.subsamp) { - int numfill = SUBSAMP - s->l1.clipfsk.subsamp; - if (length < numfill) { - s->l1.clipfsk.subsamp += length; + if (length <= (int)s->l1.clipfsk.subsamp) { + s->l1.clipfsk.subsamp -= length; return; } - buffer.fbuffer += numfill; - length -= numfill; + buffer.fbuffer += s->l1.clipfsk.subsamp; + length -= s->l1.clipfsk.subsamp; s->l1.clipfsk.subsamp = 0; } - for (; length >= SUBSAMP; length -= SUBSAMP, buffer.fbuffer += SUBSAMP) { + for (; length > 0; length -= SUBSAMP, buffer.fbuffer += SUBSAMP) { f = fsqr(mac(buffer.fbuffer, corr_mark_i, CORRLEN)) + fsqr(mac(buffer.fbuffer, corr_mark_q, CORRLEN)) - fsqr(mac(buffer.fbuffer, corr_space_i, CORRLEN)) - @@ -112,7 +111,7 @@ static void clipfsk_demod(struct demod_state *s, buffer_t buffer, int length) clip_rxbit(s, curbit); } } - s->l1.clipfsk.subsamp = length; + s->l1.clipfsk.subsamp = -length; } /* ---------------------------------------------------------------------- */ diff --git a/demod_eas.c b/demod_eas.c index e3b295b..88b724d 100644 --- a/demod_eas.c +++ b/demod_eas.c @@ -5,6 +5,8 @@ * * Copyright (C) 2000 * A. Maitland Bottoms +* Copyright (C) 2024 +* Marat Fayzullin * * Licensed under same terms and based upon the * demod_afsk12.c -- 1200 baud AFSK demodulator @@ -253,20 +255,19 @@ static void eas_demod(struct demod_state *s, buffer_t buffer, int length) float f; unsigned char curbit; float dll_gain; - + if (s->l1.eas.subsamp) { - int numfill = SUBSAMP - s->l1.eas.subsamp; - if (length < numfill) { - s->l1.eas.subsamp += length; + if (length <= (int)s->l1.eas.subsamp) { + s->l1.eas.subsamp -= length; return; } - buffer.fbuffer += numfill; - length -= numfill; + buffer.fbuffer += s->l1.eas.subsamp; + length -= s->l1.eas.subsamp; s->l1.eas.subsamp = 0; } // We use a sliding window correlator which advances by SUBSAMP // each time. One correlator sample is output for each SUBSAMP symbols - for (; length >= SUBSAMP; length -= SUBSAMP, buffer.fbuffer += SUBSAMP) { + for (; length > 0; length -= SUBSAMP, buffer.fbuffer += SUBSAMP) { f = fsqr(mac(buffer.fbuffer, eascorr_mark_i, CORRLEN)) + fsqr(mac(buffer.fbuffer, eascorr_mark_q, CORRLEN)) - fsqr(mac(buffer.fbuffer, eascorr_space_i, CORRLEN)) - @@ -286,14 +287,13 @@ static void eas_demod(struct demod_state *s, buffer_t buffer, int length) { s->l1.eas.dcd_integrator -= 1; } - + verbprintf(9, "%c", '0'+(s->l1.afsk12.dcd_shreg & 1)); - - + /* * check if transition occurred on time */ - + if (s->l2.eas.state != EAS_L2_IDLE) dll_gain = DLL_GAIN_SYNC; else @@ -313,7 +313,6 @@ static void eas_demod(struct demod_state *s, buffer_t buffer, int length) else { // after center; check for increment - if (s->l1.eas.sphase < (0x10000u - SPHASEINC/2)) { s->l1.eas.sphase += MIN((int)((0x10000u - s->l1.eas.sphase)* @@ -325,20 +324,20 @@ static void eas_demod(struct demod_state *s, buffer_t buffer, int length) } s->l1.eas.sphase += SPHASEINC; - + if (s->l1.eas.sphase >= 0x10000u) { // end of bit period. s->l1.eas.sphase = 1; //was &= 0xffffu; s->l1.eas.lasts >>= 1; - + // if at least half of the values in the integrator are 1, // declare a 1 received s->l1.afsk12.lasts |= ((s->l1.eas.dcd_integrator >= 0) << 7) & 0x80u; - + curbit = (s->l1.eas.lasts >> 7) & 0x1u; verbprintf(9, " "); verbprintf(7, "%c", '0'+curbit); - + // check for sync sequence // do not resync when we're reading a message! if (s->l1.eas.lasts == PREAMBLE @@ -369,12 +368,11 @@ static void eas_demod(struct demod_state *s, buffer_t buffer, int length) s->l1.eas.byte_counter = 0; } } - - + verbprintf(9, "\n"); } } - s->l1.eas.subsamp = length; + s->l1.eas.subsamp = -length; } /* ---------------------------------------------------------------------- */ diff --git a/demod_fmsfsk.c b/demod_fmsfsk.c index 32e712a..914ca69 100644 --- a/demod_fmsfsk.c +++ b/demod_fmsfsk.c @@ -1,7 +1,7 @@ /* * demod_fmsfsk.c -- 1200 baud FMS FSK demodulator * - * Copyright (C) 2014 + * Copyright (C) 2014, 2024 * * 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 @@ -78,16 +78,15 @@ static void fmsfsk_demod(struct demod_state *s, buffer_t buffer, int length) unsigned char curbit; if (s->l1.fmsfsk.subsamp) { - int numfill = SUBSAMP - s->l1.fmsfsk.subsamp; - if (length < numfill) { - s->l1.fmsfsk.subsamp += length; + if (length <= (int)s->l1.fmsfsk.subsamp) { + s->l1.fmsfsk.subsamp -= length; return; } - buffer.fbuffer += numfill; - length -= numfill; + buffer.fbuffer += s->l1.fmsfsk.subsamp; + length -= s->l1.fmsfsk.subsamp; s->l1.fmsfsk.subsamp = 0; } - for (; length >= SUBSAMP; length -= SUBSAMP, buffer.fbuffer += SUBSAMP) { + for (; length > 0; length -= SUBSAMP, buffer.fbuffer += SUBSAMP) { f = fsqr(mac(buffer.fbuffer, corr_1_i, CORRLEN)) + fsqr(mac(buffer.fbuffer, corr_1_q, CORRLEN)) - fsqr(mac(buffer.fbuffer, corr_0_i, CORRLEN)) - @@ -112,7 +111,7 @@ static void fmsfsk_demod(struct demod_state *s, buffer_t buffer, int length) fms_rxbit(s, curbit); } } - s->l1.fmsfsk.subsamp = length; + s->l1.fmsfsk.subsamp = -length; } /* ---------------------------------------------------------------------- */ diff --git a/demod_ufsk12.c b/demod_ufsk12.c index 268dfb5..aae015a 100644 --- a/demod_ufsk12.c +++ b/demod_ufsk12.c @@ -1,7 +1,7 @@ /* * demod_ufsk12.c -- 1200 baud FSK demodulator * - * Copyright (C) 2007 + * Copyright (C) 2007, 2024 * * 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 @@ -78,16 +78,15 @@ static void ufsk12_demod(struct demod_state *s, buffer_t buffer, int length) unsigned char curbit; if (s->l1.ufsk12.subsamp) { - int numfill = SUBSAMP - s->l1.ufsk12.subsamp; - if (length < numfill) { - s->l1.ufsk12.subsamp += length; + if (length <= (int)s->l1.ufsk12.subsamp) { + s->l1.ufsk12.subsamp -= length; return; } - buffer.fbuffer += numfill; - length -= numfill; + buffer.fbuffer += s->l1.ufsk12.subsamp; + length -= s->l1.ufsk12.subsamp; s->l1.ufsk12.subsamp = 0; } - for (; length >= SUBSAMP; length -= SUBSAMP, buffer.fbuffer += SUBSAMP) { + for (; length > 0; length -= SUBSAMP, buffer.fbuffer += SUBSAMP) { f = fsqr(mac(buffer.fbuffer, corr_mark_i, CORRLEN)) + fsqr(mac(buffer.fbuffer, corr_mark_q, CORRLEN)) - fsqr(mac(buffer.fbuffer, corr_space_i, CORRLEN)) - @@ -112,7 +111,7 @@ static void ufsk12_demod(struct demod_state *s, buffer_t buffer, int length) uart_rxbit(s, curbit); } } - s->l1.ufsk12.subsamp = length; + s->l1.ufsk12.subsamp = -length; } /* ---------------------------------------------------------------------- */