Browse Source

Reshuffle lots of config code

Add rawdata and symbol data modes
Beacon can be on channel 1
master
Jeroen Vreeken 2 months ago
parent
commit
3dc0ae493a
10 changed files with 265 additions and 145 deletions
  1. +1
    -1
      Makefile.am
  2. +93
    -53
      freedv_eth.c
  3. +1
    -0
      freedv_eth.conf
  4. +10
    -12
      freedv_eth.h
  5. +1
    -1
      freedv_eth_baseband_in.c
  6. +43
    -30
      freedv_eth_rx.c
  7. +3
    -0
      freedv_eth_rx.h
  8. +7
    -4
      freedv_eth_rxa.c
  9. +57
    -18
      freedv_eth_tx.c
  10. +49
    -26
      freedv_eth_txa.c

+ 1
- 1
Makefile.am View File

@ -22,7 +22,7 @@ analog_trx_SOURCES = sound.c dsp.c io.c interface.c analog_trx.c freedv_eth_conf
analog_trx_LDADD = libeth_ar.la
analog_trx_LDFLAGS = -lcodec2 -lsamplerate -lasound -lhamlib -lpthread -lm
freedv_eth_SOURCES = sound.c dsp.c io.c interface.c nmea.c freedv_eth.c freedv_eth_rx.c freedv_eth_config.c freedv_eth_transcode.c freedv_eth_queue.c freedv_eth_tx.c freedv_eth_txa.c ctcss.c beacon.c emphasis.c freedv_eth_rxa.c freedv_eth_baseband_in.c
freedv_eth_SOURCES = sound.c dsp.c io.c interface.c nmea.c freedv_eth.c freedv_eth_modem.c freedv_eth_rx.c freedv_eth_config.c freedv_eth_transcode.c freedv_eth_queue.c freedv_eth_tx.c freedv_eth_txa.c ctcss.c beacon.c emphasis.c freedv_eth_rxa.c freedv_eth_baseband_in.c
freedv_eth_LDADD = libeth_ar.la
freedv_eth_LDFLAGS = -lcodec2 -lsamplerate -lasound -lhamlib -lpthread -lm


+ 93
- 53
freedv_eth.c View File

@ -62,9 +62,6 @@ static bool baseband_in_tx;
static int tx_delay_msec;
static int tx_tail_msec;
static int tx_header_msec = 500;
static int tx_header_max_msec = 5000;
static int tx_fprs_msec = 30000;
static bool freedv_hasdata;
static uint8_t mac[ETH_AR_MAC_SIZE];
@ -302,18 +299,24 @@ int main(int argc, char **argv)
{
int fd_int;
int fd_nmea = -1;
int fd_modem = -1;
struct pollfd *fds;
int sound_fdc_tx;
int sound_fdc_rx;
int sound_fdc_tx = 0;
int sound_fdc_rx = 0;
int nfds;
int poll_int;
int poll_i = 0;
int poll_int = 0;
int poll_nmea = 0;
int poll_modem = 0;
uint16_t type;
int nr_samples;
int freedv_mode;
int nr_samples = 0;
int freedv_mode = -1;
rig_model_t rig_model;
ptt_type_t ptt_type = RIG_PTT_NONE;
dcd_type_t dcd_type = RIG_DCD_NONE;
bool analog_in = false;
bool need_sound = false;
if (argc < 2) {
usage();
@ -343,27 +346,20 @@ int main(int argc, char **argv)
vc_control = atoi(freedv_eth_config_value("control_vc", NULL, "0"));
char *rig_ptt_type = freedv_eth_config_value("rig_ptt_type", NULL, "NONE");
char *rig_dcd_type = freedv_eth_config_value("rig_dcd_type", NULL, "NONE");
double analog_tx_amp = atof(freedv_eth_config_value("analog_tx_amp", NULL, "1.0"));
double freedv_tx_amp = atof(freedv_eth_config_value("freedv_tx_amp", NULL, "1.0"));
char *freedv_tx_sound_channel = freedv_eth_config_value("freedv_tx_sound_channel", NULL, "left");
char *freedv_rx_sound_channel = freedv_eth_config_value("freedv_rx_sound_channel", NULL, "left");
char *analog_rx_sound_channel = freedv_eth_config_value("analog_rx_sound_channel", NULL, "left");
float analog_rx_gain = atof(freedv_eth_config_value("analog_rx_gain", NULL, "1.0"));
char *tx_mode_str = freedv_eth_config_value("tx_mode", NULL, "freedv");
char *rx_mode_str = freedv_eth_config_value("rx_mode", NULL, "freedv");
double rx_ctcss_f = atof(freedv_eth_config_value("analog_rx_ctcss_frequency", NULL, "0.0"));
double tx_ctcss_f = atof(freedv_eth_config_value("analog_tx_ctcss_frequency", NULL, "0.0"));
double tx_ctcss_amp = atof(freedv_eth_config_value("analog_tx_ctcss_amp", NULL, "0.15"));
int beacon_interval = atoi(freedv_eth_config_value("analog_tx_beacon_interval", NULL, "0"));
char *beacon_msg = freedv_eth_config_value("analog_tx_beacon_message", NULL, "");
bool tx_emphasis = atoi(freedv_eth_config_value("analog_tx_emphasis", NULL, "0"));
bool rx_emphasis = atoi(freedv_eth_config_value("analog_rx_emphasis", NULL, "0"));
int dcd_threshold = atoi(freedv_eth_config_value("analog_rx_dcd_threshold", NULL, "1"));
bool tx_tone = atoi(freedv_eth_config_value("analog_tx_tone", NULL, "0"));
int dtmf_mute = atoi(freedv_eth_config_value("analog_dtmf_mute", NULL, "1"));
baseband_out = atoi(freedv_eth_config_value("baseband_out", NULL, "0"));
baseband_in = atoi(freedv_eth_config_value("baseband_in", NULL, "0"));
baseband_in_tx = atoi(freedv_eth_config_value("baseband_in_tx", NULL, "0"));
char *modem_file = freedv_eth_config_value("external_modem", NULL, NULL);
if (!modem_file) {
need_sound = true;
}
if (!strcmp(freedv_mode_str, "1600")) {
freedv_mode = FREEDV_MODE_1600;
@ -407,27 +403,35 @@ int main(int argc, char **argv)
return -1;
}
printf("TX mode: %s\n", tx_mode_str);
if (!strcmp(tx_mode_str, "none")) {
tx_mode = TX_MODE_NONE;
} else if (!strcmp(tx_mode_str, "freedv")) {
tx_mode = TX_MODE_FREEDV;
} else if (!strcmp(tx_mode_str, "analog")) {
tx_mode = TX_MODE_ANALOG;
need_sound = true;
analog_in = true;
} else if (!strcmp(rx_mode_str, "mixed")) {
tx_mode = RX_MODE_MIXED;
need_sound = true;
analog_in = true;
} else {
printf("Invalid tx_mode\n");
return -1;
}
printf("RX mode: %s\n", rx_mode_str);
if (!strcmp(rx_mode_str, "none")) {
rx_mode = RX_MODE_NONE;
} else if (!strcmp(rx_mode_str, "freedv")) {
rx_mode = RX_MODE_FREEDV;
} else if (!strcmp(rx_mode_str, "analog")) {
rx_mode = RX_MODE_ANALOG;
need_sound = true;
} else if (!strcmp(rx_mode_str, "mixed")) {
rx_mode = RX_MODE_MIXED;
need_sound = true;
} else {
printf("Invalid rx_mode\n");
return -1;
@ -510,6 +514,7 @@ int main(int argc, char **argv)
return -1;
}
printf("Opening freedv: mode %s: %d\n", freedv_mode_str, freedv_mode);
freedv = freedv_open(freedv_mode);
freedv_set_callback_txt(freedv, freedv_eth_rx_vc_callback, freedv_eth_tx_vc_callback, NULL);
@ -527,26 +532,31 @@ int main(int argc, char **argv)
force_channels_in = 2;
fd_int = interface_init(netname, mac, true, 0);
sound_rate = sound_init(sounddev, cb_sound_in, sound_rate, force_channels_in, 2);
if (sound_rate < 0)
return -1;
if (need_sound) {
sound_rate = sound_init(sounddev, cb_sound_in, sound_rate, force_channels_in, 2);
if (sound_rate < 0)
return -1;
}
tc = freedv_eth_transcode_init(sound_rate);
tc_iface = freedv_eth_transcode_init(sound_rate);
if (tx_mode == TX_MODE_FREEDV) {
int freedv_rate = freedv_get_modem_sample_rate(freedv);
printf("freedv sample rate: %d\n", freedv_rate);
nr_samples = freedv_get_n_nom_modem_samples(freedv) * sound_rate / freedv_rate;
} else {
nr_samples = FREEDV_ALAW_NR_SAMPLES * sound_rate / FREEDV_ALAW_RATE;
}
printf("nom number of modem samples: %d\n", nr_samples);
sound_set_nr(nr_samples);
if (need_sound) {
if (tx_mode == TX_MODE_FREEDV) {
int freedv_rate = freedv_get_modem_sample_rate(freedv);
printf("freedv sample rate: %d\n", freedv_rate);
nr_samples = freedv_get_n_nom_modem_samples(freedv) * sound_rate / freedv_rate;
} else {
nr_samples = FREEDV_ALAW_NR_SAMPLES * sound_rate / FREEDV_ALAW_RATE;
}
printf("nom number of modem samples: %d\n", nr_samples);
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, nr_samples);
if (analog_in)
freedv_eth_rxa_init(sound_rate, mac, nr_samples);
if (baseband_in)
freedv_eth_bb_in_init(sound_rate, mac, nr_samples);
@ -556,20 +566,13 @@ int main(int argc, char **argv)
freedv_eth_tx_init(freedv, mac, nmea, fullduplex,
sound_rate,
tx_tail_msec, tx_delay_msec,
tx_header_msec, tx_header_max_msec,
tx_fprs_msec,
freedv_tx_channel,
freedv_tx_amp);
modem_file ? true : false);
}
if (tx_mode == TX_MODE_ANALOG || tx_mode == TX_MODE_MIXED) {
freedv_eth_txa_init(fullduplex,
sound_rate,
tx_tail_msec,
tx_ctcss_f, tx_ctcss_amp,
beacon_interval, beacon_msg,
tx_emphasis,
tx_tone,
analog_tx_amp);
tx_tail_msec);
}
if (nmeadev) {
@ -579,6 +582,13 @@ int main(int argc, char **argv)
printf("GPS device: %s\n", nmeadev);
}
}
if (modem_file) {
fd_modem = freedv_eth_modem_init(modem_file, freedv);
if (fd_modem < 0) {
printf("Could not open modem: %s\n", modem_file);
return -1;
}
}
prio();
@ -588,25 +598,47 @@ int main(int argc, char **argv)
return -1;
}
sound_fdc_tx = sound_poll_count_tx();
sound_fdc_rx = sound_poll_count_rx();
nfds = sound_fdc_tx + sound_fdc_rx + 1 + (nmea ? 1 : 0);
if (need_sound) {
sound_fdc_tx = sound_poll_count_tx();
sound_fdc_rx = sound_poll_count_rx();
}
nfds = sound_fdc_tx + sound_fdc_rx + 1 + (nmea ? 1 : 0) + (modem_file ? 1 : 0);
fds = calloc(sizeof(struct pollfd), nfds);
sound_poll_fill_tx(fds, sound_fdc_tx);
sound_poll_fill_rx(fds + sound_fdc_tx, sound_fdc_rx);
poll_int = sound_fdc_tx + sound_fdc_rx;
poll_i = 0;
if (need_sound) {
sound_poll_fill_tx(fds, sound_fdc_tx);
sound_poll_fill_rx(fds + sound_fdc_tx, sound_fdc_rx);
poll_i += sound_fdc_tx + sound_fdc_rx;
}
poll_int = poll_i++;
fds[poll_int].fd = fd_int;
fds[poll_int].events = POLLIN;
if (nmea) {
poll_nmea = poll_int + 1;
poll_nmea = poll_i++;
fds[poll_nmea].fd = fd_nmea;
fds[poll_nmea].events = POLLIN;
}
if (modem_file) {
poll_modem = poll_i++;
fds[poll_modem].fd = fd_modem;
}
do {
if (modem_file) {
freedv_eth_modem_poll(&fds[poll_modem].events);
}
poll(fds, nfds, -1);
if (sound_poll_out_tx(fds, sound_fdc_tx)) {
bool do_tx_state_machine;
if (modem_file) {
do_tx_state_machine = freedv_eth_modem_tx_empty(fd_modem);
} else {
do_tx_state_machine = need_sound && sound_poll_out_tx(fds, sound_fdc_tx);
}
if (do_tx_state_machine) {
if (tx_mode == TX_MODE_MIXED) {
bool q_v = queue_voice_filled(1);
bool q_d = queue_data_filled() || queue_control_filled();
@ -629,12 +661,20 @@ int main(int argc, char **argv)
if (fds[poll_int].revents & POLLIN) {
interface_tx_raw(cb_int_tx);
}
if (sound_poll_in_rx(fds + sound_fdc_tx, sound_fdc_rx)) {
if (need_sound && sound_poll_in_rx(fds + sound_fdc_tx, sound_fdc_rx)) {
sound_rx();
}
if (nmea && fds[poll_nmea].revents & POLLIN) {
read_nmea(fd_nmea);
}
if (modem_file) {
if (fds[poll_modem].revents & POLLIN) {
freedv_eth_modem_rx(fd_modem);
}
if (fds[poll_modem].revents & POLLOUT) {
freedv_eth_modem_tx(fd_modem);
}
}
} while (1);


+ 1
- 0
freedv_eth.conf View File

@ -65,6 +65,7 @@
#analog_tx_beacon_message = beacon
## Pre-emphasis on or off
#analog_tx_emphasis = 0
#analog_tx_beacon_sound_channel = left
#analog_rx_dcd_threshold = 1
#analog_rx_ctcss_frequency = 0.0


+ 10
- 12
freedv_eth.h View File

@ -125,10 +125,8 @@ int freedv_eth_tx_init(struct freedv *init_freedv, uint8_t init_mac[6],
struct nmea_state *init_nmea, bool init_fullduplex,
int hw_rate,
int tx_tail_msec, int tx_delay_msec,
int tx_header_msec, int tx_header_max_msec,
int tx_fprs_msec,
int tx_channel,
double tx_amp);
bool modem);
char freedv_eth_tx_vc_callback(void *arg);
void freedv_eth_tx_state_machine(void);
bool freedv_eth_tx_ptt(void);
@ -138,22 +136,22 @@ void freedv_eth_tx_cb_datatx(void *arg, unsigned char *packet, size_t *size);
#define FREEDV_ALAW_RATE 8000
int freedv_eth_txa_init(bool init_fullduplex, int hw_rate,
int tx_tail_msec,
double ctcss_f, double ctcss_amp,
int beacon_interval, char *beacon_msg,
bool emphasis,
bool init_output_tone,
double tx_amp);
int tx_tail_msec);
void freedv_eth_txa_state_machine(void);
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, int hw_nr);
int freedv_eth_rxa_init(int hw_rate, uint8_t mac_init[6], 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);
bool freedv_eth_baseband_in_cdc(void);
int freedv_eth_modem_init(char *modem_file, struct freedv *init_freedv);
void freedv_eth_modem_poll(short *events);
void freedv_eth_modem_rx(int fd_modem);
void freedv_eth_modem_tx(int fd_modem);
void freedv_eth_modem_tx_add(signed char *tx_sym, size_t nr);
bool freedv_eth_modem_tx_empty(int fd_modem);
#endif /* _INCLUDE_FREEDV_ETH_H_ */

+ 1
- 1
freedv_eth_baseband_in.c View File

@ -35,7 +35,7 @@ static uint8_t bcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
static bool cdc = false;
static struct sound_resample *sr = NULL;
static float rx_gain = 1.0;
SpeexPreprocessState *st;
static SpeexPreprocessState *st;
static uint8_t transmission = 0;
static double level_dbm = -10;


+ 43
- 30
freedv_eth_rx.c View File

@ -57,39 +57,10 @@ bool freedv_eth_rx_cdc(void)
return cdc;
}
void freedv_eth_rx(int16_t *hw_samples, int hw_nr)
static void freedv_eth_rx_rawdata(int ret, unsigned char *packed_codec_bits)
{
int nr;
int16_t *samples;
if (sr) {
nr = sound_resample_nr_out(sr, hw_nr);
samples = alloca(sizeof(int16_t) * nr);
sound_resample_perform(sr, samples, hw_samples, nr, hw_nr);
} else {
nr = hw_nr;
samples = hw_samples;
}
while (nr) {
int nin = freedv_nin(freedv);
int copy = nin - nr_rx;
if (copy > nr)
copy = nr;
memcpy(samples_rx + nr_rx, samples, copy * sizeof(int16_t));
samples += copy;
nr -= copy;
nr_rx += copy;
if (nr_rx == nin) {
unsigned char packed_codec_bits[bytes_per_freedv_frame];
bool old_cdc = cdc;
int ret = freedv_rawdatarx(freedv, packed_codec_bits, samples_rx);
/* Don't 'detect' a voice signal to soon.
*/
int sync;
@ -140,13 +111,55 @@ void freedv_eth_rx(int16_t *hw_samples, int hw_nr)
queue_voice_end(transmission);
transmission++;
}
}
void freedv_eth_rx(int16_t *hw_samples, int hw_nr)
{
int nr;
int16_t *samples;
if (sr) {
nr = sound_resample_nr_out(sr, hw_nr);
samples = alloca(sizeof(int16_t) * nr);
sound_resample_perform(sr, samples, hw_samples, nr, hw_nr);
} else {
nr = hw_nr;
samples = hw_samples;
}
while (nr) {
int nin = freedv_nin(freedv);
int copy = nin - nr_rx;
if (copy > nr)
copy = nr;
memcpy(samples_rx + nr_rx, samples, copy * sizeof(int16_t));
samples += copy;
nr -= copy;
nr_rx += copy;
if (nr_rx == nin) {
unsigned char packed_codec_bits[bytes_per_freedv_frame];
int ret = freedv_rawdatarx(freedv, packed_codec_bits, samples_rx);
freedv_eth_rx_rawdata(ret, packed_codec_bits);
nr_rx = 0;
}
}
}
void freedv_eth_symrx(signed char *rxsym)
{
unsigned char packed_codec_bits[bytes_per_freedv_frame];
int ret = freedv_rawdatasymrx(freedv, packed_codec_bits, rxsym);
freedv_eth_rx_rawdata(ret, packed_codec_bits);
}
void freedv_eth_rx_cb_datarx(void *arg, unsigned char *packet, size_t size)
{
if (rx_sync < RX_SYNC_DATABONUS)


+ 3
- 0
freedv_eth_rx.h View File

@ -32,4 +32,7 @@ bool freedv_eth_rx_cdc(void);
void freedv_eth_rx_vc_callback(void *arg, char c);
void freedv_eth_rx_cb_datarx(void *arg, unsigned char *packet, size_t size);
void freedv_eth_symrx(signed char *rxsym);
#endif /* _INCLUDE_FREEDV_ETH_RX_H_ */

+ 7
- 4
freedv_eth_rxa.c View File

@ -55,7 +55,7 @@ enum dtmf_state {
static enum dtmf_state dtmf_state = DTMF_IDLE;
SpeexPreprocessState *st = NULL;
static SpeexPreprocessState *st = NULL;
bool freedv_eth_rxa_cdc(void)
{
@ -134,10 +134,13 @@ void freedv_eth_rxa(int16_t *samples, int nr)
}
}
int freedv_eth_rxa_init(int hw_rate, uint8_t mac_init[ETH_AR_MAC_SIZE],
bool emphasis, double ctcss_freq, int dtmf_mute_init,
float rx_gain_init, int hw_nr)
int freedv_eth_rxa_init(int hw_rate, uint8_t mac_init[ETH_AR_MAC_SIZE], int hw_nr)
{
double ctcss_freq = atof(freedv_eth_config_value("analog_rx_ctcss_frequency", NULL, "0.0"));
bool emphasis = atoi(freedv_eth_config_value("analog_rx_emphasis", NULL, "0"));
float rx_gain_init = atof(freedv_eth_config_value("analog_rx_gain", NULL, "1.0"));
int dtmf_mute_init = atoi(freedv_eth_config_value("analog_dtmf_mute", NULL, "1"));
rx_gain = rx_gain_init;
memcpy(mac, mac_init, 6);
printf("Analog rx gain: %f\n", rx_gain);


+ 57
- 18
freedv_eth_tx.c View File

@ -58,8 +58,11 @@ static struct nmea_state *nmea;
static struct freedv *freedv = NULL;
static bool modem;
static int nom_modem_samples;
static int16_t *mod_out;
static int modem_symbols;
static signed char *sym_out = NULL;
static struct sound_resample *sr0 = NULL;
static struct sound_resample *sr1 = NULL;
static bool deemph = false;
@ -131,15 +134,20 @@ static void check_tx_add(void)
static void data_tx(void)
{
freedv_datatx(freedv, mod_out);
if (!deemph) {
sound_gain(mod_out, nom_modem_samples, tx_amp);
if (modem) {
freedv_datasymtx(freedv, sym_out);
freedv_eth_modem_tx_add(sym_out, modem_symbols);
} else {
emphasis_prede_48_gain(deemph_state, mod_out, nom_modem_samples, tx_amp);
}
freedv_datatx(freedv, mod_out);
tx_sound_out(mod_out, nom_modem_samples);
if (!deemph) {
sound_gain(mod_out, nom_modem_samples, tx_amp);
} else {
emphasis_prede_48_gain(deemph_state, mod_out, nom_modem_samples, tx_amp);
}
tx_sound_out(mod_out, nom_modem_samples);
}
if (tx_state == TX_STATE_ON) {
if (queue_voice_filled(bytes_per_freedv_frame))
@ -202,15 +210,20 @@ static void tx_voice(void)
if (send_data_frame) {
data_tx();
} else {
freedv_rawdatatx(freedv, mod_out, data);
if (!deemph) {
sound_gain(mod_out, nom_modem_samples, tx_amp);
if (modem) {
freedv_rawdatasymtx(freedv, sym_out, data);
freedv_eth_modem_tx_add(sym_out, modem_symbols);
} else {
emphasis_prede_48_gain(deemph_state, mod_out, nom_modem_samples, tx_amp);
freedv_rawdatatx(freedv, mod_out, data);
if (!deemph) {
sound_gain(mod_out, nom_modem_samples, tx_amp);
} else {
emphasis_prede_48_gain(deemph_state, mod_out, nom_modem_samples, tx_amp);
}
tx_sound_out(mod_out, nom_modem_samples);
}
tx_sound_out(mod_out, nom_modem_samples);
printf("-");
fflush(NULL);
}
@ -242,6 +255,22 @@ char freedv_eth_tx_vc_callback(void *arg)
return c;
}
void tx_idle(void)
{
if (modem) {
int nr_sym = freedv_get_n_modem_symbols(freedv);
signed char sym_out[nr_sym];
int i;
signed char sym = 1;
for (i = 0; i < nr_sym; i++) {
sym_out[i] = sym;
sym = -sym;
}
freedv_eth_modem_tx_add(sym_out, nr_sym);
} else {
sound_silence();
}
}
void freedv_eth_tx_state_machine(void)
{
@ -260,7 +289,7 @@ void freedv_eth_tx_state_machine(void)
check_tx_add();
} else {
sound_silence();
tx_idle();
break;
}
case TX_STATE_DELAY:
@ -381,11 +410,16 @@ int freedv_eth_tx_init(struct freedv *init_freedv, uint8_t init_mac[6],
struct nmea_state *init_nmea, bool init_fullduplex,
int hw_rate,
int tx_tail_msec, int tx_delay_msec,
int tx_header_msec, int tx_header_max_msec,
int tx_fprs_msec,
int tx_channel_init,
double tx_amp_init)
bool modem_init)
{
double tx_amp_init = atof(freedv_eth_config_value("freedv_tx_amp", NULL, "1.0"));
int tx_fprs_msec = 30000;
int tx_header_msec = 500;
int tx_header_max_msec = 5000;
modem = modem_init;
freedv = init_freedv;
nmea = init_nmea;
fullduplex = init_fullduplex;
@ -438,6 +472,11 @@ int freedv_eth_tx_init(struct freedv *init_freedv, uint8_t init_mac[6],
free(mod_out);
mod_out = calloc(sizeof(int16_t), nom_modem_samples);
modem_symbols = freedv_get_n_modem_symbols(freedv);
free(sym_out);
sym_out = calloc(sizeof(signed char), modem_symbols);
/* Yes, de-emph to 'fix' transmitters doing emphasis */
deemph = atoi(freedv_eth_config_value("freedv_tx_deemph", NULL, "0"));
printf("TX de-emph: %d\n", deemph);


+ 49
- 26
freedv_eth_txa.c View File

@ -51,6 +51,7 @@ static bool output_tone = false;
static enum io_hl_ptt ptt = IO_HL_PTT_OFF;
static bool tx_tail_other = false;
static double amp = 1.0;
static int beacon_channel = 0;
struct beacon_sample *beep_1k;
struct beacon_sample *beep_1k2;
@ -134,49 +135,59 @@ static void tx_voice(void)
if (!beacon) {
tx_silence();
} else {
int16_t buffer[nr_samples];
int16_t *bp1 = NULL;
int16_t buffer0[nr_samples];
int16_t buffer_tone[nr_samples];
int16_t *bpb = NULL;
int16_t *bpt = NULL;
memset(buffer0, 0, sizeof(int16_t)*nr_samples);
memset(buffer_tone, 0, sizeof(int16_t)*nr_samples);
if (beacon_channel == 0)
bpb = buffer0;
else
bpb = buffer_tone;
beacon_generate(beacon, bpb, nr_samples);
beacon_generate(beacon, buffer, nr_samples);
if (tx_hadvoice) {
if (ctcss) {
if (output_tone) {
bp1 = buffer_tone;
memset(buffer_tone, 0, sizeof(int16_t)*nr_samples);
ctcss_add(ctcss, buffer_tone, nr_samples);
bpt = buffer_tone;
} else {
ctcss_add(ctcss, buffer, nr_samples);
bpt = buffer0;
}
ctcss_add(ctcss, bpt, nr_samples);
}
}
if (emphasis_p)
emphasis_pre(emphasis_p, buffer, nr_samples);
tx_sound_out(buffer, bp1, nr_samples);
emphasis_pre(emphasis_p, buffer0, nr_samples);
tx_sound_out(buffer0, buffer_tone, nr_samples);
}
} else {
int nr = packet->len / sizeof(short);
int16_t buffer[nr];
int16_t *bp1 = NULL;
int16_t buffer0[nr];
int16_t buffer_tone[nr];
tx_hadvoice = true;
memcpy(buffer, packet->data, packet->len);
memcpy(buffer0, packet->data, packet->len);
memset(buffer_tone, 0, packet->len);
if (beacon)
beacon_generate_add(beacon, buffer, nr);
if (beacon) {
int16_t *bpb = buffer0;
if (beacon_channel == 1)
bpb = buffer_tone;
beacon_generate_add(beacon, bpb, nr);
}
if (emphasis_p)
emphasis_pre(emphasis_p, buffer, nr);
emphasis_pre(emphasis_p, buffer0, nr);
if (ctcss) {
if (output_tone) {
bp1 = buffer_tone;
memset(buffer_tone, 0, packet->len);
ctcss_add(ctcss, buffer_tone, nr);
} else {
ctcss_add(ctcss, buffer, nr);
ctcss_add(ctcss, buffer0, nr);
}
}
tx_sound_out(buffer, bp1, nr);
tx_sound_out(buffer0, buffer_tone, nr);
packet = dequeue_voice();
tx_packet_free(packet);
@ -313,14 +324,26 @@ bool freedv_eth_txa_ptt(void)
return tx_state != TX_STATE_OFF;
}
int freedv_eth_txa_init(bool init_fullduplex, int hw_rate,
int tx_tail_msec,
double ctcss_f, double ctcss_amp,
int beacon_interval, char *beacon_msg,
bool emphasis,
bool init_output_tone,
double analog_amp)
int freedv_eth_txa_init(bool init_fullduplex, int hw_rate, int tx_tail_msec)
{
double analog_amp = atof(freedv_eth_config_value("analog_tx_amp", NULL, "1.0"));
double ctcss_f = atof(freedv_eth_config_value("analog_tx_ctcss_frequency", NULL, "0.0"));
double ctcss_amp = atof(freedv_eth_config_value("analog_tx_ctcss_amp", NULL, "0.15"));
int beacon_interval = atoi(freedv_eth_config_value("analog_tx_beacon_interval", NULL, "0"));
char *beacon_msg = freedv_eth_config_value("analog_tx_beacon_message", NULL, "");
bool emphasis = atoi(freedv_eth_config_value("analog_tx_emphasis", NULL, "0"));
bool init_output_tone = atoi(freedv_eth_config_value("analog_tx_tone", NULL, "0"));
char *beacon_sound_channel = freedv_eth_config_value("analog_tx_beacon_sound_channel", NULL, "left");
if (!strcmp(beacon_sound_channel, "left")) {
beacon_channel = 0;
} else if (!strcmp(beacon_sound_channel, "right")) {
beacon_channel = 1;
} else {
/* Assume it is a number and limit it to odd or even */
beacon_channel = atoi(beacon_sound_channel) & 0x1;
}
beep_1k = beacon_beep_create(hw_rate, 1000.0, 0.45, 0.25, 0.25);
beep_1k2 = beacon_beep_create(hw_rate, 1200.0, 0.15, 0.15, 0.25);
beep_2k = beacon_beep_create(hw_rate, 2000.0, 0.10, 0.20, 0.25);


Loading…
Cancel
Save