AMPS: Add option to be more tollerant to sync detection

Also it detects more false syncs, but this is ignored if decoding fails.
This commit is contained in:
Andreas Eversberg 2016-10-29 09:15:00 +02:00
parent 42ddd3320e
commit bb92a1f3b0
5 changed files with 41 additions and 10 deletions

View File

@ -340,7 +340,7 @@ static amps_t *search_pc(void)
static void amps_go_idle(amps_t *amps);
/* Create transceiver instance and link to a list. */
int amps_create(int channel, enum amps_chan_type chan_type, const char *sounddev, int samplerate, int cross_channels, double rx_gain, int pre_emphasis, int de_emphasis, const char *write_wave, const char *read_wave, amps_si *si, uint16_t sid, uint8_t sat, int polarity, int loopback)
int amps_create(int channel, enum amps_chan_type chan_type, const char *sounddev, int samplerate, int cross_channels, double rx_gain, int pre_emphasis, int de_emphasis, const char *write_wave, const char *read_wave, amps_si *si, uint16_t sid, uint8_t sat, int polarity, int tolerant, int loopback)
{
sender_t *sender;
amps_t *amps;
@ -407,7 +407,7 @@ int amps_create(int channel, enum amps_chan_type chan_type, const char *sounddev
}
/* init audio processing */
rc = dsp_init_sender(amps, (de_emphasis == 0));
rc = dsp_init_sender(amps, (de_emphasis == 0), tolerant);
if (rc < 0) {
PDEBUG(DAMPS, DEBUG_ERROR, "Failed to init audio processing!\n");
goto error;

View File

@ -77,6 +77,7 @@ typedef struct amps {
double fsk_rx_elapsed; /* bit duration since last level change */
enum fsk_rx_sync fsk_rx_sync; /* sync state */
uint16_t fsk_rx_sync_register; /* shift register to detect sync word */
int fsk_rx_sync_tolerant; /* be more tolerant to sync */
/* the dotting buffer stores the elapsed samples, so we can calculate
* an average time of zero-crossings during dotting sequence.
* this buffer wrapps every 256 values */
@ -160,7 +161,7 @@ const char *amps_min12number(uint32_t min1);
void amps_number2min(const char *number, uint32_t *min1, uint16_t *min2);
const char *amps_min2number(uint32_t min1, uint16_t min2);
const char *amps_scm(uint8_t scm);
int amps_create(int channel, enum amps_chan_type chan_type, const char *sounddev, int samplerate, int cross_channels, double rx_gain, int pre_emphasis, int de_emphasis, const char *write_wave, const char *read_wave, amps_si *si, uint16_t sid, uint8_t sat, int polarity, int loopback);
int amps_create(int channel, enum amps_chan_type chan_type, const char *sounddev, int samplerate, int cross_channels, double rx_gain, int pre_emphasis, int de_emphasis, const char *write_wave, const char *read_wave, amps_si *si, uint16_t sid, uint8_t sat, int polarity, int tolerant, int loopback);
void amps_destroy(sender_t *sender);
void amps_rx_signaling_tone(amps_t *amps, int tone, double quality);
void amps_rx_sat(amps_t *amps, int tone, double quality);

View File

@ -125,6 +125,8 @@ static double sat_freq[5] = {
static int dsp_sine_sat[256];
static uint8_t dsp_sync_check[0x800];
/* global init for FSK */
void dsp_init(void)
{
@ -136,6 +138,17 @@ void dsp_init(void)
s = sin((double)i / 256.0 * 2.0 * PI);
dsp_sine_sat[i] = (int)(s * SAT_DEVIATION);
}
/* sync checker */
for (i = 0; i < 0x800; i++) {
dsp_sync_check[i] = 0xff; /* no sync */
}
for (i = 0; i < 11; i++) {
dsp_sync_check[0x712 ^ (1 << i)] = 0x01; /* one bit error */
dsp_sync_check[0x0ed ^ (1 << i)] = 0x81; /* one bit error */
}
dsp_sync_check[0x712] = 0x00; /* no bit error */
dsp_sync_check[0x0ed] = 0x80; /* no bit error */
}
static void dsp_init_ramp(amps_t *amps)
@ -160,7 +173,7 @@ static void dsp_init_ramp(amps_t *amps)
static void sat_reset(amps_t *amps, const char *reason);
/* Init FSK of transceiver */
int dsp_init_sender(amps_t *amps, int high_pass)
int dsp_init_sender(amps_t *amps, int high_pass, int tolerant)
{
double coeff;
int16_t *spl;
@ -240,6 +253,9 @@ int dsp_init_sender(amps_t *amps, int high_pass)
amps->highpass_factor = RC / (RC + dt);
}
/* be more tolerant when syncing */
amps->fsk_rx_sync_tolerant = tolerant;
return 0;
error:
@ -508,7 +524,11 @@ static void fsk_rx_bit(amps_t *amps, int16_t *spl, int len, int pos, int begin,
if (amps->fsk_rx_sync != FSK_SYNC_POSITIVE && amps->fsk_rx_sync != FSK_SYNC_NEGATIVE) {
amps->fsk_rx_sync_register = (amps->fsk_rx_sync_register << 1) | bit;
/* check if we received a sync */
if ((amps->fsk_rx_sync_register & 0x7ff) == 0x712) {
switch (dsp_sync_check[amps->fsk_rx_sync_register & 0x7ff]) {
case 0x01:
if (!amps->fsk_rx_sync_tolerant)
break;
case 0x00:
#ifdef DEBUG_DECODER
printf("Sync word detected (positive)\n");
#endif
@ -520,8 +540,10 @@ prepare_frame:
amps->fsk_rx_sync_register = 0x555;
amps->when_received = get_time() - (21.0 / (double)BITRATE);
return;
}
if ((amps->fsk_rx_sync_register & 0x7ff) == 0x0ed) {
case 0x81:
if (!amps->fsk_rx_sync_tolerant)
break;
case 0x80:
#ifdef DEBUG_DECODER
printf("Sync word detected (negative)\n");
#endif

View File

@ -1,6 +1,6 @@
void dsp_init(void);
int dsp_init_sender(amps_t *amps, int high_pass);
int dsp_init_sender(amps_t *amps, int high_pass, int tolerant);
void dsp_cleanup_sender(amps_t *amps);
void amps_set_dsp_mode(amps_t *amps, enum dsp_mode mode, int frame_length);

View File

@ -45,6 +45,7 @@ int num_chan_type = 0;
enum amps_chan_type chan_type[MAX_SENDER] = { CHAN_TYPE_CC_PC_VC };
const char *flip_polarity = "";
int ms_power = 4, dcc = 0, scc = 0, sid = 40, regh = 1, regr = 1, pureg = 1, pdreg = 1, locaid = -1, regincr = 300, bis = 0;
int tolerant = 0;
void print_help(const char *arg0)
{
@ -86,6 +87,8 @@ void print_help(const char *arg0)
printf(" -S --sysinfo bis=0 | bis=1\n");
printf(" If 0, phone ignores BUSY/IDLE bit on FOCC (default = '%d')\n", bis);
printf(" If 1, be sure to have a round-trip delay (latency) not more than 5 ms\n");
printf(" -T --tolerant\n");
printf(" Be more tolerant when hunting for sync sequence\n");
printf("\nstation-id: Give 10 digit station-id, you don't need to enter it for every\n");
printf(" start of this program.\n");
}
@ -101,10 +104,11 @@ static int handle_options(int argc, char **argv)
{"flip-polarity", 1, 0, 'F'},
{"ms-power", 1, 0, 'P'},
{"sysinfo", 1, 0, 'S'},
{"tolerant", 0, 0, 'T'},
{0, 0, 0, 0}
};
set_options_common("t:F:P:S:", long_options_special);
set_options_common("t:F:P:S:T", long_options_special);
while (1) {
int option_index = 0, c;
@ -207,6 +211,10 @@ static int handle_options(int argc, char **argv)
}
skip_args += 2;
break;
case 'T':
tolerant = 1;
skip_args += 1;
break;
default:
opt_switch_common(c, argv[0], &skip_args);
}
@ -341,7 +349,7 @@ int main(int argc, char *argv[])
amps_si si;
init_sysinfo(&si, ms_power, ms_power, dcc, sid >> 1, regh, regr, pureg, pdreg, locaid, regincr, bis);
rc = amps_create(kanal[i], chan_type[i], sounddev[i], samplerate, cross_channels, rx_gain, do_pre_emphasis, do_de_emphasis, write_wave, read_wave, &si, sid, scc, polarity, loopback);
rc = amps_create(kanal[i], chan_type[i], sounddev[i], samplerate, cross_channels, rx_gain, do_pre_emphasis, do_de_emphasis, write_wave, read_wave, &si, sid, scc, polarity, tolerant, loopback);
if (rc < 0) {
fprintf(stderr, "Failed to create \"Sender\" instance. Quitting!\n");
goto fail;