Try not lost data on dsp (Less noise on small signals)

Use int64_t acc for values
Use double on calculation

Not cache freq on si5351_set_frequency_with_offset (to fast change in rare cases on cw mode, and process wrong DSP block) as i write before need change DSP delay tactic
This commit is contained in:
DiSlord 2020-03-09 01:25:46 +03:00
parent 77b5d0bcc8
commit a2d90a5e91
2 changed files with 47 additions and 38 deletions

79
dsp.c
View file

@ -41,48 +41,57 @@ const int16_t sincos_tbl[48][2] = {
{-24636, -21605 }, {-32698, -2143 }, {-27246, 18205 }, {-10533, 31029 }
};
int32_t acc_samp_s;
int32_t acc_samp_c;
int32_t acc_ref_s;
int32_t acc_ref_c;
int64_t acc_samp_s;
int64_t acc_samp_c;
int64_t acc_ref_s;
int64_t acc_ref_c;
void
dsp_process(int16_t *capture, size_t length)
{
uint32_t *p = (uint32_t*)capture;
uint32_t len = length / 2;
uint32_t i;
int32_t samp_s = 0;
int32_t samp_c = 0;
int32_t ref_s = 0;
int32_t ref_c = 0;
for (i = 0; i < len; i++) {
uint32_t sr = *p++;
int16_t ref = sr & 0xffff;
int16_t smp = (sr>>16) & 0xffff;
#if 1
acc_samp_s = 0;
acc_samp_c = 0;
acc_ref_s = 0;
acc_ref_c = 0;
for (i = 0; i < length; i+=2) {
int32_t ref = capture[i+0];
int32_t smp = capture[i+1];
#ifdef ENABLED_DUMP
ref_buf[i] = ref;
samp_buf[i] = smp;
#endif
int32_t s = sincos_tbl[i][0];
int32_t c = sincos_tbl[i][1];
samp_s += smp * s / 16;
samp_c += smp * c / 16;
ref_s += ref * s / 16;
ref_c += ref * c / 16;
#if 0
uint32_t sc = *(uint32_t)&sincos_tbl[i];
samp_s = __SMLABB(sr, sc, samp_s);
samp_c = __SMLABT(sr, sc, samp_c);
ref_s = __SMLATB(sr, sc, ref_s);
ref_c = __SMLATT(sr, sc, ref_c);
#endif
int32_t s = ((int16_t *)sincos_tbl)[i+0];
int32_t c = ((int16_t *)sincos_tbl)[i+1];
acc_samp_s += (smp * s);
acc_samp_c += (smp * c);
acc_ref_s += (ref * s);
acc_ref_c += (ref * c);
}
#else
uint32_t len = length / 2;
int64_t samp_s = 0;
int64_t samp_c = 0;
int64_t ref_s = 0;
int64_t ref_c = 0;
// HI LO
int32_t *cos_sin = (int32_t *)sincos_tbl;
int32_t *ref_smp = (int32_t *)capture;
for (i = 0; i < len; i++) {
//
samp_s = __SMLALBB(*ref_smp, *cos_sin, samp_s); // samp_s+= smp * sin
samp_c = __SMLALBT(*ref_smp, *cos_sin, samp_c); // samp_c+= smp * cos
ref_s = __SMLALTB(*ref_smp, *cos_sin, ref_s); // ref_s += ref * sin
ref_c = __SMLALTT(*ref_smp, *cos_sin, ref_c); // ref_s += ref * cos
ref_smp++;
cos_sin++;
}
acc_samp_s = samp_s;
acc_samp_c = samp_c;
acc_ref_s = ref_s;
acc_ref_c = ref_c;
acc_ref_s = ref_s;
acc_ref_c = ref_c;
#endif
}
void
@ -90,12 +99,12 @@ calculate_gamma(float gamma[2])
{
#if 1
// calculate reflection coeff. by samp divide by ref
float rs = acc_ref_s;
float rc = acc_ref_c;
float rr = rs * rs + rc * rc;
double rs = acc_ref_s;
double rc = acc_ref_c;
double rr = rs * rs + rc * rc;
//rr = sqrtf(rr) * 1e8;
float ss = acc_samp_s;
float sc = acc_samp_c;
double ss = acc_samp_s;
double sc = acc_samp_c;
gamma[0] = (sc * rc + ss * rs) / rr;
gamma[1] = (ss * rc - sc * rs) / rr;
#elif 0

View file

@ -354,13 +354,13 @@ int
si5351_set_frequency_with_offset(uint32_t freq, int offset, uint8_t drive_strength){
uint8_t band;
int delay = DELAY_NORMAL;
if (freq == current_freq)
return delay;
// if (freq == current_freq)
// return delay;
uint32_t ofreq = freq + offset;
uint32_t mul = 1, omul = 1;
uint32_t rdiv = SI5351_R_DIV_1;
uint32_t fdiv;
current_freq = freq;
// current_freq = freq;
if (freq >= config.harmonic_freq_threshold * 7U) {
mul = 9;
omul = 11;