Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vdr] dxr3 logarithmic volume (was Re: tiny bug in volume bar )



Steffen Beyer wrote:


Another bug, probably DXR3 related: the volume level changes linearly
instead of logarithmically, i.e. the heard volume change per bar width
decreases from left to right.
Try the patch attached. It works for me with vdr-1.2.5pre2 + dxr3-0.2.1

It requires a floating point calculation to calculate the gain factor, but at least it manipulates the audio buffer using integer math. Perhaps it could be improved by only re-calculating it when the volume level changes.

You should avoid low volumes since the software scaling loses quality
e.g. when the output level is scaled by 256, the 16 bit output device only provides 8 bits of effective audio data.

Even better would be an mixer plugin to control a specific OSS/ALSA mixer. The output of my dxr3 card goes via motherboard audio mixer which can be controlled using the ALSA Line1 mixer without any software scaling.

Jon


--- dxr3abstractiondevice.c~	2003-08-10 17:11:14.000000000 +0100
+++ dxr3abstractiondevice.c	2003-09-14 13:47:31.171073704 +0100
@@ -14,6 +14,7 @@
 #include <time.h>
 #include <pthread.h>
 #include <string>
+#include <math.h>
 
 #include "dxr3vdrincludes.h"
 
@@ -245,8 +246,9 @@
     if (m_volume == 0) {
         memset(pcmbuf, 0, size);  
     } else if (m_volume != 255) {
+	int factor = (int)pow (2.0, (double)m_volume/16) - 1;
         for (int i = 0; i < size / (int)sizeof(short); i++) {
-            pcmbuf[i] = (((int)pcmbuf[i]) * m_volume) / 256;
+            pcmbuf[i] = (((int)pcmbuf[i]) * factor) / 65536;
         }
     }
 }

Home | Main Index | Thread Index