From c84318b245793dd48aac30c0f30b5e8f356ba42e Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Wed, 15 Nov 2017 20:21:57 +0100 Subject: Restructure: Move jitter from common code to 'libjitter' --- .gitignore | 1 + configure.ac | 1 + src/Makefile.am | 2 +- src/amps/Makefile.am | 1 + src/anetz/Makefile.am | 1 + src/bnetz/Makefile.am | 1 + src/cnetz/Makefile.am | 1 + src/common/Makefile.am | 1 - src/common/jitter.c | 115 ---------------------------------------------- src/common/jitter.h | 13 ------ src/common/mncc_console.c | 2 +- src/common/sender.h | 2 +- src/jtacs/Makefile.am | 1 + src/libjitter/Makefile.am | 6 +++ src/libjitter/jitter.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++ src/libjitter/jitter.h | 13 ++++++ src/nmt/Makefile.am | 1 + src/r2000/Makefile.am | 1 + src/tacs/Makefile.am | 1 + src/test/Makefile.am | 4 ++ 20 files changed, 151 insertions(+), 132 deletions(-) delete mode 100644 src/common/jitter.c delete mode 100644 src/common/jitter.h create mode 100644 src/libjitter/Makefile.am create mode 100644 src/libjitter/jitter.c create mode 100644 src/libjitter/jitter.h diff --git a/.gitignore b/.gitignore index 11dad51..1f2f343 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ compile .libs .dirstamp m4 +src/libjitter/libjitter.a src/libsquelch/libsquelch.a src/libhagelbarger/libhagelbarger.a src/libdtmf/libdtmf.a diff --git a/configure.ac b/configure.ac index 5076aee..6fe0b3c 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/libjitter/Makefile src/libsquelch/Makefile src/libhagelbarger/Makefile src/libdtmf/Makefile diff --git a/src/Makefile.am b/src/Makefile.am index 0d379b6..76eb9e0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,3 +1,3 @@ AUTOMAKE_OPTIONS = foreign -SUBDIRS = libsquelch libhagelbarger libdtmf libgermanton libtimer libsamplerate libscrambler libfilter libwave common anetz bnetz cnetz nmt amps tacs jtacs r2000 tv test +SUBDIRS = 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 c090792..4f4d849 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/libjitter/libjitter.a \ $(top_builddir)/src/common/libmobile.a \ $(top_builddir)/src/common/libcommon.a \ $(top_builddir)/src/libtimer/libtimer.a \ diff --git a/src/anetz/Makefile.am b/src/anetz/Makefile.am index 5711ba6..2380ed8 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/libjitter/libjitter.a \ $(top_builddir)/src/libsquelch/libsquelch.a \ $(top_builddir)/src/libgermanton/libgermanton.a \ $(top_builddir)/src/common/libmobile.a \ diff --git a/src/bnetz/Makefile.am b/src/bnetz/Makefile.am index 5cd86b8..dfcc7f8 100644 --- a/src/bnetz/Makefile.am +++ b/src/bnetz/Makefile.am @@ -13,6 +13,7 @@ bnetz_SOURCES = \ main.c bnetz_LDADD = \ $(COMMON_LA) \ + $(top_builddir)/src/libjitter/libjitter.a \ $(top_builddir)/src/libsquelch/libsquelch.a \ $(top_builddir)/src/libgermanton/libgermanton.a \ $(top_builddir)/src/common/libmobile.a \ diff --git a/src/cnetz/Makefile.am b/src/cnetz/Makefile.am index 39439e6..8ab18f6 100644 --- a/src/cnetz/Makefile.am +++ b/src/cnetz/Makefile.am @@ -16,6 +16,7 @@ cnetz_SOURCES = \ main.c cnetz_LDADD = \ $(COMMON_LA) \ + $(top_builddir)/src/libjitter/libjitter.a \ $(top_builddir)/src/libgermanton/libgermanton.a \ $(top_builddir)/src/common/libmobile.a \ $(top_builddir)/src/common/libcommon.a \ diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 443823d..8ca32bb 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -7,7 +7,6 @@ libcommon_a_SOURCES = \ debug.c \ sound_alsa.c \ goertzel.c \ - jitter.c \ emphasis.c \ compandor.c \ fft.c \ diff --git a/src/common/jitter.c b/src/common/jitter.c deleted file mode 100644 index 865438b..0000000 --- a/src/common/jitter.c +++ /dev/null @@ -1,115 +0,0 @@ -/* Jitter buffering 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 "jitter.h" - -/* create jitter buffer */ -int jitter_create(jitter_t *jitter, int length) -{ - memset(jitter, 0, sizeof(*jitter)); - jitter->spl = calloc(length * sizeof(sample_t), 1); - if (!jitter->spl) { - PDEBUG(DDSP, DEBUG_ERROR, "No memory for jitter buffer.\n"); - return -ENOMEM; - } - jitter->len = length; - - return 0; -} - -void jitter_destroy(jitter_t *jitter) -{ - if (jitter->spl) { - free(jitter->spl); - jitter->spl = NULL; - } -} - -/* store audio in jitterbuffer - * - * stop if buffer is completely filled - */ -void jitter_save(jitter_t *jb, sample_t *samples, int length) -{ - sample_t *spl; - int inptr, outptr, len, space; - int i; - - spl = jb->spl; - inptr = jb->inptr; - outptr = jb->outptr; - len = jb->len; - space = (outptr - inptr + len - 1) % len; - - if (space < length) - length = space; - for (i = 0; i < length; i++) { - spl[inptr++] = *samples++; - if (inptr == len) - inptr = 0; - } - - jb->inptr = inptr; -} - -/* get audio from jitterbuffer - */ -void jitter_load(jitter_t *jb, sample_t *samples, int length) -{ - sample_t *spl; - int inptr, outptr, len, fill; - int i, ii; - - spl = jb->spl; - inptr = jb->inptr; - outptr = jb->outptr; - len = jb->len; - fill = (inptr - outptr + len) % len; - - if (fill < length) - ii = fill; - else - ii = length; - - /* fill what we got */ - for (i = 0; i < ii; i++) { - *samples++ = spl[outptr++]; - if (outptr == len) - outptr = 0; - } - /* on underrun, fill with silence */ - for (; i < length; i++) { - *samples++ = 0; - } - - jb->outptr = outptr; -} - -void jitter_clear(jitter_t *jb) -{ - jb->inptr = jb->outptr = 0; -} - diff --git a/src/common/jitter.h b/src/common/jitter.h deleted file mode 100644 index 658da19..0000000 --- a/src/common/jitter.h +++ /dev/null @@ -1,13 +0,0 @@ - -typedef struct jitter { - sample_t *spl; /* pointer to sample buffer */ - int len; /* buffer size: number of samples */ - int inptr, outptr; /* write pointer and read pointer */ -} jitter_t; - -int jitter_create(jitter_t *jitter, int length); -void jitter_destroy(jitter_t *jitter); -void jitter_save(jitter_t *jb, sample_t *samples, int length); -void jitter_load(jitter_t *jb, sample_t *samples, int length); -void jitter_clear(jitter_t *jb); - diff --git a/src/common/mncc_console.c b/src/common/mncc_console.c index fc779f4..77d820c 100644 --- a/src/common/mncc_console.c +++ b/src/common/mncc_console.c @@ -26,7 +26,7 @@ #include #include "sample.h" #include "../libsamplerate/samplerate.h" -#include "jitter.h" +#include "../libjitter/jitter.h" #include "debug.h" #include "testton.h" #include "mncc.h" diff --git a/src/common/sender.h b/src/common/sender.h index 4da32cd..6ec6ad8 100644 --- a/src/common/sender.h +++ b/src/common/sender.h @@ -4,7 +4,7 @@ #endif #include "../libwave/wave.h" #include "../libsamplerate/samplerate.h" -#include "jitter.h" +#include "../libjitter/jitter.h" #include "emphasis.h" #include "display.h" diff --git a/src/jtacs/Makefile.am b/src/jtacs/Makefile.am index cc17138..1d6ae0c 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/libjitter/libjitter.a \ $(top_builddir)/src/common/libmobile.a \ $(top_builddir)/src/common/libcommon.a \ $(top_builddir)/src/libtimer/libtimer.a \ diff --git a/src/libjitter/Makefile.am b/src/libjitter/Makefile.am new file mode 100644 index 0000000..506ef87 --- /dev/null +++ b/src/libjitter/Makefile.am @@ -0,0 +1,6 @@ +AM_CPPFLAGS = -Wall -Wextra -g $(all_includes) + +noinst_LIBRARIES = libjitter.a + +libjitter_a_SOURCES = \ + jitter.c diff --git a/src/libjitter/jitter.c b/src/libjitter/jitter.c new file mode 100644 index 0000000..5400971 --- /dev/null +++ b/src/libjitter/jitter.c @@ -0,0 +1,115 @@ +/* Jitter buffering 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 "jitter.h" + +/* create jitter buffer */ +int jitter_create(jitter_t *jitter, int length) +{ + memset(jitter, 0, sizeof(*jitter)); + jitter->spl = calloc(length * sizeof(sample_t), 1); + if (!jitter->spl) { + PDEBUG(DDSP, DEBUG_ERROR, "No memory for jitter buffer.\n"); + return -ENOMEM; + } + jitter->len = length; + + return 0; +} + +void jitter_destroy(jitter_t *jitter) +{ + if (jitter->spl) { + free(jitter->spl); + jitter->spl = NULL; + } +} + +/* store audio in jitterbuffer + * + * stop if buffer is completely filled + */ +void jitter_save(jitter_t *jb, sample_t *samples, int length) +{ + sample_t *spl; + int inptr, outptr, len, space; + int i; + + spl = jb->spl; + inptr = jb->inptr; + outptr = jb->outptr; + len = jb->len; + space = (outptr - inptr + len - 1) % len; + + if (space < length) + length = space; + for (i = 0; i < length; i++) { + spl[inptr++] = *samples++; + if (inptr == len) + inptr = 0; + } + + jb->inptr = inptr; +} + +/* get audio from jitterbuffer + */ +void jitter_load(jitter_t *jb, sample_t *samples, int length) +{ + sample_t *spl; + int inptr, outptr, len, fill; + int i, ii; + + spl = jb->spl; + inptr = jb->inptr; + outptr = jb->outptr; + len = jb->len; + fill = (inptr - outptr + len) % len; + + if (fill < length) + ii = fill; + else + ii = length; + + /* fill what we got */ + for (i = 0; i < ii; i++) { + *samples++ = spl[outptr++]; + if (outptr == len) + outptr = 0; + } + /* on underrun, fill with silence */ + for (; i < length; i++) { + *samples++ = 0; + } + + jb->outptr = outptr; +} + +void jitter_clear(jitter_t *jb) +{ + jb->inptr = jb->outptr = 0; +} + diff --git a/src/libjitter/jitter.h b/src/libjitter/jitter.h new file mode 100644 index 0000000..658da19 --- /dev/null +++ b/src/libjitter/jitter.h @@ -0,0 +1,13 @@ + +typedef struct jitter { + sample_t *spl; /* pointer to sample buffer */ + int len; /* buffer size: number of samples */ + int inptr, outptr; /* write pointer and read pointer */ +} jitter_t; + +int jitter_create(jitter_t *jitter, int length); +void jitter_destroy(jitter_t *jitter); +void jitter_save(jitter_t *jb, sample_t *samples, int length); +void jitter_load(jitter_t *jb, sample_t *samples, int length); +void jitter_clear(jitter_t *jb); + diff --git a/src/nmt/Makefile.am b/src/nmt/Makefile.am index 7598971..d8a3c1e 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/libjitter/libjitter.a \ $(top_builddir)/src/libhagelbarger/libhagelbarger.a \ $(top_builddir)/src/libdtmf/libdtmf.a \ $(top_builddir)/src/common/libmobile.a \ diff --git a/src/r2000/Makefile.am b/src/r2000/Makefile.am index d6dabca..eacd6cb 100644 --- a/src/r2000/Makefile.am +++ b/src/r2000/Makefile.am @@ -12,6 +12,7 @@ radiocom2000_SOURCES = \ main.c radiocom2000_LDADD = \ $(COMMON_LA) \ + $(top_builddir)/src/libjitter/libjitter.a \ $(top_builddir)/src/libhagelbarger/libhagelbarger.a \ $(top_builddir)/src/common/libmobile.a \ $(top_builddir)/src/common/libcommon.a \ diff --git a/src/tacs/Makefile.am b/src/tacs/Makefile.am index 2221706..fcb486e 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/libjitter/libjitter.a \ $(top_builddir)/src/common/libmobile.a \ $(top_builddir)/src/common/libcommon.a \ $(top_builddir)/src/libtimer/libtimer.a \ diff --git a/src/test/Makefile.am b/src/test/Makefile.am index 412fd5c..7e5ce3e 100644 --- a/src/test/Makefile.am +++ b/src/test/Makefile.am @@ -15,6 +15,7 @@ test_filter_LDADD = \ $(COMMON_LA) \ $(top_builddir)/src/common/libmobile.a \ $(top_builddir)/src/common/libcommon.a \ + $(top_builddir)/src/libjitter/libjitter.a \ $(top_builddir)/src/libtimer/libtimer.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libfilter/libfilter.a \ @@ -41,6 +42,7 @@ test_emphasis_LDADD = \ $(COMMON_LA) \ $(top_builddir)/src/common/libmobile.a \ $(top_builddir)/src/common/libcommon.a \ + $(top_builddir)/src/libjitter/libjitter.a \ $(top_builddir)/src/libtimer/libtimer.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libfilter/libfilter.a \ @@ -57,6 +59,7 @@ test_dms_LDADD = \ $(top_builddir)/src/nmt/libdmssms.a \ $(top_builddir)/src/common/libmobile.a \ $(top_builddir)/src/common/libcommon.a \ + $(top_builddir)/src/libjitter/libjitter.a \ $(top_builddir)/src/libtimer/libtimer.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libfilter/libfilter.a \ @@ -73,6 +76,7 @@ test_sms_LDADD = \ $(top_builddir)/src/nmt/libdmssms.a \ $(top_builddir)/src/common/libmobile.a \ $(top_builddir)/src/common/libcommon.a \ + $(top_builddir)/src/libjitter/libjitter.a \ $(top_builddir)/src/libtimer/libtimer.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libfilter/libfilter.a \ -- cgit v1.2.3