From a22822379944f278043c19ed0ed45a4fe0b91395 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Hamal=20Dvo=C5=99=C3=A1k?= <mordae@anilinux.org>
Date: Sat, 24 Feb 2024 21:08:53 +0100
Subject: [PATCH] Use more sensible output scaling

---
 src/main.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/src/main.c b/src/main.c
index d921e45..5a8046a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -551,8 +551,7 @@ static void rf_rx(void)
 
 	int64_t dcI = 0, dcQ = 0;
 
-	int noise_floor = sqrt((float)CLK_SYS_HZ / BANDWIDTH * DECIMATION * 3.0 / 4.0);
-	int64_t noise_floor_inv = (1ll << 32) / noise_floor;
+	const int amp_max = (float)CLK_SYS_HZ / BANDWIDTH * DECIMATION * 3.0 / 4.0 / 2.0;
 
 	while (true) {
 		if (multicore_fifo_rvalid()) {
@@ -630,11 +629,8 @@ static void rf_rx(void)
 				dcQ = ((dcQ << 20) - dcQ + Q64) >> 20;
 			}
 
-			dI = (dI * noise_floor_inv) >> 32;
-			dQ = (dQ * noise_floor_inv) >> 32;
-
-			*blockptr++ = dI;
-			*blockptr++ = dQ;
+			*blockptr++ = 127 * dI / amp_max;
+			*blockptr++ = 127 * dQ / amp_max;
 		}
 
 		if (!queue_try_add(&iq_queue, block)) {