Skip to contentSkip to conversation

stv090x: use lookup tables for carrier/noise ratio

PATCH In review Joerg Riechardt 2 participants 3 messages Sep 17, 2013 – Aug 29, 2015 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 stv090x: use lookup tables for carrier/noise ratio

The stv090x driver uses the lookup table for signal strength already, with this patch we use the lookup tables for carrier/noise ratio as well.
This has the advantage, that values for DVB-S and DVB-S2 are now corresponding, while before they were way off. The values are now proportional to real carrier/noise ratio, while before they were corresponding to register values. So now applications are able to give the user real carrier/noise ratio.

Because the output has to be within 0x0000...0xFFFF the three negative values for DVB-S2 are omitted. This is no significant loss, because reception is lost at 7.5 dB already (TT S2-1600, Cine S2), so the negative values are not really important, and also for DVB-S they don´t exist.

Regards,
Joerg

stv090x.c renamed from stv090x.c.bak +11 -9
@@ -173,9 +173,9 @@
 
 /* DVBS2 C/N Lookup table */
 static const struct stv090x_tab stv090x_s2cn_tab[] = {
-	{ -30, 13348 }, /* -3.0dB */
-	{ -20, 12640 }, /* -2d.0B */
-	{ -10, 11883 }, /* -1.0dB */
+//	{ -30, 13348 }, /* -3.0dB */
+//	{ -20, 12640 }, /* -2d.0B */
+//	{ -10, 11883 }, /* -1.0dB */
 	{   0, 11101 }, /* -0.0dB */
 	{   5, 10718 }, /*  0.5dB */
 	{  10, 10339 }, /*  1.0dB */
@@ -3697,9 +3697,10 @@
 			}
 			val /= 16;
 			last = ARRAY_SIZE(stv090x_s2cn_tab) - 1;
-			div = stv090x_s2cn_tab[0].read -
-			      stv090x_s2cn_tab[last].read;
-			*cnr = 0xFFFF - ((val * 0xFFFF) / div);
+			div = stv090x_s2cn_tab[last].real -
+			      stv090x_s2cn_tab[0].real;
+			val = stv090x_table_lookup(stv090x_s2cn_tab, last, val);
+			*cnr = val * 0xFFFF / div;
 		}
 		break;
 
@@ -3719,9 +3720,10 @@
 			}
 			val /= 16;
 			last = ARRAY_SIZE(stv090x_s1cn_tab) - 1;
-			div = stv090x_s1cn_tab[0].read -
-			      stv090x_s1cn_tab[last].read;
-			*cnr = 0xFFFF - ((val * 0xFFFF) / div);
+			div = stv090x_s1cn_tab[last].real -
+			      stv090x_s1cn_tab[0].real;
+			val = stv090x_table_lookup(stv090x_s1cn_tab, last, val);
+			*cnr = val * 0xFFFF / div;
 		}
 		break;
 	default:
#1 lore raw

Em Wed, 18 Sep 2013 01:05:20 +0200
Joerg Riechardt <[email protected]> escreveu:

Quoted 24 lines

The stv090x driver uses the lookup table for signal strength already, with this patch we use the lookup tables for carrier/noise ratio as well. This has the advantage, that values for DVB-S and DVB-S2 are now corresponding, while before they were way off. The values are now proportional to real carrier/noise ratio, while before they were corresponding to register values. So now applications are able to give the user real carrier/noise ratio.

Because the output has to be within 0x0000...0xFFFF the three negative values for DVB-S2 are omitted. This is no significant loss, because reception is lost at 7.5 dB already (TT S2-1600, Cine S2), so the negative values are not really important, and also for DVB-S they don´t exist.

Regards,
Joerg

stv090x.c renamed from stv090x.c.bak +0 -0
@@ -173,9 +173,9 @@
 
 /* DVBS2 C/N Lookup table */

stv090x.c line 181

Quoted 10 lines
stv090x.c renamed from stv090x.c.bak +3 -3
 static const struct stv090x_tab stv090x_s2cn_tab[] = {
-	{ -30, 13348 }, /* -3.0dB */
-	{ -20, 12640 }, /* -2d.0B */
-	{ -10, 11883 }, /* -1.0dB */
+//	{ -30, 13348 }, /* -3.0dB */
+//	{ -20, 12640 }, /* -2d.0B */
+//	{ -10, 11883 }, /* -1.0dB */
 	{   0, 11101 }, /* -0.0dB */
 	{   5, 10718 }, /*  0.5dB */
 	{  10, 10339 }, /*  1.0dB */

Instead of commenting, just truncate the value at the DVBv3 stats function.

Quoted 16 lines
stv090x.c renamed from stv090x.c.bak +4 -3
@@ -3697,9 +3697,10 @@
 			}
 			val /= 16;
 			last = ARRAY_SIZE(stv090x_s2cn_tab) - 1;
-			div = stv090x_s2cn_tab[0].read -
-			      stv090x_s2cn_tab[last].read;
-			*cnr = 0xFFFF - ((val * 0xFFFF) / div);
+			div = stv090x_s2cn_tab[last].real -
+			      stv090x_s2cn_tab[0].real;
+			val = stv090x_table_lookup(stv090x_s2cn_tab, last, val);
+			*cnr = val * 0xFFFF / div;
 		}
 		break;
 
@@ -3719,9 +3720,10 @@
 			}

stv090x.c line 3727

Quoted 10 lines
stv090x.c renamed from stv090x.c.bak +4 -3
 			val /= 16;
 			last = ARRAY_SIZE(stv090x_s1cn_tab) - 1;
-			div = stv090x_s1cn_tab[0].read -
-			      stv090x_s1cn_tab[last].read;
-			*cnr = 0xFFFF - ((val * 0xFFFF) / div);
+			div = stv090x_s1cn_tab[last].real -
+			      stv090x_s1cn_tab[0].real;
+			val = stv090x_table_lookup(stv090x_s1cn_tab, last, val);
+			*cnr = val * 0xFFFF / div;
 		}

As, with this patch, C/N will be a properly scaled value, the best is to add support for DVBv5 stats. With DVBv5 stats, the scale can be sent to userspace.

stv090x.c line 3729

Quoted 2 lines
stv090x.c renamed from stv090x.c.bak +0 -0
 		break;
 	default:

Regards,
Mauro

#2 lore raw

Am 11.11.2014 um 11:28 schrieb Mauro Carvalho Chehab:

Quoted 26 lines

Em Wed, 18 Sep 2013 01:05:20 +0200
Joerg Riechardt <[email protected]> escreveu:

Quoted 23 lines

The stv090x driver uses the lookup table for signal strength already, with this patch we use the lookup tables for carrier/noise ratio as well. This has the advantage, that values for DVB-S and DVB-S2 are now corresponding, while before they were way off. The values are now proportional to real carrier/noise ratio, while before they were corresponding to register values. So now applications are able to give the user real carrier/noise ratio.

Because the output has to be within 0x0000...0xFFFF the three negative values for DVB-S2 are omitted. This is no significant loss, because reception is lost at 7.5 dB already (TT S2-1600, Cine S2), so the negative values are not really important, and also for DVB-S they don´t exist.

Regards,
Joerg

stv090x.c renamed from stv090x.c.bak +0 -0
@@ -173,9 +173,9 @@
 
Quoted 14 lines

stv090x.c line 181

Quoted 11 lines
stv090x.c renamed from stv090x.c.bak +3 -3
  /* DVBS2 C/N Lookup table */
  static const struct stv090x_tab stv090x_s2cn_tab[] = {
-	{ -30, 13348 }, /* -3.0dB */
-	{ -20, 12640 }, /* -2d.0B */
-	{ -10, 11883 }, /* -1.0dB */
+//	{ -30, 13348 }, /* -3.0dB */
+//	{ -20, 12640 }, /* -2d.0B */
+//	{ -10, 11883 }, /* -1.0dB */
  	{   0, 11101 }, /* -0.0dB */
  	{   5, 10718 }, /*  0.5dB */
  	{  10, 10339 }, /*  1.0dB */

Instead of commenting, just truncate the value at the DVBv3 stats function.

Ok, done.
Changed patch attached.

Quoted 15 lines
Quoted 15 lines
stv090x.c renamed from stv090x.c.bak +4 -3
@@ -3697,9 +3697,10 @@
  			}
  			val /= 16;
  			last = ARRAY_SIZE(stv090x_s2cn_tab) - 1;
-			div = stv090x_s2cn_tab[0].read -
-			      stv090x_s2cn_tab[last].read;
-			*cnr = 0xFFFF - ((val * 0xFFFF) / div);
+			div = stv090x_s2cn_tab[last].real -
+			      stv090x_s2cn_tab[0].real;
+			val = stv090x_table_lookup(stv090x_s2cn_tab, last, val);
+			*cnr = val * 0xFFFF / div;
  		}
  		break;
 
Quoted 16 lines

stv090x.c line 3727

Quoted 12 lines
stv090x.c renamed from stv090x.c.bak +4 -3
@@ -3719,9 +3720,10 @@
  			}
  			val /= 16;
  			last = ARRAY_SIZE(stv090x_s1cn_tab) - 1;
-			div = stv090x_s1cn_tab[0].read -
-			      stv090x_s1cn_tab[last].read;
-			*cnr = 0xFFFF - ((val * 0xFFFF) / div);
+			div = stv090x_s1cn_tab[last].real -
+			      stv090x_s1cn_tab[0].real;
+			val = stv090x_table_lookup(stv090x_s1cn_tab, last, val);
+			*cnr = val * 0xFFFF / div;
  		}

As, with this patch, C/N will be a properly scaled value, the best is to add support for DVBv5 stats. With DVBv5 stats, the scale can be sent to userspace.

Sorry, I have no plans to add DVBv5 stats, although I agree, it would be nice, if someone did.

Regards,
Joerg

Quoted 7 lines

stv090x.c line 3729

Quoted 3 lines
stv090x.c renamed from stv090x.c.bak +0 -0
  		break;
  	default:

Regards,
Mauro

stv090x.c +10 -6
diff -Nru A/stv090x.c B/stv090x.c
@@ -3726,9 +3726,12 @@
 			}
 			val /= 16;
 			last = ARRAY_SIZE(stv090x_s2cn_tab) - 1;
-			div = stv090x_s2cn_tab[0].read -
-			      stv090x_s2cn_tab[last].read;
-			*cnr = 0xFFFF - ((val * 0xFFFF) / div);
+			div = stv090x_s2cn_tab[last].real -
+			      stv090x_s2cn_tab[3].real;
+			val = stv090x_table_lookup(stv090x_s2cn_tab, last, val);
+			if (val < 0)
+				val = 0;
+			*cnr = val * 0xFFFF / div;
 		}
 		break;
 
@@ -3748,9 +3751,10 @@
 			}
 			val /= 16;
 			last = ARRAY_SIZE(stv090x_s1cn_tab) - 1;
-			div = stv090x_s1cn_tab[0].read -
-			      stv090x_s1cn_tab[last].read;
-			*cnr = 0xFFFF - ((val * 0xFFFF) / div);
+			div = stv090x_s1cn_tab[last].real -
+			      stv090x_s1cn_tab[0].real;
+			val = stv090x_table_lookup(stv090x_s1cn_tab, last, val);
+			*cnr = val * 0xFFFF / div;
 		}
 		break;
 	default: