Browse Source

tx gain

master
Jeroen Vreeken 9 months ago
parent
commit
0e005f94cf
7 changed files with 81 additions and 15 deletions
  1. +19
    -3
      freedv_eth.c
  2. +3
    -1
      freedv_eth.h
  3. +6
    -4
      freedv_eth_rx.c
  4. +27
    -6
      freedv_eth_tx.c
  5. +6
    -1
      freedv_eth_txa.c
  6. +18
    -0
      sound.c
  7. +2
    -0
      sound.h

+ 19
- 3
freedv_eth.c View File

@ -52,6 +52,7 @@ static bool vc_control;
static struct freedv *freedv;
static int freedv_rx_channel;
static int freedv_tx_channel;
static int tx_codecmode;
static int analog_rx_channel;
@ -340,6 +341,9 @@ 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"));
@ -427,6 +431,14 @@ int main(int argc, char **argv)
return -1;
}
if (!strcmp(freedv_tx_sound_channel, "left")) {
freedv_tx_channel = 0;
} else if (!strcmp(freedv_tx_sound_channel, "right")) {
freedv_tx_channel = 1;
} else {
/* Assume it is a number and limit it to odd or even */
freedv_tx_channel = atoi(freedv_tx_sound_channel) & 0x1;
}
if (!strcmp(freedv_rx_sound_channel, "left")) {
freedv_rx_channel = 0;
} else if (!strcmp(freedv_rx_sound_channel, "right")) {
@ -543,7 +555,9 @@ int main(int argc, char **argv)
sound_rate,
tx_tail_msec, tx_delay_msec,
tx_header_msec, tx_header_max_msec,
tx_fprs_msec);
tx_fprs_msec,
freedv_tx_channel,
freedv_tx_amp);
} else if (tx_mode == TX_MODE_ANALOG || tx_mode == TX_MODE_MIXED) {
freedv_eth_txa_init(fullduplex,
sound_rate,
@ -551,7 +565,8 @@ int main(int argc, char **argv)
tx_ctcss_f, tx_ctcss_amp,
beacon_interval, beacon_msg,
tx_emphasis,
tx_tone);
tx_tone,
analog_tx_amp);
}
if (nmeadev) {
@ -595,7 +610,8 @@ int main(int argc, char **argv)
bool tx_v = freedv_eth_txa_ptt();
bool tx_d = freedv_eth_tx_ptt();
if (tx_d || (!tx_v && !q_v && q_d)) {
/* voice has preference */
if (!tx_v && !q_v && (q_d || tx_d)) {
freedv_eth_tx_state_machine();
} else {
freedv_eth_txa_state_machine();


+ 3
- 1
freedv_eth.h View File

@ -126,7 +126,9 @@ int freedv_eth_tx_init(struct freedv *init_freedv, uint8_t init_mac[6],
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_fprs_msec,
int tx_channel,
double tx_amp);
char freedv_eth_tx_vc_callback(void *arg);
void freedv_eth_tx_state_machine(void);
bool freedv_eth_tx_ptt(void);


+ 6
- 4
freedv_eth_rx.c View File

@ -1,5 +1,5 @@
/*
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2016
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2016, 2020
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
@ -25,6 +25,8 @@
#include <stdio.h>
#include <codec2/codec2.h>
static bool cdc_voice = false;
static int nr_rx;
static float rx_sync = 0;
@ -85,7 +87,7 @@ void freedv_eth_rx(int16_t *hw_samples, int hw_nr)
bool old_cdc = cdc;
int ret = freedv_codecrx(freedv, packed_codec_bits, samples_rx);
int ret = freedv_rawdatarx(freedv, packed_codec_bits, samples_rx);
/* Don't 'detect' a voice signal to soon.
*/
@ -222,11 +224,11 @@ int freedv_eth_rx_init(struct freedv *init_freedv, uint8_t init_mac[6], int hw_r
sr = NULL;
}
bytes_per_codec2_frame = codec2_bits_per_frame(freedv_get_codec2(freedv));
bytes_per_codec2_frame = freedv_get_bits_per_codec_frame(freedv);
bytes_per_codec2_frame += 7;
bytes_per_codec2_frame /= 8;
printf("RX bytes per codec2 frame: %d\n", bytes_per_codec2_frame);
int rat = freedv_get_n_codec_bits(freedv) / codec2_bits_per_frame(freedv_get_codec2(freedv));
int rat = freedv_get_bits_per_modem_frame(freedv) / freedv_get_bits_per_codec_frame(freedv);
printf("RX codec2 frames per freedv frame: %d\n", rat);
bytes_per_freedv_frame = bytes_per_codec2_frame * rat;
printf("RX bytes per freedv frame: %d\n", bytes_per_freedv_frame);


+ 27
- 6
freedv_eth_tx.c View File

@ -1,5 +1,5 @@
/*
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2016, 2017
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2016, 2017, 2020
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
@ -25,6 +25,7 @@
#include <stdio.h>
#include <eth_ar/fprs.h>
enum tx_state {
TX_STATE_OFF,
TX_STATE_DELAY,
@ -48,6 +49,8 @@ static int tx_tail;
static int tx_header;
static int tx_header_max;
static int tx_fprs;
static int tx_channel = 0;
static double tx_amp;
static struct nmea_state *nmea;
@ -80,7 +83,16 @@ static int tx_sound_out(int16_t *samples, int nr)
if (samples1) {
sound_resample_perform(sr1, hw_mod_out1, samples1, nr_out, nr);
}
sound_out_lr(hw_mod_out0, samples1 ? hw_mod_out1 : NULL, nr_out);
int16_t *hw0;
int16_t *hw1;
if (tx_channel == 0) {
hw0 = hw_mod_out0;
hw1 = samples1 ? hw_mod_out1 : NULL;
} else {
hw1 = hw_mod_out0;
hw0 = samples1 ? hw_mod_out1 : NULL;
}
sound_out_lr(hw0, hw1, nr_out);
}
if (packet) {
@ -117,6 +129,8 @@ static void data_tx(void)
{
freedv_datatx(freedv, mod_out);
sound_gain(mod_out, nom_modem_samples, tx_amp);
tx_sound_out(mod_out, nom_modem_samples);
if (tx_state == TX_STATE_ON) {
@ -175,8 +189,9 @@ static void tx_voice(void)
if (send_data_frame) {
data_tx();
} else {
freedv_codectx(freedv, mod_out, data);
freedv_rawdatatx(freedv, mod_out, data);
sound_gain(mod_out, nom_modem_samples, tx_amp);
tx_sound_out(mod_out, nom_modem_samples);
printf("-");
@ -350,22 +365,28 @@ int freedv_eth_tx_init(struct freedv *init_freedv, uint8_t init_mac[6],
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_fprs_msec,
int tx_channel_init,
double tx_amp_init)
{
freedv = init_freedv;
nmea = init_nmea;
fullduplex = init_fullduplex;
memcpy(mac, init_mac, 6);
memcpy(tx_add, mac, 6);
tx_amp = tx_amp_init;
tx_state = TX_STATE_OFF;
io_hl_ptt_set(IO_HL_PTT_OFF);
bytes_per_codec2_frame = codec2_bits_per_frame(freedv_get_codec2(freedv));
tx_channel = tx_channel_init;
printf("TX channel %d\n", tx_channel);
bytes_per_codec2_frame = freedv_get_bits_per_codec_frame(freedv);
bytes_per_codec2_frame += 7;
bytes_per_codec2_frame /= 8;
printf("TX bytes per codec2 frame: %d\n", bytes_per_codec2_frame);
int rat = freedv_get_n_codec_bits(freedv) / codec2_bits_per_frame(freedv_get_codec2(freedv));
int rat = freedv_get_bits_per_modem_frame(freedv) / freedv_get_bits_per_codec_frame(freedv);
printf("TX codec2 frames per freedv frame: %d\n", rat);
bytes_per_freedv_frame = bytes_per_codec2_frame * rat;
printf("TX bytes per freedv frame: %d\n", bytes_per_freedv_frame);


+ 6
- 1
freedv_eth_txa.c View File

@ -50,6 +50,7 @@ static int nr_samples = FREEDV_ALAW_NR_SAMPLES;
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;
struct beacon_sample *beep_1k;
struct beacon_sample *beep_1k2;
@ -64,6 +65,8 @@ static int tx_sound_out(int16_t *samples0, int16_t *samples1, int nr)
samples1 = (int16_t*)packet->data;
}
sound_gain(samples0, nr, amp);
sound_out_lr(samples0, samples1, nr);
if (packet) {
@ -314,7 +317,8 @@ int freedv_eth_txa_init(bool init_fullduplex, int hw_rate,
double ctcss_f, double ctcss_amp,
int beacon_interval, char *beacon_msg,
bool emphasis,
bool init_output_tone)
bool init_output_tone,
double analog_amp)
{
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);
@ -322,6 +326,7 @@ int freedv_eth_txa_init(bool init_fullduplex, int hw_rate,
fullduplex = init_fullduplex;
output_tone = init_output_tone;
amp = analog_amp;
tx_state = TX_STATE_OFF;
io_hl_ptt_set(false);


+ 18
- 0
sound.c View File

@ -481,3 +481,21 @@ int sound_set_nr(int nr_set)
return 0;
}
int sound_gain(int16_t *samples, int nr, double gain)
{
int i;
for (i = 0; i < nr; i++) {
double sample = samples[i];
sample *= gain;
if (sample > 32767)
sample = 32767;
if (sample < -32768)
sample = -32768;
samples[i] = sample;
}
return 0;
}

+ 2
- 0
sound.h View File

@ -49,4 +49,6 @@ int sound_resample_nr_in(struct sound_resample *sr, int nr_out);
int sound_gain_limit(int16_t *samples, int nr, float gain, float *limit);
int sound_gain(int16_t *samples, int nr, double gain);
#endif /* _INCLUDE_SOUND_H_ */

Loading…
Cancel
Save