From 16194c15f9827edf9cfde9a5c18ccb06353c34a3 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Thu, 16 Nov 2017 07:34:16 +0100 Subject: Restructure: Move goertzel from common code to 'libgoertzel' --- .gitignore | 1 + configure.ac | 1 + src/Makefile.am | 2 +- src/amps/Makefile.am | 1 + src/amps/amps.h | 2 +- src/anetz/Makefile.am | 1 + src/anetz/anetz.h | 2 +- src/bnetz/dsp.c | 1 - src/common/Makefile.am | 1 - src/common/goertzel.c | 104 -------------------------------------------- src/common/goertzel.h | 10 ----- src/jtacs/Makefile.am | 1 + src/libgoertzel/Makefile.am | 6 +++ src/libgoertzel/goertzel.c | 104 ++++++++++++++++++++++++++++++++++++++++++++ src/libgoertzel/goertzel.h | 10 +++++ src/nmt/Makefile.am | 1 + src/nmt/nmt.h | 2 +- src/tacs/Makefile.am | 1 + 18 files changed, 131 insertions(+), 120 deletions(-) delete mode 100644 src/common/goertzel.c delete mode 100644 src/common/goertzel.h create mode 100644 src/libgoertzel/Makefile.am create mode 100644 src/libgoertzel/goertzel.c create mode 100644 src/libgoertzel/goertzel.h diff --git a/.gitignore b/.gitignore index 1f2f343..bc50bf0 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ compile .libs .dirstamp m4 +src/libgoertzel/libgoertzel.a src/libjitter/libjitter.a src/libsquelch/libsquelch.a src/libhagelbarger/libhagelbarger.a diff --git a/configure.ac b/configure.ac index 6fe0b3c..18d8f86 100644 --- a/configure.ac +++ b/configure.ac @@ -75,6 +75,7 @@ AS_IF([test "x$with_soapy" == "xyes"],[AC_MSG_NOTICE( Compiling with SoapySDR su AS_IF([test "x$somethingmagick" == "xyes"],[AC_MSG_NOTICE( Compiling with ImageMagick )],[AC_MSG_NOTICE( ImageMagick not supported )]) AC_OUTPUT( + src/libgoertzel/Makefile src/libjitter/Makefile src/libsquelch/Makefile src/libhagelbarger/Makefile diff --git a/src/Makefile.am b/src/Makefile.am index 76eb9e0..9d081bc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,3 +1,3 @@ AUTOMAKE_OPTIONS = foreign -SUBDIRS = libjitter libsquelch libhagelbarger libdtmf libgermanton libtimer libsamplerate libscrambler libfilter libwave common anetz bnetz cnetz nmt amps tacs jtacs r2000 tv test +SUBDIRS = libgoertzel libjitter libsquelch libhagelbarger libdtmf libgermanton libtimer libsamplerate libscrambler libfilter libwave common anetz bnetz cnetz nmt amps tacs jtacs r2000 tv test diff --git a/src/amps/Makefile.am b/src/amps/Makefile.am index 4f4d849..9734b8d 100644 --- a/src/amps/Makefile.am +++ b/src/amps/Makefile.am @@ -26,6 +26,7 @@ amps_SOURCES = \ amps_LDADD = \ $(COMMON_LA) \ libamps.a \ + $(top_builddir)/src/libgoertzel/libgoertzel.a \ $(top_builddir)/src/libjitter/libjitter.a \ $(top_builddir)/src/common/libmobile.a \ $(top_builddir)/src/common/libcommon.a \ diff --git a/src/amps/amps.h b/src/amps/amps.h index 390ec84..232745a 100644 --- a/src/amps/amps.h +++ b/src/amps/amps.h @@ -1,4 +1,4 @@ -#include "../common/goertzel.h" +#include "../libgoertzel/goertzel.h" #include "../common/sender.h" #include "../libtimer/timer.h" #include "../common/compandor.h" diff --git a/src/anetz/Makefile.am b/src/anetz/Makefile.am index 2380ed8..98c13f2 100644 --- a/src/anetz/Makefile.am +++ b/src/anetz/Makefile.am @@ -11,6 +11,7 @@ anetz_SOURCES = \ main.c anetz_LDADD = \ $(COMMON_LA) \ + $(top_builddir)/src/libgoertzel/libgoertzel.a \ $(top_builddir)/src/libjitter/libjitter.a \ $(top_builddir)/src/libsquelch/libsquelch.a \ $(top_builddir)/src/libgermanton/libgermanton.a \ diff --git a/src/anetz/anetz.h b/src/anetz/anetz.h index a4d2d6b..9303280 100644 --- a/src/anetz/anetz.h +++ b/src/anetz/anetz.h @@ -1,5 +1,5 @@ #include "../libsquelch/squelch.h" -#include "../common/goertzel.h" +#include "../libgoertzel/goertzel.h" #include "../common/sender.h" enum dsp_mode { diff --git a/src/bnetz/dsp.c b/src/bnetz/dsp.c index 8ee1492..e61972d 100644 --- a/src/bnetz/dsp.c +++ b/src/bnetz/dsp.c @@ -28,7 +28,6 @@ #include "../common/sample.h" #include "../common/debug.h" #include "../common/call.h" -#include "../common/goertzel.h" #include "bnetz.h" #include "dsp.h" diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 8ca32bb..02bdf9f 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -6,7 +6,6 @@ libcommon_a_SOURCES = \ sample.c \ debug.c \ sound_alsa.c \ - goertzel.c \ emphasis.c \ compandor.c \ fft.c \ diff --git a/src/common/goertzel.c b/src/common/goertzel.c deleted file mode 100644 index ccfbd12..0000000 --- a/src/common/goertzel.c +++ /dev/null @@ -1,104 +0,0 @@ -/* Goertzel functions - * - * (C) 2016 by Andreas Eversberg - * All Rights Reserved - * - * 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include "sample.h" -#include "debug.h" -#include "goertzel.h" - -/* - * audio level calculation - */ - -/* Return average value (rectified value) - * The input must not have any dc offset! - * For a perfect rectangualr wave, the result would equal the peak level. - * For a sine wave the result would be factor (2 / PI) below peak level. - */ -double audio_level(sample_t *samples, int length) -{ - double level, sk; - int n; - - /* level calculation */ - level = 0; - for (n = 0; n < length; n++) { - sk = samples[n]; - if (sk < 0) - level -= (double)sk; - if (sk > 0) - level += (double)sk; - } - level = level / (double)length; - - return level; -} - -void audio_goertzel_init(goertzel_t *goertzel, double freq, int samplerate) -{ - memset(goertzel, 0, sizeof(*goertzel)); - goertzel->coeff = 2.0 * cos(2.0 * M_PI * freq / (double)samplerate); -} - -/* - * goertzel filter - */ - -/* filter frequencies and return their levels - * - * samples: pointer to sample buffer - * length: length of buffer - * offset: for ring buffer, start here and wrap arround to 0 when length has been hit - * coeff: array of coefficients (coeff << 15) - * result: array of result levels (average value of the sine, that is 1 / (PI/2) of the sine's peak) - * k: number of frequencies to check - */ -void audio_goertzel(goertzel_t *goertzel, sample_t *samples, int length, int offset, double *result, int k) -{ - double sk, sk1, sk2; - double cos2pik; - int i, n; - - /* we do goertzel */ - for (i = 0; i < k; i++) { - sk = 0; - sk1 = 0; - sk2 = 0; - cos2pik = goertzel[i].coeff; - /* note: after 'length' cycles, offset is restored to its initial value */ - for (n = 0; n < length; n++) { - sk = (cos2pik * sk1) - sk2 + samples[offset++]; - sk2 = sk1; - sk1 = sk; - if (offset == length) - offset = 0; - } - /* compute level of signal */ - result[i] = sqrt( - (sk * sk) - - (cos2pik * sk * sk2) + - (sk2 * sk2) - ) / (double)length * 2.0 * 0.63662; /* 1 / (PI/2) */ - } -} - diff --git a/src/common/goertzel.h b/src/common/goertzel.h deleted file mode 100644 index 58fcbb8..0000000 --- a/src/common/goertzel.h +++ /dev/null @@ -1,10 +0,0 @@ - -double audio_level(sample_t *samples, int length); - -typedef struct goertzel { - double coeff; -} goertzel_t; - -void audio_goertzel_init(goertzel_t *goertzel, double freq, int samplerate); -void audio_goertzel(goertzel_t *goertzel, sample_t *samples, int length, int offset, double *result, int k); - diff --git a/src/jtacs/Makefile.am b/src/jtacs/Makefile.am index 1d6ae0c..d5abc41 100644 --- a/src/jtacs/Makefile.am +++ b/src/jtacs/Makefile.am @@ -12,6 +12,7 @@ jtacs_SOURCES = \ jtacs_LDADD = \ $(COMMON_LA) \ ../amps/libamps.a \ + $(top_builddir)/src/libgoertzel/libgoertzel.a \ $(top_builddir)/src/libjitter/libjitter.a \ $(top_builddir)/src/common/libmobile.a \ $(top_builddir)/src/common/libcommon.a \ diff --git a/src/libgoertzel/Makefile.am b/src/libgoertzel/Makefile.am new file mode 100644 index 0000000..56e731d --- /dev/null +++ b/src/libgoertzel/Makefile.am @@ -0,0 +1,6 @@ +AM_CPPFLAGS = -Wall -Wextra -g $(all_includes) + +noinst_LIBRARIES = libgoertzel.a + +libgoertzel_a_SOURCES = \ + goertzel.c diff --git a/src/libgoertzel/goertzel.c b/src/libgoertzel/goertzel.c new file mode 100644 index 0000000..7c926fb --- /dev/null +++ b/src/libgoertzel/goertzel.c @@ -0,0 +1,104 @@ +/* Goertzel functions + * + * (C) 2016 by Andreas Eversberg + * All Rights Reserved + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include "../common/sample.h" +#include "../common/debug.h" +#include "goertzel.h" + +/* + * audio level calculation + */ + +/* Return average value (rectified value) + * The input must not have any dc offset! + * For a perfect rectangualr wave, the result would equal the peak level. + * For a sine wave the result would be factor (2 / PI) below peak level. + */ +double audio_level(sample_t *samples, int length) +{ + double level, sk; + int n; + + /* level calculation */ + level = 0; + for (n = 0; n < length; n++) { + sk = samples[n]; + if (sk < 0) + level -= (double)sk; + if (sk > 0) + level += (double)sk; + } + level = level / (double)length; + + return level; +} + +void audio_goertzel_init(goertzel_t *goertzel, double freq, int samplerate) +{ + memset(goertzel, 0, sizeof(*goertzel)); + goertzel->coeff = 2.0 * cos(2.0 * M_PI * freq / (double)samplerate); +} + +/* + * goertzel filter + */ + +/* filter frequencies and return their levels + * + * samples: pointer to sample buffer + * length: length of buffer + * offset: for ring buffer, start here and wrap arround to 0 when length has been hit + * coeff: array of coefficients (coeff << 15) + * result: array of result levels (average value of the sine, that is 1 / (PI/2) of the sine's peak) + * k: number of frequencies to check + */ +void audio_goertzel(goertzel_t *goertzel, sample_t *samples, int length, int offset, double *result, int k) +{ + double sk, sk1, sk2; + double cos2pik; + int i, n; + + /* we do goertzel */ + for (i = 0; i < k; i++) { + sk = 0; + sk1 = 0; + sk2 = 0; + cos2pik = goertzel[i].coeff; + /* note: after 'length' cycles, offset is restored to its initial value */ + for (n = 0; n < length; n++) { + sk = (cos2pik * sk1) - sk2 + samples[offset++]; + sk2 = sk1; + sk1 = sk; + if (offset == length) + offset = 0; + } + /* compute level of signal */ + result[i] = sqrt( + (sk * sk) - + (cos2pik * sk * sk2) + + (sk2 * sk2) + ) / (double)length * 2.0 * 0.63662; /* 1 / (PI/2) */ + } +} + diff --git a/src/libgoertzel/goertzel.h b/src/libgoertzel/goertzel.h new file mode 100644 index 0000000..58fcbb8 --- /dev/null +++ b/src/libgoertzel/goertzel.h @@ -0,0 +1,10 @@ + +double audio_level(sample_t *samples, int length); + +typedef struct goertzel { + double coeff; +} goertzel_t; + +void audio_goertzel_init(goertzel_t *goertzel, double freq, int samplerate); +void audio_goertzel(goertzel_t *goertzel, sample_t *samples, int length, int offset, double *result, int k); + diff --git a/src/nmt/Makefile.am b/src/nmt/Makefile.am index d8a3c1e..6edcc0e 100644 --- a/src/nmt/Makefile.am +++ b/src/nmt/Makefile.am @@ -22,6 +22,7 @@ nmt_SOURCES = \ nmt_LDADD = \ $(COMMON_LA) \ libdmssms.a \ + $(top_builddir)/src/libgoertzel/libgoertzel.a \ $(top_builddir)/src/libjitter/libjitter.a \ $(top_builddir)/src/libhagelbarger/libhagelbarger.a \ $(top_builddir)/src/libdtmf/libdtmf.a \ diff --git a/src/nmt/nmt.h b/src/nmt/nmt.h index aaa61f6..163c0af 100644 --- a/src/nmt/nmt.h +++ b/src/nmt/nmt.h @@ -4,7 +4,7 @@ #include "../libdtmf/dtmf_encode.h" #include "../common/call.h" #include "../common/fsk.h" -#include "../common/goertzel.h" +#include "../libgoertzel/goertzel.h" #include "dms.h" #include "sms.h" diff --git a/src/tacs/Makefile.am b/src/tacs/Makefile.am index fcb486e..6c6b0eb 100644 --- a/src/tacs/Makefile.am +++ b/src/tacs/Makefile.am @@ -13,6 +13,7 @@ tacs_SOURCES = \ tacs_LDADD = \ $(COMMON_LA) \ ../amps/libamps.a \ + $(top_builddir)/src/libgoertzel/libgoertzel.a \ $(top_builddir)/src/libjitter/libjitter.a \ $(top_builddir)/src/common/libmobile.a \ $(top_builddir)/src/common/libcommon.a \ -- cgit v1.2.3