aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2017-11-15 18:45:56 +0100
committerAndreas Eversberg <jolly@eversberg.eu>2017-11-25 19:23:46 +0100
commitfd3a4d7ac2d0a3759067c08c67cfad406fbcfb3c (patch)
treeca0a5640df0777ddd7c38000ac5c0ac963e6d5ff
parent17b34fbae63f0ddebcb82e9714718c030e770300 (diff)
Restructure: Move dtmf from common code to 'libdtmf'
-rw-r--r--.gitignore1
-rw-r--r--configure.ac1
-rw-r--r--src/Makefile.am2
-rw-r--r--src/common/Makefile.am1
-rw-r--r--src/libdtmf/Makefile.am6
-rw-r--r--src/libdtmf/dtmf_encode.c (renamed from src/common/dtmf.c)18
-rw-r--r--src/libdtmf/dtmf_encode.h (renamed from src/common/dtmf.h)10
-rw-r--r--src/nmt/Makefile.am1
-rw-r--r--src/nmt/dsp.c6
-rw-r--r--src/nmt/nmt.c4
-rw-r--r--src/nmt/nmt.h4
11 files changed, 31 insertions, 23 deletions
diff --git a/.gitignore b/.gitignore
index 1cc062d..f9fe084 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,6 +20,7 @@ compile
.libs
.dirstamp
m4
+src/libdtmf/libdtmf.a
src/libgermanton/libgermanton.a
src/libtimer/libtimer.a
src/libsamplerate/libsamplerate.a
diff --git a/configure.ac b/configure.ac
index 4f44bf8..006acc0 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/libdtmf/Makefile
src/libgermanton/Makefile
src/libtimer/Makefile
src/libsamplerate/Makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index c2b8808..187ab9d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,3 +1,3 @@
AUTOMAKE_OPTIONS = foreign
-SUBDIRS = libgermanton libtimer libsamplerate libscrambler libfilter common anetz bnetz cnetz nmt amps tacs jtacs r2000 tv test
+SUBDIRS = libdtmf libgermanton libtimer libsamplerate libscrambler libfilter common anetz bnetz cnetz nmt amps tacs jtacs r2000 tv test
diff --git a/src/common/Makefile.am b/src/common/Makefile.am
index fa686ef..35b1e5f 100644
--- a/src/common/Makefile.am
+++ b/src/common/Makefile.am
@@ -9,7 +9,6 @@ libcommon_a_SOURCES = \
wave.c \
goertzel.c \
jitter.c \
- dtmf.c \
emphasis.c \
compandor.c \
fft.c \
diff --git a/src/libdtmf/Makefile.am b/src/libdtmf/Makefile.am
new file mode 100644
index 0000000..a44d4f6
--- /dev/null
+++ b/src/libdtmf/Makefile.am
@@ -0,0 +1,6 @@
+AM_CPPFLAGS = -Wall -Wextra -g $(all_includes)
+
+noinst_LIBRARIES = libdtmf.a
+
+libdtmf_a_SOURCES = \
+ dtmf_encode.c
diff --git a/src/common/dtmf.c b/src/libdtmf/dtmf_encode.c
index f3d3283..6413954 100644
--- a/src/common/dtmf.c
+++ b/src/libdtmf/dtmf_encode.c
@@ -20,19 +20,19 @@
#include <stdint.h>
#include <string.h>
#include <math.h>
-#include "sample.h"
-#include "dtmf.h"
+#include "../common/sample.h"
+#include "dtmf_encode.h"
#define PI M_PI
-static double tx_peak_dtmf_low = 0.2818 / SPEECH_LEVEL; /* -11 dBm, relative to speech level */
-static double tx_peak_dtmf_high = 0.3548 / SPEECH_LEVEL;/* -9 dBm, relative to speech level */
+#define PEAK_DTMF_LOW 0.2818 /* -11 dBm, relative to 0 dBm level */
+#define PEAK_DTMF_HIGH 0.3548 /* -9 dBm, relative to 0 dBm level */
#define DTMF_DURATION 0.100 /* duration in seconds */
static sample_t dsp_sine_dtmf_low[65536];
static sample_t dsp_sine_dtmf_high[65536];
-void dtmf_init(dtmf_t *dtmf, int samplerate)
+void dtmf_encode_init(dtmf_enc_t *dtmf, int samplerate, double dBm_level)
{
int i;
@@ -42,13 +42,13 @@ void dtmf_init(dtmf_t *dtmf, int samplerate)
// FIXME: do this globally and not per instance */
for (i = 0; i < 65536; i++) {
- dsp_sine_dtmf_low[i] = sin((double)i / 65536.0 * 2.0 * PI) * tx_peak_dtmf_low;
- dsp_sine_dtmf_high[i] = sin((double)i / 65536.0 * 2.0 * PI) * tx_peak_dtmf_high;
+ dsp_sine_dtmf_low[i] = sin((double)i / 65536.0 * 2.0 * PI) * PEAK_DTMF_LOW * dBm_level;
+ dsp_sine_dtmf_high[i] = sin((double)i / 65536.0 * 2.0 * PI) * PEAK_DTMF_HIGH * dBm_level;
}
}
/* set dtmf tone */
-void dtmf_set_tone(dtmf_t *dtmf, char tone)
+void dtmf_encode_set_tone(dtmf_enc_t *dtmf, char tone)
{
double f1, f2;
@@ -80,7 +80,7 @@ void dtmf_set_tone(dtmf_t *dtmf, char tone)
}
/* Generate audio stream from DTMF tone. Keep phase for next call of function. */
-void dtmf_tone(dtmf_t *dtmf, sample_t *samples, int length)
+void dtmf_encode(dtmf_enc_t *dtmf, sample_t *samples, int length)
{
double *phaseshift, *phase;
int i, pos, max;
diff --git a/src/common/dtmf.h b/src/libdtmf/dtmf_encode.h
index d6a5322..15ac05e 100644
--- a/src/common/dtmf.h
+++ b/src/libdtmf/dtmf_encode.h
@@ -1,14 +1,14 @@
-typedef struct dtmf {
+typedef struct dtmf_enc {
int samplerate; /* samplerate */
char tone; /* current tone to be played */
int pos; /* sample counter for tone */
int max; /* max number of samples for tone duration */
double phaseshift65536[2]; /* how much the phase of sine wave changes per sample */
double phase65536[2]; /* current phase */
-} dtmf_t;
+} dtmf_enc_t;
-void dtmf_init(dtmf_t *dtmf, int samplerate);
-void dtmf_set_tone(dtmf_t *dtmf, char tone);
-void dtmf_tone(dtmf_t *dtmf, sample_t *samples, int length);
+void dtmf_encode_init(dtmf_enc_t *dtmf, int samplerate, double dBm_level);
+void dtmf_encode_set_tone(dtmf_enc_t *dtmf, char tone);
+void dtmf_encode(dtmf_enc_t *dtmf, sample_t *samples, int length);
diff --git a/src/nmt/Makefile.am b/src/nmt/Makefile.am
index e3dd06b..ddaabd9 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/libdtmf/libdtmf.a \
$(top_builddir)/src/common/libmobile.a \
$(top_builddir)/src/common/libcommon.a \
$(top_builddir)/src/libtimer/libtimer.a \
diff --git a/src/nmt/dsp.c b/src/nmt/dsp.c
index 84a33a6..8f58352 100644
--- a/src/nmt/dsp.c
+++ b/src/nmt/dsp.c
@@ -148,8 +148,8 @@ int dsp_init_sender(nmt_t *nmt, double deviation_factor)
nmt->dial_phaseshift65536 = 65536.0 / ((double)nmt->sender.samplerate / DIALTONE_HZ);
PDEBUG(DDSP, DEBUG_DEBUG, "dial_phaseshift = %.4f\n", nmt->dial_phaseshift65536);
- /* dtmf */
- dtmf_init(&nmt->dtmf, 8000);
+ /* dtmf, generate tone relative to speech level */
+ dtmf_encode_init(&nmt->dtmf, 8000, 1.0 / SPEECH_LEVEL);
nmt->dmp_frame_level = display_measurements_add(&nmt->sender, "Frame Level", "%.1f %% (last)", DISPLAY_MEAS_LAST, DISPLAY_MEAS_LEFT, 0.0, 150.0, 100.0);
nmt->dmp_frame_quality = display_measurements_add(&nmt->sender, "Frame Quality", "%.1f %% (last)", DISPLAY_MEAS_LAST, DISPLAY_MEAS_LEFT, 0.0, 100.0, 100.0);
@@ -342,7 +342,7 @@ void sender_receive(sender_t *sender, sample_t *samples, int length, double __at
if (nmt->compandor)
expand_audio(&nmt->cstate, samples, count);
if (nmt->dsp_mode == DSP_MODE_DTMF)
- dtmf_tone(&nmt->dtmf, samples, count);
+ dtmf_encode(&nmt->dtmf, samples, count);
spl = nmt->sender.rxbuf;
pos = nmt->sender.rxbuf_pos;
for (i = 0; i < count; i++) {
diff --git a/src/nmt/nmt.c b/src/nmt/nmt.c
index 4fdc195..0287292 100644
--- a/src/nmt/nmt.c
+++ b/src/nmt/nmt.c
@@ -1454,7 +1454,7 @@ static void rx_active(nmt_t *nmt, frame_t *frame)
break;
}
digit = nmt_value2digit(frame->digit);
- dtmf_set_tone(&nmt->dtmf, digit);
+ dtmf_encode_set_tone(&nmt->dtmf, digit);
PDEBUG_CHAN(DNMT, DEBUG_INFO, "Received (odd) digit %c.\n", digit);
nmt->mft_num++;
break;
@@ -1477,7 +1477,7 @@ static void rx_active(nmt_t *nmt, frame_t *frame)
break;
}
digit = nmt_value2digit(frame->digit);
- dtmf_set_tone(&nmt->dtmf, digit);
+ dtmf_encode_set_tone(&nmt->dtmf, digit);
PDEBUG_CHAN(DNMT, DEBUG_INFO, "Received (even) digit %c.\n", digit);
nmt->mft_num++;
break;
diff --git a/src/nmt/nmt.h b/src/nmt/nmt.h
index c1c83da..aaa61f6 100644
--- a/src/nmt/nmt.h
+++ b/src/nmt/nmt.h
@@ -1,7 +1,7 @@
#include "../common/sender.h"
#include "../libtimer/timer.h"
#include "../common/compandor.h"
-#include "../common/dtmf.h"
+#include "../libdtmf/dtmf_encode.h"
#include "../common/call.h"
#include "../common/fsk.h"
#include "../common/goertzel.h"
@@ -77,7 +77,7 @@ typedef struct nmt {
sender_t sender;
nmt_sysinfo_t sysinfo;
compandor_t cstate;
- dtmf_t dtmf;
+ dtmf_enc_t dtmf;
struct transaction *trans; /* pointer to transaction, if bound to channel */
/* sender's states */