From 57e36203aa4ef0d2d86fa90cfb7390fe7f23127b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Hamal=20Dvo=C5=99=C3=A1k?= Date: Wed, 10 Jul 2024 10:21:04 +0200 Subject: [PATCH] Tweak LO dithering for better performance --- src/main.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main.c b/src/main.c index cd0186c..524900f 100644 --- a/src/main.c +++ b/src/main.c @@ -251,12 +251,11 @@ static void lo_generate(uint32_t *buf, double freq, uint32_t phase) { freq_step = STEP_BASE * freq; - unsigned down = 4 + __builtin_clz(freq_step); + unsigned down = 2 + __builtin_clz(freq_step); for (size_t i = 0; i < LO_WORDS; i++) { uint32_t bits = 0; - int shift = (rnd_next() >> down) - (rnd_next() >> down) + (rnd_next() >> down) - - (rnd_next() >> down); + int shift = (rnd_next() >> down) - (rnd_next() >> down); for (int j = 0; j < 32; j++) { bits |= (phase + shift) >> 31; @@ -272,13 +271,12 @@ static void lo_tweak(uint32_t *buf, uint32_t phase) { static size_t i = 0; uint32_t bits = 0; - unsigned down = 4 + __builtin_clz(freq_step); + unsigned down = 2 + __builtin_clz(freq_step); phase += freq_step * i * 32; for (int j = 0; j < 32; j++) { - int shift = (rnd_next() >> down) - (rnd_next() >> down) + (rnd_next() >> down) - - (rnd_next() >> down); + int shift = (rnd_next() >> down) - (rnd_next() >> down); bits |= (phase + shift) >> 31; bits <<= 1; phase += freq_step; @@ -602,8 +600,10 @@ static void rf_rx(void) iq_queue_pos = (iq_queue_pos + 1) & (IQ_QUEUE_LEN - 1); } - lo_tweak(lo_cos, COS_PHASE); - lo_tweak(lo_sin, SIN_PHASE); + for (int i = 0; i < 8; i++) { + lo_tweak(lo_cos, COS_PHASE); + lo_tweak(lo_sin, SIN_PHASE); + } } }