aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2016-04-23 18:50:11 +0200
committerAndreas Eversberg <jolly@eversberg.eu>2016-04-24 15:14:56 +0200
commit4356c93afa77734ce880651a2b0333378267e165 (patch)
tree8ead169110de367bba3e009fff322574246763d2 /src/test
parent5062628e52a1a4d60d4b76266c1cfdb42c529e87 (diff)
common: Add pre and de emphasis, if the radio does not support it
Connect to the oscillator of the transmitter - good girl! You need to enable pre emphasis in this case. Connect to the discriminator of the receiver - good boy! You need to enable de emphasis in this case.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/Makefile.am10
-rw-r--r--src/test/test_emphasis.c75
2 files changed, 84 insertions, 1 deletions
diff --git a/src/test/Makefile.am b/src/test/Makefile.am
index 2375047..0463b49 100644
--- a/src/test/Makefile.am
+++ b/src/test/Makefile.am
@@ -1,7 +1,8 @@
AM_CPPFLAGS = -Wall -g $(all_includes)
noinst_PROGRAMS = \
- test_compander
+ test_compander \
+ test_emphasis
test_compander_SOURCES = test_compander.c
@@ -10,3 +11,10 @@ test_compander_LDADD = \
$(top_builddir)/src/common/libcommon.a \
-lm
+test_emphasis_SOURCES = test_emphasis.c
+
+test_emphasis_LDADD = \
+ $(COMMON_LA) \
+ $(top_builddir)/src/common/libcommon.a \
+ -lm
+
diff --git a/src/test/test_emphasis.c b/src/test/test_emphasis.c
new file mode 100644
index 0000000..b93d0c3
--- /dev/null
+++ b/src/test/test_emphasis.c
@@ -0,0 +1,75 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <math.h>
+#include <string.h>
+#include "../common/emphasis.h"
+
+#define level2db(level) (20 * log10(level))
+#define db2level(db) pow(10, (double)db / 20.0)
+
+#define SAMPLERATE 48000
+#define DEVIATION 8000.0
+
+static void check_level(int16_t *samples, const char *desc)
+{
+ int i;
+ int last = 0, envelope = 0;
+ int up = 0;
+ int freq;
+
+ for (i = 0; i < SAMPLERATE; i++) {
+ if (last < samples[i]) {
+ up = 1;
+ } else if (last > samples[i]) {
+ if (up) {
+ envelope = last;
+ }
+ up = 0;
+ }
+ if ((i % (SAMPLERATE/40)) == 0) {
+ freq = 500 + 500 * (i / (SAMPLERATE / 8));
+ printf("%s: f = %d envelop = %.4f\n", desc, freq, level2db((double)envelope / DEVIATION));
+ }
+ last = samples[i];
+ }
+}
+
+static void gen_samples(int16_t *samples)
+{
+ int i;
+ double value;
+ int freq;
+
+ for (i = 0; i < SAMPLERATE; i++) {
+ freq = 500 + 500 * (i / (SAMPLERATE / 8));
+ value = sin(2.0 * M_PI * (double)freq / (double)SAMPLERATE * (double)i);
+ samples[i] = value * DEVIATION;
+ }
+}
+
+int main(void)
+{
+ emphasis_t estate;
+ int16_t samples[SAMPLERATE];
+
+ /* generate sweep 0..4khz */
+ gen_samples(samples);
+
+ init_emphasis(&estate, SAMPLERATE);
+
+// check_level(samples, "unchanged");
+
+ pre_emphasis(&estate, samples, SAMPLERATE);
+
+ check_level(samples, "pre-emphasis");
+
+ /* generate sweep 0..4khz */
+ gen_samples(samples);
+
+ de_emphasis(&estate, samples, SAMPLERATE);
+
+ check_level(samples, "de-emphasis");
+
+ return 0;
+}
+