Browse Source

Added test interface.

Added analog rx denoise filter (using speex)
master
Jeroen Vreeken 2 years ago
parent
commit
d38655f13e
7 changed files with 191 additions and 8 deletions
  1. +9
    -2
      Makefile.am
  2. +67
    -0
      eth_ar_callssid2mac.c
  3. +3
    -3
      freedv_eth.c
  4. +1
    -1
      freedv_eth.h
  5. +1
    -1
      freedv_eth_baseband_in.c
  6. +33
    -1
      freedv_eth_rxa.c
  7. +77
    -0
      test_eth.c

+ 9
- 2
Makefile.am View File

@ -11,9 +11,9 @@ libeth_ar_la_LDFLAGS= -fPIC -version-info 1:0:1 -lm
nobase_include_HEADERS = eth_ar/eth_ar.h eth_ar/fprs.h
if ENABLE_HAMLIB
bin_PROGRAMS = analog_trx freedv_eth fprs2aprs_gate eth_ar_if fprs_request fprs_destination fprs_monitor
bin_PROGRAMS = analog_trx freedv_eth fprs2aprs_gate eth_ar_if fprs_request fprs_destination fprs_monitor eth_ar_callssid2mac
endif
noinst_PROGRAMS = fprs_test emphasis_test eth_ar_test
noinst_PROGRAMS = fprs_test emphasis_test eth_ar_test test_eth
analog_trx_SOURCES = sound.c alaw.c ulaw.c dsp.c io.c interface.c analog_trx.c freedv_eth_config.c
analog_trx_LDADD = libeth_ar.la
@ -23,6 +23,10 @@ freedv_eth_SOURCES = sound.c alaw.c ulaw.c dsp.c io.c interface.c nmea.c freedv_
freedv_eth_LDADD = libeth_ar.la
freedv_eth_LDFLAGS = -lcodec2 -lsamplerate -lasound -lhamlib -lpthread -lm
test_eth_SOURCES = interface.c beacon.c test_eth.c
test_eth_LDADD = libeth_ar.la
test_eth_LDFLAGS = -lm
eth_ar_test_SOURCES = eth_ar_test.c
eth_ar_test_LDADD = libeth_ar.la
@ -46,3 +50,6 @@ eth_ar_if_LDADD = libeth_ar.la
emphasis_test_SOURCES = emphasis_test.c emphasis.c
emphasis_test_LDFLAGS = -lm
eth_ar_callssid2mac_SOURCES = eth_ar_callssid2mac.c
eth_ar_callssid2mac_LDADD = libeth_ar.la

+ 67
- 0
eth_ar_callssid2mac.c View File

@ -0,0 +1,67 @@
/*
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2019
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 <http://www.gnu.org/licenses/>.
*/
#include <eth_ar/eth_ar.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void usage(void)
{
printf("Usage:\n");
printf("\n");
printf("eth_ar_if <call>\n");
printf("eth_ar_if <call>-<ssid>\n");
printf("\n");
}
int main(int argc, char **argv)
{
char *call = "";
if (argc < 2) {
usage();
goto err_usage;
}
call = argv[1];
uint8_t mac[6];
if (eth_ar_callssid2mac(mac, call, false)) {
perror("Could not convert callsign\n");
goto err_2mac;
}
char callsign[ETH_AR_CALL_SIZE];
int ssid = 0;
bool multicast;
if (eth_ar_mac2call(callsign, &ssid, &multicast, mac)) {
goto err_2call;
}
printf("%s-%d\n", callsign, ssid);
printf("%02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
return 0;
err_2call:
err_2mac:
err_usage:
return -1;
}

+ 3
- 3
freedv_eth.c View File

@ -34,10 +34,10 @@
#include <codec2/freedv_api.h>
#include "interface.h"
#include <eth_ar/eth_ar.h>
#include "eth_ar/eth_ar.h"
#include "eth_ar_codec2.h"
#include "sound.h"
#include <eth_ar/fprs.h>
#include "eth_ar/fprs.h"
#include "nmea.h"
#include "freedv_eth_rx.h"
#include "freedv_eth.h"
@ -510,7 +510,7 @@ int main(int argc, char **argv)
sound_set_nr(nr_samples);
freedv_eth_rx_init(freedv, mac, sound_rate);
freedv_eth_rxa_init(sound_rate, mac, rx_emphasis, rx_ctcss_f, dtmf_mute, analog_rx_gain);
freedv_eth_rxa_init(sound_rate, mac, rx_emphasis, rx_ctcss_f, dtmf_mute, analog_rx_gain, nr_samples);
if (baseband_in)
freedv_eth_bb_in_init(sound_rate, mac, nr_samples);


+ 1
- 1
freedv_eth.h View File

@ -125,7 +125,7 @@ bool freedv_eth_txa_ptt(void);
bool freedv_eth_rxa_cdc(void);
int freedv_eth_rxa_init(int hw_rate, uint8_t mac_init[6],
bool emphasis, double ctcss_freq, int dtmf_mute,
float rx_gain);
float rx_gain, int hw_nr);
void freedv_eth_rxa(int16_t *samples, int nr);
int freedv_eth_bb_in_init(int hw_rate, uint8_t mac_init[6], int nr_hw);


+ 1
- 1
freedv_eth_baseband_in.c View File

@ -97,7 +97,7 @@ int freedv_eth_bb_in_init(int hw_rate, uint8_t mac_init[6], int nr_hw)
val=1;
speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_AGC, &val);
fval=32768;
fval=32768 / rx_gain;
speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_AGC_LEVEL, &fval);
val = 40;


+ 33
- 1
freedv_eth_rxa.c View File

@ -28,6 +28,7 @@
#include "eth_ar_codec2.h"
#include <string.h>
#include <speex/speex_preprocess.h>
static struct emphasis *emphasis_d = NULL;
static uint8_t mac[6];
@ -52,6 +53,8 @@ enum dtmf_state {
static enum dtmf_state dtmf_state = DTMF_IDLE;
SpeexPreprocessState *st = NULL;
bool freedv_eth_rxa_cdc(void)
{
return cdc;
@ -84,6 +87,9 @@ void freedv_eth_rxa(int16_t *samples, int nr)
bool detected;
bool new_cdc;
if (st)
speex_preprocess_run(st, samples);
sound_resample_perform_gain_limit(sr, mod_a, samples, nr_a, nr, rx_gain);
if (emphasis_d)
@ -116,7 +122,7 @@ void freedv_eth_rxa(int16_t *samples, int nr)
int freedv_eth_rxa_init(int hw_rate, uint8_t mac_init[6],
bool emphasis, double ctcss_freq, int dtmf_mute_init,
float rx_gain_init)
float rx_gain_init, int hw_nr)
{
int a_rate = FREEDV_ALAW_RATE;
@ -146,5 +152,31 @@ int freedv_eth_rxa_init(int hw_rate, uint8_t mac_init[6],
} else {
ctcss_sql = false;
}
bool denoise = atoi(freedv_eth_config_value("analog_rx_denoise", NULL, "1"));
if (denoise) {
printf("Analog denoise and AGC active\n");
int val;
float fval;
st = speex_preprocess_state_init(hw_nr, hw_rate);
val= denoise;
speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_DENOISE, &val);
val = -30;
speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_NOISE_SUPPRESS, &val);
val=1;
speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_AGC, &val);
fval=32768 / rx_gain;
speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_AGC_LEVEL, &fval);
val = 40;
speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_AGC_INCREMENT, &val);
val=60;
speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_AGC_MAX_GAIN, &val);
} else {
printf("Analog denoise and AGC\n");
}
return 0;
}

+ 77
- 0
test_eth.c View File

@ -0,0 +1,77 @@
/*
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2019
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 <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include "eth_ar/eth_ar.h"
#include "eth_ar_codec2.h"
#include "interface.h"
#include "beacon.h"
#define RATE 8000
#define NR_SAMPLES 160
uint8_t bcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
uint8_t mac[6];
uint8_t transmission = 42;
uint8_t level = 30;
int main(int argc, char **argv)
{
char *netname = "test";
char *call = "test";
if (eth_ar_callssid2mac(mac, call, false)) {
printf("Callsign could not be converted to a valid MAC address\n");
return -1;
}
int fd_int = interface_init(netname, mac, true, 0);
if (fd_int < 0) {
printf("Could not create interface\n");
return -1;
}
struct beacon_sample *beep_1k, *beep_2k, *b;
beep_1k = beacon_beep_create(RATE, 1.0, 0, 1.0, 0.25);
beep_2k = beacon_beep_create(RATE, 2.0, 0, 1.0, 0.25);
int beacon = 0;
while (1) {
sleep(5);
if (beacon & 1) {
b = beep_1k;
} else {
b = beep_2k;
}
printf("Sending beep\n");
int nr;
for (nr = 0; nr < b->nr; nr += NR_SAMPLES) {
interface_rx(bcast, mac, ETH_P_NATIVE16,
(uint8_t*)(b->samples+nr), 2*NR_SAMPLES,
transmission, level);
}
}
return 0;
}

Loading…
Cancel
Save