Browse Source

Add optional de-emphasis on freedv tx

master
Jeroen Vreeken 9 months ago
parent
commit
fca226e562
3 changed files with 54 additions and 3 deletions
  1. +28
    -0
      emphasis.c
  2. +2
    -0
      emphasis.h
  3. +24
    -3
      freedv_eth_tx.c

+ 28
- 0
emphasis.c View File

@ -17,6 +17,7 @@
*/
#include "emphasis.h"
#include <math.h>
struct emphasis {
float prev_de;
@ -93,3 +94,30 @@ int emphasis_de(struct emphasis *emphasis, int16_t *sound, int nr)
return 0;
}
/* 48kHz de emphasis used before transmitting */
int emphasis_prede_48_gain(struct emphasis *emphasis, int16_t *sound, int nr, double gain)
{
int i;
for (i = 0; i < nr; i++) {
float sample = sound[i] / 32767.0;
sample *= gain;
float f = emphasis->prev_de;
float absf = fabsf(i) / 100;
f = f * (1.0 - absf);
f += sample / 32;
if (f > 1.0)
f = 1.0;
if (f < -1.0)
f = -1.0;
emphasis->prev_de = f;
sound[i] = f * 32767.0;
}
return 0;
}

+ 2
- 0
emphasis.h View File

@ -31,4 +31,6 @@ int emphasis_reset(struct emphasis *emphasis);
int emphasis_pre(struct emphasis *emphasis, int16_t *sound, int nr);
int emphasis_de(struct emphasis *emphasis, int16_t *sound, int nr);
int emphasis_prede_48_gain(struct emphasis *emphasis, int16_t *sound, int nr, double gain);
#endif /* _INCLUDE_EMPHASIS_H_ */

+ 24
- 3
freedv_eth_tx.c View File

@ -18,8 +18,10 @@
#include "freedv_eth.h"
#include "sound.h"
#include "freedv_eth_rx.h"
//#include "freedv_eth_rx.h"
#include "freedv_eth_config.h"
#include "io.h"
#include "emphasis.h"
#include <string.h>
#include <stdio.h>
@ -60,6 +62,8 @@ static int nom_modem_samples;
static int16_t *mod_out;
static struct sound_resample *sr0 = NULL;
static struct sound_resample *sr1 = NULL;
static bool deemph = false;
static struct emphasis *deemph_state = NULL;
static int tx_sound_out(int16_t *samples, int nr)
{
@ -129,7 +133,11 @@ static void data_tx(void)
{
freedv_datatx(freedv, mod_out);
sound_gain(mod_out, nom_modem_samples, tx_amp);
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);
@ -196,7 +204,11 @@ static void tx_voice(void)
} else {
freedv_rawdatatx(freedv, mod_out, data);
sound_gain(mod_out, nom_modem_samples, tx_amp);
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);
printf("-");
@ -426,5 +438,14 @@ 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);
/* 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);
if (deemph_state)
emphasis_destroy(deemph_state);
deemph_state = NULL;
if (deemph)
deemph_state = emphasis_init();
return 0;
}

Loading…
Cancel
Save